STopMenu.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { ref as y, reactive as _, watch as v, onMounted as w, openBlock as E, createElementBlock as M, createElementVNode as g, createVNode as k } from "vue";
  2. import { l as $, aE as S, aF as h, aG as O } from "./index2.js";
  3. import { c as T } from "./index20.js";
  4. function U(c) {
  5. if (!c) return null;
  6. c = T(c);
  7. let l = Array.isArray(c) ? c.concat() : [c];
  8. for (; l.length; ) {
  9. const p = l.length;
  10. for (let r = 0; r < p; r++) {
  11. const e = l.shift();
  12. !e.children || !e.children.length || (e.children.forEach((a) => {
  13. a.path[0] !== "/" && !a.path.startsWith("http") && (a.path = e.path.replace(/(\w*)[/]*$/, `$1/${a.path}`));
  14. }), l = l.concat(e.children));
  15. }
  16. }
  17. return c;
  18. }
  19. const x = { class: "s-menu-top-common" }, A = { class: "menu-wrap" }, N = {
  20. __name: "STopMenu",
  21. setup(c) {
  22. const l = S(), p = y([]), r = y(""), e = _({
  23. collapsed: !1,
  24. selectedKeys: [],
  25. openKeys: [],
  26. preOpenKeys: []
  27. });
  28. v(
  29. () => e.openKeys,
  30. (n, s) => {
  31. e.preOpenKeys = s;
  32. }
  33. );
  34. const a = (n) => n.map((t) => {
  35. const o = {
  36. key: t.path,
  37. // icon: item.icon ? () => h(item.icon) : null,
  38. icon: null,
  39. label: t.name || t.meta.title,
  40. title: t.name || t,
  41. path: t.path
  42. };
  43. return t.children && (o.children = a(t.children)), o;
  44. }), K = (n) => {
  45. l.push(n.key), e.selectedKeys = [n.key], window.$utils.ls.set("selectedKeys", e.selectedKeys);
  46. }, m = (n) => {
  47. const s = n.filter((i) => !e.preOpenKeys.includes(i)), t = s[s.length - 1];
  48. e.openKeys = [t], h().setMenuOpenKeys(e.openKeys);
  49. };
  50. return w(() => {
  51. r.value = window.$utils.env.VITE_APP_MENU_THEME || "dark";
  52. const n = h(), s = n.dynamics, t = U(s.find((u) => u.path === "/")), o = t && t.children || [];
  53. p.value = a([...o].filter((u) => {
  54. var d;
  55. return !((d = u.meta) != null && d.hidden);
  56. }));
  57. const i = location.pathname;
  58. window.$utils.ls.set("selectedKeys", [i]), e.selectedKeys = window.$utils.ls.get("selectedKeys") || [];
  59. const f = n.openKeys || [];
  60. e.openKeys = f;
  61. }), (n, s) => {
  62. const t = O;
  63. return E(), M("div", x, [
  64. g("div", A, [
  65. k(t, {
  66. openKeys: e.openKeys,
  67. "onUpdate:openKeys": s[0] || (s[0] = (o) => e.openKeys = o),
  68. selectedKeys: e.selectedKeys,
  69. "onUpdate:selectedKeys": s[1] || (s[1] = (o) => e.selectedKeys = o),
  70. mode: "horizontal",
  71. theme: r.value,
  72. items: p.value,
  73. onSelect: K,
  74. onOpenChange: m
  75. }, null, 8, ["openKeys", "selectedKeys", "theme", "items"])
  76. ])
  77. ]);
  78. };
  79. }
  80. }, B = /* @__PURE__ */ $(N, [["__scopeId", "data-v-ad258b82"]]);
  81. export {
  82. B as default
  83. };