!385 fix: 用户头像、昵称修改,同步更新Layout/UserInfo

Merge pull request !385 from dhb52/hotfix/dhb52/avatarupdate
This commit is contained in:
芋道源码
2024-02-17 12:37:34 +00:00
committed by Gitee
6 changed files with 42 additions and 24 deletions

View File

@ -21,11 +21,13 @@ import {
updateUserProfile,
UserProfileUpdateReqVO
} from '@/api/system/user/profile'
import { useUserStore } from '@/store/modules/user'
defineOptions({ name: 'BasicInfo' })
const { t } = useI18n()
const message = useMessage() // 消息弹窗
const userStore = useUserStore()
// 表单校验
const rules = reactive<FormRules>({
nickname: [{ required: true, message: t('profile.rules.nickname'), trigger: 'blur' }],
@ -78,13 +80,15 @@ const submit = () => {
const data = unref(formRef)?.formModel as UserProfileUpdateReqVO
await updateUserProfile(data)
message.success(t('common.updateSuccess'))
await init()
const profile = await init()
userStore.setUserNicknameAction(profile.nickname)
}
})
}
const init = async () => {
const res = await getUserProfile()
unref(formRef)?.setValues(res)
return res
}
onMounted(async () => {
await init()

View File

@ -14,6 +14,8 @@
import { propTypes } from '@/utils/propTypes'
import { uploadAvatar } from '@/api/system/user/profile'
import { CropperAvatar } from '@/components/Cropper'
import { useUserStore } from '@/store/modules/user'
defineOptions({ name: 'UserAvatar' })
@ -21,10 +23,14 @@ defineProps({
img: propTypes.string.def('')
})
const userStore = useUserStore()
const cropperRef = ref()
const handelUpload = async ({ data }) => {
await uploadAvatar({ avatarFile: data })
const res = await uploadAvatar({ avatarFile: data })
cropperRef.value.close()
userStore.setUserAvatarAction(res.data)
}
</script>