This commit is contained in:
shijing 2022-07-15 17:16:14 +08:00
commit 90f9fcc2ca
3 changed files with 148 additions and 95 deletions

View File

@ -277,7 +277,6 @@ export default {
// delete reqData[config.request.pageSize] // delete reqData[config.request.pageSize]
} }
Object.assign(reqData, this.tableParams); Object.assign(reqData, this.tableParams);
debugger;
try { try {
var res = await this.apiObj.req(reqData); var res = await this.apiObj.req(reqData);
if (this.hidePagination) { if (this.hidePagination) {

View File

@ -32,8 +32,8 @@ const routes = [
"path": "/home", "path": "/home",
"meta": { "meta": {
"title": "首页", "title": "首页",
"icon": "el-icon-house", "icon": "el-icon-home-filled",
"type": "menu" "type": "menu",
}, },
"children": [ "children": [
{ {
@ -41,8 +41,8 @@ const routes = [
"path": "/dashboard", "path": "/dashboard",
"meta": { "meta": {
"title": "控制台", "title": "控制台",
"icon": "el-icon-menu", "icon": "el-icon-monitor",
"affix": true "affix": true,
}, },
"component": "home" "component": "home"
}, },
@ -51,7 +51,7 @@ const routes = [
"path": "/bigScreen", "path": "/bigScreen",
"meta": { "meta": {
"title": "驾驶舱", "title": "驾驶舱",
"icon": "el-icon-platform", "icon": "el-icon-position",
"fullpage": true "fullpage": true
}, },
"component": "bigScreen" "component": "bigScreen"
@ -72,8 +72,8 @@ const routes = [
"path": "/ecm", "path": "/ecm",
"meta": { "meta": {
"title": "事件", "title": "事件",
"icon": "el-icon-goods", "icon": "el-icon-goods-filled",
"type": "menu" "type": "menu",
}, },
"children": [ "children": [
{ {
@ -81,9 +81,10 @@ const routes = [
"path": "/ecm/event", "path": "/ecm/event",
"meta": { "meta": {
"title": "事件列表", "title": "事件列表",
"icon": "el-icon-menu", "icon": "el-icon-document",
"perms": ["event"]
}, },
"component": "ecm/event" "component": "ecm/event",
} }
, ,
{ {
@ -112,7 +113,7 @@ const routes = [
"path": "/ecm/myevent", "path": "/ecm/myevent",
"meta": { "meta": {
"title": "我的事件", "title": "我的事件",
"icon": "el-icon-menu", "icon": "el-icon-document-remove",
}, },
"component": "ecm/myevent" "component": "ecm/myevent"
}, },
@ -121,7 +122,7 @@ const routes = [
"path": "/ecm/notify_setting", "path": "/ecm/notify_setting",
"meta": { "meta": {
"title": "提醒配置", "title": "提醒配置",
"icon": "el-icon-menu", "icon": "el-icon-setting",
}, },
"component": "ecm/notify_setting" "component": "ecm/notify_setting"
}, },
@ -131,7 +132,7 @@ const routes = [
"path": "/ecm/algo", "path": "/ecm/algo",
"meta": { "meta": {
"title": "算法配置", "title": "算法配置",
"icon": "el-icon-menu", "icon": "el-icon-setting",
}, },
"component": "ecm/algo" "component": "ecm/algo"
} }
@ -142,7 +143,7 @@ const routes = [
"path": "/wf", "path": "/wf",
"meta": { "meta": {
"title": "工单", "title": "工单",
"icon": "el-icon-goods", "icon": "el-icon-circle-check-filled",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -151,7 +152,7 @@ const routes = [
"path": "/wf/workflow", "path": "/wf/workflow",
"meta": { "meta": {
"title": "工作流", "title": "工作流",
"icon": "el-icon-menu", "icon": "el-icon-guide",
}, },
"component": "wf/workflow" "component": "wf/workflow"
}, },
@ -171,7 +172,7 @@ const routes = [
"path": "/wf/allwork", "path": "/wf/allwork",
"meta": { "meta": {
"title": "全部工单", "title": "全部工单",
"icon": "el-icon-menu", "icon": "el-icon-folder",
}, },
"component": "wf/allwork" "component": "wf/allwork"
@ -181,7 +182,7 @@ const routes = [
"path": "/wf/ownerwork", "path": "/wf/ownerwork",
"meta": { "meta": {
"title": "我创建的", "title": "我创建的",
"icon": "el-icon-menu", "icon": "el-icon-folder-add",
}, },
"component": "wf/ownerwork" "component": "wf/ownerwork"
@ -193,7 +194,7 @@ const routes = [
"path": "/wf/dutywork", "path": "/wf/dutywork",
"meta": { "meta": {
"title": "待办工单", "title": "待办工单",
"icon": "el-icon-menu", "icon": "el-icon-folder-opened",
}, },
"component": "wf/dutywork" "component": "wf/dutywork"
@ -203,7 +204,7 @@ const routes = [
"path": "/wf/worked", "path": "/wf/worked",
"meta": { "meta": {
"title": "我处理的", "title": "我处理的",
"icon": "el-icon-menu", "icon": "el-icon-expand",
}, },
"component": "wf/worked" "component": "wf/worked"
@ -213,7 +214,7 @@ const routes = [
"path": "/wf/ccwork", "path": "/wf/ccwork",
"meta": { "meta": {
"title": "抄送我的", "title": "抄送我的",
"icon": "el-icon-menu", "icon": "el-icon-edit-pen",
}, },
"component": "wf/ccwork" "component": "wf/ccwork"
@ -238,7 +239,7 @@ const routes = [
"path": "/opm", "path": "/opm",
"meta": { "meta": {
"title": "作业", "title": "作业",
"icon": "el-icon-goods", "icon": "el-icon-list",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -247,7 +248,7 @@ const routes = [
"path": "/opm/operation", "path": "/opm/operation",
"meta": { "meta": {
"title": "作业列表", "title": "作业列表",
"icon": "el-icon-menu", "icon": "el-icon-tickets",
}, },
"component": "opm/operation" "component": "opm/operation"
}, },
@ -256,11 +257,10 @@ const routes = [
"path": "/opm/oplcate", "path": "/opm/oplcate",
"meta": { "meta": {
"title": "许可证分类", "title": "许可证分类",
"icon": "el-icon-menu", "icon": "el-icon-ticket",
}, },
"component": "opm/oplcate" "component": "opm/oplcate"
}, },
,
{ {
"name": "opl", "name": "opl",
"path": "/opm/opl", "path": "/opm/opl",
@ -271,7 +271,6 @@ const routes = [
}, },
"component": "opm/opl" "component": "opm/opl"
}, },
,
{ {
"name": "fire", "name": "fire",
"path": "/opm/fire", "path": "/opm/fire",
@ -282,7 +281,6 @@ const routes = [
}, },
"component": "opm/fire" "component": "opm/fire"
}, },
,
{ {
"name": "space", "name": "space",
"path": "/opm/space", "path": "/opm/space",
@ -293,7 +291,6 @@ const routes = [
}, },
"component": "opm/space" "component": "opm/space"
}, },
,
{ {
"name": "clear", "name": "clear",
"path": "/opm/clear", "path": "/opm/clear",
@ -344,7 +341,6 @@ const routes = [
}, },
"component": "opm/cooler" "component": "opm/cooler"
}, },
,
{ {
"name": "soil", "name": "soil",
"path": "/opm/soil", "path": "/opm/soil",
@ -372,7 +368,7 @@ const routes = [
"path": "/rpm", "path": "/rpm",
"meta": { "meta": {
"title": "相关方", "title": "相关方",
"icon": "el-icon-goods", "icon": "el-icon-avatar",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -381,7 +377,7 @@ const routes = [
"path": "/rpm/rparty", "path": "/rpm/rparty",
"meta": { "meta": {
"title": "相关方列表", "title": "相关方列表",
"icon": "el-icon-menu", "icon": "el-icon-tickets",
}, },
"component": "rpm/rparty" "component": "rpm/rparty"
}, },
@ -390,7 +386,7 @@ const routes = [
"path": "/rpm/remployee", "path": "/rpm/remployee",
"meta": { "meta": {
"title": "相关方人员", "title": "相关方人员",
"icon": "el-icon-menu", "icon": "el-icon-user",
}, },
"component": "rpm/remployee" "component": "rpm/remployee"
}, },
@ -399,7 +395,7 @@ const routes = [
"path": "/rpm/rcertificate", "path": "/rpm/rcertificate",
"meta": { "meta": {
"title": "人员证书", "title": "人员证书",
"icon": "el-icon-menu", "icon": "el-icon-postcard",
}, },
"component": "rpm/rcertificate" "component": "rpm/rcertificate"
}, },
@ -408,7 +404,7 @@ const routes = [
"path": "/rpm/rfile", "path": "/rpm/rfile",
"meta": { "meta": {
"title": "资料库", "title": "资料库",
"icon": "el-icon-menu", "icon": "el-icon-shopping-bag",
}, },
"component": "rpm/rfile" "component": "rpm/rfile"
}, },
@ -417,7 +413,7 @@ const routes = [
"path": "/rpm/rpj", "path": "/rpm/rpj",
"meta": { "meta": {
"title": "入厂项目", "title": "入厂项目",
"icon": "el-icon-menu", "icon": "el-icon-calendar",
}, },
"component": "rpm/rpj" "component": "rpm/rpj"
}, },
@ -439,7 +435,7 @@ const routes = [
"path": "/vm", "path": "/vm",
"meta": { "meta": {
"title": "访客", "title": "访客",
"icon": "el-icon-goods", "icon": "el-icon-user-filled",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -448,7 +444,7 @@ const routes = [
"path": "/vm/visit", "path": "/vm/visit",
"meta": { "meta": {
"title": "来访项目", "title": "来访项目",
"icon": "el-icon-menu", "icon": "el-icon-tickets",
}, },
"component": "vm/visit" "component": "vm/visit"
}, },
@ -457,7 +453,7 @@ const routes = [
"path": "/vm/visitor", "path": "/vm/visitor",
"meta": { "meta": {
"title": "来访人员", "title": "来访人员",
"icon": "el-icon-menu", "icon": "el-icon-user",
}, },
"component": "vm/visitor" "component": "vm/visitor"
},{ },{
@ -489,7 +485,7 @@ const routes = [
"path": "/am", "path": "/am",
"meta": { "meta": {
"title": "区域", "title": "区域",
"icon": "el-icon-goods", "icon": "el-icon-location-filled",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -498,7 +494,7 @@ const routes = [
"path": "/am/area", "path": "/am/area",
"meta": { "meta": {
"title": "区域列表", "title": "区域列表",
"icon": "el-icon-menu", "icon": "el-icon-tickets",
}, },
"component": "am/area" "component": "am/area"
}, },
@ -507,7 +503,7 @@ const routes = [
"path": "/am/eqm", "path": "/am/eqm",
"meta": { "meta": {
"title": "门禁通道", "title": "门禁通道",
"icon": "el-icon-menu", "icon": "el-icon-phone",
}, },
"component": "am/em1" "component": "am/em1"
}, },
@ -516,7 +512,7 @@ const routes = [
"path": "/am/monitor", "path": "/am/monitor",
"meta": { "meta": {
"title": "视频通道", "title": "视频通道",
"icon": "el-icon-menu", "icon": "el-icon-video-camera",
}, },
"component": "am/monitor" "component": "am/monitor"
}, },
@ -525,7 +521,7 @@ const routes = [
"path": "/am/audio", "path": "/am/audio",
"meta": { "meta": {
"title": "喇叭通道", "title": "喇叭通道",
"icon": "el-icon-menu", "icon": "el-icon-mic",
}, },
"component": "am/audio" "component": "am/audio"
},{ },{
@ -533,7 +529,7 @@ const routes = [
"path": "/am/blt", "path": "/am/blt",
"meta": { "meta": {
"title": "定位标签", "title": "定位标签",
"icon": "el-icon-menu", "icon": "el-icon-map-location",
}, },
"component": "am/blt" "component": "am/blt"
}, },
@ -544,7 +540,7 @@ const routes = [
"path": "/hrm", "path": "/hrm",
"meta": { "meta": {
"title": "人事", "title": "人事",
"icon": "el-icon-user", "icon": "el-icon-platform",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -554,7 +550,7 @@ const routes = [
"path": "/hrm/employee", "path": "/hrm/employee",
"meta": { "meta": {
"title": "企业员工", "title": "企业员工",
"icon": "el-icon-menu", "icon": "el-icon-user",
}, },
"component": "hrm/employee" "component": "hrm/employee"
} }
@ -564,7 +560,7 @@ const routes = [
"path": "/hrm/certificates", "path": "/hrm/certificates",
"meta": { "meta": {
"title": "证书列表", "title": "证书列表",
"icon": "el-icon-menu", "icon": "el-icon-tickets",
}, },
"component": "hrm/certificates" "component": "hrm/certificates"
} }
@ -587,7 +583,7 @@ const routes = [
"path": "/sys", "path": "/sys",
"meta": { "meta": {
"title": "系统", "title": "系统",
"icon": "el-icon-setting", "icon": "el-icon-tools",
"type": "menu" "type": "menu"
}, },
"children": [ "children": [
@ -658,8 +654,9 @@ const routes = [
"path": "/ops", "path": "/ops",
"meta": { "meta": {
"title": "运维", "title": "运维",
"icon": "el-icon-user", "icon": "el-icon-wallet-filled",
"type": "menu" "type": "menu",
"perms": ["ops"]
}, },
"children": [ "children": [
{ {
@ -668,6 +665,7 @@ const routes = [
"meta": { "meta": {
"title": "菜单管理", "title": "菜单管理",
"icon": "el-icon-fold", "icon": "el-icon-fold",
"perms": ["menu"]
}, },
"component": "ops/menu" "component": "ops/menu"
}, },
@ -677,6 +675,7 @@ const routes = [
"meta": { "meta": {
"title": "请求日志", "title": "请求日志",
"icon": "el-icon-fold", "icon": "el-icon-fold",
"perms": ["log"]
}, },
"component": "ops/log_request" "component": "ops/log_request"
}, },
@ -686,6 +685,7 @@ const routes = [
"meta": { "meta": {
"title": "第三方日志", "title": "第三方日志",
"icon": "el-icon-fold", "icon": "el-icon-fold",
"perms": ["third_log"]
}, },
"component": "ops/thirdLogs" "component": "ops/thirdLogs"
}, },
@ -695,6 +695,7 @@ const routes = [
"meta": { "meta": {
"title": "文件日志", "title": "文件日志",
"icon": "el-icon-fold", "icon": "el-icon-fold",
"perms": ["file_log"]
}, },
"component": "ops/files" "component": "ops/files"
}, },

View File

@ -1,4 +1,4 @@
import {createRouter, createWebHashHistory} from 'vue-router'; import { createRouter, createWebHashHistory } from 'vue-router';
import { ElNotification } from 'element-plus'; import { ElNotification } from 'element-plus';
import config from "@/config" import config from "@/config"
import NProgress from 'nprogress' import NProgress from 'nprogress'
@ -6,7 +6,7 @@ import 'nprogress/nprogress.css'
import tool from '@/utils/tool'; import tool from '@/utils/tool';
import systemRouter from './systemRouter'; import systemRouter from './systemRouter';
import userRoutes from '@/config/route'; import userRoutes from '@/config/route';
import {beforeEach, afterEach} from './scrollBehavior'; import { beforeEach, afterEach } from './scrollBehavior';
//系统路由 //系统路由
const routes = systemRouter const routes = systemRouter
@ -17,7 +17,7 @@ const routes_404 = {
hidden: true, hidden: true,
component: () => import(/* webpackChunkName: "404" */ '@/layout/other/404'), component: () => import(/* webpackChunkName: "404" */ '@/layout/other/404'),
} }
let routes_404_r = ()=>{} let routes_404_r = () => { }
const router = createRouter({ const router = createRouter({
history: createWebHashHistory(), history: createWebHashHistory(),
@ -38,7 +38,7 @@ router.beforeEach(async (to, from, next) => {
let token = tool.cookie.get("TOKEN"); let token = tool.cookie.get("TOKEN");
if(to.path === "/login"){ if (to.path === "/login") {
//删除路由(替换当前layout路由) //删除路由(替换当前layout路由)
router.addRoute(routes[0]) router.addRoute(routes[0])
//删除路由(404) //删除路由(404)
@ -48,12 +48,12 @@ router.beforeEach(async (to, from, next) => {
return false; return false;
} }
if(routes.findIndex(r => r.path === to.path) >= 0){ if (routes.findIndex(r => r.path === to.path) >= 0) {
next(); next();
return false; return false;
} }
if(!token){ if (!token) {
next({ next({
path: '/login' path: '/login'
}); });
@ -61,18 +61,20 @@ router.beforeEach(async (to, from, next) => {
} }
//整页路由处理 //整页路由处理
if(to.meta.fullpage){ if (to.meta.fullpage) {
to.matched = [to.matched[to.matched.length-1]] to.matched = [to.matched[to.matched.length - 1]]
} }
//加载动态/静态路由 //加载动态/静态路由
if(!isGetRouter){ if (!isGetRouter) {
// let apiMenu = tool.data.get("MENU") || [] // let apiMenu = tool.data.get("MENU") || []
debugger;
let userInfo = tool.data.get("USER_INFO");
let permissions = tool.data.get("PERMISSIONS"); let permissions = tool.data.get("PERMISSIONS");
let userMenu = treeFilter(userRoutes, node => { let userMenu = userRoutes;
return node.meta.perms ? node.meta.perms.filter(item=>userInfo.perms.indexOf(item)>-1).length > 0 : true 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] // let menu = [...userMenu, ...apiMenu]
var menuRouter = filterAsyncRouter(userMenu); var menuRouter = filterAsyncRouter(userMenu);
menuRouter = flatAsyncRoutes(menuRouter); menuRouter = flatAsyncRoutes(menuRouter);
@ -80,8 +82,7 @@ router.beforeEach(async (to, from, next) => {
router.addRoute("layout", item) router.addRoute("layout", item)
}); });
routes_404_r = router.addRoute(routes_404); routes_404_r = router.addRoute(routes_404);
debugger; if (to.matched.length == 0) {
if (to.matched.length ==0||permissions[0]==='superuser') {
router.push(to.fullPath); router.push(to.fullPath);
} }
isGetRouter = true; isGetRouter = true;
@ -106,10 +107,14 @@ router.onError((error) => {
//入侵追加自定义方法、对象 //入侵追加自定义方法、对象
router.sc_getMenu = () => { router.sc_getMenu = () => {
// var apiMenu = tool.data.get("MENU") || [] // var apiMenu = tool.data.get("MENU") || []
let userInfo = tool.data.get("USER_INFO") let permissions = tool.data.get("PERMISSIONS");
let userMenu = treeFilter(userRoutes, node => { let userMenu = userRoutes;
return node.meta.perms ? node.meta.perms.filter(item=>userInfo.perms.indexOf(item)>-1).length > 0 : true 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] // var menu = [...userMenu, ...apiMenu]
return userMenu return userMenu
} }
@ -118,9 +123,9 @@ router.sc_getMenu = () => {
function filterAsyncRouter(routerMap) { function filterAsyncRouter(routerMap) {
const accessedRouters = [] const accessedRouters = []
routerMap.forEach(item => { 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.meta.url = item.path;
item.path = `/i/${item.name}`; item.path = `/i/${item.name}`;
} }
@ -137,39 +142,39 @@ function filterAsyncRouter(routerMap) {
}) })
return accessedRouters return accessedRouters
} }
function loadComponent(component){ function loadComponent(component) {
if(component){ if (component) {
return () => import(/* webpackChunkName: "[request]" */ `@/views/${component}`) return () => import(/* webpackChunkName: "[request]" */ `@/views/${component}`)
}else{ } else {
return () => import(`@/layout/other/empty`) return () => import(`@/layout/other/empty`)
} }
} }
//路由扁平化 //路由扁平化
function flatAsyncRoutes(routes, breadcrumb=[]) { function flatAsyncRoutes(routes, breadcrumb = []) {
let res = [] let res = []
routes.forEach(route => { routes.forEach(route => {
const tmp = {...route} const tmp = { ...route }
if (tmp.children) { if (tmp.children) {
let childrenBreadcrumb = [...breadcrumb] let childrenBreadcrumb = [...breadcrumb]
childrenBreadcrumb.push(route) childrenBreadcrumb.push(route)
let tmpRoute = { ...route } let tmpRoute = { ...route }
tmpRoute.meta.breadcrumb = childrenBreadcrumb tmpRoute.meta.breadcrumb = childrenBreadcrumb
delete tmpRoute.children delete tmpRoute.children
res.push(tmpRoute) res.push(tmpRoute)
let childrenRoutes = flatAsyncRoutes(tmp.children, childrenBreadcrumb) let childrenRoutes = flatAsyncRoutes(tmp.children, childrenBreadcrumb)
childrenRoutes.map(item => { childrenRoutes.map(item => {
res.push(item) res.push(item)
}) })
} else { } else {
let tmpBreadcrumb = [...breadcrumb] let tmpBreadcrumb = [...breadcrumb]
tmpBreadcrumb.push(tmp) tmpBreadcrumb.push(tmp)
tmp.meta.breadcrumb = tmpBreadcrumb tmp.meta.breadcrumb = tmpBreadcrumb
res.push(tmp) res.push(tmp)
} }
}) })
return res return res
} }
//过滤树 //过滤树
@ -180,4 +185,52 @@ function treeFilter(tree, func) {
}) })
} }
function hasPerm(perms_need, perms_have) {
let has = false
for (var m = 0; m < perms_need.length; m++) {
if (perms_have.indexOf(perms_need[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 export default router