Skip to content

Commit ef90faf

Browse files
committed
fix:关闭头像上传时,又自动打开
reactor:头像上传时,通过前端 httpRequest ,可支持前端直传
1 parent 165ce58 commit ef90faf

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/api/system/user/profile.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ export interface ProfileVO {
3232
}
3333

3434
export interface UserProfileUpdateReqVO {
35-
nickname: string
36-
email: string
37-
mobile: string
38-
sex: number
35+
nickname?: string
36+
email?: string
37+
mobile?: string
38+
sex?: number
39+
avatar?: string
3940
}
4041

4142
// 查询用户个人信息
@@ -58,8 +59,3 @@ export const updateUserPassword = (oldPassword: string, newPassword: string) =>
5859
}
5960
})
6061
}
61-
62-
// 用户头像上传
63-
export const uploadAvatar = (data) => {
64-
return request.upload({ url: '/system/user/profile/update-avatar', data: data })
65-
}

src/components/Cropper/src/CopperModal.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div @click.stop>
33
<Dialog
44
v-model="dialogVisible"
55
:canFullscreen="false"
@@ -181,6 +181,7 @@ function openModal() {
181181
}
182182
183183
function closeModal() {
184+
debugger
184185
dialogVisible.value = false
185186
}
186187

src/views/Profile/components/UserAvatar.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
</template>
1313
<script lang="ts" setup>
1414
import { propTypes } from '@/utils/propTypes'
15-
import { uploadAvatar } from '@/api/system/user/profile'
15+
import { updateUserProfile } from '@/api/system/user/profile'
1616
import { CropperAvatar } from '@/components/Cropper'
1717
import { useUserStore } from '@/store/modules/user'
18+
import { useUpload } from '@/components/UploadFile/src/useUpload'
19+
import { UploadRequestOptions } from 'element-plus/es/components/upload/src/upload'
1820
1921
// TODO @芋艿:合并到 ProfileUser 组件中,更简洁一点
2022
defineOptions({ name: 'UserAvatar' })
@@ -27,10 +29,16 @@ const userStore = useUserStore()
2729
2830
const cropperRef = ref()
2931
const handelUpload = async ({ data }) => {
30-
// TODO @芋艿:去掉这个接口,使用 url 直接上传
31-
const res = await uploadAvatar({ avatarFile: data })
32+
const { httpRequest } = useUpload()
33+
const avatar = ((await httpRequest({
34+
file: data,
35+
filename: 'avatar.png',
36+
} as UploadRequestOptions)) as unknown as { data: string }).data
37+
await updateUserProfile({ avatar })
38+
39+
// 关闭弹窗,并更新 userStore
3240
cropperRef.value.close()
33-
userStore.setUserAvatarAction(res.data)
41+
await userStore.setUserAvatarAction(avatar)
3442
}
3543
</script>
3644

0 commit comments

Comments
 (0)