@ditari/bsui 1.0.38 → 1.0.39

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"),M=()=>{const{saveBreadcrumb:u}=m.useBreadcrumbStore(),e=d.ref(null);return{getRoutes:async r=>{const a=[];for await(const o of Object.values(r)){const c=await o();a.push(...c.default)}return f(a)},setMatched:(r,a)=>{var c;const o=d.ref([]);try{const n=((c=e.value)==null?void 0:c.resolve(r,a).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=[]}u(o.value)},createMatcher:r=>{e.value=v.createRouterMatcher(r,{})}}};function f(u,e=""){const s=[];for(const t of u)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=M;
@@ -1,9 +1,9 @@
1
1
  import { RouteLocationNormalized, RouteRecordRaw } 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;
8
+ createMatcher: (routes: RouteRecordRaw[]) => void;
9
9
  };
@@ -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,9 @@
1
1
  import { RouteLocationNormalized, RouteRecordRaw } 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;
8
+ createMatcher: (routes: RouteRecordRaw[]) => void;
9
9
  };
@@ -1,41 +1,46 @@
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 y = () => {
5
+ const { saveBreadcrumb: u } = v(), e = f(null);
6
+ return {
7
+ getRoutes: async (o) => {
8
+ const s = [];
9
+ for await (const r of Object.values(o)) {
10
+ const c = await r();
11
+ s.push(...c.default);
12
+ }
13
+ return p(s);
14
+ },
15
+ setMatched: (o, s) => {
16
+ var c;
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;
14
- return h.some(
15
- (p) => p.path === o.path
16
- ) || h.push({
17
- path: o.path,
18
- title: ((l = o.meta) == null ? void 0 : l.title) ?? "未设置标题"
19
- }), h;
19
+ const h = ((c = e.value) == null ? void 0 : c.resolve(o, s).matched) ?? [];
20
+ r.value = h.reduce((n, l) => {
21
+ var i;
22
+ return n.some(
23
+ (d) => d.path === l.path
24
+ ) || n.push({
25
+ path: l.path,
26
+ title: ((i = l.meta) == null ? void 0 : i.title) ?? "未设置标题"
27
+ }), n;
20
28
  }, []);
21
- } catch (c) {
22
- console.log(c), t.value = [];
29
+ } catch (h) {
30
+ console.log(h), r.value = [];
23
31
  }
24
- s(t.value);
32
+ u(r.value);
33
+ },
34
+ createMatcher: (o) => {
35
+ e.value = m(o, {});
25
36
  }
26
37
  };
27
38
  };
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
- }, []);
39
+ function p(u, e = "") {
40
+ const a = [];
41
+ for (const t of u)
42
+ t.path === "" ? t.path = e : t.path.startsWith("/") || (t.path = `${e}/${t.path}`), t.children && (a.push(...p(t.children, t.path)), delete t.children), a.push(t);
43
+ return a;
39
44
  }
40
45
  export {
41
46
  y as useDitariRoute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditari/bsui",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
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,27 @@ 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
20
  /**
28
- * 进行匹配
29
- * @param to
30
- * @param from
21
+ * 创建匹配器
22
+ * @param routes 路由信息
31
23
  */
24
+ const createMatcher = (routes: RouteRecordRaw[]) => {
25
+ routerMatcher.value = createRouterMatcher(routes, {});
26
+ };
27
+
32
28
  const setMatched = (
33
29
  to: RouteLocationNormalized,
34
30
  from: RouteLocationNormalized
35
31
  ) => {
32
+ // 匹配到的路由数据
33
+ const matched = ref<RouteLocationMatched[]>([]);
36
34
  try {
37
35
  const rs = routerMatcher.value?.resolve(to, from).matched ?? [];
38
36
  matched.value = rs.reduce((preValue: any[], curValue) => {
@@ -51,34 +49,120 @@ export const useDitariRoute = (routes: RouteRecordRaw[]) => {
51
49
  console.log(e);
52
50
  matched.value = [];
53
51
  }
54
- // 匹配到的数据保存到route store
52
+ // 匹配到的数据保存到面包屑store
55
53
  saveBreadcrumb(matched.value);
56
54
  };
57
55
 
56
+ /**
57
+ * 获取路由信息
58
+ * @param routeFiles 路由文件
59
+ */
60
+ const getRoutes = async (
61
+ routeFiles: Record<string, () => Promise<unknown>>
62
+ ) => {
63
+ const routes: any[] = [];
64
+ // 遍历路由文件并将路由合并到 routes 数组中
65
+ for await (const routeFile of Object.values(routeFiles)) {
66
+ const routeModule: any = await routeFile();
67
+ routes.push(...routeModule.default);
68
+ }
69
+ // 数组打平
70
+ return flattenRoutes(routes);
71
+ };
72
+
58
73
  return {
59
- flatRoutes,
60
- setMatched
74
+ getRoutes,
75
+ setMatched,
76
+ createMatcher
61
77
  };
62
78
  };
63
79
 
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));
80
+ // export const useDitariRoute = (routes: RouteRecordRaw[]) => {
81
+ // const { saveBreadcrumb } = useBreadcrumbStore();
82
+ // // 路由匹配器
83
+ // const routerMatcher = ref<RouterMatcher | null>(null);
84
+ // // 匹配到的路由数据
85
+ // const matched = ref<RouteLocationMatched[]>([]);
86
+ // //创建匹配器
87
+ // routerMatcher.value = createRouterMatcher(routes, {});
88
+ // // 保存打平后的路由
89
+ // const flatRoutes = flattenRoutes(routes, null);
90
+ //
91
+ // /**
92
+ // * 进行匹配
93
+ // * @param to
94
+ // * @param from
95
+ // */
96
+ // const setMatched = (
97
+ // to: RouteLocationNormalized,
98
+ // from: RouteLocationNormalized
99
+ // ) => {
100
+ // try {
101
+ // const rs = routerMatcher.value?.resolve(to, from).matched ?? [];
102
+ // matched.value = rs.reduce((preValue: any[], curValue) => {
103
+ // const flag = preValue.some(
104
+ // (item: RouteRecord) => item.path === curValue.path
105
+ // );
106
+ // if (!flag) {
107
+ // preValue.push({
108
+ // path: curValue.path,
109
+ // title: curValue.meta?.title ?? "未设置标题"
110
+ // });
111
+ // }
112
+ // return preValue;
113
+ // }, []);
114
+ // } catch (e) {
115
+ // console.log(e);
116
+ // matched.value = [];
117
+ // }
118
+ // // 匹配到的数据保存到route store
119
+ // saveBreadcrumb(matched.value);
120
+ // };
121
+ //
122
+ // return {
123
+ // flatRoutes,
124
+ // setMatched
125
+ // };
126
+ // };
127
+
128
+ // function flattenRoutes(
129
+ // routes: RouteRecordRaw[],
130
+ // parentRoute: RouteRecordRaw | null
131
+ // ) {
132
+ // return routes.reduce((acc: any[], route) => {
133
+ // if (route.children) {
134
+ // acc.push(...flattenRoutes(route.children, route));
135
+ // }
136
+ // // 只有有组件的route才加入数组
137
+ // if (route.component) {
138
+ // // 路径 如果当前路径为空,则说明是父组件重定向的地址 则追加为""空字符串
139
+ // const path =
140
+ // `${parentRoute?.path}` + (route.path ? "/" + route.path : "");
141
+ // acc.push({
142
+ // ...route,
143
+ // path: path
144
+ // });
145
+ // }
146
+ // return acc;
147
+ // }, []);
148
+ // }
149
+
150
+ function flattenRoutes(routes: any[], parentPath = ""): any {
151
+ const result = [];
152
+ for (const route of routes) {
153
+ if (route.path === "") {
154
+ // 如果path为空,则使用父级的path
155
+ route.path = parentPath;
156
+ } else if (!route.path.startsWith("/")) {
157
+ // 如果path不为空,但是不以/开头,则需要拼接父级的path
158
+ route.path = `${parentPath}/${route.path}`;
71
159
  }
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
- });
160
+ if (route.children) {
161
+ // 如果有子路由,则递归处理
162
+ result.push(...flattenRoutes(route.children, route.path));
163
+ delete route.children;
81
164
  }
82
- return acc;
83
- }, []);
165
+ result.push(route);
166
+ }
167
+ return result;
84
168
  }