fix: 控制台加权限,登录跳转资产信息
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 7m4s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 7m4s
This commit is contained in:
@@ -274,12 +274,15 @@ async function processBackendMenu(router: Router): Promise<void> {
|
||||
/**
|
||||
* 合并默认菜单
|
||||
* 将配置的默认菜单合并到后端返回的菜单中
|
||||
* 注意: /dashboard 及其子路由(console/analysis/ecommerce)不再作为默认菜单强制显示
|
||||
* 这些路由只有在后端 menus 中返回时才会显示
|
||||
*/
|
||||
function mergeDefaultMenus(
|
||||
backendMenus: AppRouteRecord[],
|
||||
routeMap: Map<string, AppRouteRecord>
|
||||
): AppRouteRecord[] {
|
||||
const defaultMenuPaths = ['/dashboard']
|
||||
// 移除 /dashboard 作为默认菜单,现在仪表台路由完全由后端控制
|
||||
const defaultMenuPaths: string[] = []
|
||||
|
||||
const defaultMenus: AppRouteRecord[] = defaultMenuPaths
|
||||
.map((path) => {
|
||||
|
||||
@@ -12,6 +12,28 @@ export const router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }) // 滚动行为
|
||||
})
|
||||
|
||||
// 处理路由错误(Chunk 加载失败等)
|
||||
router.onError((error) => {
|
||||
const pattern = /Loading chunk (\d+) failed|Failed to fetch dynamically imported module|Couldn't resolve component/
|
||||
const isChunkLoadFailed = error.message && pattern.test(error.message)
|
||||
|
||||
if (isChunkLoadFailed) {
|
||||
const key = '__route_chunk_reload__'
|
||||
const hasReloaded = sessionStorage.getItem(key)
|
||||
|
||||
if (!hasReloaded) {
|
||||
console.warn('检测到 chunk 加载失败,尝试刷新页面...')
|
||||
sessionStorage.setItem(key, '1')
|
||||
window.location.reload()
|
||||
} else {
|
||||
console.error('页面刷新后仍然无法加载组件,请联系管理员')
|
||||
sessionStorage.removeItem(key)
|
||||
}
|
||||
} else {
|
||||
console.error('[路由错误]:', error)
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化路由
|
||||
export function initRouter(app: App<Element>): void {
|
||||
configureNProgress() // 顶部进度条
|
||||
|
||||
@@ -105,5 +105,5 @@ export enum RoutesAlias {
|
||||
Calendar = '/template/calendar' // 日历
|
||||
}
|
||||
|
||||
// 主页路由
|
||||
export const HOME_PAGE = RoutesAlias.Dashboard
|
||||
// 主页路由 - 修改为资产信息页面
|
||||
export const HOME_PAGE = RoutesAlias.AssetInformation
|
||||
|
||||
@@ -98,17 +98,13 @@ function checkDuplicateRoutes(routes: AppRouteRecord[], parentPath = ''): void {
|
||||
* 获取组件路径的字符串表示
|
||||
*/
|
||||
function getComponentPathString(component: any): string {
|
||||
// 只处理字符串类型的组件路径
|
||||
if (typeof component === 'string') {
|
||||
return component
|
||||
}
|
||||
|
||||
// 对于其他别名路由,获取组件名称
|
||||
for (const key in RoutesAlias) {
|
||||
if (RoutesAlias[key as keyof typeof RoutesAlias] === component) {
|
||||
return `RoutesAlias.${key}`
|
||||
}
|
||||
}
|
||||
|
||||
// 对于函数类型的组件(懒加载),返回空字符串
|
||||
// 因为这些组件已经是有效的组件定义,不需要再次处理
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -250,9 +246,8 @@ function handleNormalRoute(
|
||||
routeName: string
|
||||
): void {
|
||||
if (component) {
|
||||
const aliasComponent = RoutesAlias[
|
||||
component as keyof typeof RoutesAlias
|
||||
] as unknown as RouteRecordRaw['component']
|
||||
converted.component = aliasComponent || loadComponent(component as string, routeName)
|
||||
// 直接使用 loadComponent 加载组件
|
||||
// component 参数是路由路径(如 "/system/role"),loadComponent 会将其转换为组件导入路径
|
||||
converted.component = loadComponent(component as string, routeName)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user