Browse Source

toLogin放到util里,避险循环引用

CzRger 1 year ago
parent
commit
33270b12ac
4 changed files with 9 additions and 8 deletions
  1. 1 1
      src/api/interceptors.ts
  2. 1 1
      src/layout/header/head-com.vue
  3. 1 6
      src/router/index.ts
  4. 6 0
      src/utils/permissions.ts

+ 1 - 1
src/api/interceptors.ts

@@ -1,5 +1,5 @@
 import axios from 'axios';
-import {toLogin} from '@/router/index'
+import {toLogin} from "@/utils/permissions";
 import {ElMessage} from "element-plus";
 export class Interceptors {
   public instance: any

+ 1 - 1
src/layout/header/head-com.vue

@@ -29,7 +29,7 @@ import {
 } from 'vue'
 import {useStore} from 'vuex'
 import {useRouter, useRoute} from 'vue-router'
-import {toLogin} from '@/router/index'
+import {toLogin} from "@/utils/permissions";
 import {ElMessageBox} from "element-plus";
 
 export default defineComponent({

+ 1 - 6
src/router/index.ts

@@ -8,6 +8,7 @@ import RouterViewCom from "@/layout/router-view.vue";
 import {stagingRouterMap, stagingRouter} from './modules/staging'
 import {systemRouterMap, systemRouter} from './modules/system'
 import {ElMessage} from "element-plus";
+import {toLogin} from "@/utils/permissions";
 
 export const RoutersMap = new Map([
   ...stagingRouterMap,
@@ -78,12 +79,6 @@ const getInit = (to: any, next: any) => {
     }
 }
 
-//跳转登录
-export const toLogin = () => {
-    sessionStorage.clear();
-    window.location.replace("/login");
-};
-
 export const initMainRouter = async () => {
     if (sessionStorage.getItem("sg_token") && location.pathname !== '/login') {
         store.dispatch('app/LOAD_TIMESTAMP')

+ 6 - 0
src/utils/permissions.ts

@@ -1,5 +1,11 @@
 import store from '@/store/index'
 
+//跳转登录
+export const toLogin = () => {
+  sessionStorage.clear();
+  window.location.replace("/login");
+}
+
 export const has = (value: any) => {
   const permissions = store.state.app.permissions;
   let hasPermissions = null