123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- import Vue from 'vue'
- import Router from 'vue-router'
- import page from '@/config/page'
- import store from '@/vendors/vuex'
- import { renewalHead } from '@/model/indexRx'
- 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' },
- children: [
- {
- path: 'home',
- component: () => page('home'),
- name: 'home',
- meta: { title: 'home', icon: '-index-copy', affix: true, auth: 'homePage' },
- 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) => {
- // 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
- ) {
- sessionStorage.setItem(
- 'ws-pf_moduleName',
- to.matched[1].parent.meta.title
- )
- } else {
- sessionStorage.setItem('ws-pf_moduleName', to.meta.title)
- }
- if (to.meta.module || to.meta.auth) {
- sessionStorage.setItem('ws-pf_authority', to.meta.auth || to.meta.module)
- }
- }
- sessionStorage.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(() => {
- next()
- })
- } else {
- next()
- }
- })
- export default router
|