【同步】前端项目源码

【修复】工作流兼容问题
This commit is contained in:
chudong
2025-05-10 11:53:11 +08:00
parent c514471adc
commit f1a75afaba
584 changed files with 55714 additions and 110 deletions

View File

@@ -0,0 +1,31 @@
import { createDiscreteApi } from 'naive-ui'
import type { Router, RouteLocationNormalized, NavigationGuardNext } from '@baota/router/each'
import { useCreateRouterEach } from '@baota/router/each' // 全局路由守卫
// 创建离散API
const { loadingBar } = createDiscreteApi(['loadingBar'])
/**
* @description 全局路由守卫
* @param {Router} router 路由实例
* @return {void}
*/
const useRouterEach = (router: Router) =>
useCreateRouterEach(router, {
beforeEach: (to: RouteLocationNormalized, _: RouteLocationNormalized, next: NavigationGuardNext) => {
// 开始加载
loadingBar.start()
// 判断当前路由是否存在,如果不存在,则跳转到 404
if (!router.hasRoute(to.name as string)) {
if (!to.path.includes('/404')) return next({ path: '/404' })
}
next()
},
afterEach: (to: RouteLocationNormalized) => {
loadingBar.finish()
console.log('afterEach', to)
},
})
export default useRouterEach

View File

@@ -0,0 +1,17 @@
import { getBuildRoutes } from '@baota/router/import'
import routeConfig from '@config/route'
/**
* @description 创建路由,动态获取路由配置
* @returns {RouteRecordRaw[]} 路由配置
*/
export const createRoutes = () => {
const modules = import.meta.glob('../views/*/index.tsx')
const childrenModules = import.meta.glob(`../views/*/children/*/index.tsx`)
return getBuildRoutes(modules, childrenModules, {
framework: routeConfig.frameworkRoute,
system: routeConfig.systemRoute,
sort: routeConfig.sortRoute,
disabled: routeConfig.disabledRoute,
})
}

View File

@@ -0,0 +1,17 @@
import { createWebHistory, useCreateRouter } from '@baota/router' // 框架路由
import { createRoutes } from './import' // 自动导入路由配置
import useRouterEach from './each' // 全局路由守卫
// 获取路由
const { routeGroup, routes } = createRoutes() // 获取路由配置
// 创建路由
const router = useCreateRouter({
routes: routeGroup,
history: createWebHistory(),
})
// 全局路由守卫
useRouterEach(router)
export { router, routes }