feat: 添加功能开关机制
All checks were successful
continuous-integration/drone/push Build is passing

- 添加环境变量配置 VITE_FEATURE_DUO_PRACTICE 等
- env.ts 新增 isFeatureEnabled 方法
- 菜单根据功能开关动态显示/隐藏
- 路由守卫拦截未启用功能的直接访问
- 开发环境默认开启双人对练,生产环境默认关闭
This commit is contained in:
yuliang_guo
2026-01-31 14:26:52 +08:00
parent d2e6abfc80
commit 8500308919
6 changed files with 52 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import { ElMessage } from 'element-plus'
import { authManager } from '@/utils/auth'
import { loadingManager } from '@/utils/loadingManager'
import { checkTeamMembership, checkCourseAccess, clearPermissionCache } from '@/utils/permissionChecker'
import { env } from '@/config/env'
// 白名单路由(不需要登录)
const WHITE_LIST = ['/login', '/register', '/404']
@@ -102,6 +103,14 @@ async function handleRouteGuard(
}
}
// 检查功能开关
const feature = to.meta?.feature as string | undefined
if (feature && !env.isFeatureEnabled(feature)) {
ElMessage.warning('此功能暂未开放')
next(authManager.getDefaultRoute())
return
}
// 检查路由权限
if (!checkRoutePermission(path)) {
ElMessage.error('您没有访问此页面的权限')
@@ -302,5 +311,6 @@ declare module 'vue-router' {
affix?: boolean
breadcrumb?: boolean
activeMenu?: string
feature?: string // 功能开关标识
}
}