import { request } from '@shared/utils/request' ; import md5 from 'md5' ; import { setUserJWT } from '@shared/utils/jwt-helper' ; import { CachePolicy , buildCacheFactory , buildCacheHashFnPrefix , } from '@shared/utils/cache-factory' ; import { getAnalytics } from '@shared/manager/analytics' ; export interface PlayerUser { id : number ; name ? : string ; uuid : string ; username : string ; nickname : string ; avatar : string ; last_login : string ; last_ip : string ; sex : UserGender ; sign : string ; alignment : UserAlignment ; qq_number : string ; token ? : string ; app_token ? : string ; createdAt : string ; updatedAt : string ; deletedAt : string ; } export interface PlayerUserLoginLogType { id : number ; user_uuid : string ; user_name : string ; type : 'standard' | 'token' | 'app_standard' | 'app_token' ; channel : string ; socket_id : string ; ip : string ; ip_address : string ; platform : string ; device_info : object ; is_success : boolean ; offline_date : string ; createdAt : string ; } export type UserAlignment = 'LG' | 'NG' | 'CG' | 'LN' | 'TN' | 'CN' | 'LE' | 'NE' | 'CE' ; export type UserGender = '男' | '女' | '其他' | '保密' ; param username param password export async function loginWithPassword ( username , password ) { const { data } = await request . post ( '/player/sso/login' , { username , password : md5 ( password ) , } ) ; const { jwt , info } = data ; await setUserJWT ( jwt ) ; getAnalytics ( ) . setAnalyticsUser ( info ) ; return { jwt , info } ; } param username param password export const registerAccount = ( username , password ) => { return request . post ( '/player/register' , { username , password : md5 ( password ) , } ) ; } ; /**
 * 获取用户信息
 */ export const fetchUserInfo = buildCacheFactory < PlayerUser > ( CachePolicy . Temporary , async ( uuid ) => { const { data } = await request . get ( `/player/info/${ uuid }` ) ; return data . user ; } , buildCacheHashFnPrefix ( 'fetchUserInfo' ) ) ; /**
 * 获取用户登录记录
 */ export const fetchUserPrivateLoginLog = buildCacheFactory < PlayerUserLoginLogType [ ] > ( CachePolicy . Temporary , async ( ) => { const { data } = await request . get ( `/player/login/history/private` ) ; return data . logs ?? [ ] ; } ) ;