feat: 个人信息修改
This commit is contained in:
@@ -7,7 +7,15 @@ import {
|
||||
type LoginRequest,
|
||||
type RegisterRequest
|
||||
} from '@/api/modules/account'
|
||||
import { getUserInfo, updateStatus as updateStatusApi, type UserStatusType } from '@/api/modules/user'
|
||||
import {
|
||||
getUserInfo,
|
||||
updateUserInfo as updateUserInfoApi,
|
||||
uploadAvatar as uploadAvatarApi,
|
||||
deleteAvatar as deleteAvatarApi,
|
||||
updateStatus as updateStatusApi,
|
||||
type UserStatusType,
|
||||
type UpdateUserInfoRequest
|
||||
} from '@/api/modules/user'
|
||||
|
||||
/** 账户信息 */
|
||||
export interface AccountState {
|
||||
@@ -109,6 +117,35 @@ export const useAccountStore = defineStore(
|
||||
return accessToken.value
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户的个人资料
|
||||
* 调用后端接口持久化,并同步更新本地 accountInfo
|
||||
* @param data - 要更新的字段(所有字段可选)
|
||||
*/
|
||||
const updateProfile = async (data: UpdateUserInfoRequest) => {
|
||||
const res = await updateUserInfoApi(data)
|
||||
accountInfo.value = res.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
* 调用后端接口上传文件并更新 DB,同步更新本地 accountInfo
|
||||
* @param file - 头像文件
|
||||
*/
|
||||
const uploadAvatar = async (file: File) => {
|
||||
const res = await uploadAvatarApi(file)
|
||||
accountInfo.value = res.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户头像
|
||||
* 调用后端接口删除文件并清空 DB,同步更新本地 accountInfo
|
||||
*/
|
||||
const removeAvatar = async () => {
|
||||
const res = await deleteAvatarApi()
|
||||
accountInfo.value = res.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户的在线状态
|
||||
* 调用后端接口持久化,并同步更新本地 accountInfo
|
||||
@@ -141,6 +178,9 @@ export const useAccountStore = defineStore(
|
||||
logout,
|
||||
refreshAccessToken,
|
||||
fetchUserInfo,
|
||||
updateProfile,
|
||||
uploadAvatar,
|
||||
removeAvatar,
|
||||
updateUserStatus
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user