From 8661a7e3de4455260dbd23ca60f9755359c272a2 Mon Sep 17 00:00:00 2001 From: dhy1725534722 <1725534722@qq.com> Date: Tue, 1 Aug 2023 10:16:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 84 +++++++------ src/views/index.vue | 284 ++++++++++++++++---------------------------- 2 files changed, 148 insertions(+), 220 deletions(-) diff --git a/src/permission.js b/src/permission.js index 52fea0a..c65d0ac 100644 --- a/src/permission.js +++ b/src/permission.js @@ -6,11 +6,11 @@ import "nprogress/nprogress.css"; import { getToken } from "@/utils/auth"; // 踢出系统 -// function kickOut() { -// if (process.env.NODE_ENV === "production") { -// location.href = location.origin + "/login"; -// } -// } +function kickOut() { + if (process.env.NODE_ENV === "production") { + location.href = location.origin + "/login"; + } +} NProgress.configure({ showSpinner: false }); const whiteList = [ "/login", @@ -21,10 +21,16 @@ const whiteList = [ "/personalData", "/changePassword", "/statistics", + + "/administrative", + "/enterpriseMsg", + "/productsMsg", + "/logout", ]; router.beforeEach((to, from, next) => { NProgress.start(); if (getToken()) { + console.log('有token'); to.meta.title && store.dispatch("settings/setTitle", to.meta.title); /* has token*/ if (to.path === "/login") { @@ -36,39 +42,39 @@ router.beforeEach((to, from, next) => { } else { // 没有token if (whiteList.indexOf(to.path) !== -1) { - // next(); - let token = localStorage.getItem("MSSM-LIAONING__TOKEN"); - if (token) { - if (store.state.myselfPermission.routerList.length > 0) { - let current = store.state.myselfPermission.routerList.filter( - (item) => item.path == to.path || from.path == "/" - ); - if (current.length > 0) { - next(); - } else { - Message.error("无权限访问!"); - } - } else { - store - .dispatch("GetPermission") - .then((res) => { - if (res.length > 0) { - next({ path: res }); - } else { - // kickOut(); - } - }) - .catch((error) => { - // kickOut(); - }); - } - } else { - // //没有token踢出去 - // Message.error("获取令牌失败!"); - // kickOut(); - next(); - - } + next() + // let token = localStorage.getItem("MSSM-LIAONING__TOKEN"); + // if (token) { + // if (store.state.myselfPermission.routerList.length > 0) { + // let current = store.state.myselfPermission.routerList.filter( + // (item) => item.path == to.path || from.path == "/" + // ); + // if (current.length > 0) { + // next(); + // } else { + // next(); + // // Message.error("无权限访问!"); + // } + // } else { + // store + // .dispatch("GetPermission") + // .then((res) => { + // console.log(res); + // if (res.length > 0) { + // next({ path: res }); + // } else { + // kickOut(); + // } + // }) + // .catch((error) => { + // kickOut(); + // }); + // } + // } else { + // //没有token踢出去 + // Message.error("获取令牌失败!"); + // kickOut(); + // } } else { // kickOut(); NProgress.done(); @@ -78,4 +84,4 @@ router.beforeEach((to, from, next) => { router.afterEach(() => { NProgress.done(); -}); +}); \ No newline at end of file diff --git a/src/views/index.vue b/src/views/index.vue index 7a84513..0ff23c2 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -2,8 +2,8 @@
- - - - +
@@ -139,20 +142,17 @@ export default { computed: { //获取自定义路由 myRouter() { + console.log(this.$router.options.routes); // let staticRouter = router.options.routes.filter( // (item) => item.isDiy == true // )[0].children; // return staticRouter; // return this.$store.state.myselfPermission.routerList; + console.log(this.$router.options.routes[6].children); return this.$router.options.routes[6].children; }, - }, - methods:{ - handleOpen(key, keyPath) { - console.log(key, keyPath); - }, - handleClose(key, keyPath) { - console.log(key, keyPath); + get1(e) { + console.log(e); }, }, created() {}, @@ -160,6 +160,28 @@ export default { + \ No newline at end of file