Files
webgame-frontend/src/api/modules/user/info.ts
2026-06-22 11:19:11 +08:00

81 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { requestClient } from '@/api/request'
/**
* 性别枚举
*
* 对应 OpenAPI: Sex (x-enums)
* 1 = 男2 = 女
*/
export const Sex = {
/** 男 */
MALE: 1,
/** 女 */
FEMALE: 2
} as const
/** 性别类型 */
export type SexType = (typeof Sex)[keyof typeof Sex]
/**
* 用户信息响应
*
* 对应 OpenAPI: UserInfoResponse
* 所有字段均为可选,部分字段可能为 null
*/
/** 在线状态枚举 */
export const UserStatus = {
ONLINE: 'ONLINE',
AWAY: 'AWAY',
DND: 'DND',
INVISIBLE: 'INVISIBLE'
} as const
/** 在线状态类型 */
export type UserStatusType = (typeof UserStatus)[keyof typeof UserStatus]
export interface UserInfoResponse {
/** 用户唯一标识UUID */
userId?: string
/** 用户昵称,最长 16 位 */
nickName?: string
/** 头像图片 URL 地址,可能为 null */
avatar?: string | null
/** 个性签名,最长 64 位,可能为 null */
signature?: string | null
/** 年龄,可能为 null */
age?: number | null
/** 性别1=男2=女,可能为 null */
sex?: SexType | null
/** 生日ISO 8601 日期格式),可能为 null */
birthday?: string | null
/** 在线状态ONLINE / AWAY / DND / INVISIBLE */
status?: UserStatusType
}
/** 更新在线状态请求 */
export interface UpdateStatusRequest {
/** 状态值ONLINE、AWAY、DND、INVISIBLE */
status: UserStatusType
}
/**
* 获取当前登录用户信息
*
* 根据请求头中的 saToken 获取当前登录用户的详细信息。
* 需登录认证。
*
* @returns 当前登录用户的详细信息
*/
export function getUserInfo() {
return requestClient.get<UserInfoResponse>('/user/info')
}
/**
* 更新当前登录用户在线状态
*
* @param data - 状态更新请求
*/
export function updateStatus(data: UpdateStatusRequest) {
return requestClient.patch<void>('/user/status', data)
}