Generating commit message...

This commit is contained in:
2025-08-30 14:33:49 +08:00
parent 4d469e95f0
commit 7f9bfbb381
99 changed files with 69225 additions and 35 deletions

View File

@@ -0,0 +1,142 @@
import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
// 基础路由
const routes: RouteRecordRaw[] = [
{
path: '/',
redirect: '/dashboard',
meta: { requiresAuth: true }
},
{
path: '/login',
name: 'Login',
component: () => import('@/pages/Login.vue'),
meta: { requiresAuth: false, layout: 'auth' }
},
{
path: '/dashboard',
name: 'Dashboard',
component: () => import('@/pages/dashboard/index.vue'),
meta: {
requiresAuth: true,
title: '仪表板',
icon: 'DashboardOutlined'
}
},
{
path: '/users',
name: 'Users',
component: () => import('@/pages/user/index.vue'),
meta: {
requiresAuth: true,
title: '用户管理',
icon: 'UserOutlined',
permissions: ['user:read']
}
},
{
path: '/merchants',
name: 'Merchants',
component: () => import('@/pages/merchant/index.vue'),
meta: {
requiresAuth: true,
title: '商家管理',
icon: 'ShopOutlined',
permissions: ['merchant:read']
}
},
{
path: '/travel',
name: 'Travel',
component: () => import('@/pages/travel/index.vue'),
meta: {
requiresAuth: true,
title: '旅行管理',
icon: 'CompassOutlined',
permissions: ['travel:read']
}
},
{
path: '/animals',
name: 'Animals',
component: () => import('@/pages/animal/index.vue'),
meta: {
requiresAuth: true,
title: '动物管理',
icon: 'HeartOutlined',
permissions: ['animal:read']
}
},
{
path: '/orders',
name: 'Orders',
component: () => import('@/pages/order/index.vue'),
meta: {
requiresAuth: true,
title: '订单管理',
icon: 'ShoppingCartOutlined',
permissions: ['order:read']
}
},
{
path: '/promotion',
name: 'Promotion',
component: () => import('@/pages/promotion/index.vue'),
meta: {
requiresAuth: true,
title: '推广管理',
icon: 'GiftOutlined',
permissions: ['promotion:read']
}
},
{
path: '/system',
name: 'System',
component: () => import('@/pages/system/index.vue'),
meta: {
requiresAuth: true,
title: '系统设置',
icon: 'SettingOutlined',
permissions: ['system:read']
}
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('@/pages/NotFound.vue'),
meta: { requiresAuth: false }
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
// 路由守卫
router.beforeEach(async (to, from, next) => {
const { meta } = to
const isAuthenticated = localStorage.getItem('admin_token') !== null
// 检查是否需要认证
if (meta.requiresAuth && !isAuthenticated) {
next({ name: 'Login', query: { redirect: to.fullPath } })
return
}
// 如果已认证且访问登录页,重定向到首页
if (to.name === 'Login' && isAuthenticated) {
next({ name: 'Dashboard' })
return
}
next()
})
// 错误处理
router.onError((error) => {
console.error('🚨 路由错误:', error)
})
export default router