import Vue from 'vue'; import Router from 'vue-router'; import store from '../store' import menu from '../menu/menu.js' import { getToken } from '@/utils/auth'; // get token from cookie Vue.use(Router); /* Layout */ import Layout from '@/layout'; import AppMain from '@/layout/components/AppMain.vue'; /** * 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 */ export const constantRoutes = [ { path: '/login', component: () => import('@/views/login/index'), hidden: true, }, { path: '/404', component: () => import('@/views/404'), hidden: true, }, { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', name: 'Dashboard', component: () => import('@/views/dashboard/index'), meta: { title: '首页', icon: 'dashboard' }, }, //全病历质控 { path: '/caseNumber', name: 'caseNumber', component: () => import('@/views/allcase/caseNumber'), hidden: true, //不在导航栏展示 meta: { title: '病案数量' }, }, { path: '/defectNumber', name: 'defectNumber', component: () => import('@/views/allcase/defectNumber'), hidden: true,//不在导航栏展示 meta: { title: '缺陷病案'}, }, { path: '/homePage', name: 'homePage', component: () => import('@/views/allcase/homePage'), hidden: true,//不在导航栏展示 meta: { title: '出院记录'}, }, { path: '/caseViews', name: 'caseViews', component: () => import('@/views/allcase/caseViews'), hidden: true,//不在导航栏展示 meta: { title: '出院记录'}, }, //首页数据质控 { path: '/defectList', name: 'defectList', component: () => import('@/views/data/medicalRecords/defectList'), hidden: true,//不在导航栏展示 meta: { title: '质量分析缺陷病案', keepAlive:true } }, { path: '/medicalRecords', name: 'medicalRecords', component: () => import('@/views/data/medicalRecords'), hidden: true, //不在导航栏展示 meta: { title: '质量分析病案数量',keepAlive:true } }, { path: '/errorList', name: 'errorList', component: () => import('@/views/data/medicalRecords/errorList'), hidden: true, //不在导航栏展示 meta: { title: '病案数' } }, { path: '/department', name: 'department', component: () => import('@/views/data/medicalRecords/department'), hidden: true, //不在导航栏展示 meta: { title: '总缺陷'} }, { path: '/TotalRankingList', name: 'TotalRankingList', component: () => import('@/views/data/frontHome/TotalRankingList'), hidden: true, //不在导航栏展示 meta: { title: '总排名' }, }, { path: '/codeList', name: 'codeList', component: () => import('@/views/data/medicalRecords/codeList'), hidden: true, //不在导航栏展示 meta: { title: '编码员' } }, { path: '/details', name: 'details', component: () => import('@/views/data/query/details'), hidden: true, //不在导航栏展示 meta: { title: '病案首页质控详情' } }, { path: '/ChargeDetails', name: 'ChargeDetails', hidden: true, //不在导航栏展示 component: () => import('@/views/data/query/ChargeDetails'), meta: { title: '费用明细' } }, { path: '/StatementList', name: 'StatementList', component: () => import('@/views/SettlementList/StatementList'), hidden: true,//不在导航栏展示 meta: { title: '结算清单数量'} }, // 医保结算清单 { path: '/SetDetails', name: 'SetDetails', component: () => import('@/views/SettlementList/SetDetails'), hidden: true,//不在导航栏展示 meta: { title: '医保结算单病案数量' } }, { path: '/StatementListquery', name: 'StatementListquery', component: () => import('@/views/SettlementList/StatementListquery'), hidden: true,//不在导航栏展示 meta: { title: '医保结算单病案数量'} }, { path: '/defectStatementList', name: 'defectStatementList', hidden: true,//不在导航栏展示 component: () => import('@/views/SettlementList/defectStatementList'), meta: { title: '缺陷结算清单数量'} }, { path: '/caseIndex', name: 'caseIndex', component: () => import('@/views/allcase/caseIndex'), hidden: true, meta: { title: '病案指标', keepAlive:true}, }, { path: '/caseIndexList', name: 'caseIndexList', component: () => import('@/views/allcase/caseIndexList'), hidden: true, meta: { title: '指标列表', keepAlive:true }, }, { path: '/caseIndexAnalysis', name: 'CaseIndexAnalysis', component: () => import('@/views/allcase/caseIndexAnalysis'), hidden: true, meta: { title: '指标分析', keepAlive:true }, }, { path: '/caseIndexAnalysisList', name: 'CaseIndexAnalysisList', component: () => import('@/views/allcase/caseIndexAnalysisList'), hidden: true, meta: { title: '指标分析-科室详情' }, }, { path: '/searchSystem', name: 'SearchSystem', component: () => import('@/views/searchSystem/index'), hidden: true, meta: { title: '医院大数据自助查询系统', keepAlive:true, icon: 'dashboard' }, }, ], }, // 医院大数据自助查询系统 { path: '/hospital', component: AppMain, redirect: '/hospital-search', children: [ { path: '/hospital-search', name: 'HospitalSearch', component: () => import('@/views/searchSystem/index'), meta: { keepAlive:true }, hidden: true }, { path: '/hospital-caseViews', name: 'HospitalCaseViews', component: () => import('@/views/allcase/caseViews'), hidden: true }, { path: '/hospital-details', name: 'HospitalDetails', component: () => import('@/views/data/query/details'), hidden: true }, { path: '/hospital-chargeDetails', name: 'HospitalChargeDetails', hidden: true, component: () => import('@/views/data/query/ChargeDetails') }, ] }, { path: '/embedIndex', component: AppMain, redirect: '/embedIndex-home', children: [ { path: '/embedIndex-home', name: 'EmbedIndexHome', component: () => import('@/views/embedIndex/index'), meta: { keepAlive:true }, hidden: true } ] }, ]; const createRouter = () => new Router({ // mode: 'history', // require service support scrollBehavior: () => ({ y: 0 }), routes: constantRoutes, }); const router = createRouter(); const whiteList = ['/login','/404']; // 添加路由白名单 //路由判断 router.beforeEach(async (to, from, next) => { const hasToken = getToken(); if(hasToken){ if (!store.state.user.menu.length) { // 判断当前用户是否已拉取完权限菜单信息 // 如果本地不存在权限菜单,则获取权限菜单,生成菜单列表 if(!sessionStorage.getItem("route")){ //获取路由菜单 menu.getMenu().then(response =>{ //保险起见,组装一次数据 menu.parseRoute(JSON.parse(sessionStorage.getItem("route")),[]).then(res =>{ //添加路由并进行跳转 menu.addMenu(res).then(e =>{ next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 }) }) }).catch(err =>{//失败则直接跳转登录页面 next(`/login?redirect=${to.path}`); }) }else{//从缓存中读取用户权限列表,并添加菜单到侧边栏和路由元 menu.parseRoute(JSON.parse(sessionStorage.getItem("route")),[]).then(res =>{ menu.addMenu(res).then(e =>{ next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 }) }) } }else{ // 有路由表直接放行 next(); } }else{ if (whiteList.indexOf(to.path) !== -1) { // 在白名单内直接放行 next(); } else { console.log('1') // 其他没有访问权限的页面将被重定向到登录页面。 next(`/login?redirect=${to.path}`); } } if(to.path == from.path ){ // 让 列表页 即不缓存,刷新 to.meta.keepAlive = false; } next() }) // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 export function resetRouter() { const newRouter = createRouter(); router.matcher = newRouter.matcher; // reset router } export default router;