index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import utils from '@/libs/utils'
  4. // import Home from '../views/Home.vue'
  5. const Login = ()=>import("@/login/Login.vue")
  6. const DownAllQualityReport = ()=>import("@/login/DownAllQualityReport.vue")
  7. const DownAppQualityReport = ()=>import("@/login/DownAppQualityReport.vue")
  8. const MainPage = ()=>import('@/views/MainPage.vue')
  9. const HomePage = ()=>import('@/views/homecomponents/HomePage.vue')
  10. const EquipmentMonitor = ()=>import('@/views/homecomponents/EquipmentAnalysis/EquipmentMonitor.vue')
  11. const AlarmMonitor = ()=>import('@/views/homecomponents/EquipmentAnalysis/AlarmMonitor.vue')
  12. const AlarmHandling = ()=>import('@/views/homecomponents/EquipmentAnalysis/AlarmHandling.vue')
  13. const PolicyConfigManage = ()=>import('@/views/homecomponents/EquipmentAnalysis/PolicyConfigManage.vue')
  14. const ComprehensiveQuery = ()=>import('@/views/homecomponents/EquipmentAnalysis/ComprehensiveQuery.vue')
  15. const LineStationManage = ()=>import('@/views/homecomponents/BasicInfomation/LineStationManage.vue')
  16. const ApplicationManage = ()=>import('@/views/homecomponents/BasicInfomation/ApplicationManage.vue')
  17. const DeviceManage = ()=>import('@/views/homecomponents/BasicInfomation/DeviceManage.vue')
  18. const InstruManage = ()=>import('@/views/homecomponents/BasicInfomation/InstruManage.vue')
  19. const OperaTimeManage = ()=>import('@/views/homecomponents/BasicInfomation/OperaTimeManage.vue')
  20. const Organization = ()=>import('@/views/homecomponents/SystemSettings/Organization.vue')
  21. const UserManagement = ()=>import('@/views/homecomponents/SystemSettings/UserManagement.vue')
  22. const RolePermissions = ()=>import('@/views/homecomponents/SystemSettings/RolePermissions.vue')
  23. const ResourceManagement = ()=>import('@/views/homecomponents/SystemSettings/ResourceManagement.vue')
  24. const OperationLog = ()=>import('@/views/homecomponents/SystemSettings/OperationLog.vue')
  25. const DataMonitor = ()=>import('@/views/homecomponents/DataManagement/DataMonitor.vue')
  26. const DataRules = ()=>import('@/views/homecomponents/DataManagement/DataRules.vue')
  27. const DataReport = ()=>import('@/views/homecomponents/DataManagement/DataReport.vue')
  28. Vue.use(VueRouter)
  29. const routes = [
  30. {
  31. path: '/',
  32. name: 'Login',
  33. component: Login,
  34. },
  35. {
  36. path: '/login/DownAllQualityReport',
  37. name: 'DownAllQualityReport',
  38. component: DownAllQualityReport,
  39. },
  40. {
  41. path: '/login/DownAppQualityReport',
  42. name: 'DownAppQualityReport',
  43. component: DownAppQualityReport,
  44. },
  45. {
  46. path: '/MainPage',
  47. component: MainPage,
  48. meta: { Auth: true }, // 添加该字段,表示进入这个路由是需要登录的
  49. beforeEnter: (to, from, next) => {
  50. if (!utils.storage('sw_user')) {
  51. next({ path: '/login' })
  52. return false
  53. }
  54. next()
  55. },
  56. children: [
  57. // 首页
  58. {
  59. path: '',
  60. name: 'HomePage',
  61. component: HomePage,
  62. },
  63. // 设备分析
  64. {
  65. path: 'EquipmentMonitor',
  66. name: 'EquipmentMonitor',
  67. component: EquipmentMonitor
  68. },
  69. {
  70. path: 'AlarmMonitor',
  71. name: 'AlarmMonitor',
  72. component: AlarmMonitor
  73. },
  74. {
  75. path: 'AlarmHandling',
  76. name: 'AlarmHandling',
  77. component: AlarmHandling
  78. },
  79. {
  80. path: 'PolicyConfigManage',
  81. name: 'PolicyConfigManage',
  82. component: PolicyConfigManage
  83. },
  84. {
  85. path: 'ComprehensiveQuery',
  86. name: 'ComprehensiveQuery',
  87. component: ComprehensiveQuery
  88. },
  89. // 基础信息
  90. {
  91. path: 'LineStationManage',
  92. name: 'LineStationManage',
  93. component: LineStationManage
  94. },
  95. {
  96. path: 'ApplicationManage',
  97. // path: '/MainPage/ApplicationManage/:type?',
  98. name: 'ApplicationManage',
  99. component: ApplicationManage
  100. },
  101. {
  102. path: 'DeviceManage',
  103. name: 'DeviceManage',
  104. component: DeviceManage
  105. },
  106. {
  107. path: 'InstruManage',
  108. name: 'InstruManage',
  109. component: InstruManage
  110. },
  111. {
  112. path: 'OperaTimeManage',
  113. name: 'OperaTimeManage',
  114. component: OperaTimeManage
  115. },
  116. //系统设置
  117. {
  118. path: 'Organization',
  119. name: 'Organization',
  120. component: Organization
  121. },
  122. {
  123. path: 'UserManagement',
  124. name: 'UserManagement',
  125. component: UserManagement
  126. },
  127. {
  128. path: 'RolePermissions',
  129. name: 'RolePermissions',
  130. component: RolePermissions
  131. },
  132. {
  133. path: 'ResourceManagement',
  134. name: 'ResourceManagement',
  135. component: ResourceManagement
  136. },
  137. {
  138. path: 'OperationLog',
  139. name: 'OperationLog',
  140. component: OperationLog
  141. },
  142. // 数据管理
  143. {
  144. path: 'DataMonitor',
  145. name: 'DataMonitor',
  146. component: DataMonitor
  147. },
  148. {
  149. path: 'DataRules',
  150. name: 'DataRules',
  151. component: DataRules
  152. },
  153. {
  154. path: 'DataReport',
  155. name: 'DataReport',
  156. component: DataReport
  157. },
  158. // {
  159. // path: 'BasicInfomation',
  160. // component: BasicInfomation,
  161. // children: [{
  162. // path: '',
  163. // name: 'StationManage',
  164. // component: StationManage
  165. // },
  166. // {
  167. // path: 'employee_search',
  168. // name: 'MoreSearch',
  169. // component: MoreSearch
  170. // }
  171. // ]
  172. // },
  173. ]
  174. },
  175. { path: '*', redirect: '/' }
  176. ]
  177. // const router = new VueRouter({
  178. // routes
  179. // })
  180. // 3. 创建 router 实例,然后传 `routes` 配置
  181. const router = new VueRouter({
  182. // mode: 'history',
  183. base: process.env.BASE_URL,
  184. routes,
  185. scrollBehavior(to, from, savedPosition) {
  186. return { x: 0, y: 0 }
  187. }
  188. })
  189. //全局前置守卫
  190. router.beforeEach(function (to, from, next) {
  191. const isAuth = to.matched.some(m => m.meta.Auth)
  192. if (isAuth) {
  193. const isLogin = utils.storage('sw_user')
  194. if (!isLogin) {
  195. next({path: '/login'})
  196. }
  197. // window._axiosPromiseArr.forEach((ele,index) => {
  198. // ele.cancel() // 路由跳转之前,清空(终止)上一个页面正在请求的内容
  199. // // 清空请求的参数 清空请求的参数
  200. // delete window._axiosPromiseArr[index]
  201. // })
  202. }
  203. next()
  204. })
  205. // 解决 Vue 重复点击相同路由 出现 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation 问题
  206. const originalPush = VueRouter.prototype.push
  207. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  208. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  209. return originalPush.call(this, location).catch(err => err)
  210. }
  211. export default router