Sfoglia il codice sorgente

第一次登录显示无权限

zhoujump 1 mese fa
parent
commit
cb0fb470ed
2 ha cambiato i file con 15 aggiunte e 22 eliminazioni
  1. 14 6
      src/App.vue
  2. 1 16
      src/router/index.js

+ 14 - 6
src/App.vue

@@ -63,14 +63,22 @@ export default {
         console.log(to)
         if (router.app.$store.getters.token) {
           if (router.app.$store.getters.user.isAdmin) {
-            this.isAnimation = true
-            setTimeout(() => {
-              this.isAnimation = false
-              next()
-            }, 400)
+            canIShow(to.meta.roles).then(res => {
+              this.isAnimation = true
+              setTimeout(() => {
+                this.isAnimation = false
+                if (res) {
+                  next()
+                } else {
+                  next({
+                    name: '401'
+                  })
+                }
+              }, 400)
+            })
           } else {
             next({
-              name: 'userForm'
+              name: 'login'
             })
           }
         } else {

+ 1 - 16
src/router/index.js

@@ -1,7 +1,7 @@
 import Vue from 'vue'
 import Router from 'vue-router'
 Vue.use(Router)
-import { canIShow } from '@/permission'
+
 import Layout from '@/layout'
 export const constantRoutes = [
   {
@@ -527,19 +527,4 @@ const createRouter = () => new Router({
   routes: constantRoutes
 })
 const router = createRouter()
-router.beforeEach((to, from, next) => {
-  canIShow(to.meta.roles).then((res) => {
-    if (res) {
-      next()
-    } else {
-      if (to.name === 'login' || to.name === 'userRegister' || to.name === 'userForm' || to.name === 'thirdLogin') {
-        next()
-      } else {
-        next({
-          name: '401'
-        })
-      }
-    }
-  })
-})
 export default router