import Layout from '@/layout/index' import ParentView from '@/components/ParentView'; import InnerLink from '@/layout/components/InnerLink' import router from '@/router' import store from '@/store' import { constantRoutes } from '@/router' export var loadView = (view) => { return (resolve) => require([`@/views/${view}`], resolve) } let spotRouter = [{ "menuId": 11220, "name": "SecondJian", "path": "/secondJian", "hidden": false, "redirect": "noRedirect", "component": "Layout", "alwaysShow": true, "meta": { "title": "二建监管平台", "icon": "date-range", "noCache": false }, "children": [ { "menuId": 11219, "name": "CourseListJian", "path": "courseListJian", "hidden": false, "component": "secondJian/courseList", "meta": { "title": "课程列表", "icon": "#", "noCache": false } }, { "menuId": 11222, "name": "CompletionListJian", "path": "completionListJian", "hidden": false, "component": "secondJian/completionList", "meta": { "title": "完成列表", "icon": "#", "noCache": false } }, { "menuId": 11223, "name": "LearningListJian", "path": "learningListJian", "hidden": false, "component": "secondJian/learningList", "meta": { "title": "学习列表", "icon": "#", "noCache": false } }] }, { "menuId": 11221, "name": "SecondZao", "path": "/secondZao", "hidden": false, "redirect": "noRedirect", "component": "Layout", "alwaysShow": true, "meta": { "title": "二造监管平台", "icon": "druid", "noCache": false }, "children": [ { "menuId": 11224, "name": "CourseListZao", "path": "courseListZao", "hidden": false, "component": "secondZao/courseList", "meta": { "title": "课程列表", "icon": "#", "noCache": false } }, { "menuId": 11225, "name": "CompletionListZao", "path": "completionListZao", "hidden": false, "component": "secondZao/completionList", "meta": { "title": "完成列表", "icon": "#", "noCache": false } }, { "menuId": 11226, "name": "LearningListZao", "path": "learningListZao", "hidden": false, "component": "secondZao/learningList", "meta": { "title": "学习列表", "icon": "#", "noCache": false } }] }, { "menuId": 11227, "path": "/", "hidden": true, "component": "Layout", "children": [{ "name": "ClassHoursReviews", "path": "classHoursReviews", "hidden": false, "component": "classHoursReview", "meta": { "title": "学时审核", "icon": "#", "noCache": false } }] }] export function spotCheckFunc(li) { ///根据缓存数据筛选分类二建二造菜单 const path = li.type == 1 ? '/secondJian' : li.type == 2 ? '/secondZao' : null const mapSpotRouter = spotRouter.filter(i => i.path === path || i.path === '/') const sidebarRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(mapSpotRouter))) const rewriteRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(mapSpotRouter)), false, true) rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) store.commit('SET_ROUTES', rewriteRoutes) store.commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) store.commit('SET_DEFAULT_ROUTES', sidebarRoutes) store.commit('SET_TOPBAR_ROUTES', sidebarRoutes) router.addRoutes(rewriteRoutes) // 动态添加可访问路由表 } export function checkSession(row) { return new Promise((resolve, reject) => { const SESSION = sessionStorage.getItem("hoursAudit"); try { if (SESSION) { let parseSession = JSON.parse(SESSION); const STATUS = parseSession.options.some((item) => { return ( item.userId == row.userId && item.goodsId == row.goodsId && item.id == row.id && item.orderGoodsId == row.orderGoodsId ); }); if (!STATUS) { parseSession.options.push(row); } parseSession.activeData = `${row.userId}-${row.goodsId}-${row.id}-${row.orderGoodsId}`; sessionStorage.setItem("hoursAudit", JSON.stringify(parseSession)); } else { let data = { activeData: `${row.userId}-${row.goodsId}-${row.id}-${row.orderGoodsId}`, options: [row], }; sessionStorage.setItem("hoursAudit", JSON.stringify(data)); } resolve(); } catch (error) { reject(); } }); } // 遍历后台传来的路由字符串,转换为组件对象 function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { return asyncRouterMap.filter(route => { if (type && route.children) { route.children = filterChildren(route.children) } if (route.component) { // Layout ParentView 组件特殊处理 if (route.component === 'Layout') { route.component = Layout } else if (route.component === 'ParentView') { route.component = ParentView } else if (route.component === 'InnerLink') { route.component = InnerLink } else { route.component = loadView(route.component) } } if (route.children != null && route.children && route.children.length) { route.children = filterAsyncRouter(route.children, route, type) } else { delete route['children'] delete route['redirect'] } return true }) } function filterChildren(childrenMap, lastRouter = false) { var children = [] childrenMap.forEach((el, index) => { if (el.children && el.children.length) { if (el.component === 'ParentView' && !lastRouter) { el.children.forEach(c => { c.path = el.path + '/' + c.path if (c.children && c.children.length) { children = children.concat(filterChildren(c.children, c)) return } children.push(c) }) return } } if (lastRouter) { el.path = lastRouter.path + '/' + el.path } children = children.concat(el) }) return children }