From 03fefae930b7be9fa7e7c85c571c82917c951eeb Mon Sep 17 00:00:00 2001 From: "1054425342@qq.com" <1054425342@qq.com> Date: Wed, 24 Sep 2025 14:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subPackages/user/profile.vue | 67 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/subPackages/user/profile.vue b/subPackages/user/profile.vue index 0a88b0e..7b05c02 100644 --- a/subPackages/user/profile.vue +++ b/subPackages/user/profile.vue @@ -150,36 +150,43 @@ export default { }); }, onChooseAvatar(e) { - console.log(e.detail, "=="); - pathToBase64(e.detail.avatarUrl).then((base64) => { - this.Post( - { - method: "POST", - base64: base64, - }, - "/api/common/base64" - ).then((res) => { - if (res.data) { - this.Post( - { - avatar: res.data, - }, - "/api/user/profile" - ).then((res) => { - uni.showModal({ - title: "提示", - content: res.msg, - showCancel: false, - success: (res) => { - if (res.confirm) { - this.getList(); - } - }, - }); - }); - } - }); - }); + const token = uni.getStorageSync("userInfo") + ? JSON.parse(uni.getStorageSync("userInfo")).token + : ""; + const file = e.detail.avatarUrl + uni.uploadFile({ + url: this.NEWAPIURL_DES + "/system/oss/upload", // 替换为你的上传接口 + filePath: file, + name: "file", + header: { + token: token || "", + // 添加必要的请求头,如token等 + }, + success: (res) => { + let info = JSON.parse(res.data) + this.Post( + { + avatar: info.data.url, + }, + "/api/user/profile" + ).then((res) => { + uni.showModal({ + title: "提示", + content: res.msg, + showCancel: false, + success: (res) => { + if (res.confirm) { + this.getList(); + } + }, + }); + }); + }, + fail: (err) => { + reject(err); + }, + }); + }, uploadImg() { uni.chooseImage({