chore: 个人中心

This commit is contained in:
dap 2024-10-20 11:01:20 +08:00
parent 23c548ac3d
commit 71d005bd48
3 changed files with 14 additions and 7 deletions

View File

@ -15,9 +15,9 @@ import { userProfileUpdate } from '#/api/system/profile';
import { useAuthStore } from '#/store';
import { getDictOptions } from '#/utils/dict';
const props = defineProps<{ profile: UserProfile }>();
import { emitter } from '../mitt';
const emit = defineEmits<{ reload: [] }>();
const props = defineProps<{ profile: UserProfile }>();
const userStore = useUserStore();
const authStore = useAuthStore();
@ -93,7 +93,7 @@ async function handleSubmit(values: Recordable<any>) {
const userInfo = await authStore.fetchUserInfo();
userStore.setUserInfo(userInfo);
// reload
emit('reload');
emitter.emit('updateProfile');
} catch (error) {
console.error(error);
} finally {
@ -109,9 +109,7 @@ onMounted(() => {
'phonenumber',
'sex',
]);
for (const key in data) {
formApi.setFieldValue(key, data[key as keyof typeof data]);
}
formApi.setValues(data);
});
</script>

View File

@ -9,6 +9,7 @@ import { useUserStore } from '@vben/stores';
import { userProfile } from '#/api/system/profile';
import { useAuthStore } from '#/store';
import { emitter } from './mitt';
import ProfilePanel from './profile-panel.vue';
import SettingPanel from './setting-panel.vue';
@ -32,6 +33,8 @@ async function handleUploadFinish() {
const userInfo = await authStore.fetchUserInfo();
userStore.setUserInfo(userInfo);
}
emitter.on('updateProfile', loadProfile);
</script>
<template>
@ -44,7 +47,6 @@ async function handleUploadFinish() {
v-if="profile"
:profile="profile"
class="flex-1 overflow-hidden"
@reload="loadProfile"
/>
</div>
</Page>

View File

@ -0,0 +1,7 @@
import { mitt } from '@vben/utils';
type Events = {
updateProfile: void;
};
export const emitter = mitt<Events>();