import { queenApi } from "queenjs"; import { AuthModule } from "../.."; import { User_Config } from "../config"; export const loginActions = AuthModule.action({ async pwdLogin(data: any) { const ret = await this.https.personPwdLogin({ ...data, key: this.config.key, }); this.actions.getUserInfo(); this.actions.saveToken(ret.result.token); this.actions.jump("loginSucc"); }, async wechatLogin(code: string) { const res = await this.https.personWechatLogin({ code }); this.actions.getUserInfo(); this.actions.saveToken(res.result.token); this.actions.jump("loginSucc"); }, async checkLoginExpire(result: any) { if (result.errorNo === 401) { this.store.clearUserInfo(); if (!this.helper.isLoginPage()) { this.actions.jump("tokenExpire"); } } }, logout() { this.store.clearUserInfo(); this.actions.jump("logout"); }, async getSmsCode(data: { email?: string; phone?: string; use: "register" | "resetPasswd" | "login"; }) { await this.https.getSmsCode(data); }, async personRegister(data: any) { const ret = await this.https.personRegister({ ...data, regInfo: this.config.regInfo, }); this.actions.getUserInfo(); this.actions.saveToken(ret.result.token); this.actions.jump("loginSucc"); }, async emailRegister(data: any) { const ret = await this.https.emailRegist({ ...data, regInfo: this.config.regInfo, }); this.actions.getUserInfo(); this.actions.saveToken(ret.result.token); this.actions.jump("loginSucc"); }, async resetPassword(data: { email?: string; phone?: string; password: string; code: string; }) { await this.https.resetPwd(data); queenApi.messageSuccess("修改成功"); if (this.helper.isLoginPage()) { setTimeout(() => { queenApi.router.back(); }, 1000); } }, saveToken(token: string) { this.store.setToken(token); }, jump(jumpType: keyof typeof User_Config["jumpOptions"]) { this.config.jumpOptions[jumpType].action.call(this); }, });