user.ts 801 B

12345678910111213141516171819202122232425262728
  1. import { queenApi } from "queenjs";
  2. import { AuthModule } from "../..";
  3. export const userActions = AuthModule.action("keepActive", {
  4. async initUser() {
  5. await queenApi.router.isReady();
  6. if (this.store.token) {
  7. await this.actions.getUserInfo();
  8. // 判断是登录页, 则跳转页面
  9. if (this.helper.isLoginPage()) {
  10. this.actions.jump("loginSucc");
  11. }
  12. }
  13. // 不是登录页没有token, 判断是否需要登录
  14. else if (this.helper.isCurrPathNeedAuth()) {
  15. this.actions.jump("needLogin");
  16. }
  17. },
  18. async getUserInfo() {
  19. try {
  20. const { result } = await this.https.getProfile();
  21. this.store.setUserInfo(result.user);
  22. } catch (error: any) {
  23. this.actions.checkLoginExpire(error.result);
  24. throw error;
  25. }
  26. },
  27. });