2018-01-14 22:51:12 +08:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import VueRouter from 'vue-router'
|
2018-01-27 10:25:59 +08:00
|
|
|
import Cookies from 'js-cookie'
|
2018-01-14 22:51:12 +08:00
|
|
|
|
2018-06-05 16:21:06 +08:00
|
|
|
Vue.use(VueRouter)
|
2018-06-05 15:33:21 +08:00
|
|
|
|
2018-06-05 16:21:06 +08:00
|
|
|
const routes = [
|
|
|
|
|
// 首页
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
redirect: { name: 'index' },
|
2018-06-06 23:00:11 +08:00
|
|
|
component: () => import('@/components/core/MainLayout/index.vue'),
|
2018-06-05 16:21:06 +08:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: 'index',
|
|
|
|
|
name: 'index',
|
|
|
|
|
meta: { requiresAuth: true },
|
2018-06-06 23:00:11 +08:00
|
|
|
component: () => import('@/pages/core/index/index.vue')
|
2018-06-05 16:21:06 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
2018-06-08 23:52:13 +08:00
|
|
|
{
|
|
|
|
|
path: '/demo/components',
|
|
|
|
|
name: 'demo-components',
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
redirect: { name: 'demo-components-index' },
|
|
|
|
|
component: () => import('@/components/core/MainLayout/index.vue'),
|
2018-06-09 20:00:01 +08:00
|
|
|
children: (pre => [
|
2018-06-08 23:52:13 +08:00
|
|
|
{ path: 'container/full', name: `${pre}container-full`, component: () => import('@/pages/demo/components/container/full.vue') },
|
|
|
|
|
{ path: 'container/ghost', name: `${pre}container-ghost`, component: () => import('@/pages/demo/components/container/ghost.vue') },
|
|
|
|
|
{ path: 'container/normal', name: `${pre}container-normal`, component: () => import('@/pages/demo/components/container/normal.vue') },
|
|
|
|
|
{ path: 'countup', name: `${pre}countup`, component: () => import('@/pages/demo/components/countup/index.vue') },
|
|
|
|
|
{ path: 'editor-quill', name: `${pre}editor-quill`, component: () => import('@/pages/demo/components/editor-quill/index.vue') },
|
|
|
|
|
{ path: 'editor-simpleMDE', name: `${pre}editor-simpleMDE`, component: () => import('@/pages/demo/components/editor-simpleMDE/index.vue') },
|
|
|
|
|
{ path: 'highlight', name: `${pre}highlight`, component: () => import('@/pages/demo/components/highlight/index.vue') },
|
|
|
|
|
{ path: 'icon/icon', name: `${pre}icon-icon`, component: () => import('@/pages/demo/components/icon/icon.vue') },
|
|
|
|
|
{ path: 'icon/list', name: `${pre}icon-list`, component: () => import('@/pages/demo/components/icon/list.vue') },
|
|
|
|
|
{ path: 'icon/select', name: `${pre}icon-select`, component: () => import('@/pages/demo/components/icon/select.vue') },
|
|
|
|
|
{ path: 'icon/svg', name: `${pre}icon-svg`, component: () => import('@/pages/demo/components/icon/svg.vue') },
|
|
|
|
|
{ path: 'index', name: `${pre}index`, component: () => import('@/pages/demo/components/index/index.vue') },
|
2018-06-09 19:29:47 +08:00
|
|
|
{ path: 'layout/grid', name: `${pre}layout-grid`, component: () => import('@/pages/demo/components/layout/grid.vue') },
|
|
|
|
|
{ path: 'layout/splitpane', name: `${pre}layout-splitpane`, component: () => import('@/pages/demo/components/layout/splitpane.vue') },
|
2018-06-08 23:52:13 +08:00
|
|
|
{ path: 'markdown', name: `${pre}markdown`, component: () => import('@/pages/demo/components/markdown/index.vue') }
|
|
|
|
|
])('demo-components-')
|
|
|
|
|
},
|
2018-06-05 16:21:06 +08:00
|
|
|
{
|
|
|
|
|
path: '/demo/plugins',
|
|
|
|
|
name: 'demo-plugins',
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
redirect: { name: 'demo-plugins-index' },
|
2018-06-06 23:00:11 +08:00
|
|
|
component: () => import('@/components/core/MainLayout/index.vue'),
|
2018-06-09 20:00:01 +08:00
|
|
|
children: (pre => [
|
2018-06-06 23:02:52 +08:00
|
|
|
{ path: 'build', name: `${pre}build`, component: () => import('@/pages/demo/plugins/build/index.vue') },
|
|
|
|
|
{ path: 'clipboard-polyfill', name: `${pre}clipboard-polyfill`, component: () => import('@/pages/demo/plugins/clipboard-polyfill/index.vue') },
|
|
|
|
|
{ path: 'export/table', name: `${pre}export-table`, component: () => import('@/pages/demo/plugins/export/table.vue') },
|
|
|
|
|
{ path: 'export/txt', name: `${pre}export-txt`, component: () => import('@/pages/demo/plugins/export/txt.vue') },
|
|
|
|
|
{ path: 'i18n/demo1', name: `${pre}i18n-demo1`, component: () => import('@/pages/demo/plugins/i18n/demo1.vue') },
|
|
|
|
|
{ path: 'i18n/demo2', name: `${pre}i18n-demo2`, component: () => import('@/pages/demo/plugins/i18n/demo2.vue') },
|
|
|
|
|
{ path: 'import/csv', name: `${pre}import-csv`, component: () => import('@/pages/demo/plugins/import/csv.vue') },
|
|
|
|
|
{ path: 'import/xlsx', name: `${pre}import-xlsx`, component: () => import('@/pages/demo/plugins/import/xlsx.vue') },
|
|
|
|
|
{ path: 'index', name: `${pre}index`, component: () => import('@/pages/demo/plugins/index/index.vue') },
|
|
|
|
|
{ path: 'js-cookie', name: `${pre}js-cookie`, component: () => import('@/pages/demo/plugins/js-cookie/index.vue') },
|
|
|
|
|
{ path: 'mock/ajax', name: `${pre}mock-ajax`, component: () => import('@/pages/demo/plugins/mock/ajax.vue') },
|
|
|
|
|
{ path: 'mock/dpd', name: `${pre}mock-dpd`, component: () => import('@/pages/demo/plugins/mock/dpd.vue') },
|
|
|
|
|
{ path: 'mock/dtd', name: `${pre}mock-dtd`, component: () => import('@/pages/demo/plugins/mock/dtd.vue') },
|
|
|
|
|
{ path: 'timeago', name: `${pre}timeago`, component: () => import('@/pages/demo/plugins/timeago/index.vue') }
|
2018-06-06 23:00:11 +08:00
|
|
|
])('demo-plugins-')
|
2018-06-05 16:21:06 +08:00
|
|
|
},
|
2018-06-09 20:00:01 +08:00
|
|
|
{
|
|
|
|
|
path: '/demo/chart',
|
|
|
|
|
name: 'demo-chart',
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
redirect: { name: 'demo-chart-index' },
|
|
|
|
|
component: () => import('@/components/core/MainLayout/index.vue'),
|
|
|
|
|
children: (pre => [
|
|
|
|
|
{ path: 'all', name: `${pre}all`, component: () => import('@/pages/demo/chart/all/index.vue') },
|
|
|
|
|
{ path: 'demo/areaBase', name: `${pre}demo-areaBase`, component: () => import('@/pages/demo/chart/demo/areaBase.vue') },
|
|
|
|
|
{ path: 'demo/barBase', name: `${pre}demo-barBase`, component: () => import('@/pages/demo/chart/demo/barBase.vue') },
|
|
|
|
|
{ path: 'demo/columnBase', name: `${pre}demo-columnBase`, component: () => import('@/pages/demo/chart/demo/columnBase.vue') },
|
|
|
|
|
{ path: 'demo/lineBase', name: `${pre}demo-lineBase`, component: () => import('@/pages/demo/chart/demo/lineBase.vue') },
|
|
|
|
|
{ path: 'demo/lineStep', name: `${pre}demo-lineStep`, component: () => import('@/pages/demo/chart/demo/lineStep.vue') },
|
|
|
|
|
{ path: 'demo/nightingaleRoseBase', name: `${pre}demo-nightingaleRoseBase`, component: () => import('@/pages/demo/chart/demo/nightingaleRoseBase.vue') },
|
|
|
|
|
{ path: 'demo/PieBase', name: `${pre}demo-PieBase`, component: () => import('@/pages/demo/chart/demo/PieBase.vue') },
|
|
|
|
|
{ path: 'demo/radarBase', name: `${pre}demo-radarBase`, component: () => import('@/pages/demo/chart/demo/radarBase.vue') },
|
|
|
|
|
{ path: 'dynamicSize', name: `${pre}dynamicSize`, component: () => import('@/pages/demo/chart/dynamicSize/index.vue') },
|
|
|
|
|
{ path: 'index', name: `${pre}index`, component: () => import('@/pages/demo/chart/index/index.vue') }
|
|
|
|
|
])('demo-chart-')
|
|
|
|
|
},
|
2018-06-09 20:35:03 +08:00
|
|
|
{
|
|
|
|
|
path: '/demo/business',
|
|
|
|
|
name: 'demo-business',
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
redirect: { name: 'demo-business-index' },
|
|
|
|
|
component: () => import('@/components/core/MainLayout/index.vue'),
|
|
|
|
|
children: (pre => [
|
|
|
|
|
{ path: 'index', name: `${pre}index`, component: () => import('@/pages/demo/business/index/index.vue') }
|
|
|
|
|
])('demo-business-')
|
|
|
|
|
},
|
2018-06-05 16:21:06 +08:00
|
|
|
// 登陆
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
2018-06-06 23:00:11 +08:00
|
|
|
component: () => import('@/pages/core/login/index.vue')
|
2018-06-05 16:21:06 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2018-06-09 20:00:01 +08:00
|
|
|
routes[3].children.forEach(e => {
|
2018-06-08 23:52:13 +08:00
|
|
|
console.log(`{ path: \`\${pre}${e.path}\`, title: 'title' }`)
|
|
|
|
|
})
|
2018-06-05 16:21:06 +08:00
|
|
|
|
2018-06-06 22:42:53 +08:00
|
|
|
let router = new VueRouter({ routes })
|
2018-01-27 10:25:59 +08:00
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
// 需要身份校验
|
|
|
|
|
if (to.meta.requiresAuth) {
|
2018-03-21 21:59:10 +08:00
|
|
|
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
|
|
|
|
|
// 请根据自身业务需要修改
|
2018-01-27 10:25:59 +08:00
|
|
|
if (Cookies.get('token')) {
|
|
|
|
|
next()
|
|
|
|
|
} else {
|
|
|
|
|
// 没有登陆的时候跳转到登陆界面
|
|
|
|
|
next({
|
|
|
|
|
name: 'login'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 不需要身份校验 直接通过
|
|
|
|
|
next()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|