feat(admin): 新增题库、排行榜、实时结果和模板管理功能
- 添加题库管理页面及相关组件 - 实现排行榜管理功能,包括列表和详情页 - 新增实时结果展示页面 - 添加模板制作和管理功能 - 完善路由配置和国际化支持 - 新增阿里云OSS文件上传服务 - 添加多种工具函数和类型定义 - 优化表格和表单组件 - 调整布局和样式细节
This commit is contained in:
@ -30,27 +30,26 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
const { bool: isInitAuthRoute, setBool: setIsInitAuthRoute } = useBoolean()
|
||||
|
||||
/**
|
||||
* Auth route mode
|
||||
* 权限路由模式
|
||||
*
|
||||
* It recommends to use static mode in the development environment, and use dynamic mode in the production
|
||||
* environment, if use static mode in development environment, the auth routes will be auto generated by plugin
|
||||
* "@elegant-router/vue"
|
||||
* 建议在开发环境中使用静态模式,在生产环境中使用动态模式
|
||||
* 如果在开发环境中使用静态模式,权限路由将由插件 "@elegant-router/vue" 自动生成
|
||||
*/
|
||||
const authRouteMode = ref(import.meta.env.VITE_AUTH_ROUTE_MODE)
|
||||
|
||||
/** Home route key */
|
||||
/** 首页路由 key */
|
||||
const routeHome = ref(import.meta.env.VITE_ROUTE_HOME)
|
||||
|
||||
/**
|
||||
* Set route home
|
||||
* 设置首页路由
|
||||
*
|
||||
* @param routeKey Route key
|
||||
* @param routeKey 路由 key
|
||||
*/
|
||||
function setRouteHome(routeKey: LastLevelRouteKey) {
|
||||
routeHome.value = routeKey
|
||||
}
|
||||
|
||||
/** constant routes */
|
||||
/** 常量路由 */
|
||||
const constantRoutes = shallowRef<ElegantConstRoute[]>([])
|
||||
|
||||
function addConstantRoutes(routes: ElegantConstRoute[]) {
|
||||
@ -63,7 +62,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
constantRoutes.value = Array.from(constantRoutesMap.values())
|
||||
}
|
||||
|
||||
/** auth routes */
|
||||
/** 权限路由 */
|
||||
const authRoutes = shallowRef<ElegantConstRoute[]>([])
|
||||
|
||||
function addAuthRoutes(routes: ElegantConstRoute[]) {
|
||||
@ -78,44 +77,51 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
|
||||
const removeRouteFns: (() => void)[] = []
|
||||
|
||||
/** Global menus */
|
||||
/** 全局菜单 */
|
||||
const menus = ref<App.Global.Menu[]>([])
|
||||
const menusForBreadcrumb = ref<App.Global.Menu[]>([])
|
||||
const searchMenus = computed(() => transformMenuToSearchMenus(menus.value))
|
||||
|
||||
/** Get global menus */
|
||||
/**
|
||||
* 获取全局菜单
|
||||
*
|
||||
* @param routes 路由
|
||||
*/
|
||||
function getGlobalMenus(routes: ElegantConstRoute[]) {
|
||||
menus.value = getGlobalMenusByAuthRoutes(routes)
|
||||
menus.value = getGlobalMenusByAuthRoutes(routes, true, false)
|
||||
menusForBreadcrumb.value = getGlobalMenusByAuthRoutes(routes, false, true)
|
||||
}
|
||||
|
||||
/** Update global menus by locale */
|
||||
/** 根据语言更新全局菜单 */
|
||||
function updateGlobalMenusByLocale() {
|
||||
menus.value = updateLocaleOfGlobalMenus(menus.value)
|
||||
menusForBreadcrumb.value = updateLocaleOfGlobalMenus(menusForBreadcrumb.value)
|
||||
}
|
||||
|
||||
/** Cache routes */
|
||||
/** 缓存路由 */
|
||||
const cacheRoutes = ref<RouteKey[]>([])
|
||||
|
||||
/**
|
||||
* Exclude cache routes
|
||||
* 排除缓存路由
|
||||
*
|
||||
* for reset route cache
|
||||
* 用于重置路由缓存
|
||||
*/
|
||||
const excludeCacheRoutes = ref<RouteKey[]>([])
|
||||
|
||||
/**
|
||||
* Get cache routes
|
||||
* 获取缓存路由
|
||||
*
|
||||
* @param routes Vue routes
|
||||
* @param routes Vue 路由
|
||||
*/
|
||||
function getCacheRoutes(routes: RouteRecordRaw[]) {
|
||||
cacheRoutes.value = getCacheRouteNames(routes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset route cache
|
||||
* 重置路由缓存
|
||||
*
|
||||
* @default
|
||||
* @param routeKey
|
||||
* @param routeKey 路由 key
|
||||
*/
|
||||
async function resetRouteCache(routeKey?: RouteKey) {
|
||||
const routeName = routeKey || (router.currentRoute.value.name as RouteKey)
|
||||
@ -127,10 +133,10 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
excludeCacheRoutes.value = []
|
||||
}
|
||||
|
||||
/** Global breadcrumbs */
|
||||
const breadcrumbs = computed(() => getBreadcrumbsByRoute(router.currentRoute.value, menus.value))
|
||||
/** 全局面包屑 */
|
||||
const breadcrumbs = computed(() => getBreadcrumbsByRoute(router.currentRoute.value, menusForBreadcrumb.value))
|
||||
|
||||
/** Reset store */
|
||||
/** 重置 store */
|
||||
async function resetStore() {
|
||||
const routeStore = useRouteStore()
|
||||
|
||||
@ -138,34 +144,35 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
|
||||
resetVueRoutes()
|
||||
|
||||
// after reset store, need to re-init constant route
|
||||
// 重置 store 后,需要重新初始化常量路由
|
||||
await initConstantRoute()
|
||||
}
|
||||
|
||||
/** Reset vue routes */
|
||||
/** 重置 vue 路由 */
|
||||
function resetVueRoutes() {
|
||||
removeRouteFns.forEach(fn => fn())
|
||||
removeRouteFns.length = 0
|
||||
}
|
||||
|
||||
/** init constant route */
|
||||
/** 初始化常量路由 */
|
||||
async function initConstantRoute() {
|
||||
if (isInitConstantRoute.value)
|
||||
return
|
||||
|
||||
// 静态路由
|
||||
const staticRoute = createStaticRoutes()
|
||||
|
||||
if (authRouteMode.value === 'static') {
|
||||
// 如果是静态路由模式,直接添加静态常量路由
|
||||
if (authRouteMode.value === 'static') { // 静态路由模式
|
||||
addConstantRoutes(staticRoute.constantRoutes)
|
||||
}
|
||||
else {
|
||||
}else {// 动态路由模式
|
||||
const { data, error } = await fetchGetConstantRoutes()
|
||||
|
||||
if (!error) {
|
||||
addConstantRoutes(data)
|
||||
}
|
||||
else {
|
||||
// if fetch constant routes failed, use static constant routes
|
||||
// 如果获取常量路由失败,使用静态常量路由
|
||||
addConstantRoutes(staticRoute.constantRoutes)
|
||||
}
|
||||
}
|
||||
@ -177,9 +184,9 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
tabStore.initHomeTab()
|
||||
}
|
||||
|
||||
/** Init auth route */
|
||||
/** 初始化权限路由 */
|
||||
async function initAuthRoute() {
|
||||
// check if user info is initialized
|
||||
// 检查用户信息是否已初始化
|
||||
if (!authStore.userInfo.userId) {
|
||||
await authStore.initUserInfo()
|
||||
}
|
||||
@ -194,7 +201,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
tabStore.initHomeTab()
|
||||
}
|
||||
|
||||
/** Init static auth route */
|
||||
/** 初始化静态权限路由 */
|
||||
function initStaticAuthRoute() {
|
||||
const { authRoutes: staticAuthRoutes } = createStaticRoutes()
|
||||
|
||||
@ -212,7 +219,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
setIsInitAuthRoute(true)
|
||||
}
|
||||
|
||||
/** Init dynamic auth route */
|
||||
/** 初始化动态权限路由 */
|
||||
async function initDynamicAuthRoute() {
|
||||
const { data, error } = await fetchGetUserRoutes()
|
||||
|
||||
@ -230,12 +237,12 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
setIsInitAuthRoute(true)
|
||||
}
|
||||
else {
|
||||
// if fetch user routes failed, reset store
|
||||
// 如果获取用户路由失败,重置 store
|
||||
authStore.resetStore()
|
||||
}
|
||||
}
|
||||
|
||||
/** handle constant and auth routes */
|
||||
/** 处理常量路由和权限路由 */
|
||||
function handleConstantAndAuthRoutes() {
|
||||
const allRoutes = [...constantRoutes.value, ...authRoutes.value]
|
||||
|
||||
@ -253,9 +260,9 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add routes to vue router
|
||||
* 添加路由到 vue router
|
||||
*
|
||||
* @param routes Vue routes
|
||||
* @param routes Vue 路由
|
||||
*/
|
||||
function addRoutesToVueRouter(routes: RouteRecordRaw[]) {
|
||||
routes.forEach((route) => {
|
||||
@ -265,18 +272,18 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add remove route fn
|
||||
* 添加删除路由函数
|
||||
*
|
||||
* @param fn
|
||||
* @param fn 删除函数
|
||||
*/
|
||||
function addRemoveRouteFn(fn: () => void) {
|
||||
removeRouteFns.push(fn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update root route redirect when auth route mode is dynamic
|
||||
* 当权限路由模式为动态时,更新根路由重定向
|
||||
*
|
||||
* @param redirectKey Redirect route key
|
||||
* @param redirectKey 重定向路由 key
|
||||
*/
|
||||
function handleUpdateRootRouteRedirect(redirectKey: LastLevelRouteKey) {
|
||||
const redirect = getRoutePath(redirectKey)
|
||||
@ -293,9 +300,9 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is auth route exist
|
||||
* 获取权限路由是否存在
|
||||
*
|
||||
* @param routePath Route path
|
||||
* @param routePath 路由路径
|
||||
*/
|
||||
async function getIsAuthRouteExist(routePath: RouteMap[RouteKey]) {
|
||||
const routeName = getRouteName(routePath)
|
||||
@ -315,20 +322,20 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selected menu key path
|
||||
* 获取选中的菜单 key 路径
|
||||
*
|
||||
* @param selectedKey Selected menu key
|
||||
* @param selectedKey 选中的菜单 key
|
||||
*/
|
||||
function getSelectedMenuKeyPath(selectedKey: string) {
|
||||
return getSelectedMenuKeyPathByKey(selectedKey, menus.value)
|
||||
}
|
||||
|
||||
async function onRouteSwitchWhenLoggedIn() {
|
||||
// some global init logic when logged in and switch route
|
||||
// 登录并切换路由时的一些全局初始化逻辑
|
||||
}
|
||||
|
||||
async function onRouteSwitchWhenNotLoggedIn() {
|
||||
// some global init logic if it does not need to be logged in
|
||||
// 如果不需要登录时的一些全局初始化逻辑
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user