60 lines
2.5 KiB
JavaScript
60 lines
2.5 KiB
JavaScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import { isLoggedIn } from '@/utils/auth'
|
|
import { canAccessRoute } from '@/utils/permission'
|
|
|
|
const AdminLayout = () => import('@/layouts/AdminLayout.vue')
|
|
const Login = () => import('@/views/Login.vue')
|
|
|
|
const Dashboard = () => import('@/views/Dashboard.vue')
|
|
const UserList = () => import('@/views/users/UserList.vue')
|
|
const GameList = () => import('@/views/games/GameList.vue')
|
|
const OrderList = () => import('@/views/orders/OrderList.vue')
|
|
const ReportAnalysis = () => import('@/views/reports/ReportAnalysis.vue')
|
|
const Settings = () => import('@/views/settings/Settings.vue')
|
|
const LinkGenerate = () => import('@/views/links/LinkGenerate.vue')
|
|
const ErrorTest = () => import('@/views/ErrorTest.vue')
|
|
const PermissionTest = () => import('@/views/PermissionTest.vue')
|
|
const NotFound = () => import('@/views/NotFound.vue')
|
|
|
|
export const routes = [
|
|
{ path: '/login', name: 'Login', component: Login, meta: { public: true, title: '登录' } },
|
|
{
|
|
path: '/',
|
|
component: AdminLayout,
|
|
children: [
|
|
{ path: '', name: 'Dashboard', component: Dashboard, meta: { title: '仪表盘' } },
|
|
{ path: 'users', name: 'Users', component: UserList, meta: { title: '用户管理' } },
|
|
{ path: 'games', name: 'Games', component: GameList, meta: { title: '游戏管理' } },
|
|
{ path: 'orders', name: 'Orders', component: OrderList, meta: { title: '订单管理' } },
|
|
{ path: 'reports', name: 'Reports', component: ReportAnalysis, meta: { title: '报表分析' } },
|
|
{ path: 'settings', name: 'Settings', component: Settings, meta: { title: '系统设置' } },
|
|
{ path: 'links', name: 'Links', component: LinkGenerate, meta: { title: '链接管理' } },
|
|
{ path: 'error-test', name: 'ErrorTest', component: ErrorTest, meta: { title: '错误处理测试' } },
|
|
{ path: 'permission-test', name: 'PermissionTest', component: PermissionTest, meta: { title: '权限测试' } },
|
|
],
|
|
},
|
|
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound, meta: { public: true, title: '未找到' } },
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.meta?.public) return next()
|
|
if (!isLoggedIn()) {
|
|
return next({ name: 'Login', query: { redirect: to.fullPath } })
|
|
}
|
|
|
|
// 检查路由权限
|
|
if (to.name && !canAccessRoute(to.name)) {
|
|
return next({ name: 'Dashboard' }) // 无权限时跳转到仪表盘
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|
|
|