Former-commit-id: eee1f4b4c260bfcbd529e5e7b9bfd851183ab029
This commit is contained in:
liyang
2018-07-07 12:13:20 +08:00
parent f2c19bf06e
commit 980450f37f
122 changed files with 20451 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
import Cookies from 'js-cookie';
import util from '@/libs/util';
// 路由数据
import routes from './routes';
Vue.use(VueRouter);
const router = new VueRouter({ routes });
/**
* 路由拦截
* 权限验证
*/
router.beforeEach((to, from, next) => {
// 验证当前路由所有的匹配中是否需要有登陆验证的
if (to.matched.some(r => r.meta.requiresAuth)) {
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
// 请根据自身业务需要修改
if (Cookies.get('token')) {
next();
} else {
// 没有登陆的时候跳转到登陆界面
next({
name: 'login',
});
}
} else {
// 不需要身份校验 直接通过
next();
}
});
router.afterEach((to) => {
// 需要的信息
const { app } = router;
const { name, params, query } = to;
// 多页控制 打开新的页面
util.openNewPage(app, name, params, query);
// 更改标题
util.title(to.meta.title);
});
export default router;
+70
View File
@@ -0,0 +1,70 @@
const meta = { requiresAuth: true };
/**
* 在主框架内显示
*/
const frameIn = [
// 首页
{
path: '/',
redirect: { name: 'index' },
component: () => import('@/components/core/d2-layout-main'),
children: [
{
path: 'index',
name: 'index',
meta,
component: () => import('@/pages/core/index'),
},
],
},
{
path: '/core/setting',
name: 'core-setting',
meta,
redirect: { name: 'core-setting-index' },
component: () => import('@/components/core/d2-layout-main'),
children: (pre => [
{
path: 'index', name: `${pre}index`, component: () => import('@/pages/core/setting/index'), meta: { ...meta, title: '设置首页' },
},
{
path: 'releases', name: `${pre}releases`, component: () => import('@/pages/core/setting/releases'), meta: { ...meta, title: '版本' },
},
])('core-setting-'),
},
];
/**
* 错误页面
*/
const errorPage = [
// 404
{
path: '*',
name: '404',
component: () => import('@/pages/core/404'),
},
];
/**
* 在主框架之外显示
*/
const frameOut = [
// 登陆
{
path: '/login',
name: 'login',
component: () => import('@/pages/core/login'),
},
];
// 导出需要显示菜单的
export const frameInRoutes = frameIn;
// 重新组织后导出
export default [
...frameIn,
...frameOut,
...errorPage,
];