瀏覽代碼

商品模块 动态路由

e 5 年之前
父節點
當前提交
231fa535ad
共有 2 個文件被更改,包括 47 次插入24 次删除
  1. 9 22
      src/router/index.js
  2. 38 2
      src/store/modules/permission.js

+ 9 - 22
src/router/index.js

@@ -145,27 +145,6 @@ export const constantRoutes = [
         component: () => import('@/views/goods/list'),
         meta: { title: '商品列表', icon: 'list' }
       },
-      {
-        path: 'list/preferred',
-        name: 'PreferredProduct',
-        component: () => import('@/views/goods/list-preferred'),
-        meta: { title: '星范优惠', noCache: true, activeMenu: '/goods/list' },
-        hidden: true
-      },
-      {
-        path: 'list/preferential',
-        name: 'PreferentialProduct',
-        component: () => import('@/views/goods/list-preferential'),
-        meta: { title: '星范精品', noCache: true, activeMenu: '/goods/list' },
-        hidden: true
-      },
-      {
-        path: 'list/commonly',
-        name: 'CommonlyProduct',
-        component: () => import('@/views/goods/list-commonly'),
-        meta: { title: '常用商品', noCache: true, activeMenu: '/goods/list' },
-        hidden: true
-      },
       {
         path: 'list/select/:type(\\d+)',
         name: 'SelectProduct',
@@ -175,7 +154,6 @@ export const constantRoutes = [
       }
     ]
   },
-
   {
     path: '/order',
     component: Layout,
@@ -294,6 +272,15 @@ export const constantRoutes = [
  * the routes that need to be dynamically loaded based on user roles
  */
 export const asyncRoutes = [
+  {
+    path: '/goods',
+    component: Layout,
+    redirect: '/goods/list',
+    name: 'Goods',
+    meta: { title: '商品管理', icon: 'shopping' },
+    hidden: true,
+    children: []
+  },
   // 404 page must be placed at the end !!!
   { path: '*', redirect: '/404', hidden: true }
 ]

+ 38 - 2
src/store/modules/permission.js

@@ -1,4 +1,5 @@
 import { asyncRoutes, constantRoutes } from '@/router'
+import { getModule } from '@/api/goods'
 
 /**
  * Use meta.role to determine if the current user has permission
@@ -55,8 +56,43 @@ const actions = {
       } else {
         accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
       }
-      commit('SET_ROUTES', accessedRoutes)
-      resolve(accessedRoutes)
+      getModule({ organizeID: 1 }).then(response => {
+        const modules = response.data[0]
+        if (accessedRoutes[0].name === 'Goods') {
+          if (modules && modules.firstModulesName) {
+            accessedRoutes[0].children.unshift({
+              path: '/goods/list/preferred',
+              name: 'PreferredProduct',
+              component: () => import('@/views/goods/list-preferred'),
+              meta: { title: modules.firstModulesName, noCache: true, activeMenu: '/goods/list' },
+              hidden: true
+            })
+          }
+          if (modules && modules.secondModulesName) {
+            accessedRoutes[0].children.unshift({
+              path: '/goods/list/preferential',
+              name: 'PreferentialProduct',
+              component: () => import('@/views/goods/list-preferential'),
+              meta: { title: modules.secondModulesName, noCache: true, activeMenu: '/goods/list' },
+              hidden: true
+            })
+          }
+          if (modules && modules.thirdModulesName) {
+            accessedRoutes[0].children.unshift({
+              path: '/goods/list/commonly',
+              name: 'CommonlyProduct',
+              component: () => import('@/views/goods/list-commonly'),
+              meta: { title: modules.thirdModulesName, noCache: true, activeMenu: '/goods/list' },
+              hidden: true
+            })
+          }
+        }
+        commit('SET_ROUTES', accessedRoutes)
+        resolve(accessedRoutes)
+      }).catch(() => {
+        commit('SET_ROUTES', accessedRoutes)
+        resolve(accessedRoutes)
+      })
     })
   }
 }