fix:关闭头像上传时,又自动打开

reactor:头像上传时,通过前端 httpRequest ,可支持前端直传
This commit is contained in:
YunaiV 2025-04-30 20:35:16 +08:00
parent 165ce58abb
commit ef90faf77b
3 changed files with 19 additions and 14 deletions

View File

@ -32,10 +32,11 @@ export interface ProfileVO {
}
export interface UserProfileUpdateReqVO {
nickname: string
email: string
mobile: string
sex: number
nickname?: string
email?: string
mobile?: string
sex?: number
avatar?: string
}
// 查询用户个人信息
@ -58,8 +59,3 @@ export const updateUserPassword = (oldPassword: string, newPassword: string) =>
}
})
}
// 用户头像上传
export const uploadAvatar = (data) => {
return request.upload({ url: '/system/user/profile/update-avatar', data: data })
}

View File

@ -1,5 +1,5 @@
<template>
<div>
<div @click.stop>
<Dialog
v-model="dialogVisible"
:canFullscreen="false"
@ -181,6 +181,7 @@ function openModal() {
}
function closeModal() {
debugger
dialogVisible.value = false
}

View File

@ -12,9 +12,11 @@
</template>
<script lang="ts" setup>
import { propTypes } from '@/utils/propTypes'
import { uploadAvatar } from '@/api/system/user/profile'
import { updateUserProfile } from '@/api/system/user/profile'
import { CropperAvatar } from '@/components/Cropper'
import { useUserStore } from '@/store/modules/user'
import { useUpload } from '@/components/UploadFile/src/useUpload'
import { UploadRequestOptions } from 'element-plus/es/components/upload/src/upload'
// TODO @ ProfileUser
defineOptions({ name: 'UserAvatar' })
@ -27,10 +29,16 @@ const userStore = useUserStore()
const cropperRef = ref()
const handelUpload = async ({ data }) => {
// TODO @使 url
const res = await uploadAvatar({ avatarFile: data })
const { httpRequest } = useUpload()
const avatar = ((await httpRequest({
file: data,
filename: 'avatar.png',
} as UploadRequestOptions)) as unknown as { data: string }).data
await updateUserProfile({ avatar })
// userStore
cropperRef.value.close()
userStore.setUserAvatarAction(res.data)
await userStore.setUserAvatarAction(avatar)
}
</script>