import { DataModel } from '@imengyu/js-request-transform'; import { AppServerRequestModule } from '../RequestModules'; export class LoginResult extends DataModel { constructor() { super(LoginResult, "登录结果"); this._convertTable = { token: { clientSide: 'string', clientSideRequired: true }, }; this._afterSolveServer = () => { this.userInfo.id = this.id; this.userInfo.mobile = this.mobile; this.userInfo.nickname = this.nickname; this.userInfo.avatar = this.avatar; this.userInfo.username = this.username; } } id = 0; username = ''; nickname = ''; mobile = ''; avatar = ''; bio = ''; score = null as number|null; token = ''; userId = null as number|null; createtime = null as number|null; expiretime = null as number|null; expiresIn = null as number|null; inheritorId = null as number|null; userInfo = new UserInfo(); } export class UserInfo extends DataModel { constructor() { super(UserInfo, "用户信息"); this.setNameMapperCase('Camel', 'Snake'); this._convertTable = { id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true }, } } id = 0; userId = 0; mobile = ''; nickname = ''; avatar = ''; username = ''; } export class UserApi extends AppServerRequestModule { constructor() { super(); } async login(data: { mobile: string, password: string, }) { return (await this.post('/ich/inheritor/login', data, '登录', undefined, LoginResult)).data as LoginResult; } async refresh() { return (await this.post('/ich/inheritor/refresh', {}, '刷新token', undefined, LoginResult)).data as LoginResult; } } export default new UserApi();