better-staridc-MNBT
1import { createRouter, createWebHashHistory } from 'vue-router'
2
3const UserLoginView = () => import('@/user/views/LoginView.vue')
4const UserLayout = () => import('@/user/layouts/UserLayout.vue')
5const UserDashboardView = () => import('@/user/views/dashboard/DashboardView.vue')
6const UserSiteStatsView = () => import('@/user/views/stats/SiteStatsView.vue')
7const UserSettingsView = () => import('@/user/views/settings/SettingsView.vue')
8const UserMonitorView = () => import('@/user/views/monitor/MonitorView.vue')
9const UserMonitorLogView = () => import('@/user/views/monitor/MonitorLogView.vue')
10const UserNoticeView = () => import('@/user/views/NoticeView.vue')
11const UserDeployView = () => import('@/user/views/deploy/DeployView.vue')
12const UserSqlBackupView = () => import('@/user/views/database/SqlBackupView.vue')
13const UserFtpView = () => import('@/user/views/ftp/FtpView.vue')
14const UserPluginView = () => import('@/user/views/PluginView.vue')
15
16const routes = [
17 { path: '/login', name: 'user-login', component: UserLoginView, meta: { guest: true, title: '登录' } },
18 {
19 path: '/',
20 component: UserLayout,
21 meta: { auth: true },
22 children: [
23 { path: '', redirect: '/dashboard' },
24 { path: 'dashboard', name: 'user-dashboard', component: UserDashboardView, meta: { title: '控制面板' } },
25 { path: 'stats', name: 'user-stats', component: UserSiteStatsView, meta: { title: '站点统计' } },
26 { path: 'settings/:tab', name: 'user-settings', component: UserSettingsView, meta: { title: '站点设置' } },
27 { path: 'monitor', name: 'user-monitor', component: UserMonitorView, meta: { title: '监控任务' } },
28 { path: 'monitor-log', name: 'user-monitor-log', component: UserMonitorLogView, meta: { title: '监控日志' } },
29 { path: 'notice', name: 'user-notice', component: UserNoticeView, meta: { title: '通知日志' } },
30 { path: 'deploy', name: 'user-deploy', component: UserDeployView, meta: { title: '一键部署' } },
31 { path: 'sql-backup', name: 'user-sql-backup', component: UserSqlBackupView, meta: { title: 'SQL数据备份' } },
32 { path: 'ftp', name: 'user-ftp', component: UserFtpView, meta: { title: '在线文件管理' } },
33 { path: 'plugin', name: 'user-plugin', component: UserPluginView, meta: { title: '插件页面' } },
34 ],
35 },
36 { path: '/:pathMatch(.*)*', redirect: '/dashboard' },
37]
38
39const router = createRouter({
40 history: createWebHashHistory(),
41 routes,
42 scrollBehavior() {
43 return { top: 0 }
44 },
45})
46
47router.beforeEach((to, _from, next) => {
48 const boot = window.__TD_BOOT__ || {}
49 const loggedIn = !!boot.loggedIn
50 document.title = `${to.meta.title || '控制面板'} · ${boot.siteName || 'MNBT'}`
51
52 if (to.meta.guest && loggedIn) {
53 next('/dashboard')
54 return
55 }
56 if (to.meta.auth && !loggedIn && to.path !== '/login') {
57 next('/login')
58 return
59 }
60 next()
61})
62
63export default router