lanjianrong 3 лет назад
Родитель
Сommit
55105be580
3 измененных файлов с 7 добавлено и 3 удалено
  1. 1 1
      src/components/Navigation/index.tsx
  2. 5 2
      src/store/mobx/user/index.ts
  3. 1 0
      src/utils/consts.ts

+ 1 - 1
src/components/Navigation/index.tsx

@@ -59,7 +59,7 @@ class NavigationGuards extends Component<NavigationGuardsProps, any> {
 
   componentDidMount() {
     this.changDocumentTitle(this.props.location.pathname)
-    userStore.check()
+    userStore.check(location?.pathname)
   }
   // shouldComponentUpdate(nextProps: any) {
 

+ 5 - 2
src/store/mobx/user/index.ts

@@ -4,7 +4,7 @@ import { iFromValues } from '@/types/login'
 import { ProjectInfo } from '@/types/project'
 import { iGroup, iUserInfo } from '@/types/setting'
 import { apiGetGroupList, apiProjectInfo, apiUserInfo } from '@/utils/common/api'
-import { delUserInfo, getUserInfo, saveUserInfo } from '@/utils/common/user'
+import { saveUserInfo } from '@/utils/common/user'
 import consts from '@/utils/consts'
 import history from '@/utils/history'
 import { action, computed, observable } from 'mobx'
@@ -79,7 +79,10 @@ class UserState {
     history.replace('/login')
   }
 
-  @action async check() {
+  @action async check(pathname?: string) {
+    if (pathname && consts.ROUTES_WHILE.includes(pathname)) {
+      return
+    }
     if (!this.userInfo?.id) {
       this.toggleLoading()
       await this.getUserInfo()

+ 1 - 0
src/utils/consts.ts

@@ -6,6 +6,7 @@ export default {
     DEV: '',
     PROD: ''
   },
+  ROUTES_WHILE: [ '/auth', '/login' ], // 路由的白名单
   TOKEN_API: '', // 获取token
   TOKEN_INVALID_CODE: [ 1 ], // 接口返回码如果是1 则表明token过期或无效 需要重新登录
   TOKEN_WHITE_LIST: [ '/api/login' ], // 不需要设置token的白名单