|
@@ -1,6 +1,7 @@
|
|
import Vue from 'vue'
|
|
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
import VueRouter from 'vue-router'
|
|
import Store from '../store'
|
|
import Store from '../store'
|
|
|
|
+import Cookies from 'js-cookie'
|
|
Vue.use(VueRouter)
|
|
Vue.use(VueRouter)
|
|
|
|
|
|
const originalPush = VueRouter.prototype.push
|
|
const originalPush = VueRouter.prototype.push
|
|
@@ -14,8 +15,8 @@ const routes = [
|
|
},
|
|
},
|
|
|
|
|
|
{
|
|
{
|
|
- path:'/register',
|
|
|
|
- name:'Register',
|
|
|
|
|
|
+ path: '/register',
|
|
|
|
+ name: 'Register',
|
|
meta: {
|
|
meta: {
|
|
title: '注册'
|
|
title: '注册'
|
|
},
|
|
},
|
|
@@ -37,7 +38,7 @@ const routes = [
|
|
},
|
|
},
|
|
]
|
|
]
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
]
|
|
]
|
|
/* 后台管理系统Layout */
|
|
/* 后台管理系统Layout */
|
|
import administrator_layout from '@/views/backStageManage/layout/Layout.vue'
|
|
import administrator_layout from '@/views/backStageManage/layout/Layout.vue'
|
|
@@ -46,23 +47,23 @@ export const backStageManageRouterItem = [
|
|
path: '/administrator',
|
|
path: '/administrator',
|
|
component: administrator_layout,
|
|
component: administrator_layout,
|
|
redirect: '/administrator/home',
|
|
redirect: '/administrator/home',
|
|
- meta: {title: '首页', icon: 'home'},
|
|
|
|
|
|
+ meta: { title: '首页', icon: 'home' },
|
|
children: [
|
|
children: [
|
|
{
|
|
{
|
|
path: 'home',
|
|
path: 'home',
|
|
name: 'Administrator_home',
|
|
name: 'Administrator_home',
|
|
component: () => import('@/views/backStageManage/home/index.vue'),
|
|
component: () => import('@/views/backStageManage/home/index.vue'),
|
|
- meta: {title: '首页', icon: 'home'}
|
|
|
|
|
|
+ meta: { title: '首页', icon: 'home' }
|
|
},
|
|
},
|
|
]
|
|
]
|
|
},
|
|
},
|
|
|
|
|
|
{
|
|
{
|
|
path: '/administrator',
|
|
path: '/administrator',
|
|
- name:'Administrator_application',
|
|
|
|
|
|
+ name: 'Administrator_application',
|
|
component: administrator_layout,
|
|
component: administrator_layout,
|
|
redirect: '/administrator/apply',
|
|
redirect: '/administrator/apply',
|
|
- meta: {title: '应用管理', icon: 'application'},
|
|
|
|
|
|
+ meta: { title: '应用管理', icon: 'application' },
|
|
children: [
|
|
children: [
|
|
{
|
|
{
|
|
path: 'addApply',
|
|
path: 'addApply',
|
|
@@ -75,13 +76,13 @@ export const backStageManageRouterItem = [
|
|
path: 'apply',
|
|
path: 'apply',
|
|
name: 'Administrator_apply',
|
|
name: 'Administrator_apply',
|
|
component: () => import('@/views/backStageManage/application/apply/index.vue'),
|
|
component: () => import('@/views/backStageManage/application/apply/index.vue'),
|
|
- meta: {title: '应用功能清单', icon: 'apply'}
|
|
|
|
|
|
+ meta: { title: '应用功能清单', icon: 'apply' }
|
|
},
|
|
},
|
|
{
|
|
{
|
|
path: 'vision',
|
|
path: 'vision',
|
|
name: 'Administrator_vision',
|
|
name: 'Administrator_vision',
|
|
component: () => import('@/views/backStageManage/application/vision/index.vue'),
|
|
component: () => import('@/views/backStageManage/application/vision/index.vue'),
|
|
- meta: {title: '应用版本清单', icon: 'vision'}
|
|
|
|
|
|
+ meta: { title: '应用版本清单', icon: 'vision' }
|
|
},
|
|
},
|
|
{
|
|
{
|
|
path: 'addVersion',
|
|
path: 'addVersion',
|
|
@@ -129,7 +130,7 @@ export const backStageManage = [
|
|
children: [
|
|
children: [
|
|
{
|
|
{
|
|
path: '/',
|
|
path: '/',
|
|
- name:'Administrator_Index',
|
|
|
|
|
|
+ name: 'Administrator_Index',
|
|
meta: {
|
|
meta: {
|
|
title: '后台管理',
|
|
title: '后台管理',
|
|
},
|
|
},
|
|
@@ -137,7 +138,7 @@ export const backStageManage = [
|
|
},
|
|
},
|
|
{
|
|
{
|
|
path: 'login',
|
|
path: 'login',
|
|
- name:'Administrator_login',
|
|
|
|
|
|
+ name: 'Administrator_login',
|
|
meta: {
|
|
meta: {
|
|
title: '后台管理-登录',
|
|
title: '后台管理-登录',
|
|
},
|
|
},
|
|
@@ -151,31 +152,53 @@ export const backStageManage = [
|
|
const router = new VueRouter({
|
|
const router = new VueRouter({
|
|
mode: 'history',
|
|
mode: 'history',
|
|
base: '/',
|
|
base: '/',
|
|
- routes:process.env.NODE_ENV !== 'production'?[...routes,...backStageManage]:routes
|
|
|
|
|
|
+ routes: process.env.NODE_ENV !== 'production' ? [...routes, ...backStageManage] : routes
|
|
})
|
|
})
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.meta.title) {
|
|
if (to.meta.title) {
|
|
document.title = to.meta.title;
|
|
document.title = to.meta.title;
|
|
}
|
|
}
|
|
- next();
|
|
|
|
|
|
+ if (to.path == '/administrator/login'|| routeExists(routes,to.path) || to.meta.notLogin) {
|
|
|
|
+ Cookies.remove("token")
|
|
|
|
+ localStorage.removeItem('vuex')
|
|
|
|
+ next()
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ const tokenStr = Cookies.get('token')
|
|
|
|
+ switch (tokenStr) {
|
|
|
|
+ case undefined:
|
|
|
|
+ if (to.meta.title) {
|
|
|
|
+ document.title = to.meta.title;
|
|
|
|
+ }
|
|
|
|
+ next({ name: 'Administrator_login' })
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ if (to.meta.title) {
|
|
|
|
+ document.title = to.meta.title;
|
|
|
|
+ }
|
|
|
|
+ next()
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
|
|
-function routeExists(array,path,parentPath){
|
|
|
|
- for(var i = 0;i<array.length;i++){
|
|
|
|
|
|
+function routeExists(array, path, parentPath) {
|
|
|
|
+ for (var i = 0; i < array.length; i++) {
|
|
var item = array[i]
|
|
var item = array[i]
|
|
var nowPath = item.path
|
|
var nowPath = item.path
|
|
- if(item.path.indexOf('/') != 0){
|
|
|
|
|
|
+ if (item.path.indexOf('/') != 0) {
|
|
nowPath = parentPath + '/' + nowPath
|
|
nowPath = parentPath + '/' + nowPath
|
|
}
|
|
}
|
|
- if(!item.children || item.children.length == 0){
|
|
|
|
- if(path == nowPath){
|
|
|
|
|
|
+ if (!item.children || item.children.length == 0) {
|
|
|
|
+ if (path == nowPath) {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
var data = item.children
|
|
var data = item.children
|
|
- var sign = routeExists(data,path,nowPath)
|
|
|
|
- if(sign){
|
|
|
|
|
|
+ var sign = routeExists(data, path, nowPath)
|
|
|
|
+ if (sign) {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -184,22 +207,22 @@ function routeExists(array,path,parentPath){
|
|
}
|
|
}
|
|
// 在你的路由配置文件中
|
|
// 在你的路由配置文件中
|
|
router.afterEach((to, from) => {
|
|
router.afterEach((to, from) => {
|
|
- var sign = routeExists(backStageManageRouterItem,to.path)
|
|
|
|
- if(!sign){
|
|
|
|
|
|
+ var sign = routeExists(backStageManageRouterItem, to.path)
|
|
|
|
+ if (!sign) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
var obj = {
|
|
var obj = {
|
|
- name:to.meta.title,
|
|
|
|
- path:to.path,
|
|
|
|
- route:{
|
|
|
|
- name:to.name,
|
|
|
|
- path:to.path,
|
|
|
|
- query:to.query,
|
|
|
|
- params:to.params
|
|
|
|
|
|
+ name: to.meta.title,
|
|
|
|
+ path: to.path,
|
|
|
|
+ route: {
|
|
|
|
+ name: to.name,
|
|
|
|
+ path: to.path,
|
|
|
|
+ query: to.query,
|
|
|
|
+ params: to.params
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Store.commit('addHistory',obj);
|
|
|
|
- Store.commit('addHistoryPath',to.path);
|
|
|
|
|
|
+ Store.commit('addHistory', obj);
|
|
|
|
+ Store.commit('addHistoryPath', to.path);
|
|
});
|
|
});
|
|
|
|
|
|
export default router
|
|
export default router
|