2021-12-30 17:25:51 +08:00
|
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
|
|
import type { RouteRecordRaw } from 'vue-router'
|
|
|
|
import type { App } from 'vue'
|
2022-01-12 16:44:57 +08:00
|
|
|
import { Layout, getParentLayout } from '@/utils/routerHelper'
|
2022-01-09 10:57:50 +08:00
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
2022-01-11 10:47:10 +08:00
|
|
|
|
2022-01-09 10:57:50 +08:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
2021-12-30 17:25:51 +08:00
|
|
|
export const constantRouterMap: AppRouteRecordRaw[] = [
|
2022-01-09 10:57:50 +08:00
|
|
|
{
|
|
|
|
path: '/redirect',
|
|
|
|
component: Layout,
|
|
|
|
name: 'Redirect',
|
|
|
|
children: [
|
|
|
|
{
|
2022-01-11 10:47:10 +08:00
|
|
|
path: '/redirect/:path(.*)',
|
2022-01-09 10:57:50 +08:00
|
|
|
name: 'Redirect',
|
|
|
|
component: () => import('@/views/Redirect/Redirect.vue'),
|
|
|
|
meta: {}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
meta: {
|
2022-01-16 17:55:20 +08:00
|
|
|
hidden: true,
|
|
|
|
noTagsView: true
|
2022-01-09 10:57:50 +08:00
|
|
|
}
|
|
|
|
},
|
2021-12-30 17:25:51 +08:00
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
component: () => import('@/views/Login/Login.vue'),
|
|
|
|
name: 'Login',
|
|
|
|
meta: {
|
|
|
|
hidden: true,
|
2022-01-09 10:57:50 +08:00
|
|
|
title: t('router.login'),
|
2021-12-30 17:25:51 +08:00
|
|
|
noTagsView: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-01-11 10:47:10 +08:00
|
|
|
export const asyncRouterMap: AppRouteRecordRaw[] = [
|
2022-01-22 19:39:44 +08:00
|
|
|
{
|
|
|
|
path: '/dashboard',
|
|
|
|
component: Layout,
|
|
|
|
redirect: '/dashboard/analysis',
|
|
|
|
name: 'Dashboard',
|
|
|
|
meta: {
|
|
|
|
title: t('router.dashboard'),
|
|
|
|
icon: 'ant-design:dashboard-filled',
|
|
|
|
alwaysShow: true
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'analysis',
|
|
|
|
component: () => import('@/views/Dashboard/Analysis.vue'),
|
|
|
|
name: 'Analysis',
|
|
|
|
meta: {
|
|
|
|
title: t('router.analysis'),
|
2022-01-23 21:54:27 +08:00
|
|
|
noCache: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'workplace',
|
|
|
|
component: () => import('@/views/Dashboard/Workplace.vue'),
|
|
|
|
name: 'Workplace',
|
|
|
|
meta: {
|
|
|
|
title: t('router.workplace'),
|
|
|
|
noCache: true
|
2022-01-22 19:39:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-01-25 17:43:53 +08:00
|
|
|
{
|
|
|
|
path: '/guide',
|
|
|
|
component: Layout,
|
|
|
|
name: 'Guide',
|
|
|
|
meta: {},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
component: () => import('@/views/Guide/Guide.vue'),
|
|
|
|
name: 'GuideDemo',
|
|
|
|
meta: {
|
|
|
|
title: t('router.guide'),
|
|
|
|
icon: 'cib:telegram-plane'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-01-26 11:27:06 +08:00
|
|
|
{
|
|
|
|
path: '/components',
|
|
|
|
component: Layout,
|
|
|
|
redirect: '/components/icon',
|
|
|
|
name: 'ComponentsDemo',
|
|
|
|
meta: {
|
|
|
|
title: t('router.component'),
|
|
|
|
icon: 'bx:bxs-component',
|
|
|
|
alwaysShow: true
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'icon',
|
|
|
|
component: () => import('@/views/Components/Icon.vue'),
|
|
|
|
name: 'Icon',
|
|
|
|
meta: {
|
|
|
|
title: t('router.icon')
|
|
|
|
}
|
2022-01-26 14:08:37 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'echart',
|
|
|
|
component: () => import('@/views/Components/Echart.vue'),
|
|
|
|
name: 'Echart',
|
|
|
|
meta: {
|
|
|
|
title: t('router.echart')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'count-to',
|
|
|
|
component: () => import('@/views/Components/CountTo.vue'),
|
|
|
|
name: 'CountTo',
|
|
|
|
meta: {
|
|
|
|
title: t('router.countTo')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'watermark',
|
|
|
|
component: () => import('@/views/Components/Watermark.vue'),
|
|
|
|
name: 'Watermark',
|
|
|
|
meta: {
|
|
|
|
title: t('router.watermark')
|
|
|
|
}
|
2022-01-26 11:27:06 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-01-11 10:47:10 +08:00
|
|
|
{
|
|
|
|
path: '/level',
|
|
|
|
component: Layout,
|
|
|
|
redirect: '/level/menu1/menu1-1/menu1-1-1',
|
|
|
|
name: 'Level',
|
|
|
|
meta: {
|
2022-01-12 16:44:57 +08:00
|
|
|
title: t('router.level'),
|
|
|
|
icon: 'carbon:skill-level-advanced'
|
2022-01-11 10:47:10 +08:00
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'menu1',
|
|
|
|
name: 'Menu1',
|
|
|
|
component: getParentLayout(),
|
|
|
|
redirect: '/level/menu1/menu1-1/menu1-1-1',
|
|
|
|
meta: {
|
|
|
|
title: t('router.menu1')
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'menu1-1',
|
|
|
|
name: 'Menu11',
|
|
|
|
component: getParentLayout(),
|
|
|
|
redirect: '/level/menu1/menu1-1/menu1-1-1',
|
|
|
|
meta: {
|
|
|
|
title: t('router.menu11'),
|
|
|
|
alwaysShow: true
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'menu1-1-1',
|
|
|
|
name: 'Menu111',
|
|
|
|
component: () => import('@/views/Level/Menu111.vue'),
|
|
|
|
meta: {
|
|
|
|
title: t('router.menu111')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'menu1-2',
|
|
|
|
name: 'Menu12',
|
|
|
|
component: () => import('@/views/Level/Menu12.vue'),
|
|
|
|
meta: {
|
|
|
|
title: t('router.menu12')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'menu2',
|
|
|
|
name: 'Menu2Demo',
|
|
|
|
component: () => import('@/views/Level/Menu2.vue'),
|
|
|
|
meta: {
|
|
|
|
title: t('router.menu2')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2022-01-09 14:28:51 +08:00
|
|
|
|
2021-12-30 17:25:51 +08:00
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHashHistory(),
|
2022-01-03 09:41:34 +08:00
|
|
|
strict: true,
|
2021-12-30 17:25:51 +08:00
|
|
|
routes: constantRouterMap as RouteRecordRaw[],
|
|
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
|
|
})
|
|
|
|
|
2022-01-15 14:24:50 +08:00
|
|
|
export const resetRouter = (): void => {
|
2021-12-30 17:25:51 +08:00
|
|
|
const resetWhiteNameList = ['RedirectRoot', 'Redirect', 'Login', 'Root', 'Dashboard', 'Page404']
|
|
|
|
router.getRoutes().forEach((route) => {
|
|
|
|
const { name } = route
|
|
|
|
if (name && !resetWhiteNameList.includes(name as string)) {
|
|
|
|
router.hasRoute(name) && router.removeRoute(name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-15 14:24:50 +08:00
|
|
|
export const setupRouter = (app: App<Element>) => {
|
2021-12-30 17:25:51 +08:00
|
|
|
app.use(router)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default router
|