import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) /* Layout */ import Layout from '@/layout' /** * Note: sub-menu only appear when route children.length >= 1 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html * * hidden: true if set true, item will not show in the sidebar(default is false) * alwaysShow: true if set true, will always show the root menu * if not set alwaysShow, when item has more than one children route, * it will becomes nested mode, otherwise not show the root menu * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb * name:'router-name' the name is used by (must set!!!) * meta : { roles: ['admin','editor'] control the page roles (you can set multiple roles) title: 'title' the name show in sidebar and breadcrumb (recommend set) icon: 'svg-name'/'el-icon-x' the icon show in the sidebar breadcrumb: false if set false, the item will hidden in breadcrumb(default is true) activeMenu: '/example/list' if set path, the sidebar will highlight the path you set } */ /** * constantRoutes * a base page that does not have permission requirements * all roles can be accessed */ function getRoutes() { let constantRoutes = [ { path: '/login', component: () => import('@/views/login/index'), hidden: true }, { path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/addCommision', component: () => import('@/views/inspectionManagement/commissionInspection/addCommision'), hidden: true }, { path: '/', component: Layout, redirect: '/home', // meta: { title: '主页', icon: 'el-icon-s-home' }, children: [{ path: 'home', name: 'Home', component: () => import('@/views/home/index'), meta: { title: '主页', icon: 'el-icon-s-home' } }] }, { path: '/addCommision/:viewId', hidden: true, component: () => import('@/views/inspectionManagement/commissionInspection/addCommision'), }, { path: '/standardLibrary', component: Layout, redirect: '/standardLibrary/index', meta: { title: '标准库', icon: 'el-icon-s-help' }, children: [ { path: 'index', name: 'StandardLibrary', component: () => import('@/views/standardLibrary/index'), meta: { title: '标准库', icon: 'form' } }, { path: 'specificationDetails/:id', name: 'SpecificationDetails', // hidden: true, component: () => import('@/views/standardLibrary/SpecificationDetails'), meta: { title: '产品规格详情', icon: 'form', show: false } } ] }, // { // path: '/rawMaterials', // component: Layout, // redirect: '/rawMaterials/reportForInspection', // name: 'rawMaterials', // meta: { title: '检验', icon: 'el-icon-s-help' }, // children: [ // { // path: 'reportForInspection', // name: 'ReportForInspection', // component: () => import('@/views/rawMaterials/reportForInspection/index'), // meta: { title: '原材料报检', icon: 'table' }, // children: [ // // { // // path: 'index', // // name: 'ReportForInspectionIndex', // // // hidden: true, // // component: () => import('@/views/rawMaterials/reportForInspection/index'), // // meta: { title: '原材料报检', icon: 'table' } // // }, // { // path: 'forInspectionDetail', // name: 'ForInspectionDetail', // hidden: true, // component: () => import('@/views/rawMaterials/reportForInspection/forInspectionDetail'), // meta: { title: '新增检验单详情', icon: 'table' } // } // ] // }, // { // path: 'print', // name: 'Print', // component: () => import('@/views/rawMaterials/print/index'), // meta: { title: '条码打印', icon: 'tree' } // }, // { // path: 'planAssignments', // name: 'PlanAssignments', // component: () => import('@/views/rawMaterials/planAssignments/index'), // meta: { title: '检验计划分配', icon: 'tree' } // }, // { // path: 'rawMaterialInspection', // name: 'RawMaterialInspection', // component: () => import('@/views/rawMaterials/rawMaterialInspection/index'), // meta: { title: '原材料检验', icon: 'tree' } // }, // { // path: 'checkTheReport', // name: 'CheckTheReport', // component: () => import('@/views/rawMaterials/checkTheReport/index'), // meta: { title: '检验报告', icon: 'tree' } // }, // { // path: 'reportAuditing', // name: 'ReportAuditing', // component: () => import('@/views/rawMaterials/reportAuditing/index'), // meta: { title: '报告审核', icon: 'tree' } // }, // { // path: 'nonConformanceReview', // name: 'NonConformanceReview', // component: () => import('@/views/rawMaterials/nonConformanceReview/index'), // meta: { title: '不合格反馈', icon: 'tree' } // }, // { // path: 'nonConformingFeedback', // name: 'NonConformingFeedback', // component: () => import('@/views/rawMaterials/nonConformingFeedback/index'), // meta: { title: '不合格评审', icon: 'tree' } // }, // { // path: 'passRateStatistics', // name: 'PassRateStatistics', // component: () => import('@/views/rawMaterials/passRateStatistics/index'), // meta: { title: '合格率统计', icon: 'tree' } // } // ] // }, { path: '/inspectionManagement', component: Layout, redirect: '/inspectionManagement/commissionInspection', name: 'InspectionManagement', meta: { title: '报检管理', icon: 'el-icon-s-help' }, children: [ { path: 'commissionInspection', name: 'CommissionInspection', component: () => import('@/views/inspectionManagement/commissionInspection/index'), meta: { title: '委托检验', icon: 'table' } }, { path: 'reportForInspection', name: 'ReportForInspection', component: () => import('@/views/inspectionManagement/reportForInspection/index'), meta: { title: '原材料报检', icon: 'tree' } } ] }, { path: '/experiment', component: Layout, redirect: '/experiment/inspectionApplication', name: 'Experiment', meta: { title: '试验管理', icon: 'el-icon-s-help' }, children: [ { path: 'inspectionApplication', name: 'inspectionApplication', component: () => import('@/views/experiment/inspectionApplication/index'), meta: { title: '新增检验', icon: 'tree' } }, { path: 'Viewdetails', name: 'Viewdetails', hidden: true, component: () => import('@/views/experiment/inspectionApplication/Viewdetails/index'), meta: { title: '详情页', icon: 'tree' } }, { path: 'planAssignments', name: 'PlanAssignments', component: () => import('@/views/experiment/planAssignments/plan'), meta: { title: '检验计划', icon: 'tree' } }, { path: 'checkTheReport', name: 'CheckTheReport', component: () => import('@/views/experiment/checkTheReport/index'), meta: { title: '检验报告', icon: 'tree' } }, { path: 'reportAuditing', name: 'ReportAuditing', component: () => import('@/views/experiment/reportAuditing/index'), meta: { title: '报告审核', icon: 'tree' } }, { path: 'nonConformanceReview', name: 'NonConformanceReview', component: () => import('@/views/experiment/nonConformanceReview/index'), meta: { title: '不合格品反馈', icon: 'tree' } }, { path: 'nonConformingFeedback', name: 'NonConformingFeedback', component: () => import('@/views/experiment/nonConformingFeedback/index'), meta: { title: '不合格品评审', icon: 'tree' } }, { path: 'passRateStatistics', name: 'PassRateStatistics', component: () => import('@/views/experiment/passRateStatistics/index'), meta: { title: '合格率统计', icon: 'tree' } } ] }, // { // path: '/finishedProduct', // component: Layout, // redirect: '/finishedProduct/reportForInspection', // name: 'FinishedProduct', // meta: { title: '成品检验', icon: 'el-icon-s-help' }, // children: [ // { // path: 'reportForInspection', // name: 'ReportForInspection', // component: () => import('@/views/rawMaterials/reportForInspection/index'), // meta: { title: '成品送检登记', icon: 'table' } // }, // { // path: 'print', // name: 'Print', // component: () => import('@/views/rawMaterials/print/index'), // meta: { title: '条码打印', icon: 'tree' } // }, // { // path: 'planAssignments', // name: 'PlanAssignments', // component: () => import('@/views/rawMaterials/planAssignments/index'), // meta: { title: '检验计划分配', icon: 'tree' } // }, // { // path: 'rawMaterialInspection', // name: 'RawMaterialInspection', // component: () => import('@/views/rawMaterials/rawMaterialInspection/index'), // meta: { title: '成品检验', icon: 'tree' } // }, // { // path: 'checkTheReport', // name: 'CheckTheReport', // component: () => import('@/views/rawMaterials/checkTheReport/index'), // meta: { title: '检验报告', icon: 'tree' } // }, // { // path: 'reportAuditing', // name: 'ReportAuditing', // component: () => import('@/views/rawMaterials/reportAuditing/index'), // meta: { title: '报告审核', icon: 'tree' } // }, // { // path: 'nonConformanceReview', // name: 'NonConformanceReview', // component: () => import('@/views/rawMaterials/nonConformanceReview/index'), // meta: { title: '不合格反馈', icon: 'tree' } // }, // { // path: 'nonConformingFeedback', // name: 'NonConformingFeedback', // component: () => import('@/views/rawMaterials/nonConformingFeedback/index'), // meta: { title: '不合格评审', icon: 'tree' } // }, // { // path: 'passRateStatistics', // name: 'PassRateStatistics', // component: () => import('@/views/rawMaterials/passRateStatistics/index'), // meta: { title: '合格率统计', icon: 'tree' } // } // ] // }, { path: '/laboratory', component: Layout, redirect: '/laboratory/ledger', name: 'Laboratory', meta: { title: '实验室管理', icon: 'el-icon-s-help' }, children: [ { path: 'ledger', name: 'Ledger', component: () => import('@/views/laboratory/ledger/index'), meta: { title: '设备台账', icon: 'table' } }, { path: 'measure', name: 'Measure', component: () => import('@/views/laboratory/measure/index'), meta: { title: '计量管理', icon: 'tree' } }, { path: 'gather', name: 'Gather', component: () => import('@/views/laboratory/gather/index'), meta: { title: '设备采集', icon: 'tree' } }, { path: 'personnel', name: 'Personnel', component: () => import('@/views/laboratory/personnel/index'), meta: { title: '人员管理', icon: 'tree' } }, { path: 'org', name: 'Organizational', component: () => import('@/views/laboratory/organizational/index.vue'), meta: { title: '组织架构', icon: 'tree' } }, { path: 'role', name: 'Role', component: () => import('@/views/laboratory/role/index'), meta: { title: '角色管理', icon: 'tree' } } ] }, { path: '/CNAS', component: Layout, redirect: '/CNAS/reviewAnnualPlan', name: 'CNAS', meta: { title: 'CNAS管理', icon: 'el-icon-s-help' }, children: [ { path: 'reviewAnnualPlan', name: 'ReviewAnnualPlan', component: () => import('@/views/CNAS/reviewAnnualPlan/index'), meta: { title: '审核年度计划', icon: 'table' } }, { path: 'nonConformanceManage', name: 'NonConformanceManage', component: () => import('@/views/CNAS/nonConformanceManage/index'), meta: { title: '不符合项管理', icon: 'tree' } }, { path: 'nonConformanceStatistics', name: 'NonConformanceStatistics', component: () => import('@/views/CNAS/nonConformanceStatistics/index'), meta: { title: '不符合项统计', icon: 'tree' } }, { path: 'satisfactionSurveys', name: 'SatisfactionSurveys', component: () => import('@/views/CNAS/satisfactionSurveys/index'), meta: { title: '满意度调查', icon: 'tree' } } ] }, { path: '/chart', component: Layout, redirect: '/chart/center', name: 'Chart', meta: { title: '智能图表', icon: 'el-icon-s-help' }, children: [ { path: 'center', name: 'center', component: () => import('@/views/chart/center/index'), meta: { title: '实验中心', icon: 'table' } }, { path: 'spc', name: 'Spc', component: () => import('@/views/chart/spc/index'), meta: { title: 'SPC控制图', icon: 'tree' } }, { path: 'shota', name: 'Shota', component: () => import('@/views/chart/shota/index'), meta: { title: '正太分布图', icon: 'tree' } }, { path: 'work', name: 'Work', component: () => import('@/views/chart/work/index'), meta: { title: '工作统计', icon: 'tree' } } ] }, { path: '/message', component: Layout, redirect: '/message/toDo', name: 'Message', meta: { title: '消息待办', icon: 'el-icon-s-help' }, children: [ { path: 'toDo', name: 'ToDo', component: () => import('@/views/message/toDo/index'), meta: { title: '我的待办', icon: 'tree' } }, { path: 'message', name: 'Message', // hidden: true, component: () => import('@/views/message/message/index'), // meta: { title: '我的消息', icon: 'table' } }, ] }, { path: '/personal', component: Layout, redirect: '/personal/myInformation', name: 'Personal', meta: { title: '个人管理', icon: 'el-icon-s-help' }, children: [ { path: 'myInformation', name: 'MyInformation', component: () => import('@/views/personal/myInformation/index'), meta: { title: '我的信息', icon: 'table' } }, { path: 'myBusiness', name: 'MyBusiness', component: () => import('@/views/personal/myBusiness/index'), meta: { title: '我的企业', icon: 'tree', show: false } } ] }, { path: '/baseData', component: Layout, redirect: '/baseData/basicDataMessage', name: 'BaseData', meta: { title: '基础数据', icon: 'el-icon-s-tools' }, children: [ { path: 'basicDataMessage', name: 'BasicDataMessage', component: () => import('@/views/basicData/index'), meta: { title: '基础数据', icon: 'el-icon-s-tools' } } ] }, { path: '*', redirect: '/404', hidden: true } ] return constantRoutes } const baseRouter = [{ path: '/login', component: () => import('@/views/login/index'), hidden: true }, { path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/addCommision', component: () => import('@/views/inspectionManagement/commissionInspection/addCommision'), hidden: true }, { path: '/', component: Layout, redirect: '/home', // meta: { title: '主页', icon: 'el-icon-s-home' }, children: [{ path: 'home', name: 'Home', component: () => import('@/views/home/index'), meta: { title: '主页', icon: 'el-icon-s-home' } }] }, { path: '/addCommision/:viewId', hidden: true, component: () => import('@/views/inspectionManagement/commissionInspection/addCommision'), }] function fn3(tempArr) { let result = []; let obj = {}; for (let i = 0; i < tempArr.length; i++) { if (!obj[tempArr[i].path]) { result.push(tempArr[i]); obj[tempArr[i].path] = true; }; }; return result; }; function createRouter(Routees) { if (JSON.parse(sessionStorage.getItem("user")) != undefined && JSON.parse(sessionStorage.getItem("user")) != null) { let sessionLayerId = JSON.parse(sessionStorage.getItem("user")).sessionLayerId if (sessionLayerId != 'f5c8bcb7d5a0fd27e2323280f7e98cad') { let role = JSON.parse(sessionStorage.getItem("user")).role let menuFather = baseRouter const dataMenuFather = fn3(menuFather) role.roleMenuList.forEach((r) => { dataMenuFather.push(Routees.filter(item => { return item.path === r.menuUrl })[0]) }) let eqChildren = []; role.roleMenuList.forEach((r) => { dataMenuFather.forEach(m => { if (r.menuUrl === m.path) { r.children.forEach(rc => { m.children.forEach(mc => { if (mc.meta != undefined) { eqChildren.push({ "path": mc.path, "meta": JSON.parse(JSON.stringify(mc.meta)) }) delete mc["meta"] } }) }) } }) }) let once = [] role.roleMenuList.forEach((r) => { r.children.forEach(rc => { eqChildren.forEach(eq => { if (eq != undefined) { if (eq.path == rc.menuUrl.split("/")[1]) { once.push(eq) } } }) }) }) dataMenuFather.forEach(m => { let i = 0 if (m.children != undefined) { m.children.forEach(mc => { once.forEach(eq => { if (eq != undefined) { if (mc.path == eq.path) { if (i === 0) { m.redirect = m.path + "/" + eq.path } i++; mc.meta = eq.meta } } }) }) } }) dataMenuFather.push({ path: '*', redirect: '/404', hidden: true }) dataMenuFather.push() Routees = dataMenuFather } } else { Routees = baseRouter } return new Router({ mode: 'history', // require service support scrollBehavior: () => ({ y: 0 }), routes: Routees }) } let router = createRouter(getRoutes()) // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 export async function resetRouter() { let newRouter = createRouter(getRoutes()) router.matcher = newRouter.matcher } router.beforeEach((to, from, next) => { /** * 委托新增 放行 */ if (to.path.indexOf("/addCommision/") === 0) { next() return } // 1. 判断是不是登录页面 // 是登录页面 if (to.path === '/login') { next() } else { // 不是登录页面 // 2. 判断 是否登录过 let token = sessionStorage.getItem('user') if (token != null && token != undefined) { resetRouter() } token ? next() : next('/login') } }) export default router