From 46f3aa725562aaf90ba3e08f7a054345266a1a2a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 16 Dec 2023 22:52:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=9A=E6=98=B5=E7=A7=B0=E3=80=81=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E3=80=81=E6=80=A7=E5=88=AB=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/user/info.vue | 67 +++++++++++++++++------------------------ sheep/api/app.js | 44 --------------------------- sheep/api/infra/file.js | 49 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 84 deletions(-) create mode 100644 sheep/api/infra/file.js diff --git a/pages/user/info.vue b/pages/user/info.vue index 255a9b3..f3784d0 100644 --- a/pages/user/info.vue +++ b/pages/user/info.vue @@ -38,7 +38,7 @@ - + - - + - @@ -185,11 +183,12 @@ diff --git a/sheep/api/app.js b/sheep/api/app.js index 5e4eb41..184882f 100644 --- a/sheep/api/app.js +++ b/sheep/api/app.js @@ -72,48 +72,4 @@ export default { method: 'GET' }), }, - - //上传 - upload: (file, group = 'ugc', callback) => { - const token = uni.getStorageSync('token'); - uni.showLoading({ - title: '上传中', - }); - return new Promise((resolve, reject) => { - // 此处先换成yudao - uni.uploadFile({ - url: 'http://api-dashboard.yudao.iocoder.cn' + '/app-api/infra/file/upload', - filePath: file, - name: 'file', - formData: { - group, - }, - header: { - // Accept: 'text/json', - // Authorization: token, - Accept : '*/*', - 'tenant-id' :'1', - Authorization: 'Bearer test247', - }, - success: (uploadFileRes) => { - let result = JSON.parse(uploadFileRes.data); - if (result.error === 1) { - uni.showToast({ - icon: 'none', - title: result.msg, - }); - } else { - return resolve(result.data); - } - }, - fail: (error) => { - console.log('上传失败:', error); - return resolve(false); - }, - complete: () => { - uni.hideLoading(); - }, - }); - }); - }, }; diff --git a/sheep/api/infra/file.js b/sheep/api/infra/file.js new file mode 100644 index 0000000..264f646 --- /dev/null +++ b/sheep/api/infra/file.js @@ -0,0 +1,49 @@ +import request2 from '@/sheep/request2'; + +const FileApi = { + // 上传文件 + uploadFile: (file) => { + const token = uni.getStorageSync('token'); + uni.showLoading({ + title: '上传中', + }); + return new Promise((resolve, reject) => { + // 此处先换成yudao + // TODO 芋艿:后续搞下 + uni.uploadFile({ + // url: 'http://api-dashboard.yudao.iocoder.cn' + '/app-api/infra/file/upload', + url: 'http://127.0.0.1:48080' + '/app-api/infra/file/upload', + filePath: file, + name: 'file', + header: { + // Accept: 'text/json', + // Authorization: token, + Accept : '*/*', + 'tenant-id' :'1', + Authorization: 'Bearer test247', + }, + success: (uploadFileRes) => { + debugger + let result = JSON.parse(uploadFileRes.data); + if (result.error === 1) { + uni.showToast({ + icon: 'none', + title: result.msg, + }); + } else { + return resolve(result); + } + }, + fail: (error) => { + console.log('上传失败:', error); + return resolve(false); + }, + complete: () => { + uni.hideLoading(); + }, + }); + }); + }, +}; + +export default FileApi;