完善功能

This commit is contained in:
wangxiaowei
2025-11-29 20:50:19 +08:00
parent 67c8e8e016
commit d38d4419d9
20 changed files with 403 additions and 98 deletions

View File

@ -71,10 +71,12 @@
<view class="flex items-center">
<view class="mr-10rpx">
<wd-upload
:header="{'token': token}"
:file-list="fileList"
:limit="1"
image-mode="scaleToFill"
:action="action">
:action="action"
@success="Profile.handleUploadSuccess">
<wd-img width="64rpx" height="64rpx" :src="user.avatar" mode="aspectFill" round />
</wd-upload>
</view>
@ -123,17 +125,17 @@
<script lang="ts" setup>
import {toast} from '@/utils/toast'
import { getUserInfo } from '@/api/user'
import { getUserInfo, updateUserInfo } from '@/api/user'
import type { IUserResult } from '@/api/types/user'
import { useUserStore } from '@/store'
import { router } from '@/utils/tools'
import { useUserStore } from '@/store'
const OSS = inject('OSS')
const showLogoutPopup = ref<boolean>(false) // 是否显示退出登录弹出框
// 上传文件
const fileList = ref<any[]>([])
const action = 'https://www.mocky.io/v2/5cc8019d300000980a055e76' // 仅做测试使用,实际请换成真实上传接口
const action = 'https://cz.stnav.com/api/upload/image' // 仅做测试使用,实际请换成真实上传接口
// 修改昵称
const showEditNicknamePopup = ref<boolean>(false) // 是否显示退款详情弹出框
@ -159,7 +161,11 @@
version: ""
})
const token = ref<string>('') // 用户token
onLoad(() => {
token.value = uni.getStorageSync('token')
Profile.handleInit()
})
@ -181,15 +187,34 @@
console.log("🚀 ~ e:", e)
},
handleUploadSuccess: async (e: any) => {
try {
const response = JSON.parse(e.file.response)
if (response.code) {
const avatarUrl = response.data.uri
await updateUserInfo({ field: 'avatar', value: avatarUrl })
user.value.avatar = avatarUrl
toast.info('头像上传成功')
} else {
throw new Error('上传失败')
}
} catch (error) {
toast.info('上传失败')
}
},
/**
* 保存昵称
*/
handleSaveNickname: () => {
handleSaveNickname: async () => {
if (!nickname.value) {
toast.info('请输入昵称')
return
}
await updateUserInfo({ field: 'nickname', value: nickname.value })
showEditNicknamePopup.value = false
user.value.nickname = nickname.value
toast.info('昵称修改成功')
},