mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 代码优化
ISSUES CLOSED: \
This commit is contained in:
@ -2,7 +2,6 @@ import type { Component } from 'vue';
|
||||
import { EnumLayoutComponentName } from '@/enum';
|
||||
import { BasicLayout, BlankLayout } from '@/layouts';
|
||||
import { views } from '@/views';
|
||||
import { consoleError } from '../common';
|
||||
|
||||
type LayoutComponent = Record<EnumType.LayoutComponentName, () => Promise<Component>>;
|
||||
|
||||
@ -24,7 +23,7 @@ export function getLayoutComponent(layoutType: EnumType.LayoutComponentName) {
|
||||
*/
|
||||
export function getViewComponent(routeKey: AuthRoute.RouteKey) {
|
||||
if (!views[routeKey]) {
|
||||
consoleError(`路由“${routeKey}”没有对应的组件文件!`);
|
||||
window.console.error(`路由“${routeKey}”没有对应的组件文件!`);
|
||||
}
|
||||
return () => setViewComponentName(views[routeKey], routeKey) as Promise<Component>;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { consoleError } from '../common';
|
||||
import { getLayoutComponent, getViewComponent } from './component';
|
||||
|
||||
/**
|
||||
@ -113,7 +112,7 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
Object.assign(itemRoute, { meta: { ...itemRoute.meta, multi: true } });
|
||||
delete itemRoute.component;
|
||||
} else {
|
||||
consoleError('多级路由缺少子路由: ', item);
|
||||
window.console.error('多级路由缺少子路由: ', item);
|
||||
}
|
||||
},
|
||||
self() {
|
||||
@ -124,17 +123,17 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
if (item.component) {
|
||||
action[item.component]();
|
||||
} else {
|
||||
consoleError('路由组件解析失败: ', item);
|
||||
window.console.error('路由组件解析失败: ', item);
|
||||
}
|
||||
} catch {
|
||||
consoleError('路由组件解析失败: ', item);
|
||||
window.console.error('路由组件解析失败: ', item);
|
||||
}
|
||||
}
|
||||
|
||||
// 注意:单独路由没有children
|
||||
if (isSingleRoute(item)) {
|
||||
if (hasChildren(item)) {
|
||||
consoleError('单独路由不应该有子路由: ', item);
|
||||
window.console.error('单独路由不应该有子路由: ', item);
|
||||
}
|
||||
|
||||
// 捕获无效路由的需特殊处理
|
||||
@ -169,7 +168,7 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
// 找出第一个不为多级路由中间级的子路由路径作为重定向路径
|
||||
const redirectPath: AuthRoute.RoutePath = (children.find(v => !v.meta?.multi)?.path || '/') as AuthRoute.RoutePath;
|
||||
if (redirectPath === '/') {
|
||||
consoleError('该多级路由没有有效的子路径', item);
|
||||
window.console.error('该多级路由没有有效的子路径', item);
|
||||
}
|
||||
|
||||
if (item.component === 'multi') {
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { consoleError } from '../common';
|
||||
|
||||
/**
|
||||
* 权限路由排序
|
||||
* @param routes - 权限路由
|
||||
@ -20,7 +18,7 @@ export function handleModuleRoutes(modules: AuthRoute.RouteModule) {
|
||||
if (item) {
|
||||
routes.push(item);
|
||||
} else {
|
||||
consoleError(`路由模块解析出错: key = ${key}`);
|
||||
window.console.error(`路由模块解析出错: key = ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user