bmp-layout 0.0.23 → 0.0.24

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/bmp-layout.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { openBlock, createBlock, unref, normalizeClass, nextTick, ref, computed, watch, withCtx, createElementBlock, createElementVNode, normalizeStyle, createVNode, Fragment, resolveComponent, defineComponent, isVNode, renderList, createCommentVNode, createTextVNode, toDisplayString, renderSlot, onBeforeMount, withModifiers, Teleport, Transition, provide, KeepAlive, resolveDynamicComponent, onMounted, TransitionGroup, mergeProps, isRef, onUnmounted, withDirectives, resolveDirective, watchEffect, vShow, useSlots, useAttrs, createSlots, inject, onBeforeUnmount, reactive, onUpdated, render, useCssVars } from "vue";
1
+ import { openBlock, createBlock, unref, normalizeClass, nextTick, ref, computed, watch, withCtx, createElementBlock, createElementVNode, normalizeStyle, createVNode, Fragment, resolveComponent, defineComponent, isVNode, renderList, createCommentVNode, createTextVNode, toDisplayString, renderSlot, onBeforeMount, withModifiers, onMounted, onUnmounted, Teleport, Transition, provide, KeepAlive, resolveDynamicComponent, TransitionGroup, mergeProps, isRef, withDirectives, resolveDirective, watchEffect, vShow, useSlots, useAttrs, createSlots, inject, onBeforeUnmount, reactive, onUpdated, render, useCssVars } from "vue";
2
2
  import { createPinia, setActivePinia, defineStore } from "pinia";
3
3
  import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
4
4
  import { cloneDeep, omit } from "lodash-es";
@@ -7664,7 +7664,7 @@ const useTagsViewStore = defineStore("layout-tagsView", {
7664
7664
  }
7665
7665
  this.visitedViews.push(visitedView);
7666
7666
  },
7667
- // 新增缓存
7667
+ // 新增缓存 —— 根据当前 visitedViews 重新计算需要缓存的路由 name 列表
7668
7668
  addCachedView() {
7669
7669
  var _a2;
7670
7670
  const cacheMap = /* @__PURE__ */ new Set();
@@ -7675,16 +7675,19 @@ const useTagsViewStore = defineStore("layout-tagsView", {
7675
7675
  continue;
7676
7676
  }
7677
7677
  const name = item.name;
7678
+ if (!name) {
7679
+ continue;
7680
+ }
7678
7681
  cacheMap.add(name);
7679
7682
  }
7680
7683
  if (Array.from(this.cachedViews).sort().toString() === Array.from(cacheMap).sort().toString())
7681
7684
  return;
7682
7685
  this.cachedViews = cacheMap;
7683
7686
  },
7684
- // 删除某个
7687
+ // 删除某个tag及其缓存
7685
7688
  delView(view) {
7686
7689
  this.delVisitedView(view);
7687
- this.delCachedView();
7690
+ this.addCachedView();
7688
7691
  },
7689
7692
  // 删除tag
7690
7693
  delVisitedView(view) {
@@ -7695,17 +7698,18 @@ const useTagsViewStore = defineStore("layout-tagsView", {
7695
7698
  }
7696
7699
  }
7697
7700
  },
7698
- // 删除缓存
7699
- delCachedView() {
7701
+ // 删除指定视图的缓存,未传 view 时使用 selectedTag(用于刷新场景)
7702
+ delCachedView(view) {
7700
7703
  var _a2;
7701
- if (((_a2 = this.selectedTag) == null ? void 0 : _a2.name) && this.cachedViews.has(this.selectedTag.name)) {
7702
- this.cachedViews.delete(this.selectedTag.name);
7704
+ const routeName = (view == null ? void 0 : view.name) || ((_a2 = this.selectedTag) == null ? void 0 : _a2.name);
7705
+ if (routeName && this.cachedViews.has(routeName)) {
7706
+ this.cachedViews.delete(routeName);
7703
7707
  }
7704
7708
  },
7705
7709
  // 删除所有缓存和tag
7706
7710
  delAllViews() {
7707
7711
  this.delAllVisitedViews();
7708
- this.delCachedView();
7712
+ this.addCachedView();
7709
7713
  },
7710
7714
  // 删除所有tag
7711
7715
  delAllVisitedViews() {
@@ -7905,7 +7909,7 @@ const useTagsView = () => {
7905
7909
  callback2 == null ? void 0 : callback2();
7906
7910
  };
7907
7911
  const refreshPage = async (view, callback2) => {
7908
- tagsViewStore.delCachedView();
7912
+ tagsViewStore.delCachedView(view || unref(currentRoute));
7909
7913
  const { path, query } = view || unref(currentRoute);
7910
7914
  await nextTick();
7911
7915
  replace({
@@ -8274,6 +8278,8 @@ const _hoisted_1$c = { class: "sidebar-inner" };
8274
8278
  const _hoisted_2$a = ["onClick"];
8275
8279
  const _hoisted_3$9 = ["onClick"];
8276
8280
  const _hoisted_4$7 = ["onClick"];
8281
+ const _hoisted_5$5 = { key: 0 };
8282
+ const _hoisted_6$4 = { key: 1 };
8277
8283
  const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel" }, {
8278
8284
  __name: "ProductServicePanel",
8279
8285
  props: {
@@ -8291,53 +8297,64 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8291
8297
  const emit = __emit;
8292
8298
  const router = useRouter();
8293
8299
  const permissionStore = usePermissionStore();
8300
+ const getMenuTitle = (item) => {
8301
+ var _a2;
8302
+ const rawTitle = ((_a2 = item.meta) == null ? void 0 : _a2.title) || item.name || "";
8303
+ return t2(rawTitle) || rawTitle;
8304
+ };
8305
+ const isVisible = (item) => {
8306
+ var _a2;
8307
+ return item.visible !== false && !((_a2 = item.meta) == null ? void 0 : _a2.hidden);
8308
+ };
8309
+ const searchInputRef = ref(null);
8294
8310
  const searchKeyword = ref("");
8311
+ const debouncedKeyword = ref("");
8312
+ let debounceTimer = null;
8313
+ watch(searchKeyword, (val) => {
8314
+ clearTimeout(debounceTimer);
8315
+ if (!val) {
8316
+ debouncedKeyword.value = "";
8317
+ } else {
8318
+ debounceTimer = setTimeout(() => {
8319
+ debouncedKeyword.value = val;
8320
+ }, 300);
8321
+ }
8322
+ });
8295
8323
  const activeCategory = ref(0);
8296
8324
  const routers = computed(() => permissionStore.getRoleRouters);
8297
8325
  const filteredMenus = computed(() => {
8298
- const keyword = searchKeyword.value.toLowerCase().trim();
8299
- const filterHiddenMenus = (items) => {
8300
- if (!items || !Array.isArray(items))
8301
- return [];
8302
- return items.filter((item) => !!item.visible).map((item) => ({
8303
- ...item,
8304
- children: item.children ? filterHiddenMenus(item.children) : []
8305
- }));
8306
- };
8307
- const baseMenus = filterHiddenMenus(routers.value);
8308
- if (!keyword) {
8309
- return baseMenus;
8310
- }
8311
- const filterFn = (items) => {
8312
- return items.reduce((result, item) => {
8313
- var _a2;
8314
- const title = ((_a2 = item.meta) == null ? void 0 : _a2.title) || "";
8315
- const isMatch = title.toLowerCase().includes(keyword);
8326
+ const keyword = debouncedKeyword.value.toLowerCase().trim();
8327
+ const items = routers.value;
8328
+ if (!items || !Array.isArray(items))
8329
+ return [];
8330
+ const filterFn = (list) => {
8331
+ return list.reduce((result, item) => {
8332
+ if (!item.visible)
8333
+ return result;
8334
+ const displayTitle = getMenuTitle(item);
8335
+ const isMatch = keyword && displayTitle.toLowerCase().includes(keyword);
8316
8336
  const children = item.children ? filterFn(item.children) : [];
8317
- if (isMatch || children.length > 0) {
8337
+ if (!keyword || isMatch || children.length > 0) {
8318
8338
  result.push({
8319
8339
  ...item,
8320
- children: children.length > 0 ? children : item.children
8340
+ children: isMatch ? item.children || [] : children
8321
8341
  });
8322
8342
  }
8323
8343
  return result;
8324
8344
  }, []);
8325
8345
  };
8326
- return filterFn(baseMenus);
8346
+ return filterFn(items);
8327
8347
  });
8328
8348
  const groupedMenus = computed(() => {
8329
8349
  return filteredMenus.value.map((menu) => {
8330
- var _a2, _b;
8350
+ var _a2;
8331
8351
  return {
8332
8352
  id: menu.id,
8333
- title: ((_a2 = menu.meta) == null ? void 0 : _a2.title) || menu.name,
8334
- icon: (_b = menu.meta) == null ? void 0 : _b.icon,
8353
+ title: getMenuTitle(menu),
8354
+ icon: (_a2 = menu.meta) == null ? void 0 : _a2.icon,
8335
8355
  path: menu.path,
8336
8356
  modulePath: menu.modulePath,
8337
- children: (menu.children || []).filter((item) => {
8338
- var _a3;
8339
- return !((_a3 = item.meta) == null ? void 0 : _a3.hidden);
8340
- })
8357
+ children: (menu.children || []).filter(isVisible)
8341
8358
  };
8342
8359
  });
8343
8360
  });
@@ -8359,10 +8376,7 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8359
8376
  const getAccessiblePath = (item, parentPath = "") => {
8360
8377
  const fullPath = joinPath(parentPath, item.path);
8361
8378
  if (item.children && item.children.length > 0) {
8362
- const visibleChildren = item.children.filter((child) => {
8363
- var _a2;
8364
- return !((_a2 = child.meta) == null ? void 0 : _a2.hidden);
8365
- });
8379
+ const visibleChildren = item.children.filter(isVisible);
8366
8380
  if (visibleChildren.length > 0) {
8367
8381
  return getAccessiblePath(visibleChildren[0], fullPath);
8368
8382
  }
@@ -8371,7 +8385,9 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8371
8385
  };
8372
8386
  const closePanel = () => {
8373
8387
  emit("update:visible", false);
8388
+ clearTimeout(debounceTimer);
8374
8389
  searchKeyword.value = "";
8390
+ debouncedKeyword.value = "";
8375
8391
  activeCategory.value = 0;
8376
8392
  };
8377
8393
  const handleSelect = (item, parentPath = "") => {
@@ -8395,12 +8411,42 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8395
8411
  const handleCategorySelect = (index) => {
8396
8412
  activeCategory.value = index;
8397
8413
  };
8414
+ watch(groupedMenus, () => {
8415
+ var _a2;
8416
+ if (activeCategory.value >= groupedMenus.value.length) {
8417
+ activeCategory.value = 0;
8418
+ }
8419
+ if (groupedMenus.value.length > 0) {
8420
+ const currentGroup = groupedMenus.value[activeCategory.value];
8421
+ if (!((_a2 = currentGroup == null ? void 0 : currentGroup.children) == null ? void 0 : _a2.length)) {
8422
+ const firstWithChildren = groupedMenus.value.findIndex((g) => {
8423
+ var _a3;
8424
+ return ((_a3 = g.children) == null ? void 0 : _a3.length) > 0;
8425
+ });
8426
+ if (firstWithChildren !== -1) {
8427
+ activeCategory.value = firstWithChildren;
8428
+ }
8429
+ }
8430
+ }
8431
+ });
8398
8432
  watch(() => props.visible, (val) => {
8399
8433
  if (val) {
8400
8434
  searchKeyword.value = "";
8435
+ debouncedKeyword.value = "";
8401
8436
  activeCategory.value = 0;
8437
+ nextTick(() => {
8438
+ var _a2;
8439
+ (_a2 = searchInputRef.value) == null ? void 0 : _a2.focus();
8440
+ });
8402
8441
  }
8403
8442
  });
8443
+ const handleKeydown = (e2) => {
8444
+ if (e2.key === "Escape" && props.visible) {
8445
+ closePanel();
8446
+ }
8447
+ };
8448
+ onMounted(() => document.addEventListener("keydown", handleKeydown));
8449
+ onUnmounted(() => document.removeEventListener("keydown", handleKeydown));
8404
8450
  return (_ctx, _cache) => {
8405
8451
  return openBlock(), createBlock(Teleport, { to: "body" }, [
8406
8452
  createVNode(Transition, { name: "fade" }, {
@@ -8434,7 +8480,7 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8434
8480
  createElementVNode("div", _hoisted_1$c, [
8435
8481
  (openBlock(true), createElementBlock(Fragment, null, renderList(groupedMenus.value, (group, index) => {
8436
8482
  return openBlock(), createElementBlock("div", {
8437
- key: index,
8483
+ key: group.id || index,
8438
8484
  class: normalizeClass([
8439
8485
  unref(prefixCls2) + "__category",
8440
8486
  { "is-active": activeCategory.value === index }
@@ -8456,6 +8502,8 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8456
8502
  class: normalizeClass([unref(prefixCls2) + "__header"])
8457
8503
  }, [
8458
8504
  createVNode(unref(ElInput), {
8505
+ ref_key: "searchInputRef",
8506
+ ref: searchInputRef,
8459
8507
  modelValue: searchKeyword.value,
8460
8508
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchKeyword.value = $event),
8461
8509
  placeholder: unref(t2)("layout.common.searchMenu"),
@@ -8485,34 +8533,29 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8485
8533
  createElementVNode("div", {
8486
8534
  class: normalizeClass([unref(prefixCls2) + "__grid-container"])
8487
8535
  }, [
8488
- currentCategoryMenus.value.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(currentCategoryMenus.value, (secondMenu, index) => {
8489
- var _a2, _b;
8536
+ currentCategoryMenus.value.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(currentCategoryMenus.value, (secondMenu) => {
8490
8537
  return openBlock(), createElementBlock("div", {
8491
- key: index,
8538
+ key: secondMenu.id || secondMenu.path,
8492
8539
  class: normalizeClass([unref(prefixCls2) + "__column"])
8493
8540
  }, [
8494
8541
  createElementVNode("div", {
8495
8542
  class: normalizeClass([unref(prefixCls2) + "__column-title"])
8496
8543
  }, [
8497
- createElementVNode("span", null, toDisplayString(((_a2 = secondMenu.meta) == null ? void 0 : _a2.title) || secondMenu.name), 1)
8544
+ createElementVNode("span", null, toDisplayString(getMenuTitle(secondMenu)), 1)
8498
8545
  ], 2),
8499
8546
  createElementVNode("div", {
8500
8547
  class: normalizeClass([unref(prefixCls2) + "__column-list"])
8501
8548
  }, [
8502
- secondMenu.children && secondMenu.children.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(secondMenu.children.filter((c) => {
8503
- var _a3;
8504
- return !((_a3 = c.meta) == null ? void 0 : _a3.hidden);
8505
- }), (thirdMenu) => {
8506
- var _a3;
8549
+ secondMenu.children && secondMenu.children.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(secondMenu.children.filter(isVisible), (thirdMenu) => {
8507
8550
  return openBlock(), createElementBlock("div", {
8508
8551
  key: thirdMenu.path,
8509
8552
  class: normalizeClass([unref(prefixCls2) + "__column-item"]),
8510
8553
  onClick: ($event) => {
8511
- var _a4;
8512
- return handleSelect(thirdMenu, joinPath((_a4 = groupedMenus.value[activeCategory.value]) == null ? void 0 : _a4.path, secondMenu.path));
8554
+ var _a2;
8555
+ return handleSelect(thirdMenu, joinPath((_a2 = groupedMenus.value[activeCategory.value]) == null ? void 0 : _a2.path, secondMenu.path));
8513
8556
  }
8514
8557
  }, [
8515
- createElementVNode("span", null, toDisplayString(((_a3 = thirdMenu.meta) == null ? void 0 : _a3.title) || thirdMenu.name), 1)
8558
+ createElementVNode("span", null, toDisplayString(getMenuTitle(thirdMenu)), 1)
8516
8559
  ], 10, _hoisted_3$9);
8517
8560
  }), 128)) : (openBlock(), createElementBlock("div", {
8518
8561
  key: 1,
@@ -8521,11 +8564,11 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8521
8564
  { [unref(prefixCls2) + "__column-item--disabled"]: secondMenu.type === 1 }
8522
8565
  ]),
8523
8566
  onClick: ($event) => {
8524
- var _a3;
8525
- return secondMenu.type === 2 && handleSelect(secondMenu, (_a3 = groupedMenus.value[activeCategory.value]) == null ? void 0 : _a3.path);
8567
+ var _a2;
8568
+ return secondMenu.type === 2 && handleSelect(secondMenu, (_a2 = groupedMenus.value[activeCategory.value]) == null ? void 0 : _a2.path);
8526
8569
  }
8527
8570
  }, [
8528
- createElementVNode("span", null, toDisplayString(secondMenu.type === 1 ? unref(t2)("layout.common.noData") || "暂无" : ((_b = secondMenu.meta) == null ? void 0 : _b.title) || secondMenu.name), 1)
8571
+ secondMenu.type === 1 ? (openBlock(), createElementBlock("span", _hoisted_5$5, toDisplayString(unref(t2)("layout.common.noData") || "暂无"), 1)) : (openBlock(), createElementBlock("span", _hoisted_6$4, toDisplayString(getMenuTitle(secondMenu)), 1))
8529
8572
  ], 10, _hoisted_4$7))
8530
8573
  ], 2)
8531
8574
  ], 2);
@@ -8570,7 +8613,7 @@ const _sfc_main$r = /* @__PURE__ */ Object.assign({ name: "ProductServicePanel"
8570
8613
  };
8571
8614
  }
8572
8615
  });
8573
- const ProductServicePanel = /* @__PURE__ */ _export_sfc(_sfc_main$r, [["__scopeId", "data-v-ab102b18"]]);
8616
+ const ProductServicePanel = /* @__PURE__ */ _export_sfc(_sfc_main$r, [["__scopeId", "data-v-909615b6"]]);
8574
8617
  const _sfc_main$q = /* @__PURE__ */ Object.assign({ name: "Logo" }, {
8575
8618
  __name: "Logo",
8576
8619
  emits: ["logo-click"],
@@ -8641,9 +8684,28 @@ const _sfc_main$p = /* @__PURE__ */ Object.assign({ name: "AppView" }, {
8641
8684
  __name: "AppView",
8642
8685
  setup(__props) {
8643
8686
  const tagsViewStore = useTagsViewStore();
8687
+ useRoute();
8644
8688
  const getCaches = computed(() => {
8645
8689
  return tagsViewStore.getCachedViews;
8646
8690
  });
8691
+ const wrapperCache = /* @__PURE__ */ new Map();
8692
+ const getWrappedComponent = (Component, routeName) => {
8693
+ if (!Component || !routeName)
8694
+ return Component;
8695
+ if (wrapperCache.has(routeName))
8696
+ return wrapperCache.get(routeName);
8697
+ const wrapper = defineComponent({
8698
+ name: routeName,
8699
+ setup(_, { slots }) {
8700
+ return () => {
8701
+ var _a2;
8702
+ return (_a2 = slots.default) == null ? void 0 : _a2.call(slots);
8703
+ };
8704
+ }
8705
+ });
8706
+ wrapperCache.set(routeName, wrapper);
8707
+ return wrapper;
8708
+ };
8647
8709
  const routerAlive = ref(true);
8648
8710
  const reload = () => {
8649
8711
  routerAlive.value = false;
@@ -8656,9 +8718,14 @@ const _sfc_main$p = /* @__PURE__ */ Object.assign({ name: "AppView" }, {
8656
8718
  unref(routerAlive) ? (openBlock(), createBlock(_component_router_view, { key: 0 }, {
8657
8719
  default: withCtx(({ Component, route }) => [
8658
8720
  (openBlock(), createBlock(KeepAlive, { include: unref(getCaches) }, [
8659
- (openBlock(), createBlock(resolveDynamicComponent(Component), {
8660
- key: route.fullPath
8661
- }))
8721
+ (openBlock(), createBlock(resolveDynamicComponent(getWrappedComponent(Component, route.name)), {
8722
+ key: route.path
8723
+ }, {
8724
+ default: withCtx(() => [
8725
+ (openBlock(), createBlock(resolveDynamicComponent(Component)))
8726
+ ]),
8727
+ _: 2
8728
+ }, 1024))
8662
8729
  ], 1032, ["include"]))
8663
8730
  ]),
8664
8731
  _: 1
@@ -10285,7 +10352,7 @@ const _sfc_main$b = /* @__PURE__ */ Object.assign({ name: "PageNavBar" }, {
10285
10352
  };
10286
10353
  }
10287
10354
  });
10288
- const PageNavBar = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-0d587176"]]);
10355
+ const PageNavBar = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-17aee006"]]);
10289
10356
  const _sfc_main$a = /* @__PURE__ */ Object.assign({ name: "Badge" }, {
10290
10357
  __name: "Badge",
10291
10358
  props: {