feat: user-bar 修改
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
type LoginRequest,
|
||||
type RegisterRequest
|
||||
} from '@/api/modules/account'
|
||||
import { getUserInfo } from '@/api/modules/user'
|
||||
import { getUserInfo, updateStatus as updateStatusApi, type UserStatusType } from '@/api/modules/user'
|
||||
|
||||
/** 账户信息 */
|
||||
export interface AccountState {
|
||||
@@ -25,6 +25,8 @@ export interface AccountState {
|
||||
sex?: number | null
|
||||
/** 生日 */
|
||||
birthday?: string | null
|
||||
/** 在线状态:ONLINE / AWAY / DND / INVISIBLE */
|
||||
status?: UserStatusType
|
||||
}
|
||||
|
||||
export const useAccountStore = defineStore(
|
||||
@@ -50,7 +52,7 @@ export const useAccountStore = defineStore(
|
||||
const res = await loginApi(params)
|
||||
accessToken.value = res.data.accessToken
|
||||
refreshToken.value = res.data.refreshToken
|
||||
// await fetchUserInfo()
|
||||
await fetchUserInfo()
|
||||
isTokenValid.value = true
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ export const useAccountStore = defineStore(
|
||||
const res = await registerApi(params)
|
||||
accessToken.value = res.data.accessToken
|
||||
refreshToken.value = res.data.refreshToken
|
||||
// await fetchUserInfo()
|
||||
await fetchUserInfo()
|
||||
isTokenValid.value = true
|
||||
}
|
||||
|
||||
@@ -107,6 +109,18 @@ export const useAccountStore = defineStore(
|
||||
return accessToken.value
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户的在线状态
|
||||
* 调用后端接口持久化,并同步更新本地 accountInfo
|
||||
* @param status - 新状态值
|
||||
*/
|
||||
const updateUserStatus = async (status: UserStatusType) => {
|
||||
await updateStatusApi({ status })
|
||||
if (accountInfo.value) {
|
||||
accountInfo.value = { ...accountInfo.value, status }
|
||||
}
|
||||
}
|
||||
|
||||
/** 清除所有认证状态 */
|
||||
const clearAuth = () => {
|
||||
accessToken.value = ''
|
||||
@@ -126,7 +140,8 @@ export const useAccountStore = defineStore(
|
||||
register,
|
||||
logout,
|
||||
refreshAccessToken,
|
||||
fetchUserInfo
|
||||
fetchUserInfo,
|
||||
updateUserStatus
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user