better-staridc-MNBT
1import { createRouter, createWebHashHistory } from 'vue-router'
2
3const LoginView = () => import('@/admin/views/LoginView.vue')
4const LayoutView = () => import('@/admin/layouts/AdminLayout.vue')
5const DashboardView = () => import('@/admin/views/DashboardView.vue')
6
7const SettingsWebsite = () => import('@/admin/views/settings/WebsiteView.vue')
8const SettingsAdmin = () => import('@/admin/views/settings/AdminView.vue')
9const SettingsApi = () => import('@/admin/views/settings/ApiView.vue')
10const SettingsMail = () => import('@/admin/views/settings/MailView.vue')
11const SettingsPanel = () => import('@/admin/views/settings/PanelView.vue')
12const SettingsMonitor = () => import('@/admin/views/settings/MonitorView.vue')
13const SettingsTheme = () => import('@/admin/views/settings/ThemeView.vue')
14
15const HostListView = () => import('@/admin/views/host/HostListView.vue')
16const HostAddView = () => import('@/admin/views/host/HostAddView.vue')
17const BaotaListView = () => import('@/admin/views/baota/BaotaListView.vue')
18const BaotaAddView = () => import('@/admin/views/baota/BaotaAddView.vue')
19const NodeListView = () => import('@/admin/views/node/NodeListView.vue')
20const NodeScanView = () => import('@/admin/views/node/NodeScanView.vue')
21
22const ProgramListView = () => import('@/admin/views/program/ProgramListView.vue')
23const ProgramAddView = () => import('@/admin/views/program/ProgramAddView.vue')
24const ProgramImportView = () => import('@/admin/views/program/ProgramImportView.vue')
25const OrderListView = () => import('@/admin/views/order/OrderListView.vue')
26const LogListView = () => import('@/admin/views/log/LogListView.vue')
27const PluginListView = () => import('@/admin/views/plugin/PluginListView.vue')
28const PluginPageView = () => import('@/admin/views/PluginPageView.vue')
29const PaySettingsView = () => import('@/admin/views/pay/PaySettingsView.vue')
30const TutorialView = () => import('@/admin/views/TutorialView.vue')
31const UpdateView = () => import('@/admin/views/UpdateView.vue')
32const RepairView = () => import('@/admin/views/RepairView.vue')
33
34const DockerNodeView = () => import('@/admin/views/docker/DockerNodeView.vue')
35const DockerNodeAddView = () => import('@/admin/views/docker/DockerNodeAddView.vue')
36const DockerUserView = () => import('@/admin/views/docker/DockerUserView.vue')
37const DockerPlanView = () => import('@/admin/views/docker/DockerPlanView.vue')
38
39const routes = [
40 { path: '/login', name: 'login', component: LoginView, meta: { guest: true, title: '登录' } },
41 {
42 path: '/',
43 component: LayoutView,
44 meta: { auth: true },
45 children: [
46 { path: '', redirect: '/dashboard' },
47 { path: 'dashboard', name: 'dashboard', component: DashboardView, meta: { title: '仪表盘' } },
48
49 { path: 'settings/website', name: 'settings-website', component: SettingsWebsite, meta: { title: '网站设置' } },
50 { path: 'settings/admin', name: 'settings-admin', component: SettingsAdmin, meta: { title: '管理设置' } },
51 { path: 'settings/api', name: 'settings-api', component: SettingsApi, meta: { title: 'API 设置' } },
52 { path: 'settings/mail', name: 'settings-mail', component: SettingsMail, meta: { title: '邮箱设置' } },
53 { path: 'settings/panel', name: 'settings-panel', component: SettingsPanel, meta: { title: '控制面板' } },
54 { path: 'settings/monitor', name: 'settings-monitor', component: SettingsMonitor, meta: { title: '监控设置' } },
55 { path: 'settings/theme', name: 'settings-theme', component: SettingsTheme, meta: { title: '前端模板' } },
56
57 { path: 'host', name: 'host', component: HostListView, meta: { title: '主机列表' } },
58 { path: 'host/add', name: 'host-add', component: HostAddView, meta: { title: '添加主机' } },
59 { path: 'baota', name: 'baota', component: BaotaListView, meta: { title: '宝塔列表' } },
60 { path: 'baota/add', name: 'baota-add', component: BaotaAddView, meta: { title: '添加宝塔' } },
61 { path: 'node', name: 'node', component: NodeListView, meta: { title: '节点列表' } },
62 { path: 'node/scan', name: 'node-scan', component: NodeScanView, meta: { title: '违禁词扫描' } },
63
64 { path: 'docker/node', name: 'docker-node', component: DockerNodeView, meta: { title: 'Docker 节点' } },
65 { path: 'docker/node/add', name: 'docker-node-add', component: DockerNodeAddView, meta: { title: '添加 Docker 节点' } },
66 { path: 'docker/user', name: 'docker-user', component: DockerUserView, meta: { title: 'Docker 用户' } },
67 { path: 'docker/plan', name: 'docker-plan', component: DockerPlanView, meta: { title: 'Docker 套餐' } },
68
69 { path: 'program', name: 'program', component: ProgramListView, meta: { title: '程序列表' } },
70 { path: 'program/add', name: 'program-add', component: ProgramAddView, meta: { title: '添加程序' } },
71 { path: 'program/import', name: 'program-import', component: ProgramImportView, meta: { title: '导入程序' } },
72 { path: 'order', name: 'order', component: OrderListView, meta: { title: '订单列表' } },
73 { path: 'log', name: 'log', component: LogListView, meta: { title: '操作日志' } },
74 { path: 'plugin', name: 'plugin', component: PluginListView, meta: { title: '插件管理' } },
75 { path: 'plugin/page', name: 'plugin-page', component: PluginPageView, meta: { title: '插件页面' } },
76 { path: 'pay', name: 'pay', component: PaySettingsView, meta: { title: '支付设置' } },
77 { path: 'tutorial', name: 'tutorial', component: TutorialView, meta: { title: '教程与监控' } },
78 { path: 'update', name: 'update', component: UpdateView, meta: { title: '系统更新' } },
79 { path: 'repair', name: 'repair', component: RepairView, meta: { title: '系统修复' } },
80 ],
81 },
82 { path: '/:pathMatch(.*)*', redirect: '/dashboard' },
83]
84
85const router = createRouter({
86 history: createWebHashHistory(),
87 routes,
88 scrollBehavior() {
89 return { top: 0 }
90 },
91})
92
93router.beforeEach((to, _from, next) => {
94 const boot = window.__TD_BOOT__ || {}
95 const loggedIn = !!boot.loggedIn
96 document.title = `${to.meta.title || '管理后台'} · ${boot.siteName || 'MNBT'}`
97
98 if (to.meta.guest && loggedIn) {
99 next('/dashboard')
100 return
101 }
102 if (to.meta.auth && !loggedIn && to.path !== '/login') {
103 next('/login')
104 return
105 }
106 next()
107})
108
109export default router