diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 76dc4cf..d63ecf2 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -71,14 +71,11 @@ export default { selectChange(val) { if (val === 'loginout') { this.$store.commit('user/RESET_STATE') + this.$store.commit('permission/SET_ROUTES', []) this.$router.push('/login') return } this.$router.push('/' + val) - }, - async logout() { - await this.$store.dispatch('user/logout') - this.$router.push(`/login?redirect=${this.$route.fullPath}`) } } } diff --git a/src/permission.js b/src/permission.js index d26d6e0..437a0d5 100644 --- a/src/permission.js +++ b/src/permission.js @@ -4,6 +4,7 @@ import store from './store' import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style import getPageTitle from '@/utils/get-page-title' +import { filterAsyncRoutes } from '@/utils' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -43,9 +44,11 @@ router.beforeEach(async(to, from, next) => { next() } else { store.commit('user/SET_CLASS', pat) - store.commit('permission/SET_ROUTES', asyncRoutes) + const asr = filterAsyncRoutes(asyncRoutes, store.getters.roleData.drug_manage) + // store.commit('permission/SET_ROUTES', asr) + // store.commit('permission/SET_ROUTES', asyncRoutes) resetRouter() - router.addRoutes(asyncRoutes) + router.addRoutes(asr) next({ ...to, replace: true }) } } diff --git a/src/router/modules/reagent.js b/src/router/modules/reagent.js index 2510a9c..211fa93 100644 --- a/src/router/modules/reagent.js +++ b/src/router/modules/reagent.js @@ -1,16 +1,17 @@ import Layout from '@/layout' const reagentRouter = [ - { - path: '/reagent', - hidden: true, - redirect: '/reagent/mainoverview/index', - meta: { classification: 'reagent' } - }, + // { + // path: '/reagent', + // hidden: true, + // redirect: '/reagent/mainoverview/index', + // meta: { classification: 'reagent', module_code: 'MainOverview' } + // }, { path: '/reagent/mainoverview', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/mainoverview/index', + meta: { classification: 'reagent', module_code: 'MainOverview' }, children: [ { path: 'index', @@ -23,7 +24,8 @@ const reagentRouter = [ { path: '/reagent/report', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/report/index', + meta: { classification: 'reagent', module_code: 'DataReportIndex' }, children: [ { path: 'index', @@ -92,7 +94,8 @@ const reagentRouter = [ { path: '/reagent/warehousing', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/warehousing/index', + meta: { classification: 'reagent', module_code: 'DataReportIndex' }, children: [ { path: 'index', @@ -105,7 +108,8 @@ const reagentRouter = [ { path: '/reagent/receiving', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/receiving/index', + meta: { classification: 'reagent', module_code: 'DrugUseView' }, children: [ { path: 'index', @@ -118,7 +122,8 @@ const reagentRouter = [ { path: '/reagent/sendback', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/sendback/index', + meta: { classification: 'reagent', module_code: 'DrugReturnView' }, children: [ { path: 'index', @@ -131,7 +136,8 @@ const reagentRouter = [ { path: '/reagent/weighing', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/weighing/index', + meta: { classification: 'reagent', module_code: 'DrugWeigh' }, children: [ { path: 'index', @@ -144,7 +150,8 @@ const reagentRouter = [ { path: '/reagent/inventory', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/inventory/index', + meta: { classification: 'reagent', module_code: 'StockTakingIndex' }, children: [ { path: 'index', @@ -158,7 +165,7 @@ const reagentRouter = [ path: '/reagent/database', component: Layout, redirect: '/reagent/database/msds', - meta: { title: '化学品数据库', icon: '化学品数据库', classification: 'reagent' }, + meta: { title: '化学品数据库', icon: '化学品数据库', classification: 'reagent', module_code: 'ChemicaDatabase' }, children: [ { path: 'msds', @@ -177,7 +184,8 @@ const reagentRouter = [ { path: '/reagent/management', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/management/index', + meta: { classification: 'reagent', module_code: 'DrugIndex' }, children: [ { path: 'index', @@ -190,7 +198,8 @@ const reagentRouter = [ { path: '/reagent/client', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/client/index', + meta: { classification: 'reagent', module_code: 'CabinetIndex' }, children: [ { path: 'index', @@ -203,7 +212,8 @@ const reagentRouter = [ { path: '/reagent/envrecord', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/envrecord/index', + meta: { classification: 'reagent', module_code: 'HumitureIndex' }, children: [ { path: 'index', @@ -216,7 +226,8 @@ const reagentRouter = [ { path: '/reagent/form', component: Layout, - meta: { classification: 'reagent' }, + redirect: '/reagent/form/index', + meta: { classification: 'reagent', module_code: 'DrugCustomForm' }, children: [ { path: 'index', @@ -226,19 +237,19 @@ const reagentRouter = [ } ] }, - { - path: '/reagent/buy', - component: Layout, - meta: { classification: 'reagent' }, - children: [ - { - path: 'index', - name: 'Buy', - component: () => import('@/views/reagent/buy/index'), - meta: { title: '请购', icon: '请购', classification: 'reagent' } - } - ] - }, + // { + // path: '/reagent/buy', + // component: Layout, + // meta: { classification: 'reagent' }, + // children: [ + // { + // path: 'index', + // name: 'Buy', + // component: () => import('@/views/reagent/buy/index'), + // meta: { title: '请购', icon: '请购', classification: 'reagent' } + // } + // ] + // }, { path: '/gotohome', redirect: '/home', diff --git a/src/router/modules/user.js b/src/router/modules/user.js index 29396dc..018f294 100644 --- a/src/router/modules/user.js +++ b/src/router/modules/user.js @@ -3,16 +3,11 @@ import Layout from '@/layout' const userRouter = [ - { - path: '/user', - redirect: '/user/info/index', - hidden: true, - meta: { classification: 'user' } - }, { path: '/user/info', component: Layout, - meta: { classification: 'user' }, + redirect: '/user/info/index', + meta: { classification: 'user', 'module_code': 'UserIndex' }, children: [ { path: 'index', @@ -25,7 +20,8 @@ const userRouter = [ { path: '/user/role', component: Layout, - meta: { classification: 'user' }, + redirect: '/user/role/index', + meta: { classification: 'user', module_code: 'UserRoleIndex' }, children: [ { path: 'index', diff --git a/src/store/getters.js b/src/store/getters.js index 4351ce4..20ce7a5 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -6,6 +6,7 @@ const getters = { name: state => state.user.name, permission_routes: state => state.permission.routes, classification: state => state.user.classification, - isMain: state => state.settings.isMain + isMain: state => state.settings.isMain, + roleData: state => state.permission.roleData } export default getters diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 711cefa..1d83881 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -36,13 +36,17 @@ export function filterAsyncRoutes(routes, roles) { const state = { routes: [], - addRoutes: [] + addRoutes: [], + roleData: {} } const mutations = { SET_ROUTES: (state, routes) => { state.addRoutes = routes state.routes = constantRoutes.concat(routes) + }, + SET_ROLE_DATA: (state, data) => { + state.roleData = data } } diff --git a/src/utils/index.js b/src/utils/index.js index a5e0e42..c9a6b13 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -149,3 +149,15 @@ export function throttle(fn, time) { } } +export function filterAsyncRoutes(routers, roles) { + return routers.filter(item => { + if (item.path === '*') { + return true + } + if (item.meta && item.meta.title === '返回主页') { + return true + } + return !!roles.find(it => it.module_code === item.meta.module_code) + }) +} + diff --git a/src/utils/request.js b/src/utils/request.js index 92171ca..6149748 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -71,6 +71,7 @@ service.interceptors.response.use( type: 'warning' }).then(() => { store.commit('user/RESET_STATE') + store.commit('permission/SET_ROUTES', []) router.push('/login') }) } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index b301891..66d0154 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -70,8 +70,9 @@