index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import Vue from 'vue';
  2. import Router from 'vue-router';
  3. import store from '../store'
  4. import menu from '../menu/menu.js'
  5. import { getToken } from '@/utils/auth'; // get token from cookie
  6. Vue.use(Router);
  7. /* Layout */
  8. import Layout from '@/layout';
  9. import AppMain from '@/layout/components/AppMain.vue';
  10. /**
  11. * Note: sub-menu only appear when route children.length >= 1
  12. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  13. *
  14. * hidden: true if set true, item will not show in the sidebar(default is false)
  15. * alwaysShow: true if set true, will always show the root menu
  16. * if not set alwaysShow, when item has more than one children route,
  17. * it will becomes nested mode, otherwise not show the root menu
  18. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  19. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  20. * meta : {
  21. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  22. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  23. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  24. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  25. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  26. }
  27. */
  28. /**
  29. * constantRoutes
  30. * a base page that does not have permission requirements
  31. * all roles can be accessed
  32. */
  33. export const constantRoutes = [
  34. {
  35. path: '/login',
  36. component: () => import('@/views/login/index'),
  37. hidden: true,
  38. },
  39. {
  40. path: '/404',
  41. component: () => import('@/views/404'),
  42. hidden: true,
  43. },
  44. {
  45. path: '/',
  46. component: Layout,
  47. redirect: '/dashboard',
  48. children: [
  49. {
  50. path: 'dashboard',
  51. name: 'Dashboard',
  52. component: () => import('@/views/dashboard/index'),
  53. meta: { title: '首页', icon: 'dashboard' },
  54. },
  55. //全病历质控
  56. {
  57. path: '/caseNumber',
  58. name: 'caseNumber',
  59. component: () => import('@/views/allcase/caseNumber'),
  60. hidden: true, //不在导航栏展示
  61. meta: { title: '病案数量' },
  62. },
  63. {
  64. path: '/defectNumber',
  65. name: 'defectNumber',
  66. component: () => import('@/views/allcase/defectNumber'),
  67. hidden: true,//不在导航栏展示
  68. meta: { title: '缺陷病案'},
  69. },
  70. {
  71. path: '/homePage',
  72. name: 'homePage',
  73. component: () => import('@/views/allcase/homePage'),
  74. hidden: true,//不在导航栏展示
  75. meta: { title: '出院记录'},
  76. },
  77. {
  78. path: '/caseViews',
  79. name: 'caseViews',
  80. component: () => import('@/views/allcase/caseViews'),
  81. hidden: true,//不在导航栏展示
  82. meta: { title: '出院记录'},
  83. },
  84. //首页数据质控
  85. {
  86. path: '/defectList',
  87. name: 'defectList',
  88. component: () => import('@/views/data/medicalRecords/defectList'),
  89. hidden: true,//不在导航栏展示
  90. meta: { title: '质量分析缺陷病案', keepAlive:true }
  91. },
  92. {
  93. path: '/medicalRecords',
  94. name: 'medicalRecords',
  95. component: () => import('@/views/data/medicalRecords'),
  96. hidden: true, //不在导航栏展示
  97. meta: { title: '质量分析病案数量',keepAlive:true }
  98. },
  99. {
  100. path: '/errorList',
  101. name: 'errorList',
  102. component: () => import('@/views/data/medicalRecords/errorList'),
  103. hidden: true, //不在导航栏展示
  104. meta: { title: '病案数' }
  105. },
  106. {
  107. path: '/department',
  108. name: 'department',
  109. component: () => import('@/views/data/medicalRecords/department'),
  110. hidden: true, //不在导航栏展示
  111. meta: { title: '总缺陷'}
  112. },
  113. {
  114. path: '/TotalRankingList',
  115. name: 'TotalRankingList',
  116. component: () => import('@/views/data/frontHome/TotalRankingList'),
  117. hidden: true, //不在导航栏展示
  118. meta: { title: '总排名' },
  119. },
  120. {
  121. path: '/codeList',
  122. name: 'codeList',
  123. component: () => import('@/views/data/medicalRecords/codeList'),
  124. hidden: true, //不在导航栏展示
  125. meta: { title: '编码员' }
  126. },
  127. {
  128. path: '/details',
  129. name: 'details',
  130. component: () => import('@/views/data/query/details'),
  131. hidden: true, //不在导航栏展示
  132. meta: { title: '病案首页质控详情' }
  133. },
  134. {
  135. path: '/ChargeDetails',
  136. name: 'ChargeDetails',
  137. hidden: true, //不在导航栏展示
  138. component: () => import('@/views/data/query/ChargeDetails'),
  139. meta: { title: '费用明细' }
  140. },
  141. {
  142. path: '/StatementList',
  143. name: 'StatementList',
  144. component: () => import('@/views/SettlementList/StatementList'),
  145. hidden: true,//不在导航栏展示
  146. meta: { title: '结算清单数量'}
  147. },
  148. // 医保结算清单
  149. {
  150. path: '/SetDetails',
  151. name: 'SetDetails',
  152. component: () => import('@/views/SettlementList/SetDetails'),
  153. hidden: true,//不在导航栏展示
  154. meta: { title: '医保结算单病案数量' }
  155. },
  156. {
  157. path: '/StatementListquery',
  158. name: 'StatementListquery',
  159. component: () => import('@/views/SettlementList/StatementListquery'),
  160. hidden: true,//不在导航栏展示
  161. meta: { title: '医保结算单病案数量'}
  162. },
  163. {
  164. path: '/defectStatementList',
  165. name: 'defectStatementList',
  166. hidden: true,//不在导航栏展示
  167. component: () => import('@/views/SettlementList/defectStatementList'),
  168. meta: { title: '缺陷结算清单数量'}
  169. },
  170. {
  171. path: '/caseIndex',
  172. name: 'caseIndex',
  173. component: () => import('@/views/allcase/caseIndex'),
  174. hidden: true,
  175. meta: { title: '病案指标', keepAlive:true},
  176. },
  177. {
  178. path: '/caseIndexList',
  179. name: 'caseIndexList',
  180. component: () => import('@/views/allcase/caseIndexList'),
  181. hidden: true,
  182. meta: { title: '指标列表', keepAlive:true },
  183. },
  184. {
  185. path: '/caseIndexAnalysis',
  186. name: 'CaseIndexAnalysis',
  187. component: () => import('@/views/allcase/caseIndexAnalysis'),
  188. hidden: true,
  189. meta: { title: '指标分析', keepAlive:true },
  190. },
  191. {
  192. path: '/caseIndexAnalysisList',
  193. name: 'CaseIndexAnalysisList',
  194. component: () => import('@/views/allcase/caseIndexAnalysisList'),
  195. hidden: true,
  196. meta: { title: '指标分析-科室详情' },
  197. },
  198. {
  199. path: '/searchSystem',
  200. name: 'SearchSystem',
  201. component: () => import('@/views/searchSystem/index'),
  202. hidden: true,
  203. meta: { title: '医院大数据自助查询系统', keepAlive:true, icon: 'dashboard' },
  204. },
  205. ],
  206. },
  207. // 医院大数据自助查询系统
  208. {
  209. path: '/hospital',
  210. component: AppMain,
  211. redirect: '/hospital-search',
  212. children: [
  213. {
  214. path: '/hospital-search',
  215. name: 'HospitalSearch',
  216. component: () => import('@/views/searchSystem/index'),
  217. meta: { keepAlive:true },
  218. hidden: true
  219. },
  220. {
  221. path: '/hospital-caseViews',
  222. name: 'HospitalCaseViews',
  223. component: () => import('@/views/allcase/caseViews'),
  224. hidden: true
  225. },
  226. {
  227. path: '/hospital-details',
  228. name: 'HospitalDetails',
  229. component: () => import('@/views/data/query/details'),
  230. hidden: true
  231. },
  232. {
  233. path: '/hospital-chargeDetails',
  234. name: 'HospitalChargeDetails',
  235. hidden: true,
  236. component: () => import('@/views/data/query/ChargeDetails')
  237. },
  238. ]
  239. },
  240. {
  241. path: '/embedIndex',
  242. component: AppMain,
  243. redirect: '/embedIndex-home',
  244. children: [
  245. {
  246. path: '/embedIndex-home',
  247. name: 'EmbedIndexHome',
  248. component: () => import('@/views/embedIndex/index'),
  249. meta: { keepAlive:true },
  250. hidden: true
  251. }
  252. ]
  253. },
  254. ];
  255. const createRouter = () =>
  256. new Router({
  257. // mode: 'history', // require service support
  258. scrollBehavior: () => ({ y: 0 }),
  259. routes: constantRoutes,
  260. });
  261. const router = createRouter();
  262. const whiteList = ['/login','/404']; // 添加路由白名单
  263. //路由判断
  264. router.beforeEach(async (to, from, next) => {
  265. const hasToken = getToken();
  266. if(hasToken){
  267. if (!store.state.user.menu.length) {
  268. // 判断当前用户是否已拉取完权限菜单信息
  269. // 如果本地不存在权限菜单,则获取权限菜单,生成菜单列表
  270. if(!sessionStorage.getItem("route")){
  271. //获取路由菜单
  272. menu.getMenu().then(response =>{
  273. //保险起见,组装一次数据
  274. menu.parseRoute(JSON.parse(sessionStorage.getItem("route")),[]).then(res =>{
  275. //添加路由并进行跳转
  276. menu.addMenu(res).then(e =>{
  277. next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  278. })
  279. })
  280. }).catch(err =>{//失败则直接跳转登录页面
  281. next(`/login?redirect=${to.path}`);
  282. })
  283. }else{//从缓存中读取用户权限列表,并添加菜单到侧边栏和路由元
  284. menu.parseRoute(JSON.parse(sessionStorage.getItem("route")),[]).then(res =>{
  285. menu.addMenu(res).then(e =>{
  286. next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  287. })
  288. })
  289. }
  290. }else{
  291. // 有路由表直接放行
  292. next();
  293. }
  294. }else{
  295. if (whiteList.indexOf(to.path) !== -1) {
  296. // 在白名单内直接放行
  297. next();
  298. } else {
  299. console.log('1')
  300. // 其他没有访问权限的页面将被重定向到登录页面。
  301. next(`/login?redirect=${to.path}`);
  302. }
  303. }
  304. if(to.path == from.path ){
  305. // 让 列表页 即不缓存,刷新
  306. to.meta.keepAlive = false;
  307. }
  308. next()
  309. })
  310. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  311. export function resetRouter() {
  312. const newRouter = createRouter();
  313. router.matcher = newRouter.matcher; // reset router
  314. }
  315. export default router;