Commit 1dc7c8b2 by 吕海涛

增加业务配置

parent 654b6802
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import Layout from '@/layout' import Layout from '@/layout'
import {routerMode} from '@/config/index' import { routerMode } from '@/config/index'
import store from '@/store/index' import store from '@/store/index'
Vue.use(VueRouter) Vue.use(VueRouter)
...@@ -10,115 +10,153 @@ Vue.use(VueRouter) ...@@ -10,115 +10,153 @@ Vue.use(VueRouter)
* 静态路由 * 静态路由
* @type {({path: string, component: (function(): *), hidden: boolean}|{path: string, component: (function(): *), hidden: boolean, name: string}|{path: string, component: (function(): *), hidden: boolean, name: string})[]} * @type {({path: string, component: (function(): *), hidden: boolean}|{path: string, component: (function(): *), hidden: boolean, name: string}|{path: string, component: (function(): *), hidden: boolean, name: string})[]}
*/ */
export const currencyRoutes = [ export const currencyRoutes = [{
{ path: '/login',
path: '/login', component: () =>
component: () => import ( /* webpackChunkName: "login" */ '@/views/login/index.vue'),
import(/* webpackChunkName: "login" */ '@/views/login/index.vue'), hidden: true
hidden: true },
}, {
{ path: '/401',
path: '/401', name: '401',
name: '401', component: () =>
component: () => import('@/views/401'), import ('@/views/401'),
hidden: true hidden: true
}, },
{ {
path: '/404', path: '/404',
name: '404', name: '404',
component: () => import('@/views/404'), component: () =>
hidden: true import ('@/views/404'),
} hidden: true
}
] ]
/** /**
* 动态路由 * 动态路由
* @type {any} * @type {any}
*/ */
export const routes = [ export const routes = [{
{ path: '/',
path: '/', name: 'Company',
name: 'Company', component: Layout,
component: Layout, redirect: '/company',
redirect: '/company', meta: {
meta: { icon: 'el-icon-office-building',
icon: 'el-icon-office-building', title: '企业管理'
title: '企业管理' },
}, children: [{
children: [{ path: '/',
path: '/', name: 'CompanyInformation',
name: 'CompanyInformation', component: () =>
component: () => import ('@/views/dashboard/index.vue'),
import('@/views/dashboard/index.vue'), meta: {
meta: { title: '企业信息',
title: '企业信息', icon: 'el-icon-s-data'
icon: 'el-icon-s-data' }
} },
}] {
} path: 'department-information',
] name: 'DepartmentInformation',
component: () =>
import ('@/views/DepartmentInformation/index.vue'),
meta: { title: '部门管理', icon: 'el-icon-user-solid' }
},
]
}, {
path: '/configure',
name: 'configure',
component: Layout,
redirect: '/configure',
meta: {
icon: 'el-icon-setting',
title: '业务配置'
},
children: [{
path: 'enclosure',
name: 'Enclosure',
component: () =>
import ('@/views/configure/enclosure.vue'),
meta: { title: '围栏管理', icon: 'el-icon-aim' }
},
{
path: 'CarModel',
name: 'CarModel',
component: () =>
import ('@/views/configure/CarModel.vue'),
meta: { title: '车型管理', icon: 'el-icon-s-data' }
},
{
path: 'site',
name: 'Site',
component: () =>
import ('@/views/configure/site.vue'),
meta: { title: '站点管理', icon: 'el-icon-s-home' }
},
]
}]
const router = new VueRouter({ const router = new VueRouter({
base: '', base: '',
mode: routerMode, mode: routerMode,
scrollBehavior: () => ({ scrollBehavior: () => ({
y: 0 y: 0
}), }),
routes: currencyRoutes routes: currencyRoutes
}) })
// 解决addRoute不能删除动态路由问题 // 解决addRoute不能删除动态路由问题
export function resetRouter() { export function resetRouter() {
router.matcher = new VueRouter({ router.matcher = new VueRouter({
base: '', base: '',
mode: routerMode, mode: routerMode,
scrollBehavior: () => ({ scrollBehavior: () => ({
y: 0 y: 0
}), }),
routes: currencyRoutes routes: currencyRoutes
}).matcher }).matcher
} }
// 导航守卫 验证是否登录了 没有登录跳转到登录页面 // 导航守卫 验证是否登录了 没有登录跳转到登录页面
router.beforeEach(async (to, from, next) => { router.beforeEach(async(to, from, next) => {
if (to.path === '/login') { if (to.path === '/login') {
next() next()
} else { } else {
let user = store.getters.token let user = store.getters.token
let hasRoles = store.getters.roles let hasRoles = store.getters.roles
let roleType = store.state.user.roleType let roleType = store.state.user.roleType
if (user) { if (user) {
if (hasRoles.length <= 0) { if (hasRoles.length <= 0) {
try { try {
const { const {
roles roles
} = await store.dispatch('user/getRoutes') } = await store.dispatch('user/getRoutes')
let addRoutes; let addRoutes;
// if (roleType == 2) { // if (roleType == 2) {
addRoutes = await store.dispatch('permission/getRoutes', roles) addRoutes = await store.dispatch('permission/getRoutes', roles)
// } else { // } else {
// addRoutes = await store.dispatch('permission/getAsyncRoutes', roles) // addRoutes = await store.dispatch('permission/getAsyncRoutes', roles)
// } // }
router.addRoutes(addRoutes) router.addRoutes(addRoutes)
next({ next({
...to, ...to,
replace: true replace: true
}) })
} catch (error) { } catch (error) {
// Message.error('此路不通') // Message.error('此路不通')
} }
} else { } else {
next() next()
} }
} else { } else {
next({ next({
path: '/login', path: '/login',
query: { query: {
redirect: to.fullPath redirect: to.fullPath
} }
}) })
} }
} }
}) })
export default router export default router
\ No newline at end of file
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
车型
</el-card>
</template>
<script>
export default {
name: "CarModel",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
围栏
</el-card>
</template>
<script>
export default {
name: "enclosure",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
站点
</el-card>
</template>
<script>
export default {
name: "site",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment