From 8441316198131a9a330add11c7887e123c46e51f Mon Sep 17 00:00:00 2001 From: TiaStars Date: Wed, 22 Nov 2023 15:22:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=90=9C=E7=B4=A2=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 72 +++++++++++---------------- src/router/index.js | 4 +- src/store/modules/myselfPermission.js | 14 +++++- src/views/index.vue | 17 +++---- src/views/portal/index.vue | 19 +++---- 5 files changed, 58 insertions(+), 68 deletions(-) diff --git a/src/permission.js b/src/permission.js index 150e7fa..e1cbe4b 100644 --- a/src/permission.js +++ b/src/permission.js @@ -11,62 +11,50 @@ function kickOut() { location.href = location.origin + "/login"; } } -const whiteList = [ - "/404", - "/401", +// const whiteList = [ + // "/404", + // "/401", // '/drugArchives', // "/cosmeticsArchives", - "/cosmeticsDetail", - "/health", - "/zyzj", -]; + // "/cosmeticsDetail", + // "/health", + // "/zyzj", +// ]; NProgress.configure({ showSpinner: false }); router.beforeEach((to, from, next) => { NProgress.start(); + let token = localStorage.getItem('MSSM-LIAONING__TOKEN') console.log(to.path); - if (whiteList.indexOf(to.path) == -1) { - if (token) { - console.log(store.state.myselfPermission.routerList,'store.state.myselfPermission.routerList') - if (store.state.myselfPermission.routerList.length > 0) { - let current = store.state.myselfPermission.routerList.filter( - (item) => item.path == to.path || from.path == "/" - ); - console.log(current,'current') - if (current.length > 0) { + if (token) { + if (store.state.myselfPermission.routerList.length == 0) { + + store.dispatch("GetPermission").then((res) => { + next({path:to.path}); + }).catch((error) => { + kickOut(); + }); + + } else { + let current = store.state.myselfPermission.routerList.filter( + (item) => item.path == to.path || from.path == "/" + ); + if (current.length > 0) { + next(); + } else { + //根据参数判断是否可以跳 + if (to.query.type && to.path == '/cosmeticsDetail') { next(); } else { - //根据参数判断是否可以跳 - if (to.query.type && to.path == '/cosmeticsDetail') { - next(); - } else { - next() - Message.error("无权限访问!"); - } + Message.error("无权限访问!"); } - } else { - store - .dispatch("GetPermission") - .then((res) => { - console.log(res,'res') - if (res.length > 0) { - next({ path: res }); - } else { - kickOut(); - } - }) - .catch((error) => { - kickOut(); - }); } - } else { - // 没有token - Message.error("获取令牌失败!"); - kickOut(); } } else { + // 没有token + Message.error("获取令牌失败!"); kickOut(); - } +} }); router.afterEach(() => { diff --git a/src/router/index.js b/src/router/index.js index 40cf452..f366f51 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -89,8 +89,8 @@ export const constantRoutes = [ meta: { title: "化妆品档案", }, }, { - path: "/productInfo", - name: "productInfo", + path: "/cosmeticsDetail", + name: "cosmeticsDetail", icon: require("@/assets/images/tree4.svg"), component: () => import("@/views/productsMsg/components/productInfo.vue"), meta: { title: "详情", }, diff --git a/src/store/modules/myselfPermission.js b/src/store/modules/myselfPermission.js index 05b6145..710b2b5 100644 --- a/src/store/modules/myselfPermission.js +++ b/src/store/modules/myselfPermission.js @@ -62,9 +62,19 @@ const selfPermission = { (item) => item.appCode == "CPGL" ); let fileTreeOut = filterTree(menuTree[0].childMenuList, []); - fileTreeOut[0].meta.affix = true + // let fileTreeOut = []; + + // menuTree[0].childMenuList.forEach((item) => { + // staticRouter.forEach((router, index) => { + // if (item.menuUrl == router.path) { + // fileTreeOut.push(router); + // } + // }); + // }); + + fileTreeOut[4].meta.affix = true commit("SET_ROUTER", fileTreeOut); - resolve(fileTreeOut.length > 0 ? fileTreeOut[0].path : []); + resolve(fileTreeOut.length > 0 ? fileTreeOut[4].path : []); }) .catch((error) => { reject(error); diff --git a/src/views/index.vue b/src/views/index.vue index 0a1e430..ed8967c 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -1,7 +1,10 @@