From 940f5da05aa8ff44258000317361e7f16a2e4273 Mon Sep 17 00:00:00 2001 From: "2309368887@qq.com" <2309368887@qq.com> Date: Fri, 15 Jul 2022 14:27:30 +0800 Subject: [PATCH 1/3] tubiaojicaidan --- src/config/route.js | 82 +++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/config/route.js b/src/config/route.js index dba6a91c..73de51ea 100644 --- a/src/config/route.js +++ b/src/config/route.js @@ -32,8 +32,9 @@ const routes = [ "path": "/home", "meta": { "title": "首页", - "icon": "el-icon-house", - "type": "menu" + "icon": "el-icon-home-filled", + "type": "menu", + }, "children": [ { @@ -41,8 +42,9 @@ const routes = [ "path": "/dashboard", "meta": { "title": "控制台", - "icon": "el-icon-menu", - "affix": true + "icon": "el-icon-monitor", + "affix": true, + }, "component": "home" }, @@ -51,7 +53,7 @@ const routes = [ "path": "/bigScreen", "meta": { "title": "驾驶舱", - "icon": "el-icon-platform", + "icon": "el-icon-position", "fullpage": true }, "component": "bigScreen" @@ -72,7 +74,7 @@ const routes = [ "path": "/ecm", "meta": { "title": "事件", - "icon": "el-icon-goods", + "icon": "el-icon-goods-filled", "type": "menu" }, "children": [ @@ -81,7 +83,7 @@ const routes = [ "path": "/ecm/event", "meta": { "title": "事件列表", - "icon": "el-icon-menu", + "icon": "el-icon-document", }, "component": "ecm/event" } @@ -112,7 +114,7 @@ const routes = [ "path": "/ecm/myevent", "meta": { "title": "我的事件", - "icon": "el-icon-menu", + "icon": "el-icon-document-remove", }, "component": "ecm/myevent" }, @@ -121,7 +123,7 @@ const routes = [ "path": "/ecm/notify_setting", "meta": { "title": "提醒配置", - "icon": "el-icon-menu", + "icon": "el-icon-setting", }, "component": "ecm/notify_setting" }, @@ -131,7 +133,7 @@ const routes = [ "path": "/ecm/algo", "meta": { "title": "算法配置", - "icon": "el-icon-menu", + "icon": "el-icon-setting", }, "component": "ecm/algo" } @@ -142,7 +144,7 @@ const routes = [ "path": "/wf", "meta": { "title": "工单", - "icon": "el-icon-goods", + "icon": "el-icon-circle-check-filled", "type": "menu" }, "children": [ @@ -151,7 +153,7 @@ const routes = [ "path": "/wf/workflow", "meta": { "title": "工作流", - "icon": "el-icon-menu", + "icon": "el-icon-guide", }, "component": "wf/workflow" }, @@ -171,7 +173,7 @@ const routes = [ "path": "/wf/allwork", "meta": { "title": "全部工单", - "icon": "el-icon-menu", + "icon": "el-icon-folder", }, "component": "wf/allwork" @@ -181,7 +183,7 @@ const routes = [ "path": "/wf/ownerwork", "meta": { "title": "我创建的", - "icon": "el-icon-menu", + "icon": "el-icon-folder-add", }, "component": "wf/ownerwork" @@ -193,7 +195,7 @@ const routes = [ "path": "/wf/dutywork", "meta": { "title": "待办工单", - "icon": "el-icon-menu", + "icon": "el-icon-folder-opened", }, "component": "wf/dutywork" @@ -203,7 +205,7 @@ const routes = [ "path": "/wf/worked", "meta": { "title": "我处理的", - "icon": "el-icon-menu", + "icon": "el-icon-expand", }, "component": "wf/worked" @@ -213,7 +215,7 @@ const routes = [ "path": "/wf/ccwork", "meta": { "title": "抄送我的", - "icon": "el-icon-menu", + "icon": "el-icon-edit-pen", }, "component": "wf/ccwork" @@ -238,7 +240,7 @@ const routes = [ "path": "/opm", "meta": { "title": "作业", - "icon": "el-icon-goods", + "icon": "el-icon-list", "type": "menu" }, "children": [ @@ -247,7 +249,7 @@ const routes = [ "path": "/opm/operation", "meta": { "title": "作业列表", - "icon": "el-icon-menu", + "icon": "el-icon-tickets", }, "component": "opm/operation" }, @@ -256,7 +258,7 @@ const routes = [ "path": "/opm/oplcate", "meta": { "title": "许可证分类", - "icon": "el-icon-menu", + "icon": "el-icon-ticket", }, "component": "opm/oplcate" }, @@ -372,7 +374,7 @@ const routes = [ "path": "/rpm", "meta": { "title": "相关方", - "icon": "el-icon-goods", + "icon": "el-icon-avatar", "type": "menu" }, "children": [ @@ -381,7 +383,7 @@ const routes = [ "path": "/rpm/rparty", "meta": { "title": "相关方列表", - "icon": "el-icon-menu", + "icon": "el-icon-tickets", }, "component": "rpm/rparty" }, @@ -390,7 +392,7 @@ const routes = [ "path": "/rpm/remployee", "meta": { "title": "相关方人员", - "icon": "el-icon-menu", + "icon": "el-icon-user", }, "component": "rpm/remployee" }, @@ -399,7 +401,7 @@ const routes = [ "path": "/rpm/rcertificate", "meta": { "title": "人员证书", - "icon": "el-icon-menu", + "icon": "el-icon-postcard", }, "component": "rpm/rcertificate" }, @@ -408,7 +410,7 @@ const routes = [ "path": "/rpm/rfile", "meta": { "title": "资料库", - "icon": "el-icon-menu", + "icon": "el-icon-shopping-bag", }, "component": "rpm/rfile" }, @@ -417,7 +419,7 @@ const routes = [ "path": "/rpm/rpj", "meta": { "title": "入厂项目", - "icon": "el-icon-menu", + "icon": "el-icon-calendar", }, "component": "rpm/rpj" }, @@ -439,7 +441,7 @@ const routes = [ "path": "/vm", "meta": { "title": "访客", - "icon": "el-icon-goods", + "icon": "el-icon-user-filled", "type": "menu" }, "children": [ @@ -448,7 +450,7 @@ const routes = [ "path": "/vm/visit", "meta": { "title": "来访项目", - "icon": "el-icon-menu", + "icon": "el-icon-tickets", }, "component": "vm/visit" }, @@ -457,7 +459,7 @@ const routes = [ "path": "/vm/visitor", "meta": { "title": "来访人员", - "icon": "el-icon-menu", + "icon": "el-icon-user", }, "component": "vm/visitor" },{ @@ -489,7 +491,7 @@ const routes = [ "path": "/am", "meta": { "title": "区域", - "icon": "el-icon-goods", + "icon": "el-icon-location-filled", "type": "menu" }, "children": [ @@ -498,7 +500,7 @@ const routes = [ "path": "/am/area", "meta": { "title": "区域列表", - "icon": "el-icon-menu", + "icon": "el-icon-tickets", }, "component": "am/area" }, @@ -507,7 +509,7 @@ const routes = [ "path": "/am/eqm", "meta": { "title": "门禁通道", - "icon": "el-icon-menu", + "icon": "el-icon-phone", }, "component": "am/em1" }, @@ -516,7 +518,7 @@ const routes = [ "path": "/am/monitor", "meta": { "title": "视频通道", - "icon": "el-icon-menu", + "icon": "el-icon-video-camera", }, "component": "am/monitor" }, @@ -525,7 +527,7 @@ const routes = [ "path": "/am/audio", "meta": { "title": "喇叭通道", - "icon": "el-icon-menu", + "icon": "el-icon-mic", }, "component": "am/audio" },{ @@ -533,7 +535,7 @@ const routes = [ "path": "/am/blt", "meta": { "title": "定位标签", - "icon": "el-icon-menu", + "icon": "el-icon-map-location", }, "component": "am/blt" }, @@ -544,7 +546,7 @@ const routes = [ "path": "/hrm", "meta": { "title": "人事", - "icon": "el-icon-user", + "icon": "el-icon-platform", "type": "menu" }, "children": [ @@ -554,7 +556,7 @@ const routes = [ "path": "/hrm/employee", "meta": { "title": "企业员工", - "icon": "el-icon-menu", + "icon": "el-icon-user", }, "component": "hrm/employee" } @@ -564,7 +566,7 @@ const routes = [ "path": "/hrm/certificates", "meta": { "title": "证书列表", - "icon": "el-icon-menu", + "icon": "el-icon-tickets", }, "component": "hrm/certificates" } @@ -587,7 +589,7 @@ const routes = [ "path": "/sys", "meta": { "title": "系统", - "icon": "el-icon-setting", + "icon": "el-icon-tools", "type": "menu" }, "children": [ @@ -658,7 +660,7 @@ const routes = [ "path": "/ops", "meta": { "title": "运维", - "icon": "el-icon-user", + "icon": "el-icon-wallet-filled", "type": "menu" }, "children": [ From 5d89acd0126d6d7e22302ebdbba6ca40deca143f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Fri, 15 Jul 2022 16:37:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/scTable/index.vue | 1 - src/config/route.js | 11 +-- src/router/index.js | 145 +++++++++++++++++++++---------- 3 files changed, 102 insertions(+), 55 deletions(-) diff --git a/src/components/scTable/index.vue b/src/components/scTable/index.vue index f03953de..3a7fedd0 100644 --- a/src/components/scTable/index.vue +++ b/src/components/scTable/index.vue @@ -277,7 +277,6 @@ export default { // delete reqData[config.request.pageSize] } Object.assign(reqData, this.tableParams); - debugger; try { var res = await this.apiObj.req(reqData); if (this.hidePagination) { diff --git a/src/config/route.js b/src/config/route.js index 709290d3..81af4d17 100644 --- a/src/config/route.js +++ b/src/config/route.js @@ -34,7 +34,6 @@ const routes = [ "title": "首页", "icon": "el-icon-home-filled", "type": "menu", - }, "children": [ { @@ -75,7 +74,7 @@ const routes = [ "meta": { "title": "事件", "icon": "el-icon-goods-filled", - "type": "menu" + "type": "menu", }, "children": [ { @@ -84,8 +83,9 @@ const routes = [ "meta": { "title": "事件列表", "icon": "el-icon-document", + "perms": ["event"] }, - "component": "ecm/event" + "component": "ecm/event", } , { @@ -262,7 +262,6 @@ const routes = [ }, "component": "opm/oplcate" }, - , { "name": "opl", "path": "/opm/opl", @@ -273,7 +272,6 @@ const routes = [ }, "component": "opm/opl" }, - , { "name": "fire", "path": "/opm/fire", @@ -284,7 +282,6 @@ const routes = [ }, "component": "opm/fire" }, - , { "name": "space", "path": "/opm/space", @@ -295,7 +292,6 @@ const routes = [ }, "component": "opm/space" }, - , { "name": "clear", "path": "/opm/clear", @@ -346,7 +342,6 @@ const routes = [ }, "component": "opm/cooler" }, - , { "name": "soil", "path": "/opm/soil", diff --git a/src/router/index.js b/src/router/index.js index ee0ec1cf..5bcb0b70 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,4 +1,4 @@ -import {createRouter, createWebHashHistory} from 'vue-router'; +import { createRouter, createWebHashHistory } from 'vue-router'; import { ElNotification } from 'element-plus'; import config from "@/config" import NProgress from 'nprogress' @@ -6,7 +6,7 @@ import 'nprogress/nprogress.css' import tool from '@/utils/tool'; import systemRouter from './systemRouter'; import userRoutes from '@/config/route'; -import {beforeEach, afterEach} from './scrollBehavior'; +import { beforeEach, afterEach } from './scrollBehavior'; //系统路由 const routes = systemRouter @@ -17,7 +17,7 @@ const routes_404 = { hidden: true, component: () => import(/* webpackChunkName: "404" */ '@/layout/other/404'), } -let routes_404_r = ()=>{} +let routes_404_r = () => { } const router = createRouter({ history: createWebHashHistory(), @@ -38,7 +38,7 @@ router.beforeEach(async (to, from, next) => { let token = tool.cookie.get("TOKEN"); - if(to.path === "/login"){ + if (to.path === "/login") { //删除路由(替换当前layout路由) router.addRoute(routes[0]) //删除路由(404) @@ -48,12 +48,12 @@ router.beforeEach(async (to, from, next) => { return false; } - if(routes.findIndex(r => r.path === to.path) >= 0){ + if (routes.findIndex(r => r.path === to.path) >= 0) { next(); return false; } - if(!token){ + if (!token) { next({ path: '/login' }); @@ -61,18 +61,20 @@ router.beforeEach(async (to, from, next) => { } //整页路由处理 - if(to.meta.fullpage){ - to.matched = [to.matched[to.matched.length-1]] + if (to.meta.fullpage) { + to.matched = [to.matched[to.matched.length - 1]] } //加载动态/静态路由 - if(!isGetRouter){ + if (!isGetRouter) { // let apiMenu = tool.data.get("MENU") || [] - debugger; - let userInfo = tool.data.get("USER_INFO"); let permissions = tool.data.get("PERMISSIONS"); - let userMenu = treeFilter(userRoutes, node => { - return node.meta.perms ? node.meta.perms.filter(item=>userInfo.perms.indexOf(item)>-1).length > 0 : true - }); + let userMenu = userRoutes; + if(permissions.indexOf('superuser')==-1){ + userMenu = treeFilter(userRoutes, node => { + return node.meta.perms ? node.meta.perms.filter(item => permissions.indexOf(item) > -1).length > 0 : true + }); + } + // let userMenu = checkRoute(userRoutes, permissions) // let menu = [...userMenu, ...apiMenu] var menuRouter = filterAsyncRouter(userMenu); menuRouter = flatAsyncRoutes(menuRouter); @@ -80,8 +82,7 @@ router.beforeEach(async (to, from, next) => { router.addRoute("layout", item) }); routes_404_r = router.addRoute(routes_404); - debugger; - if (to.matched.length ==0||permissions[0]==='superuser') { + if (to.matched.length == 0) { router.push(to.fullPath); } isGetRouter = true; @@ -106,10 +107,14 @@ router.onError((error) => { //入侵追加自定义方法、对象 router.sc_getMenu = () => { // var apiMenu = tool.data.get("MENU") || [] - let userInfo = tool.data.get("USER_INFO") - let userMenu = treeFilter(userRoutes, node => { - return node.meta.perms ? node.meta.perms.filter(item=>userInfo.perms.indexOf(item)>-1).length > 0 : true - }) + let permissions = tool.data.get("PERMISSIONS"); + let userMenu = userRoutes; + if(permissions.indexOf('superuser')==-1){ + userMenu = treeFilter(userRoutes, node => { + return node.meta.perms ? node.meta.perms.filter(item => permissions.indexOf(item) > -1).length > 0 : true + }); + } + // let userMenu = checkRoute(userRoutes, permissions) // var menu = [...userMenu, ...apiMenu] return userMenu } @@ -118,9 +123,9 @@ router.sc_getMenu = () => { function filterAsyncRouter(routerMap) { const accessedRouters = [] routerMap.forEach(item => { - item.meta = item.meta?item.meta:{}; + item.meta = item.meta ? item.meta : {}; //处理外部链接特殊路由 - if(item.meta.type=='iframe'){ + if (item.meta.type == 'iframe') { item.meta.url = item.path; item.path = `/i/${item.name}`; } @@ -137,39 +142,39 @@ function filterAsyncRouter(routerMap) { }) return accessedRouters } -function loadComponent(component){ - if(component){ +function loadComponent(component) { + if (component) { return () => import(/* webpackChunkName: "[request]" */ `@/views/${component}`) - }else{ + } else { return () => import(`@/layout/other/empty`) } } //路由扁平化 -function flatAsyncRoutes(routes, breadcrumb=[]) { +function flatAsyncRoutes(routes, breadcrumb = []) { let res = [] routes.forEach(route => { - const tmp = {...route} - if (tmp.children) { - let childrenBreadcrumb = [...breadcrumb] - childrenBreadcrumb.push(route) - let tmpRoute = { ...route } - tmpRoute.meta.breadcrumb = childrenBreadcrumb - delete tmpRoute.children - res.push(tmpRoute) - let childrenRoutes = flatAsyncRoutes(tmp.children, childrenBreadcrumb) - childrenRoutes.map(item => { - res.push(item) - }) - } else { - let tmpBreadcrumb = [...breadcrumb] - tmpBreadcrumb.push(tmp) - tmp.meta.breadcrumb = tmpBreadcrumb - res.push(tmp) - } - }) - return res + const tmp = { ...route } + if (tmp.children) { + let childrenBreadcrumb = [...breadcrumb] + childrenBreadcrumb.push(route) + let tmpRoute = { ...route } + tmpRoute.meta.breadcrumb = childrenBreadcrumb + delete tmpRoute.children + res.push(tmpRoute) + let childrenRoutes = flatAsyncRoutes(tmp.children, childrenBreadcrumb) + childrenRoutes.map(item => { + res.push(item) + }) + } else { + let tmpBreadcrumb = [...breadcrumb] + tmpBreadcrumb.push(tmp) + tmp.meta.breadcrumb = tmpBreadcrumb + res.push(tmp) + } + }) + return res } //过滤树 @@ -180,4 +185,52 @@ function treeFilter(tree, func) { }) } +function hasPerm(perms_need, perms_have) { + let has = false + for(var m=0;m-1){ + has = true + } + } + return has +} + +function checkRoute(routes, perms) { + if(perms.indexOf('superuser')>-1){ + return routes + } + for (var i = 0; i < routes.length; i++) { + if (routes[i].meta && routes[i].meta.perms) { + let has = hasPerm(routes[i].meta.perms, perms) + if(!has){ + routes.splice(i,1) + } + else if (routes[i].children){ + for (var m = 0; m < routes[i].children.length; m++){ + let child = routes[i].children[m] + if (child.meta && child.meta.perms) { + let has = hasPerm(child.meta.perms, perms) + if(!has){ + routes[i].children.splice(m,1) + } + } + } + } + } + else if (routes[i].children){ + for (var m = 0; m < routes[i].children.length; m++){ + let child = routes[i].children[m] + console.log(m, child) + if (child.meta && child.meta.perms) { + let has = hasPerm(child.meta.perms, perms) + if(!has){ + routes[i].children.splice(m,1) + } + } + } + } + } + return routes +} + export default router From ea1cffeff659c41c61f827e55de9496c838fe1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Fri, 15 Jul 2022 17:01:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?route=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/route.js | 8 ++++++-- src/router/index.js | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/config/route.js b/src/config/route.js index 81af4d17..bb45db40 100644 --- a/src/config/route.js +++ b/src/config/route.js @@ -43,7 +43,6 @@ const routes = [ "title": "控制台", "icon": "el-icon-monitor", "affix": true, - }, "component": "home" }, @@ -656,7 +655,8 @@ const routes = [ "meta": { "title": "运维", "icon": "el-icon-wallet-filled", - "type": "menu" + "type": "menu", + "perms": ["ops"] }, "children": [ { @@ -665,6 +665,7 @@ const routes = [ "meta": { "title": "菜单管理", "icon": "el-icon-fold", + "perms": ["menu"] }, "component": "ops/menu" }, @@ -674,6 +675,7 @@ const routes = [ "meta": { "title": "请求日志", "icon": "el-icon-fold", + "perms": ["log"] }, "component": "ops/log_request" }, @@ -683,6 +685,7 @@ const routes = [ "meta": { "title": "第三方日志", "icon": "el-icon-fold", + "perms": ["third_log"] }, "component": "ops/thirdLogs" }, @@ -692,6 +695,7 @@ const routes = [ "meta": { "title": "文件日志", "icon": "el-icon-fold", + "perms": ["file_log"] }, "component": "ops/files" }, diff --git a/src/router/index.js b/src/router/index.js index 5bcb0b70..9b61680a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -69,7 +69,7 @@ router.beforeEach(async (to, from, next) => { // let apiMenu = tool.data.get("MENU") || [] let permissions = tool.data.get("PERMISSIONS"); let userMenu = userRoutes; - if(permissions.indexOf('superuser')==-1){ + if (permissions.indexOf('superuser') == -1) { userMenu = treeFilter(userRoutes, node => { return node.meta.perms ? node.meta.perms.filter(item => permissions.indexOf(item) > -1).length > 0 : true }); @@ -109,7 +109,7 @@ router.sc_getMenu = () => { // var apiMenu = tool.data.get("MENU") || [] let permissions = tool.data.get("PERMISSIONS"); let userMenu = userRoutes; - if(permissions.indexOf('superuser')==-1){ + if (permissions.indexOf('superuser') == -1) { userMenu = treeFilter(userRoutes, node => { return node.meta.perms ? node.meta.perms.filter(item => permissions.indexOf(item) > -1).length > 0 : true }); @@ -187,8 +187,8 @@ function treeFilter(tree, func) { function hasPerm(perms_need, perms_have) { let has = false - for(var m=0;m-1){ + for (var m = 0; m < perms_need.length; m++) { + if (perms_have.indexOf(perms_need[m]) > -1) { has = true } } @@ -196,35 +196,35 @@ function hasPerm(perms_need, perms_have) { } function checkRoute(routes, perms) { - if(perms.indexOf('superuser')>-1){ + if (perms.indexOf('superuser') > -1) { return routes } for (var i = 0; i < routes.length; i++) { if (routes[i].meta && routes[i].meta.perms) { let has = hasPerm(routes[i].meta.perms, perms) - if(!has){ - routes.splice(i,1) + if (!has) { + routes.splice(i, 1) } - else if (routes[i].children){ - for (var m = 0; m < routes[i].children.length; m++){ + else if (routes[i].children) { + for (var m = 0; m < routes[i].children.length; m++) { let child = routes[i].children[m] if (child.meta && child.meta.perms) { let has = hasPerm(child.meta.perms, perms) - if(!has){ - routes[i].children.splice(m,1) + if (!has) { + routes[i].children.splice(m, 1) } } } } } - else if (routes[i].children){ - for (var m = 0; m < routes[i].children.length; m++){ + else if (routes[i].children) { + for (var m = 0; m < routes[i].children.length; m++) { let child = routes[i].children[m] console.log(m, child) if (child.meta && child.meta.perms) { let has = hasPerm(child.meta.perms, perms) - if(!has){ - routes[i].children.splice(m,1) + if (!has) { + routes[i].children.splice(m, 1) } } }