index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import page from '@/config/page'
  4. import store from '@/vendors/vuex'
  5. import { renewalHead } from '@/model/indexRx'
  6. import { clearStorage } from '../utils/auth'
  7. Vue.use(Router)
  8. // 组件实验室
  9. // const _Laboratory = () => import('@/components/base/_laboratory')
  10. /* Layout */
  11. import Layout from '../layout/index'
  12. /**
  13. * constantRoutes
  14. * 没有权限要求的基本页
  15. * 所有角色都可以访问
  16. * */
  17. export const constantRoutes = [
  18. {
  19. path: '/about',
  20. component: () => import('@/views/info/about'),
  21. hidden: true
  22. },
  23. {
  24. path: '/privacyAgreement',
  25. component: () => import('@/views/info/privacyAgreement'),
  26. hidden: true
  27. },
  28. {
  29. path: '/userAgreement',
  30. component: () => import('@/views/info/userAgreement'),
  31. hidden: true
  32. },
  33. {
  34. path: '/login',
  35. component: () =>
  36. import(/* webpackChunkName: "login" */ '@/views/login/index'),
  37. hidden: true
  38. },
  39. {
  40. path: '/ship_login',
  41. component: () =>
  42. import(/* webpackChunkName: "logindship" */ '@/views/login/index_ship'),
  43. hidden: true
  44. },
  45. {
  46. path: '/404',
  47. component: () => page('404'),
  48. hidden: true
  49. },
  50. {
  51. path: '/401',
  52. component: () =>
  53. import(/* webpackChunkName: "401" */ '@/views/errorPage/401'),
  54. hidden: true
  55. },
  56. {
  57. path: '/help',
  58. component: () => import('@/views/helpCenter/index'),
  59. hidden: true
  60. },
  61. {
  62. path: '/',
  63. component: Layout,
  64. redirect: { name: 'home' },
  65. meta: { title: 'home', icon: '-index-copy',showClick:true },
  66. children: [
  67. {
  68. path: 'home',
  69. component: () => page('home'),
  70. name: 'home',
  71. meta: { title: 'home', icon: '-index-copy', affix: true, auth: 'homePage',_title:'首页' },
  72. hidden: true
  73. }
  74. ]
  75. },
  76. {
  77. path: '/work',
  78. component: Layout,
  79. meta: {
  80. title: 'workNotification',
  81. icon: '-a-tongzhibeifen2'
  82. },
  83. name: 'work',
  84. children: [
  85. {
  86. path: 'work',
  87. component: () =>
  88. import(/* webpackChunkName: "work" */ '@/views/newTask/listPage'),
  89. name: 'workNotification',
  90. meta: {
  91. title: 'work',
  92. noCache: true,
  93. affix: true,
  94. auth: 'workTask',
  95. _title:'任务'
  96. },
  97. hidden: true
  98. },
  99. {
  100. path: 'message',
  101. component: () =>
  102. import(/* webpackChunkName: "message" */ '@/views/newTask/message'),
  103. name: 'message',
  104. meta: {
  105. title: 'message',
  106. noCache: true,
  107. affix: true,
  108. auth: 'workInformation',
  109. _title:'消息'
  110. },
  111. hidden: true
  112. }
  113. ],
  114. hidden: true
  115. }
  116. ]
  117. // process.env.NODE_ENV === 'development' &&
  118. // constantRoutes.push({ path: '/lab', name: '_Laboratory', component: _Laboratory })
  119. let cofigRouter = []
  120. const modulesFiles = require.context('../views', true, /.js$/)
  121. modulesFiles.keys().forEach((model_item, key) => {
  122. if (model_item === 'index.js' || modulesFiles(model_item).default === undefined || modulesFiles(model_item).default.path === undefined) return
  123. cofigRouter = cofigRouter.concat(modulesFiles(model_item).default)
  124. })
  125. // 需要根据用户角色动态加载的路由
  126. export const asyncRoutes = cofigRouter
  127. const createRouter = () =>
  128. new Router({
  129. // mode: 'history',
  130. scrollBehavior: () => ({
  131. y: 0
  132. }),
  133. linkActiveClass: 'active', // router-link .active样式
  134. routes: constantRoutes
  135. })
  136. const router = createRouter()
  137. export function resetRouter() {
  138. const newRouter = createRouter()
  139. router.matcher = newRouter.matcher // reset router
  140. }
  141. router.beforeEach(async (to, from, next) => {
  142. console.log(to,from,111111111111111111,store.getters.openRoute)
  143. var arr=store.getters.openRoute
  144. if(to.meta._title){
  145. var arr1=arr.find(function(item1,index,arr){
  146. return item1.title==to.meta._title
  147. });
  148. if(!arr1){
  149. console.log(to.meta._title)
  150. arr.push({title:to.meta._title,showClick:false,path:to.path,query: to.query})
  151. }
  152. for (let i = 0; i < arr.length; i++) {
  153. arr[i].showClick=false
  154. if(arr[i].title==to.meta._title){
  155. arr[i].showClick=true
  156. arr[i].query=to.query
  157. }
  158. }
  159. }
  160. // const { roles, isTrainDialog, guideInfo } = store.getters
  161. const { roles } = store.getters
  162. if (roles && roles.length && to.path !== '/help') {
  163. // if (Object.keys(guideInfo).length === 0) {
  164. // store.dispatch('user/getTrainInfo')
  165. // }
  166. // if (isTrainDialog.length === 0) {
  167. // store.dispatch('user/getNewLogin')
  168. // }
  169. if (
  170. to.matched[1] &&
  171. to.matched[1].parent &&
  172. to.matched[1].parent.meta &&
  173. to.matched[1].parent.meta.title
  174. ) {
  175. localStorage.setItem(
  176. 'ws-pf_moduleName',
  177. to.matched[1].parent.meta.title
  178. )
  179. } else {
  180. localStorage.setItem('ws-pf_moduleName', to.meta.title)
  181. }
  182. if (to.meta.module || to.meta.auth) {
  183. localStorage.setItem('ws-pf_authority', to.meta.auth || to.meta.module)
  184. }
  185. }
  186. localStorage.setItem('ws-pf_menuName', to.meta.title)
  187. const { baseInfo } = store.getters
  188. if (Object.keys(baseInfo).length === 0) {
  189. store.dispatch('user/getBaseInfo')
  190. }
  191. let data = {
  192. title: '',
  193. routingUri: ''
  194. }
  195. if (to.name && to.meta.shortcutEntrance) {
  196. if (to.meta.shortcutEntrance.indexOf(',') == -1) {
  197. if (to.name == 'knowledgeList' || to.name == 'dataManageMentList') {
  198. data.title = to.meta.shortcutEntrance
  199. } else {
  200. data.title = to.meta.shortcutEntrance + ',' + to.meta.title
  201. }
  202. if (to.path.split('/').length > 3 && to.path.split('/')[1] != 'crew') {
  203. data.routingUri = to.path
  204. .split('/')
  205. .slice(0, -1)
  206. .join('/')
  207. } else {
  208. data.routingUri = to.path
  209. }
  210. } else {
  211. data.title = to.meta.shortcutEntrance
  212. if (
  213. to.name != 'certificateList' &&
  214. to.name != 'impaMa' &&
  215. to.name != 'applyMa' &&
  216. to.name != 'shipMa' &&
  217. to.name != 'theLibraryMa' &&
  218. to.name != 'inventoryManagementMa'
  219. ) {
  220. data.routingUri =
  221. to.path.split('/').length > 2
  222. ? to.path
  223. .split('/')
  224. .slice(0, -1)
  225. .join('/')
  226. : to.path
  227. } else {
  228. data.routingUri = to.path
  229. }
  230. }
  231. renewalHead(data).toPromise().then(() => {
  232. console.log('paymentManagementReturn',localStorage.getItem('paymentManagementReturn'))
  233. if(to.name=='settlement'&&localStorage.getItem('paymentManagementReturn')=='true'){
  234. next(`/houseSelfCollect/paymentManagement`);
  235. }else{
  236. next()
  237. }
  238. })
  239. .catch((err) => {
  240. clearStorage()
  241. resetRouter()
  242. next(`/login?redirect=${to.path}`);
  243. })
  244. } else {
  245. data.routingUri = to.path
  246. next()
  247. }
  248. })
  249. export default router