Browse Source

✨ feat: 增加路由权限控制

Pchen. 10 months ago
parent
commit
4d623968eb
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/router/index.js

+ 7 - 2
src/router/index.js

@@ -286,12 +286,12 @@ const routes = [
         name: 'goodsManage',
         component: DEFAULT_LAYOUT,
         meta: {
-            title : '商品管理',
+            title: '商品管理',
             icon: 'icon-apps',
             permission: ['admin', 'product']
         },
         children: [
-                        {
+            {
                 path: 'goods/addGoods',
                 name: 'admin.goods.addGoods',
                 component: () => import('../pages/admin/goods/addGoods.vue'),
@@ -389,6 +389,11 @@ router.beforeEach(async (to, from, next) => {
             // Message.error('请先登录')
             return router.push(`/login?from=${to.path}`)
         }
+
+        if (to.meta && to.meta.permission && to.meta.permission.length > 0) {
+            if (!to.meta.permission.some((perm) => user.roles.includes(perm)))
+                return next('/')
+        }
     }
 
     if (to.meta && (to.meta.onlyWeb || to.meta.onlyElectron)) {