286 lines
6.5 KiB
TypeScript
286 lines
6.5 KiB
TypeScript
// Author: fruit.com.cn
|
||
|
||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||
import type { RouteRecordRaw } from 'vue-router'
|
||
import type { App } from 'vue'
|
||
import { Layout } from '@/utils/routerHelper'
|
||
import { AppIcons } from '@/constants/icons'
|
||
|
||
export const constantRouterMap: AppRouteRecordRaw[] = [
|
||
{
|
||
// 不写死 redirect:vue-router 会在守卫之前就把 '/' 解析成 redirect 目标,
|
||
// 创作者没有 /dashboard/index 路由会直接 404。落地页交给 permission.ts 按账号菜单决定。
|
||
path: '/',
|
||
component: Layout,
|
||
name: 'Root',
|
||
meta: {
|
||
hidden: true
|
||
}
|
||
},
|
||
{
|
||
path: '/redirect',
|
||
component: Layout,
|
||
name: 'RedirectParent',
|
||
children: [
|
||
{
|
||
path: '/redirect/:path(.*)',
|
||
name: 'Redirect',
|
||
component: () => import('@/views/Redirect/Redirect.vue'),
|
||
meta: {}
|
||
}
|
||
],
|
||
meta: {
|
||
hidden: true,
|
||
noTagsView: true
|
||
}
|
||
},
|
||
{
|
||
path: '/login',
|
||
component: () => import('@/views/Login/Login.vue'),
|
||
name: 'Login',
|
||
meta: {
|
||
hidden: true,
|
||
title: '登录',
|
||
noTagsView: true
|
||
}
|
||
},
|
||
{
|
||
path: '/404',
|
||
component: () => import('@/views/Error/404.vue'),
|
||
name: 'NoFind',
|
||
meta: {
|
||
hidden: true,
|
||
title: '404',
|
||
noTagsView: true
|
||
}
|
||
},
|
||
{
|
||
path: '/notifications',
|
||
component: Layout,
|
||
name: 'Notifications',
|
||
meta: {
|
||
hidden: true,
|
||
title: '通知'
|
||
},
|
||
children: [
|
||
{
|
||
path: 'transcode',
|
||
name: 'transcode-notices',
|
||
component: () => import('@/views/common/TranscodeNoticeView.vue'),
|
||
meta: {
|
||
title: '转码通知'
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
path: '/:pathMatch(.*)*',
|
||
name: 'UnresolvedPath',
|
||
component: () => import('@/views/Error/404.vue'),
|
||
meta: {
|
||
hidden: true,
|
||
title: '404',
|
||
noTagsView: true
|
||
}
|
||
}
|
||
]
|
||
|
||
export const asyncRouterMap: AppRouteRecordRaw[] = [
|
||
{
|
||
path: '/dashboard',
|
||
component: Layout,
|
||
redirect: '/dashboard/index',
|
||
name: 'Dashboard',
|
||
meta: {
|
||
title: '工作台',
|
||
icon: AppIcons.dashboard
|
||
},
|
||
children: [
|
||
{
|
||
path: 'index',
|
||
name: 'dashboard',
|
||
component: () => import('@/views/common/DashboardView.vue'),
|
||
meta: {
|
||
title: '工作台',
|
||
icon: AppIcons.dashboard,
|
||
affix: true
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
path: '/content',
|
||
component: Layout,
|
||
redirect: '/content/dramas',
|
||
name: 'Content',
|
||
meta: {
|
||
title: '内容管理',
|
||
icon: AppIcons.content,
|
||
alwaysShow: true
|
||
},
|
||
children: [
|
||
{
|
||
path: 'dramas',
|
||
name: 'dramas',
|
||
component: () => import('@/views/contentManagement/DramaManagementView.vue'),
|
||
meta: {
|
||
title: '短剧管理'
|
||
}
|
||
},
|
||
{
|
||
path: 'episodes',
|
||
name: 'episodes',
|
||
component: () => import('@/views/contentManagement/EpisodeManagementView.vue'),
|
||
meta: {
|
||
title: '剧集管理'
|
||
}
|
||
},
|
||
{
|
||
path: 'banners',
|
||
name: 'banners',
|
||
component: () => import('@/views/contentManagement/BannerManagementView.vue'),
|
||
meta: {
|
||
title: '轮播图管理'
|
||
}
|
||
},
|
||
{
|
||
path: 'categories',
|
||
name: 'categories',
|
||
component: () => import('@/views/contentManagement/CategoryManagementView.vue'),
|
||
meta: {
|
||
title: '类型管理'
|
||
}
|
||
},
|
||
{
|
||
path: 'media-transcode',
|
||
name: 'media-transcode',
|
||
component: () => import('@/views/systemManagement/TranscodeSettingsView.vue'),
|
||
meta: {
|
||
title: 'router.transcodeSettings',
|
||
permission: ['episode:upload']
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
path: '/user',
|
||
component: Layout,
|
||
redirect: '/user/app-users',
|
||
name: 'UserCenter',
|
||
meta: {
|
||
title: '用户管理',
|
||
icon: AppIcons.group,
|
||
alwaysShow: true
|
||
},
|
||
children: [
|
||
{
|
||
path: 'app-users',
|
||
name: 'app-users',
|
||
component: () => import('@/views/userManagement/AppUsersView.vue'),
|
||
meta: {
|
||
title: 'App 用户'
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
path: '/system',
|
||
component: Layout,
|
||
redirect: '/system/access',
|
||
name: 'System',
|
||
meta: {
|
||
title: '后台管理',
|
||
icon: AppIcons.settings,
|
||
alwaysShow: true
|
||
},
|
||
children: [
|
||
{
|
||
path: 'access',
|
||
name: 'access',
|
||
component: () => import('@/views/permission/RoleManagementView.vue'),
|
||
meta: {
|
||
title: '角色权限配置'
|
||
}
|
||
},
|
||
{
|
||
path: 'admin-users',
|
||
name: 'admin-users',
|
||
component: () => import('@/views/userManagement/AdminUsersView.vue'),
|
||
meta: {
|
||
title: '管理员用户列表'
|
||
}
|
||
},
|
||
{
|
||
path: 'menus',
|
||
name: 'menus',
|
||
component: () => import('@/views/permission/MenuManagementView.vue'),
|
||
meta: {
|
||
title: '菜单管理'
|
||
}
|
||
},
|
||
{
|
||
path: 'role-categories',
|
||
name: 'role-categories',
|
||
component: () => import('@/views/permission/RoleCategoriesView.vue'),
|
||
meta: {
|
||
title: '角色分类'
|
||
}
|
||
},
|
||
{
|
||
path: 'settings',
|
||
name: 'settings',
|
||
component: () => import('@/views/systemManagement/SettingsView.vue'),
|
||
meta: {
|
||
title: '系统设置'
|
||
}
|
||
},
|
||
{
|
||
path: 'operation-logs',
|
||
name: 'operation-logs',
|
||
component: () => import('@/views/systemManagement/OperationLogView.vue'),
|
||
meta: {
|
||
title: '操作日志'
|
||
}
|
||
},
|
||
{
|
||
path: 'legal-documents',
|
||
name: 'legal-documents',
|
||
component: () => import('@/views/systemManagement/LegalDocumentView.vue'),
|
||
meta: {
|
||
title: '协议设置'
|
||
}
|
||
}
|
||
]
|
||
}
|
||
]
|
||
|
||
const router = createRouter({
|
||
history: createWebHashHistory(),
|
||
strict: true,
|
||
routes: constantRouterMap as RouteRecordRaw[],
|
||
scrollBehavior: () => ({ left: 0, top: 0 })
|
||
})
|
||
|
||
export const resetRouter = (): void => {
|
||
const resetWhiteNameList = [
|
||
'Redirect',
|
||
'RedirectParent',
|
||
'Login',
|
||
'NoFind',
|
||
'Root',
|
||
'UnresolvedPath'
|
||
]
|
||
router.getRoutes().forEach((route) => {
|
||
const { name } = route
|
||
if (name && !resetWhiteNameList.includes(name as string)) {
|
||
router.hasRoute(name) && router.removeRoute(name)
|
||
}
|
||
})
|
||
}
|
||
|
||
export const setupRouter = (app: App<Element>) => {
|
||
app.use(router)
|
||
}
|
||
|
||
export default router
|