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 { export interface UserProfileUpdateReqVO {
nickname: string nickname?: string
email: string email?: string
mobile: string mobile?: string
sex: number 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> <template>
<div> <div @click.stop>
<Dialog <Dialog
v-model="dialogVisible" v-model="dialogVisible"
:canFullscreen="false" :canFullscreen="false"
@ -181,6 +181,7 @@ function openModal() {
} }
function closeModal() { function closeModal() {
debugger
dialogVisible.value = false dialogVisible.value = false
} }

View File

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