This commit is contained in:
macbook_max
2026-10-15 20:36:59 +08:00
commit 6bf949949c
7923 changed files with 1369582 additions and 0 deletions
+162
View File
@@ -0,0 +1,162 @@
/**
* 路由与角色守卫
* 角色矩阵(与《03-接口文档》第 11 章一致,super 拥有全部权限):
* - super:全部
* - reviewer:仅视频审核(待审核列表 / 审核)
* - operator:仪表盘 / 套餐管理 / 赠送
*/
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/store/auth'
// 各角色登录后的默认落地页
export const ROLE_HOME = {
super: '/dashboard',
reviewer: '/videos/pending',
operator: '/dashboard',
}
const routes = [
{
path: '/login',
name: 'login',
component: () => import('@/views/Login.vue'),
meta: { title: '登录', public: true },
},
{
path: '/',
component: () => import('@/layout/MainLayout.vue'),
redirect: '/dashboard',
children: [
{
path: 'dashboard',
name: 'dashboard',
component: () => import('@/views/Dashboard.vue'),
meta: { title: '仪表盘', icon: 'DataLine', roles: ['operator'] },
},
{
path: 'videos/pending',
name: 'video-pending',
component: () => import('@/views/VideoPending.vue'),
meta: { title: '视频审核', icon: 'VideoPlay', roles: ['reviewer'] },
},
{
path: 'videos',
name: 'video-list',
component: () => import('@/views/VideoList.vue'),
meta: { title: '视频管理', icon: 'Film', roles: [] },
},
{
path: 'comments',
name: 'comment-list',
component: () => import('@/views/CommentList.vue'),
meta: { title: '评论管理', icon: 'ChatDotRound', roles: [] },
},
{
path: 'users',
name: 'user-list',
component: () => import('@/views/UserList.vue'),
meta: { title: '用户管理', icon: 'User', roles: [] },
},
{
path: 'users/:id',
name: 'user-detail',
component: () => import('@/views/UserDetail.vue'),
meta: { title: '用户详情', roles: [], hidden: true },
},
{
path: 'points/records',
name: 'point-records',
component: () => import('@/views/PointRecords.vue'),
meta: { title: '积分流水', icon: 'Coin', roles: [] },
},
{
path: 'orders',
name: 'order-list',
component: () => import('@/views/OrderList.vue'),
meta: { title: '充值订单', icon: 'List', roles: [] },
},
{
path: 'packages',
name: 'package-list',
component: () => import('@/views/PackageList.vue'),
meta: { title: '充值套餐', icon: 'Goods', roles: ['operator'] },
},
{
path: 'gift',
name: 'gift',
component: () => import('@/views/Gift.vue'),
meta: { title: '赠送管理', icon: 'Present', roles: ['operator'] },
},
{
path: 'withdrawals',
name: 'withdrawal-list',
component: () => import('@/views/WithdrawList.vue'),
meta: { title: '提现审核', icon: 'Money', roles: [] },
},
{
path: 'referrals',
name: 'referral-list',
component: () => import('@/views/ReferralList.vue'),
meta: { title: '推荐风控', icon: 'Share', roles: [] },
},
{
path: 'reports',
name: 'report-list',
component: () => import('@/views/ReportList.vue'),
meta: { title: '举报处理', icon: 'Warning', roles: [] },
},
{
path: 'sensitive-words',
name: 'sensitive-words',
component: () => import('@/views/SensitiveWords.vue'),
meta: { title: '敏感词库', icon: 'Collection', roles: [] },
},
{
path: 'configs',
name: 'config-list',
component: () => import('@/views/ConfigList.vue'),
meta: { title: '平台配置', icon: 'Setting', roles: [] },
},
{
path: 'logs',
name: 'log-list',
component: () => import('@/views/LogList.vue'),
meta: { title: '操作日志', icon: 'Document', roles: [] },
},
],
},
{ path: '/:pathMatch(.*)*', redirect: '/dashboard' },
]
const router = createRouter({
history: createWebHistory(),
routes,
})
/** 判断角色是否可访问某路由(super 全放行;roles 为空表示仅 super) */
export function canAccess(role, routeRoles) {
if (!role) return false
if (role === 'super') return true
return Array.isArray(routeRoles) && routeRoles.includes(role)
}
router.beforeEach((to) => {
const auth = useAuthStore()
document.title = to.meta.title ? `${to.meta.title} - 短视频管理后台` : '短视频管理后台'
if (to.meta.public) {
// 已登录访问登录页 → 回到角色首页
return auth.isLoggedIn ? ROLE_HOME[auth.role] || '/dashboard' : true
}
if (!auth.isLoggedIn) {
return { path: '/login', query: { redirect: to.fullPath } }
}
if (to.meta.roles !== undefined && !canAccess(auth.role, to.meta.roles)) {
// 越权访问 → 回到该角色首页
return ROLE_HOME[auth.role] || '/login'
}
return true
})
export default router