@ditari/bsui 1.0.38 → 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.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),v=require("vue-router"),h=require("pinia"),b=require("../../store/modules/Menu.cjs.js"),K=require("../../store/modules/Settings.cjs.js");function U(o){return typeof o=="function"||Object.prototype.toString.call(o)==="[object Object]"&&!t.isVNode(o)}const j=t.defineComponent({name:"DMenu",setup(){const o=v.useRouter(),f=v.useRoute(),{componentName:s,prop:q}=t.inject("menuIcon"),g=b.useMenuStore(),{list:a,openMenusKeys:l,selectedMenuKeys:u}=h.storeToRefs(g),N=K.useSettingsStore(),{getCollapsed:S}=h.storeToRefs(N);t.watchEffect(()=>{const e=u.value.length>0?u.value[0]:"",n=i(a.value,e);l.value=n||[]});function i(e,n){for(let r=0;r<e.length;r++){if(e[r].url===n||n.startsWith(e[r].url))return[e[r].url];if(e[r].children&&e[r].children.length>0){const c=i(e[r].children,n);if(c)return[e[r].url,...c]}}return null}const m=({item:e,key:n,keyPath:r})=>{l.value=r,u.value=[n],f.path!==n&&o.push(n).then(c=>c?console.warn(c):null)},V=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-menu-item"),{key:e.url},{icon:()=>d(e),default:()=>e.title})]),M=["anticon","anticon-menu","ant-menu-item-icon"],d=e=>t.createVNode(t.Fragment,null,[e.icon?y(e.icon):t.withDirectives(t.createVNode("div",{className:M},[e.title.substring(0,1)]),[[t.vShow,S.value]])]),y=e=>s==="nativeHtml"?t.createVNode("span",{innerHTML:e},null):t.h(t.resolveComponent(s),{prop:e}),p=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-sub-menu"),{key:e.url},{title:()=>e.title,icon:()=>d(e),default:()=>e.children.map(n=>!n.children||n.children.length===0?C(n):p(n))})]),C=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-menu-item"),{key:e.url},{default:()=>e.title})]);return()=>{let e;return t.createVNode(t.Fragment,null,[l.value,t.createVNode(t.resolveComponent("a-menu"),{mode:"inline",theme:"dark",openKeys:l.value,"onUpdate:openKeys":n=>l.value=n,selectedKeys:u.value,"onUpdate:selectedKeys":n=>u.value=n,onClick:m},U(e=a.value.map(n=>{var r;return!n.children||((r=n.children)==null?void 0:r.length)===0?V(n):p(n)}))?e:{default:()=>[e]})])}}});exports.default=j;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),v=require("vue-router"),h=require("pinia"),b=require("../../store/modules/Menu.cjs.js"),K=require("../../store/modules/Settings.cjs.js");function U(o){return typeof o=="function"||Object.prototype.toString.call(o)==="[object Object]"&&!t.isVNode(o)}const j=t.defineComponent({name:"DMenu",setup(){const o=v.useRouter(),f=v.useRoute(),{componentName:s,prop:q}=t.inject("menuIcon"),g=b.useMenuStore(),{list:a,openMenusKeys:u,selectedMenuKeys:l}=h.storeToRefs(g),N=K.useSettingsStore(),{getCollapsed:S}=h.storeToRefs(N);t.watchEffect(()=>{const e=l.value.length>0?l.value[0]:"",n=i(a.value,e);u.value=n||[]});function i(e,n){for(let r=0;r<e.length;r++){if(e[r].url===n||n.startsWith(e[r].url))return[e[r].url];if(e[r].children&&e[r].children.length>0){const c=i(e[r].children,n);if(c)return[e[r].url,...c]}}return null}const m=({item:e,key:n,keyPath:r})=>{u.value=r,l.value=[n],f.path!==n&&o.push(n).then(c=>c?console.warn(c):null)},V=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-menu-item"),{key:e.url},{icon:()=>d(e),default:()=>e.title})]),M=["anticon","anticon-menu","ant-menu-item-icon"],d=e=>t.createVNode(t.Fragment,null,[e.icon?y(e.icon):t.withDirectives(t.createVNode("div",{className:M},[e.title.substring(0,1)]),[[t.vShow,S.value]])]),y=e=>s==="nativeHtml"?t.createVNode("span",{innerHTML:e},null):t.h(t.resolveComponent(s),{prop:e}),p=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-sub-menu"),{key:e.url},{title:()=>e.title,icon:()=>d(e),default:()=>e.children.map(n=>!n.children||n.children.length===0?C(n):p(n))})]),C=e=>t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-menu-item"),{key:e.url},{default:()=>e.title})]);return()=>{let e;return t.createVNode(t.Fragment,null,[t.createVNode(t.resolveComponent("a-menu"),{mode:"inline",theme:"dark",openKeys:u.value,"onUpdate:openKeys":n=>u.value=n,selectedKeys:l.value,"onUpdate:selectedKeys":n=>l.value=n,onClick:m},U(e=a.value.map(n=>{var r;return!n.children||((r=n.children)==null?void 0:r.length)===0?V(n):p(n)}))?e:{default:()=>[e]})])}}});exports.default=j;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),m=require("vue-router"),p=require("../../store/modules/Breadcrumb.cjs.js"),b=r=>{const{saveBreadcrumb:s}=p.useBreadcrumbStore(),e=l.ref(null),t=l.ref([]);return e.value=m.createRouterMatcher(r,{}),{flatRoutes:i(r,null),setMatched:(d,f)=>{var u;try{const c=((u=e.value)==null?void 0:u.resolve(d,f).matched)??[];t.value=c.reduce((a,n)=>{var h;return a.some(v=>v.path===n.path)||a.push({path:n.path,title:((h=n.meta)==null?void 0:h.title)??"未设置标题"}),a},[])}catch(c){console.log(c),t.value=[]}s(t.value)}}};function i(r,s){return r.reduce((e,t)=>{if(t.children&&e.push(...i(t.children,t)),t.component){const o=`${s==null?void 0:s.path}`+(t.path?"/"+t.path:"");e.push({...t,path:o})}return e},[])}exports.useDitariRoute=b;
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, RouteRecordRaw } from "vue-router";
1
+ import { RouteLocationNormalized } from "vue-router";
2
2
  /**
3
- * 路由管理
4
- * @param routes 未打平的路由
3
+ * 路由处理
5
4
  */
6
- export declare const useDitariRoute: (routes: RouteRecordRaw[]) => {
7
- flatRoutes: any[];
5
+ export declare const useDitariRoute: () => {
6
+ getRoutes: (routeFiles: Record<string, () => Promise<unknown>>) => Promise<any>;
8
7
  setMatched: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void;
9
8
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent as w, inject as j, watchEffect as k, createVNode as r, Fragment as i, resolveComponent as s, isVNode as N, withDirectives as I, vShow as R, h as D } from "vue";
1
+ import { defineComponent as w, inject as j, watchEffect as k, createVNode as r, Fragment as c, resolveComponent as i, isVNode as N, withDirectives as I, vShow as R, h as D } from "vue";
2
2
  import { useRouter as H, useRoute as O } from "vue-router";
3
3
  import { storeToRefs as v } from "pinia";
4
4
  import { useMenuStore as T } from "../../store/modules/Menu.esm.js";
@@ -14,23 +14,23 @@ const q = /* @__PURE__ */ w({
14
14
  prop: x
15
15
  } = j("menuIcon"), g = T(), {
16
16
  list: d,
17
- openMenusKeys: o,
18
- selectedMenuKeys: u
17
+ openMenusKeys: s,
18
+ selectedMenuKeys: o
19
19
  } = v(g), S = V(), {
20
20
  getCollapsed: y
21
21
  } = v(S);
22
22
  k(() => {
23
- const e = u.value.length > 0 ? u.value[0] : "", t = p(d.value, e);
24
- o.value = t || [];
23
+ const e = o.value.length > 0 ? o.value[0] : "", t = p(d.value, e);
24
+ s.value = t || [];
25
25
  });
26
26
  function p(e, t) {
27
27
  for (let n = 0; n < e.length; n++) {
28
28
  if (e[n].url === t || t.startsWith(e[n].url))
29
29
  return [e[n].url];
30
30
  if (e[n].children && e[n].children.length > 0) {
31
- const c = p(e[n].children, t);
32
- if (c)
33
- return [e[n].url, ...c];
31
+ const u = p(e[n].children, t);
32
+ if (u)
33
+ return [e[n].url, ...u];
34
34
  }
35
35
  }
36
36
  return null;
@@ -40,19 +40,19 @@ const q = /* @__PURE__ */ w({
40
40
  key: t,
41
41
  keyPath: n
42
42
  }) => {
43
- o.value = n, u.value = [t], m.path !== t && l.push(t).then((c) => c ? console.warn(c) : null);
44
- }, b = (e) => r(i, null, [r(s("a-menu-item"), {
43
+ s.value = n, o.value = [t], m.path !== t && l.push(t).then((u) => u ? console.warn(u) : null);
44
+ }, b = (e) => r(c, null, [r(i("a-menu-item"), {
45
45
  key: e.url
46
46
  }, {
47
47
  icon: () => f(e),
48
48
  default: () => e.title
49
- })]), C = ["anticon", "anticon-menu", "ant-menu-item-icon"], f = (e) => r(i, null, [e.icon ? K(e.icon) : I(r("div", {
49
+ })]), C = ["anticon", "anticon-menu", "ant-menu-item-icon"], f = (e) => r(c, null, [e.icon ? K(e.icon) : I(r("div", {
50
50
  className: C
51
51
  }, [e.title.substring(0, 1)]), [[R, y.value]])]), K = (e) => a === "nativeHtml" ? r("span", {
52
52
  innerHTML: e
53
- }, null) : D(s(a), {
53
+ }, null) : D(i(a), {
54
54
  prop: e
55
- }), h = (e) => r(i, null, [r(s("a-sub-menu"), {
55
+ }), h = (e) => r(c, null, [r(i("a-sub-menu"), {
56
56
  key: e.url
57
57
  }, {
58
58
  title: () => e.title,
@@ -61,20 +61,20 @@ const q = /* @__PURE__ */ w({
61
61
  (t) => !t.children || t.children.length === 0 ? U(t) : h(t)
62
62
  // 递归调用
63
63
  )
64
- })]), U = (e) => r(i, null, [r(s("a-menu-item"), {
64
+ })]), U = (e) => r(c, null, [r(i("a-menu-item"), {
65
65
  key: e.url
66
66
  }, {
67
67
  default: () => e.title
68
68
  })]);
69
69
  return () => {
70
70
  let e;
71
- return r(i, null, [o.value, r(s("a-menu"), {
71
+ return r(c, null, [r(i("a-menu"), {
72
72
  mode: "inline",
73
73
  theme: "dark",
74
- openKeys: o.value,
75
- "onUpdate:openKeys": (t) => o.value = t,
76
- selectedKeys: u.value,
77
- "onUpdate:selectedKeys": (t) => u.value = t,
74
+ openKeys: s.value,
75
+ "onUpdate:openKeys": (t) => s.value = t,
76
+ selectedKeys: o.value,
77
+ "onUpdate:selectedKeys": (t) => o.value = t,
78
78
  onClick: M
79
79
  }, _(e = d.value.map((t) => {
80
80
  var n;
@@ -1,9 +1,8 @@
1
- import { RouteLocationNormalized, RouteRecordRaw } from "vue-router";
1
+ import { RouteLocationNormalized } from "vue-router";
2
2
  /**
3
- * 路由管理
4
- * @param routes 未打平的路由
3
+ * 路由处理
5
4
  */
6
- export declare const useDitariRoute: (routes: RouteRecordRaw[]) => {
7
- flatRoutes: any[];
5
+ export declare const useDitariRoute: () => {
6
+ getRoutes: (routeFiles: Record<string, () => Promise<unknown>>) => Promise<any>;
8
7
  setMatched: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void;
9
8
  };
@@ -1,42 +1,44 @@
1
1
  import { ref as f } from "vue";
2
- import { createRouterMatcher as u } from "vue-router";
2
+ import { createRouterMatcher as m } from "vue-router";
3
3
  import { useBreadcrumbStore as v } from "../../store/modules/Breadcrumb.esm.js";
4
- const y = (a) => {
5
- const { saveBreadcrumb: s } = v(), e = f(null), t = f([]);
6
- return e.value = u(a, {}), {
7
- flatRoutes: i(a, null),
8
- setMatched: (m, d) => {
9
- var n;
4
+ const w = () => {
5
+ const { saveBreadcrumb: c } = v(), e = f(null);
6
+ return {
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
+ }
13
+ return e.value = m(o, {}), p(o);
14
+ },
15
+ setMatched: (u, o) => {
16
+ var a;
17
+ const r = f([]);
10
18
  try {
11
- const c = ((n = e.value) == null ? void 0 : n.resolve(m, d).matched) ?? [];
12
- t.value = c.reduce((h, o) => {
13
- var l;
19
+ const n = ((a = e.value) == null ? void 0 : a.resolve(u, o).matched) ?? [];
20
+ r.value = n.reduce((h, l) => {
21
+ var i;
14
22
  return h.some(
15
- (p) => p.path === o.path
23
+ (d) => d.path === l.path
16
24
  ) || h.push({
17
- path: o.path,
18
- title: ((l = o.meta) == null ? void 0 : l.title) ?? "未设置标题"
25
+ path: l.path,
26
+ title: ((i = l.meta) == null ? void 0 : i.title) ?? "未设置标题"
19
27
  }), h;
20
28
  }, []);
21
- } catch (c) {
22
- console.log(c), t.value = [];
29
+ } catch (n) {
30
+ console.log(n), r.value = [];
23
31
  }
24
- s(t.value);
32
+ c(r.value);
25
33
  }
26
34
  };
27
35
  };
28
- function i(a, s) {
29
- return a.reduce((e, t) => {
30
- if (t.children && e.push(...i(t.children, t)), t.component) {
31
- const r = `${s == null ? void 0 : s.path}` + (t.path ? "/" + t.path : "");
32
- e.push({
33
- ...t,
34
- path: r
35
- });
36
- }
37
- return e;
38
- }, []);
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;
39
41
  }
40
42
  export {
41
- y as useDitariRoute
43
+ w as useDitariRoute
42
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditari/bsui",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "files": [
5
5
  "dist/**",
6
6
  "src"
@@ -154,7 +154,6 @@ export default defineComponent({
154
154
 
155
155
  return () => (
156
156
  <>
157
- {openMenusKeys.value}
158
157
  <a-menu
159
158
  mode="inline"
160
159
  theme="dark"
@@ -10,29 +10,19 @@ import {
10
10
  import { useBreadcrumbStore } from "../../store/modules/Breadcrumb";
11
11
 
12
12
  /**
13
- * 路由管理
14
- * @param routes 未打平的路由
13
+ * 路由处理
15
14
  */
16
- export const useDitariRoute = (routes: RouteRecordRaw[]) => {
15
+ export const useDitariRoute = () => {
17
16
  const { saveBreadcrumb } = useBreadcrumbStore();
18
17
  // 路由匹配器
19
18
  const routerMatcher = ref<RouterMatcher | null>(null);
20
- // 匹配到的路由数据
21
- const matched = ref<RouteLocationMatched[]>([]);
22
- //创建匹配器
23
- routerMatcher.value = createRouterMatcher(routes, {});
24
- // 保存打平后的路由
25
- const flatRoutes = flattenRoutes(routes, null);
26
19
 
27
- /**
28
- * 进行匹配
29
- * @param to
30
- * @param from
31
- */
32
20
  const setMatched = (
33
21
  to: RouteLocationNormalized,
34
22
  from: RouteLocationNormalized
35
23
  ) => {
24
+ // 匹配到的路由数据
25
+ const matched = ref<RouteLocationMatched[]>([]);
36
26
  try {
37
27
  const rs = routerMatcher.value?.resolve(to, from).matched ?? [];
38
28
  matched.value = rs.reduce((preValue: any[], curValue) => {
@@ -51,34 +41,121 @@ export const useDitariRoute = (routes: RouteRecordRaw[]) => {
51
41
  console.log(e);
52
42
  matched.value = [];
53
43
  }
54
- // 匹配到的数据保存到route store
44
+ // 匹配到的数据保存到面包屑store
55
45
  saveBreadcrumb(matched.value);
56
46
  };
57
47
 
48
+ /**
49
+ * 获取路由信息
50
+ * @param routeFiles 路由文件
51
+ */
52
+ const getRoutes = async (
53
+ routeFiles: Record<string, () => Promise<unknown>>
54
+ ) => {
55
+ const routes: any[] = [];
56
+ // 遍历路由文件并将路由合并到 routes 数组中
57
+ for await (const routeFile of Object.values(routeFiles)) {
58
+ const routeModule: any = await routeFile();
59
+ routes.push(...routeModule.default);
60
+ }
61
+ // 创建路由匹配器
62
+ routerMatcher.value = createRouterMatcher(routes, {});
63
+ // 数组打平返回
64
+ return flattenRoutes(routes);
65
+ };
66
+
58
67
  return {
59
- flatRoutes,
68
+ getRoutes,
60
69
  setMatched
61
70
  };
62
71
  };
63
72
 
64
- function flattenRoutes(
65
- routes: RouteRecordRaw[],
66
- parentRoute: RouteRecordRaw | null
67
- ) {
68
- return routes.reduce((acc: any[], route) => {
69
- if (route.children) {
70
- acc.push(...flattenRoutes(route.children, route));
73
+ // export const useDitariRoute = (routes: RouteRecordRaw[]) => {
74
+ // const { saveBreadcrumb } = useBreadcrumbStore();
75
+ // // 路由匹配器
76
+ // const routerMatcher = ref<RouterMatcher | null>(null);
77
+ // // 匹配到的路由数据
78
+ // const matched = ref<RouteLocationMatched[]>([]);
79
+ // //创建匹配器
80
+ // routerMatcher.value = createRouterMatcher(routes, {});
81
+ // // 保存打平后的路由
82
+ // const flatRoutes = flattenRoutes(routes, null);
83
+ //
84
+ // /**
85
+ // * 进行匹配
86
+ // * @param to
87
+ // * @param from
88
+ // */
89
+ // const setMatched = (
90
+ // to: RouteLocationNormalized,
91
+ // from: RouteLocationNormalized
92
+ // ) => {
93
+ // try {
94
+ // const rs = routerMatcher.value?.resolve(to, from).matched ?? [];
95
+ // matched.value = rs.reduce((preValue: any[], curValue) => {
96
+ // const flag = preValue.some(
97
+ // (item: RouteRecord) => item.path === curValue.path
98
+ // );
99
+ // if (!flag) {
100
+ // preValue.push({
101
+ // path: curValue.path,
102
+ // title: curValue.meta?.title ?? "未设置标题"
103
+ // });
104
+ // }
105
+ // return preValue;
106
+ // }, []);
107
+ // } catch (e) {
108
+ // console.log(e);
109
+ // matched.value = [];
110
+ // }
111
+ // // 匹配到的数据保存到route store
112
+ // saveBreadcrumb(matched.value);
113
+ // };
114
+ //
115
+ // return {
116
+ // flatRoutes,
117
+ // setMatched
118
+ // };
119
+ // };
120
+
121
+ // function flattenRoutes(
122
+ // routes: RouteRecordRaw[],
123
+ // parentRoute: RouteRecordRaw | null
124
+ // ) {
125
+ // return routes.reduce((acc: any[], route) => {
126
+ // if (route.children) {
127
+ // acc.push(...flattenRoutes(route.children, route));
128
+ // }
129
+ // // 只有有组件的route才加入数组
130
+ // if (route.component) {
131
+ // // 路径 如果当前路径为空,则说明是父组件重定向的地址 则追加为""空字符串
132
+ // const path =
133
+ // `${parentRoute?.path}` + (route.path ? "/" + route.path : "");
134
+ // acc.push({
135
+ // ...route,
136
+ // path: path
137
+ // });
138
+ // }
139
+ // return acc;
140
+ // }, []);
141
+ // }
142
+
143
+ function flattenRoutes(routes: any[], parentPath = ""): any {
144
+ const result = [];
145
+ for (const route of routes) {
146
+ if (route.path === "") {
147
+ // 如果path为空,则使用父级的path
148
+ route.path = parentPath;
149
+ } else if (!route.path.startsWith("/")) {
150
+ // 如果path不为空,但是不以/开头,则需要拼接父级的path
151
+ route.path = `${parentPath}/${route.path}`;
71
152
  }
72
- // 只有有组件的route才加入数组
73
- if (route.component) {
74
- // 路径 如果当前路径为空,则说明是父组件重定向的地址 则追加为""空字符串
75
- const path =
76
- `${parentRoute?.path}` + (route.path ? "/" + route.path : "");
77
- acc.push({
78
- ...route,
79
- path: path
80
- });
153
+ if (route.children) {
154
+ // 如果有子路由,则递归处理
155
+ result.push(...flattenRoutes(route.children, route.path));
156
+ delete route.children;
81
157
  }
82
- return acc;
83
- }, []);
158
+ result.push(route);
159
+ }
160
+ return result;
84
161
  }