123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- import Vue from 'vue'
- import Router from 'vue-router'
- import page from '@/config/page'
- import store from '@/vendors/vuex'
- import { renewalHead } from '@/model/indexRx'
- import { clearStorage } from '../utils/auth'
- Vue.use(Router)
- // 组件实验室
- // const _Laboratory = () => import('@/components/base/_laboratory')
- /* Layout */
- import Layout from '../layout/index'
- /**
- * constantRoutes
- * 没有权限要求的基本页
- * 所有角色都可以访问
- * */
- export const constantRoutes = [
- {
- path: '/about',
- component: () => import('@/views/info/about'),
- hidden: true
- },
- {
- path: '/privacyAgreement',
- component: () => import('@/views/info/privacyAgreement'),
- hidden: true
- },
- {
- path: '/userAgreement',
- component: () => import('@/views/info/userAgreement'),
- hidden: true
- },
- {
- path: '/login',
- component: () =>
- import(/* webpackChunkName: "login" */ '@/views/login/index'),
- hidden: true
- },
- {
- path: '/ship_login',
- component: () =>
- import(/* webpackChunkName: "logindship" */ '@/views/login/index_ship'),
- hidden: true
- },
- {
- path: '/404',
- component: () => page('404'),
- hidden: true
- },
- {
- path: '/401',
- component: () =>
- import(/* webpackChunkName: "401" */ '@/views/errorPage/401'),
- hidden: true
- },
- {
- path: '/help',
- component: () => import('@/views/helpCenter/index'),
- hidden: true
- },
- {
- path: '/',
- component: Layout,
- redirect: { name: 'home' },
- meta: { title: 'home', icon: '-index-copy',showClick:true },
- children: [
- {
- path: 'home',
- component: () => page('home'),
- name: 'home',
- meta: { title: 'home', icon: '-index-copy', affix: true, auth: 'homePage',_title:'首页' },
- hidden: true
- }
- ]
- },
- {
- path: '/work',
- component: Layout,
- meta: {
- title: 'workNotification',
- icon: '-a-tongzhibeifen2'
- },
- name: 'work',
- children: [
- {
- path: 'work',
- component: () =>
- import(/* webpackChunkName: "work" */ '@/views/newTask/listPage'),
- name: 'workNotification',
- meta: {
- title: 'work',
- noCache: true,
- affix: true,
- auth: 'workTask',
- _title:'任务'
- },
- hidden: true
- },
- {
- path: 'message',
- component: () =>
- import(/* webpackChunkName: "message" */ '@/views/newTask/message'),
- name: 'message',
- meta: {
- title: 'message',
- noCache: true,
- affix: true,
- auth: 'workInformation',
- _title:'消息'
- },
- hidden: true
- }
- ],
- hidden: true
- }
- ]
- // process.env.NODE_ENV === 'development' &&
- // constantRoutes.push({ path: '/lab', name: '_Laboratory', component: _Laboratory })
- let cofigRouter = []
- const modulesFiles = require.context('../views', true, /.js$/)
- modulesFiles.keys().forEach((model_item, key) => {
- if (model_item === 'index.js' || modulesFiles(model_item).default === undefined || modulesFiles(model_item).default.path === undefined) return
- cofigRouter = cofigRouter.concat(modulesFiles(model_item).default)
- })
- // 需要根据用户角色动态加载的路由
- export const asyncRoutes = cofigRouter
- const createRouter = () =>
- new Router({
- // mode: 'history',
- scrollBehavior: () => ({
- y: 0
- }),
- linkActiveClass: 'active', // router-link .active样式
- routes: constantRoutes
- })
- const router = createRouter()
- export function resetRouter() {
- const newRouter = createRouter()
- router.matcher = newRouter.matcher // reset router
- }
- router.beforeEach(async (to, from, next) => {
- console.log(to,from,111111111111111111,store.getters.openRoute)
- var arr=store.getters.openRoute
- if(to.meta._title){
- var arr1=arr.find(function(item1,index,arr){
- return item1.title==to.meta._title
- });
- if(!arr1){
- console.log(to.meta._title)
- arr.push({title:to.meta._title,showClick:false,path:to.path,query: to.query})
- }
- for (let i = 0; i < arr.length; i++) {
- arr[i].showClick=false
- if(arr[i].title==to.meta._title){
- arr[i].showClick=true
- arr[i].query=to.query
- }
- }
- }
-
- // const { roles, isTrainDialog, guideInfo } = store.getters
- const { roles } = store.getters
- if (roles && roles.length && to.path !== '/help') {
- // if (Object.keys(guideInfo).length === 0) {
- // store.dispatch('user/getTrainInfo')
- // }
- // if (isTrainDialog.length === 0) {
- // store.dispatch('user/getNewLogin')
- // }
- if (
- to.matched[1] &&
- to.matched[1].parent &&
- to.matched[1].parent.meta &&
- to.matched[1].parent.meta.title
- ) {
- localStorage.setItem(
- 'ws-pf_moduleName',
- to.matched[1].parent.meta.title
- )
- } else {
- localStorage.setItem('ws-pf_moduleName', to.meta.title)
- }
- if (to.meta.module || to.meta.auth) {
- localStorage.setItem('ws-pf_authority', to.meta.auth || to.meta.module)
- }
- }
- localStorage.setItem('ws-pf_menuName', to.meta.title)
- const { baseInfo } = store.getters
- if (Object.keys(baseInfo).length === 0) {
- store.dispatch('user/getBaseInfo')
- }
- let data = {
- title: '',
- routingUri: ''
- }
- if (to.name && to.meta.shortcutEntrance) {
- if (to.meta.shortcutEntrance.indexOf(',') == -1) {
- if (to.name == 'knowledgeList' || to.name == 'dataManageMentList') {
- data.title = to.meta.shortcutEntrance
- } else {
- data.title = to.meta.shortcutEntrance + ',' + to.meta.title
- }
- if (to.path.split('/').length > 3 && to.path.split('/')[1] != 'crew') {
- data.routingUri = to.path
- .split('/')
- .slice(0, -1)
- .join('/')
- } else {
- data.routingUri = to.path
- }
- } else {
- data.title = to.meta.shortcutEntrance
- if (
- to.name != 'certificateList' &&
- to.name != 'impaMa' &&
- to.name != 'applyMa' &&
- to.name != 'shipMa' &&
- to.name != 'theLibraryMa' &&
- to.name != 'inventoryManagementMa'
- ) {
- data.routingUri =
- to.path.split('/').length > 2
- ? to.path
- .split('/')
- .slice(0, -1)
- .join('/')
- : to.path
- } else {
- data.routingUri = to.path
- }
- }
- renewalHead(data).toPromise().then(() => {
- console.log('paymentManagementReturn',localStorage.getItem('paymentManagementReturn'))
- if(to.name=='settlement'&&localStorage.getItem('paymentManagementReturn')=='true'){
- next(`/houseSelfCollect/paymentManagement`);
- }else{
- next()
- }
- })
- .catch((err) => {
- clearStorage()
- resetRouter()
- next(`/login?redirect=${to.path}`);
- })
- } else {
- data.routingUri = to.path
- next()
- }
- })
- export default router
|