12345678910111213141516171819202122232425262728 |
- import { queenApi } from "queenjs";
- import { AuthModule } from "../..";
- export const userActions = AuthModule.action("keepActive", {
- async initUser() {
- await queenApi.router.isReady();
- if (this.store.token) {
- await this.actions.getUserInfo();
- // 判断是登录页, 则跳转页面
- if (this.helper.isLoginPage()) {
- this.actions.jump("loginSucc");
- }
- }
- // 不是登录页没有token, 判断是否需要登录
- else if (this.helper.isCurrPathNeedAuth()) {
- this.actions.jump("needLogin");
- }
- },
- async getUserInfo() {
- try {
- const { result } = await this.https.getProfile();
- this.store.setUserInfo(result.user);
- } catch (error: any) {
- this.actions.checkLoginExpire(error.result);
- throw error;
- }
- },
- });
|