@ruan-cat/utils 4.3.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { RouteRecordRaw } from "vue-router";
|
|
11
11
|
import { omit } from "lodash-es";
|
|
12
|
+
import { consola } from "consola";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* 处理单个路由,包括处理空路径子路由和拼接完整路径
|
|
@@ -67,3 +68,38 @@ export function disposalAutoRouter(routes: RouteRecordRaw[]): RouteRecordRaw[] {
|
|
|
67
68
|
// 处理所有顶级路由
|
|
68
69
|
return routes.map((route) => processRoute(route));
|
|
69
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 打印自动路由信息(支持嵌套,完整打印每层对象)
|
|
74
|
+
* @param routes 路由对象或数组
|
|
75
|
+
* @param level 当前缩进层级(内部递归用)
|
|
76
|
+
* @description
|
|
77
|
+
* 一个辅助函数 帮助打印路由的信息
|
|
78
|
+
*
|
|
79
|
+
* @deprecated
|
|
80
|
+
* 废弃 不如直接json转换一次,输出效果还好。
|
|
81
|
+
* `JSON.stringify(result, null, 2)`
|
|
82
|
+
*/
|
|
83
|
+
export function printAutoRouter(routes: RouteRecordRaw[] | RouteRecordRaw, level = 0): void {
|
|
84
|
+
const indent = (n: number) => " ".repeat(n);
|
|
85
|
+
|
|
86
|
+
const printOne = (route: RouteRecordRaw, lvl: number) => {
|
|
87
|
+
const prefix = indent(lvl);
|
|
88
|
+
// console.log(`${prefix}Route Level ${lvl}`);
|
|
89
|
+
console.warn(prefix + JSON.stringify(route, null, 2));
|
|
90
|
+
if (route.children && route.children.length > 0) {
|
|
91
|
+
// console.log(`${prefix}children:`);
|
|
92
|
+
route.children.forEach((child) => printOne(child, lvl + 1));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (Array.isArray(routes)) {
|
|
97
|
+
// console.log("打印路由数组...");
|
|
98
|
+
routes.forEach((route) => printOne(route, level));
|
|
99
|
+
// console.log("打印结束");
|
|
100
|
+
} else {
|
|
101
|
+
// console.log("打印单个路由...");
|
|
102
|
+
printOne(routes, level);
|
|
103
|
+
// console.log("打印结束");
|
|
104
|
+
}
|
|
105
|
+
}
|