@ditari/bsui 1.0.39 → 1.0.40
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("vue"),v=require("vue-router"),m=require("../../store/modules/Breadcrumb.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("vue"),v=require("vue-router"),m=require("../../store/modules/Breadcrumb.cjs.js"),g=()=>{const{saveBreadcrumb:a}=m.useBreadcrumbStore(),e=d.ref(null);return{getRoutes:async c=>{const r=[];for await(const o of Object.values(c)){const u=await o();r.push(...u.default)}return e.value=v.createRouterMatcher(r,{}),f(r)},setMatched:(c,r)=>{var u;const o=d.ref([]);try{const n=((u=e.value)==null?void 0:u.resolve(c,r).matched)??[];o.value=n.reduce((h,i)=>{var l;return h.some(p=>p.path===i.path)||h.push({path:i.path,title:((l=i.meta)==null?void 0:l.title)??"未设置标题"}),h},[])}catch(n){console.log(n),o.value=[]}a(o.value)}}};function f(a,e=""){const s=[];for(const t of a)t.path===""?t.path=e:t.path.startsWith("/")||(t.path=`${e}/${t.path}`),t.children&&(s.push(...f(t.children,t.path)),delete t.children),s.push(t);return s}exports.useDitariRoute=g;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { RouteLocationNormalized
|
|
1
|
+
import { RouteLocationNormalized } from "vue-router";
|
|
2
2
|
/**
|
|
3
3
|
* 路由处理
|
|
4
4
|
*/
|
|
5
5
|
export declare const useDitariRoute: () => {
|
|
6
6
|
getRoutes: (routeFiles: Record<string, () => Promise<unknown>>) => Promise<any>;
|
|
7
7
|
setMatched: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void;
|
|
8
|
-
createMatcher: (routes: RouteRecordRaw[]) => void;
|
|
9
8
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { RouteLocationNormalized
|
|
1
|
+
import { RouteLocationNormalized } from "vue-router";
|
|
2
2
|
/**
|
|
3
3
|
* 路由处理
|
|
4
4
|
*/
|
|
5
5
|
export declare const useDitariRoute: () => {
|
|
6
6
|
getRoutes: (routeFiles: Record<string, () => Promise<unknown>>) => Promise<any>;
|
|
7
7
|
setMatched: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void;
|
|
8
|
-
createMatcher: (routes: RouteRecordRaw[]) => void;
|
|
9
8
|
};
|
|
@@ -1,47 +1,44 @@
|
|
|
1
1
|
import { ref as f } from "vue";
|
|
2
2
|
import { createRouterMatcher as m } from "vue-router";
|
|
3
3
|
import { useBreadcrumbStore as v } from "../../store/modules/Breadcrumb.esm.js";
|
|
4
|
-
const
|
|
5
|
-
const { saveBreadcrumb:
|
|
4
|
+
const w = () => {
|
|
5
|
+
const { saveBreadcrumb: c } = v(), e = f(null);
|
|
6
6
|
return {
|
|
7
|
-
getRoutes: async (
|
|
8
|
-
const
|
|
9
|
-
for await (const r of Object.values(
|
|
10
|
-
const
|
|
11
|
-
|
|
7
|
+
getRoutes: async (u) => {
|
|
8
|
+
const o = [];
|
|
9
|
+
for await (const r of Object.values(u)) {
|
|
10
|
+
const a = await r();
|
|
11
|
+
o.push(...a.default);
|
|
12
12
|
}
|
|
13
|
-
return p(
|
|
13
|
+
return e.value = m(o, {}), p(o);
|
|
14
14
|
},
|
|
15
|
-
setMatched: (
|
|
16
|
-
var
|
|
15
|
+
setMatched: (u, o) => {
|
|
16
|
+
var a;
|
|
17
17
|
const r = f([]);
|
|
18
18
|
try {
|
|
19
|
-
const
|
|
20
|
-
r.value =
|
|
19
|
+
const n = ((a = e.value) == null ? void 0 : a.resolve(u, o).matched) ?? [];
|
|
20
|
+
r.value = n.reduce((h, l) => {
|
|
21
21
|
var i;
|
|
22
|
-
return
|
|
22
|
+
return h.some(
|
|
23
23
|
(d) => d.path === l.path
|
|
24
|
-
) ||
|
|
24
|
+
) || h.push({
|
|
25
25
|
path: l.path,
|
|
26
26
|
title: ((i = l.meta) == null ? void 0 : i.title) ?? "未设置标题"
|
|
27
|
-
}),
|
|
27
|
+
}), h;
|
|
28
28
|
}, []);
|
|
29
|
-
} catch (
|
|
30
|
-
console.log(
|
|
29
|
+
} catch (n) {
|
|
30
|
+
console.log(n), r.value = [];
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
createMatcher: (o) => {
|
|
35
|
-
e.value = m(o, {});
|
|
32
|
+
c(r.value);
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
35
|
};
|
|
39
|
-
function p(
|
|
40
|
-
const
|
|
41
|
-
for (const t of
|
|
42
|
-
t.path === "" ? t.path = e : t.path.startsWith("/") || (t.path = `${e}/${t.path}`), t.children && (
|
|
43
|
-
return
|
|
36
|
+
function p(c, e = "") {
|
|
37
|
+
const s = [];
|
|
38
|
+
for (const t of c)
|
|
39
|
+
t.path === "" ? t.path = e : t.path.startsWith("/") || (t.path = `${e}/${t.path}`), t.children && (s.push(...p(t.children, t.path)), delete t.children), s.push(t);
|
|
40
|
+
return s;
|
|
44
41
|
}
|
|
45
42
|
export {
|
|
46
|
-
|
|
43
|
+
w as useDitariRoute
|
|
47
44
|
};
|
package/package.json
CHANGED
package/src/hooks/route/index.ts
CHANGED
|
@@ -17,14 +17,6 @@ export const useDitariRoute = () => {
|
|
|
17
17
|
// 路由匹配器
|
|
18
18
|
const routerMatcher = ref<RouterMatcher | null>(null);
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* 创建匹配器
|
|
22
|
-
* @param routes 路由信息
|
|
23
|
-
*/
|
|
24
|
-
const createMatcher = (routes: RouteRecordRaw[]) => {
|
|
25
|
-
routerMatcher.value = createRouterMatcher(routes, {});
|
|
26
|
-
};
|
|
27
|
-
|
|
28
20
|
const setMatched = (
|
|
29
21
|
to: RouteLocationNormalized,
|
|
30
22
|
from: RouteLocationNormalized
|
|
@@ -66,14 +58,15 @@ export const useDitariRoute = () => {
|
|
|
66
58
|
const routeModule: any = await routeFile();
|
|
67
59
|
routes.push(...routeModule.default);
|
|
68
60
|
}
|
|
69
|
-
//
|
|
61
|
+
// 创建路由匹配器
|
|
62
|
+
routerMatcher.value = createRouterMatcher(routes, {});
|
|
63
|
+
// 数组打平返回
|
|
70
64
|
return flattenRoutes(routes);
|
|
71
65
|
};
|
|
72
66
|
|
|
73
67
|
return {
|
|
74
68
|
getRoutes,
|
|
75
|
-
setMatched
|
|
76
|
-
createMatcher
|
|
69
|
+
setMatched
|
|
77
70
|
};
|
|
78
71
|
};
|
|
79
72
|
|