From cb5b55badd38b034be996be78f0317c9a89f2b6e Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Mon, 15 Sep 2025 09:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E5=A4=B4?= =?UTF-8?q?=E5=83=8F-=E4=BD=BF=E7=94=A8=E4=B8=83=E7=89=9B=E4=BA=91?= =?UTF-8?q?=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user/user.js | 39 ++++++++++++--------------------------- pages/set/set.vue | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/api/user/user.js b/api/user/user.js index da6c62f..b88e44f 100644 --- a/api/user/user.js +++ b/api/user/user.js @@ -188,35 +188,20 @@ export function submitWithdraw(data) { /** * 上传头像 - * @param {string} filePath - 文件路径 + * @param {string} avatarUrl - 文件路径 * @returns {Promise} 返回上传结果 */ -export function uploadAvatar(filePath) { - return uploadFile( - '/app/user/avatar', - filePath, - 'avatarfile', - {}, - { - timeout: 60000, - } - ) - .then(data => { - // 上传成功后更新本地存储 - const userInfo = uni.getStorageSync('userInfo') || {} - userInfo.avatar = data.data?.avatar || data.data - uni.setStorageSync('userInfo', userInfo) - - // 通知其他页面更新头像 - uni.$emit('avatarUpdated', userInfo.avatar) - - console.log('头像上传成功,已更新本地存储:', userInfo.avatar) - return data - }) - .catch(error => { - console.error('头像上传失败:', error) - throw error - }) +export function uploadAvatar(avatarUrl) { + return request({ + url: '/app/user/avatar', + method: 'PUT', + data: { + avatarUrl: avatarUrl, + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }) } /** diff --git a/pages/set/set.vue b/pages/set/set.vue index dae847e..dbf9491 100644 --- a/pages/set/set.vue +++ b/pages/set/set.vue @@ -1,24 +1,25 @@