优化更新

This commit is contained in:
2026-01-24 10:12:31 +08:00
parent c0f27fd0ef
commit 177c35cc15
9 changed files with 1842 additions and 1265 deletions

View File

@@ -58,19 +58,17 @@ import ProfileInfo from './components/ProfileInfo.vue'
import BasicInfo from './components/BasicInfo.vue'
import Password from './components/Password.vue'
import Security from './components/Security.vue'
import { useUserStore } from '@/stores/modules/user'
import api from '@/api/auth'
defineOptions({
name: 'UserCenter',
})
const userStore = useUserStore()
// 用户信息
const userInfo = ref({
username: '',
nickname: '',
phone: '',
email: '',
avatar: '',
status: 1,
gender: 0,
birthday: null,
bio: '',
})
const userInfo = ref({})
// 选中的菜单
const selectedKeys = ref(['basic'])
@@ -81,25 +79,34 @@ const avatarFileList = ref([])
const loading = ref(false)
// 初始化用户信息
const initUserInfo = () => {
// 模拟用户数据
const mockUserInfo = {
username: 'admin',
nickname: '管理员',
phone: '13800138000',
email: 'admin@example.com',
avatar: '',
status: 1,
gender: 1,
birthday: dayjs('1990-01-01'),
bio: '热爱编程,专注于前端开发技术。',
const initUserInfo = async () => {
try {
// 从 store 获取用户信息
const storeUserInfo = userStore.userInfo
if (storeUserInfo) {
userInfo.value = storeUserInfo
} else {
// 如果 store 中没有用户信息,则从接口获取
const response = await api.user.get()
if (response && response.data) {
userStore.setUserInfo(response.data)
userInfo.value = response.data
}
}
} catch (err) {
message.error(err.message || '获取用户信息失败')
}
userInfo.value = { ...mockUserInfo }
}
// 更新用户信息
const handleUpdateUserInfo = (data) => {
// 更新本地用户信息
Object.assign(userInfo.value, data)
// 如果 birthday 有值,转换为 dayjs 对象
if (data.birthday && typeof data.birthday === 'string') {
userInfo.value.birthday = dayjs(data.birthday)
}
}
// 密码修改成功