@scvzerng/element-plus-search-vue2 0.0.12 → 0.0.14

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,11 +1,11 @@
1
- import { get as j, set as B, sum as P, isFunction as T, keyBy as k, isNumber as q, isBoolean as N, isEmpty as R, chain as V, isPlainObject as I } from "lodash-unified";
1
+ import { get as B, set as j, sum as P, isFunction as T, keyBy as k, isNumber as q, isBoolean as N, isEmpty as F, chain as V, isPlainObject as I } from "lodash-unified";
2
2
  import { defineComponent as w, ref as d, shallowRef as H, reactive as K, computed as $ } from "vue";
3
- import { useMutationObserver as F, useDebounceFn as W, watchDebounced as M } from "@vueuse/core";
4
- const Re = (r) => ({
3
+ import { useMutationObserver as E, useDebounceFn as W, watchDebounced as M } from "@vueuse/core";
4
+ const Fe = (r) => ({
5
5
  model: {
6
- value: j(r, "value"),
6
+ value: B(r, "value"),
7
7
  callback: (e) => {
8
- B(r, "value", e);
8
+ j(r, "value", e);
9
9
  }
10
10
  }
11
11
  }), U = w({
@@ -29,7 +29,7 @@ const Re = (r) => ({
29
29
  c.map((g) => g.getBoundingClientRect().width)
30
30
  );
31
31
  }, u = () => t.value.getBoundingClientRect().width;
32
- return F(
32
+ return E(
33
33
  t,
34
34
  () => {
35
35
  a.value = l() > u();
@@ -60,12 +60,12 @@ var Y = function() {
60
60
  );
61
61
  const J = X.exports;
62
62
  var Q = Object.defineProperty, Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, h = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
63
- const E = 6;
63
+ const R = 6;
64
64
  class ee {
65
65
  constructor(e, t) {
66
66
  h(this, "field"), h(this, "label"), h(this, "value"), h(this, "required"), h(this, "index"), h(this, "visible"), h(this, "disabled"), h(this, "span"), h(this, "initValue"), h(this, "enable"), h(this, "tagFilter"), h(this, "render"), h(this, "transform"), h(this, "onChange");
67
67
  var s, i, a, l;
68
- this.field = e.field, this.label = e.label, this.value = e.initValue, this.required = e.required, this.initValue = e.initValue, this.index = t, this.visible = (s = e.visible) != null ? s : !0, this.span = (i = e.span) != null ? i : E, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform, this.enable = (a = e.enable) != null ? a : !0, this.disabled = (l = e.disabled) != null ? l : !1, e.onChange && (this.onChange = W((u, c) => e.onChange(u, c), 50));
68
+ this.field = e.field, this.label = e.label, this.value = e.initValue, this.required = e.required, this.initValue = e.initValue, this.index = t, this.visible = (s = e.visible) != null ? s : !0, this.span = (i = e.span) != null ? i : R, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform, this.enable = (a = e.enable) != null ? a : !0, this.disabled = (l = e.disabled) != null ? l : !1, e.onChange && (this.onChange = W((u, c) => e.onChange(u, c), 50));
69
69
  }
70
70
  clean() {
71
71
  Array.isArray(this.value) ? this.value = [] : this.value = void 0;
@@ -80,10 +80,10 @@ class ee {
80
80
  return T(this.disabled) ? this.disabled(e.getSearchObject()) : this.disabled;
81
81
  }
82
82
  }
83
- var te = Object.defineProperty, se = (r, e, t) => e in r ? te(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => se(r, typeof e != "symbol" ? e + "" : e, t);
83
+ var te = Object.defineProperty, se = (r, e, t) => e in r ? te(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e, t) => se(r, typeof e != "symbol" ? e + "" : e, t);
84
84
  class _ {
85
85
  constructor(e, t, s, i) {
86
- p(this, "field"), p(this, "span"), p(this, "index"), p(this, "visible"), this.field = e, this.span = t, this.index = s, this.visible = i;
86
+ f(this, "field"), f(this, "span"), f(this, "index"), f(this, "visible"), this.field = e, this.span = t, this.index = s, this.visible = i;
87
87
  }
88
88
  static fromSearchItem(e, t) {
89
89
  return new _(
@@ -97,7 +97,7 @@ class _ {
97
97
  var s, i;
98
98
  return new _(
99
99
  e.field,
100
- (s = e.span) != null ? s : E,
100
+ (s = e.span) != null ? s : R,
101
101
  t ?? e,
102
102
  (i = e.visible) != null ? i : !0
103
103
  );
@@ -116,7 +116,7 @@ class _ {
116
116
  const A = (r) => `searches_layouts_${r}`;
117
117
  class re {
118
118
  constructor(e, t) {
119
- p(this, "id"), p(this, "state"), p(this, "itemLayouts"), p(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = k(e.items.map(_.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
119
+ f(this, "id"), f(this, "state"), f(this, "itemLayouts"), f(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = k(e.items.map(_.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
120
120
  }
121
121
  /**
122
122
  * 恢复自缓存中的布局信息
@@ -150,7 +150,7 @@ class re {
150
150
  });
151
151
  }
152
152
  }
153
- var ie = Object.defineProperty, ae = (r, e, t) => e in r ? ie(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e, t) => ae(r, typeof e != "symbol" ? e + "" : e, t);
153
+ var ie = Object.defineProperty, ae = (r, e, t) => e in r ? ie(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => ae(r, typeof e != "symbol" ? e + "" : e, t);
154
154
  const ne = [
155
155
  {
156
156
  isApply(r) {
@@ -236,12 +236,12 @@ const ne = [
236
236
  ];
237
237
  class D {
238
238
  constructor(e, t) {
239
- f(this, "id"), f(this, "field"), f(this, "value"), f(this, "label"), f(this, "valueText"), f(this, "required"), f(this, "item"), f(this, "state");
239
+ p(this, "id"), p(this, "field"), p(this, "value"), p(this, "label"), p(this, "valueText"), p(this, "required"), p(this, "item"), p(this, "state");
240
240
  var s;
241
241
  this.id = `#${e.id}-${t.field}`, this.state = e, this.field = t.field, this.value = t.value, this.label = t.label, this.item = t, this.required = (s = t.required) != null ? s : !1, this.updateValueText();
242
242
  }
243
243
  static hasValue(e) {
244
- return q(e.value) || N(e.value) ? !0 : !R(e.value);
244
+ return q(e.value) || N(e.value) ? !0 : !F(e.value);
245
245
  }
246
246
  updateValueText() {
247
247
  const e = document.querySelector(this.id);
@@ -324,7 +324,7 @@ const ue = {
324
324
  label: "全部",
325
325
  id: "all",
326
326
  children: r.value.items.sort(
327
- (o, y) => n.config.itemLayouts[o.field].index - n.config.itemLayouts[y.field].index
327
+ (o, S) => n.config.itemLayouts[o.field].index - n.config.itemLayouts[S.field].index
328
328
  ).map((o) => ({
329
329
  label: o.label,
330
330
  id: o.field,
@@ -358,7 +358,7 @@ const ue = {
358
358
  restoreSelection: () => {
359
359
  e.value.setCheckedKeys(a.value), a.value = [];
360
360
  },
361
- allowDrop: (n, o, y) => y !== "inner",
361
+ allowDrop: (n, o, S) => S !== "inner",
362
362
  allowDrag: (n) => !n.disabled
363
363
  };
364
364
  }, de = /* @__PURE__ */ w({
@@ -376,22 +376,22 @@ const ue = {
376
376
  keepSelection: x,
377
377
  restoreSelection: m,
378
378
  save: b,
379
- reset: S
379
+ reset: y
380
380
  } = he();
381
381
  return e({
382
382
  show: u
383
- }), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: l, show: u, allowDrop: c, allowDrag: g, keepSelection: x, restoreSelection: m, save: b, reset: S };
383
+ }), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: l, show: u, allowDrop: c, allowDrag: g, keepSelection: x, restoreSelection: m, save: b, reset: y };
384
384
  }
385
385
  });
386
- var fe = function() {
386
+ var pe = function() {
387
387
  var e = this, t = e._self._c, s = e._self._setupProxy;
388
- return t("el-drawer", { attrs: { size: s.drawerWidth, title: "搜索项配置", visible: s.visible }, on: { "update:visible": function(i) {
388
+ return t("el-drawer", { attrs: { size: s.drawerWidth, title: "搜索项配置", visible: s.visible, "modal-append-to-body": !0, "append-to-body": !0 }, on: { "update:visible": function(i) {
389
389
  s.visible = i;
390
390
  } } }, [t("div", { staticClass: "setting-container" }, [t("el-tree", { ref: "treeRef", staticClass: "tree", attrs: { "default-expand-all": "", "default-checked-keys": s.defaultCheckedKeys, "node-key": "id", draggable: "", "show-checkbox": "", data: s.snapshot, "allow-drop": s.allowDrop, "allow-drag": s.allowDrag }, on: { "node-drag-start": s.keepSelection, "node-drag-end": s.restoreSelection } }), t("div", { staticClass: "footer" }, [t("el-button", { on: { click: s.reset } }, [e._v("重置")]), t("el-button", { attrs: { type: "primary" }, on: { click: s.save } }, [e._v("保存")])], 1)], 1)]);
391
- }, pe = [], ve = /* @__PURE__ */ C(
391
+ }, fe = [], ve = /* @__PURE__ */ C(
392
392
  de,
393
- fe,
394
393
  pe,
394
+ fe,
395
395
  !1,
396
396
  null,
397
397
  null
@@ -410,16 +410,16 @@ const _e = ve.exports, ge = /* @__PURE__ */ w({
410
410
  });
411
411
  var me = function() {
412
412
  var e = this, t = e._self._c, s = e._self._setupProxy;
413
- return t("div", { staticStyle: { "margin-right": "10px" } }, [t("el-button", { staticClass: "icon-button", staticStyle: { height: "100%" }, on: { click: s.showSearchLayoutDialog } }, [t("i", { staticClass: "el-icon-s-tools" })]), t(s.SearchSettingsDrawer, { ref: "searchSettingDialogRef" })], 1);
414
- }, be = [], Se = /* @__PURE__ */ C(
413
+ return t("div", { staticStyle: { "margin-right": "10px" } }, [t("el-tooltip", { attrs: { content: "搜索项设置" } }, [t("el-button", { staticClass: "icon-button", staticStyle: { height: "100%" }, on: { click: s.showSearchLayoutDialog } }, [t("i", { staticClass: "el-icon-s-tools" })])], 1), t(s.SearchSettingsDrawer, { ref: "searchSettingDialogRef" })], 1);
414
+ }, be = [], ye = /* @__PURE__ */ C(
415
415
  ge,
416
416
  me,
417
417
  be,
418
418
  !1,
419
419
  null,
420
- "61aa7563"
420
+ "b401b1ee"
421
421
  );
422
- const ye = Se.exports, we = /* @__PURE__ */ w({
422
+ const Se = ye.exports, we = /* @__PURE__ */ w({
423
423
  __name: "SearchBar",
424
424
  props: {
425
425
  searches: null,
@@ -433,7 +433,7 @@ const ye = Se.exports, we = /* @__PURE__ */ w({
433
433
  emits: ["change"],
434
434
  setup(r, { expose: e, emit: t }) {
435
435
  const s = r, i = K(new ce(s.id, s.searches, s.onSearch)), a = d(!1), l = d();
436
- F(
436
+ E(
437
437
  l,
438
438
  () => {
439
439
  i.updateTags();
@@ -443,29 +443,29 @@ const ye = Se.exports, we = /* @__PURE__ */ w({
443
443
  const u = $(() => P(Array.from(Object.values(i.config.itemLayouts)).filter((o) => o.visible).map((o) => o.span)) / 24 > s.maxRows), c = d([]);
444
444
  M(() => [i.items, i.config.itemLayouts], () => {
445
445
  const n = [...i.items];
446
- c.value = n.sort((o, y) => i.config.itemLayouts[o.field].index - i.config.itemLayouts[y.field].index).filter((o) => o.isEnable(i)), t("change", i.getSearchObject(), i);
446
+ c.value = n.sort((o, S) => i.config.itemLayouts[o.field].index - i.config.itemLayouts[S.field].index).filter((o) => o.isEnable(i)), t("change", i.getSearchObject(), i);
447
447
  }, { debounce: 100, immediate: !0, deep: !0 });
448
448
  const g = $(() => ({
449
449
  height: `${s.itemHeight * s.maxRows}px`,
450
450
  overflow: "hidden"
451
- })), x = (n) => i.config.itemLayouts[n.field], m = () => i.items, b = () => i.getSearchObject(), S = (n) => {
451
+ })), x = (n) => i.config.itemLayouts[n.field], m = () => i.items, b = () => i.getSearchObject(), y = (n) => {
452
452
  i.searching = n;
453
453
  }, L = () => i.updateTags();
454
454
  return e({
455
455
  getSearchItems: m,
456
456
  getSearchObject: b,
457
- updateSearching: S,
457
+ updateSearching: y,
458
458
  updateTags: L
459
- }), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef: l, isShowSpanIcon: u, sortedItems: c, emits: t, itemHeightStyle: g, getLayout: x, getSearchItems: m, getSearchObject: b, updateSearching: S, updateTags: L, SearchTagsRender: J, SearchItemRender: ue, SettingButton: ye };
459
+ }), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef: l, isShowSpanIcon: u, sortedItems: c, emits: t, itemHeightStyle: g, getLayout: x, getSearchItems: m, getSearchObject: b, updateSearching: y, updateTags: L, SearchTagsRender: J, SearchItemRender: ue, SettingButton: Se };
460
460
  }
461
461
  });
462
462
  var xe = function() {
463
463
  var e = this, t = e._self._c, s = e._self._setupProxy;
464
- return t("div", { staticClass: "search-bar-container" }, [t("el-row", { ref: "itemContainerRef", class: "search", staticStyle: { "flex-wrap": "wrap" }, style: s.isShowSpanIcon && !s.expanded ? s.itemHeightStyle : {}, attrs: { type: "flex", gutter: 16 } }, e._l(s.sortedItems, function(i) {
464
+ return t("div", { staticClass: "search-bar-container" }, [t("el-collapse-transition", [t("div", { directives: [{ name: "show", rawName: "v-show", value: s.expanded, expression: "expanded" }] }, [t("el-row", { ref: "itemContainerRef", class: "search", staticStyle: { "flex-wrap": "wrap" }, attrs: { type: "flex", gutter: 16 } }, e._l(s.sortedItems, function(i) {
465
465
  return t("el-col", { directives: [{ name: "show", rawName: "v-show", value: s.getLayout(i).visible, expression: "getLayout(item).visible" }], key: i.field, attrs: { span: s.getLayout(i).span } }, [t("div", { staticClass: "search-item" }, [t("div", { staticClass: "search-item-title" }, [e._v(e._s(i.label))]), t("div", { staticClass: "search-item-content", attrs: { id: `${e.id}-${i.field}` } }, [t(s.SearchItemRender, { attrs: { search: i, api: s.state } })], 1)])]);
466
- }), 1), t("div", { staticClass: "search-bottom" }, [s.state.tags.length > 0 ? t(s.SearchTagsRender, { attrs: { tags: s.state.tags } }) : e._e(), t("div", { staticClass: "actions" }, [t("el-button", { directives: [{ name: "show", rawName: "v-show", value: s.isShowSpanIcon, expression: "isShowSpanIcon" }], staticClass: "icon-button", staticStyle: { "margin-right": "10px" }, on: { click: function(i) {
466
+ }), 1)], 1)]), t("div", { staticClass: "search-bottom" }, [s.state.tags.length > 0 ? t(s.SearchTagsRender, { attrs: { tags: s.state.tags } }) : e._e(), t("div", { staticClass: "actions" }, [t("el-tooltip", { attrs: { content: s.expanded ? "收起" : "更多搜索条件" } }, [t("el-button", { staticClass: "icon-button", staticStyle: { "margin-right": "10px" }, on: { click: function(i) {
467
467
  s.expanded = !s.expanded;
468
- } } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })]), t(s.SettingButton, { attrs: { state: s.state } }), t("el-button", { attrs: { type: "primary", loading: s.state.searching, disabled: s.state.searching }, on: { click: () => s.state.doSearch() } }, [e._v("查 询")]), t("el-button", { on: { click: () => s.state.reset(e.resetAutoSearch) } }, [e._v("重 置")])], 1)], 1)], 1);
468
+ } } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })])], 1), t(s.SettingButton, { attrs: { state: s.state } }), t("el-button", { attrs: { type: "primary", loading: s.state.searching, disabled: s.state.searching }, on: { click: () => s.state.doSearch() } }, [e._v("查 询")]), t("el-button", { on: { click: () => s.state.reset(e.resetAutoSearch) } }, [e._v("重 置")])], 1)], 1)], 1);
469
469
  }, Ce = [], Le = /* @__PURE__ */ C(
470
470
  we,
471
471
  xe,
@@ -474,9 +474,9 @@ var xe = function() {
474
474
  null,
475
475
  null
476
476
  );
477
- const Fe = Le.exports;
477
+ const Ee = Le.exports;
478
478
  var Oe = Object.defineProperty, Te = (r, e, t) => e in r ? Oe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, $e = (r, e, t) => Te(r, e + "", t);
479
- const Ee = (r) => R(r), je = () => !0, Be = (r, e) => {
479
+ const Re = (r) => F(r), Be = () => !0, je = (r, e) => {
480
480
  const t = r.getSearchObject();
481
481
  let s = !0;
482
482
  for (const [i, a] of Object.entries(e)) {
@@ -536,11 +536,11 @@ class O {
536
536
  }
537
537
  }
538
538
  export {
539
- je as APPLY_ALWAYS,
540
- Ee as APPLY_WHEN_NOT_VALUE,
541
- Be as APPLY_WITH_MULTIPLE_VALUE,
542
- Fe as SearchBar,
539
+ Be as APPLY_ALWAYS,
540
+ Re as APPLY_WHEN_NOT_VALUE,
541
+ je as APPLY_WITH_MULTIPLE_VALUE,
542
+ Ee as SearchBar,
543
543
  O as Searches,
544
544
  ke as useSearchProxy,
545
- Re as vModel
545
+ Fe as vModel
546
546
  };
@@ -1 +1 @@
1
- (function(h,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("lodash-unified"),require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue","@vueuse/core"],c):(h=typeof globalThis<"u"?globalThis:h||self,c(h.ElementPlusSearch={},h.lodashUnified,h.vue,h.core))})(this,function(h,c,n,x){"use strict";const E=r=>({model:{value:c.get(r,"value"),callback:e=>{c.set(r,"value",e)}}}),F=n.defineComponent({name:"SearchTags"}),R=n.defineComponent({...F,props:{tags:null},setup(r){const e=r,t=n.ref(),s=()=>{t.value.scrollBy({left:-200,behavior:"smooth"})},i=()=>{t.value.scrollBy({left:200,behavior:"smooth"})},a=n.ref(!1),o=()=>{const d=Array.from(t.value.children);return c.sum(d.map(b=>b.getBoundingClientRect().width))},p=()=>t.value.getBoundingClientRect().width;return x.useMutationObserver(t,()=>{a.value=o()>p()},{subtree:!0,childList:!0,attributes:!0}),{__sfc:!0,props:e,scrollContainer:t,scrollLeft:s,scrollRight:i,showScrollBar:a,getTagsWidth:o,getContainerWidth:p}}});function L(r,e,t,s,i,a,o,p){var d=typeof r=="function"?r.options:r;return e&&(d.render=e,d.staticRenderFns=t,d._compiled=!0),a&&(d._scopeId="data-v-"+a),{exports:r,options:d}}var j=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"tags-scroll-container"},[t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-left-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollLeft}},[t("i",{staticClass:"el-icon-arrow-left"})]),t("div",{ref:"scrollContainer",staticClass:"search-tags"},e._l(e.tags,function(i){return t("el-tag",{key:i.field,staticClass:"search-tag",attrs:{"disable-transitions":"",closable:!i.required,type:i.required?"primary":"info"},on:{close:()=>i.clean()}},[t("span",[e._v(" "+e._s(i.label)+" ")]),e._v(": "),t("span",{domProps:{innerHTML:e._s(i.valueText)}})])}),1),t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-right-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollRight}},[t("i",{staticClass:"el-icon-arrow-right"})])],1)},B=[],q=L(R,j,B,!1,null,null);const N=q.exports;var k=Object.defineProperty,V=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,f=(r,e,t)=>V(r,typeof e!="symbol"?e+"":e,t);const P=6;class I{constructor(e,t){f(this,"field"),f(this,"label"),f(this,"value"),f(this,"required"),f(this,"index"),f(this,"visible"),f(this,"disabled"),f(this,"span"),f(this,"initValue"),f(this,"enable"),f(this,"tagFilter"),f(this,"render"),f(this,"transform"),f(this,"onChange");var s,i,a,o;this.field=e.field,this.label=e.label,this.value=e.initValue,this.required=e.required,this.initValue=e.initValue,this.index=t,this.visible=(s=e.visible)!=null?s:!0,this.span=(i=e.span)!=null?i:P,this.render=e.render,this.tagFilter=e.tagFilter,this.transform=e.transform,this.enable=(a=e.enable)!=null?a:!0,this.disabled=(o=e.disabled)!=null?o:!1,e.onChange&&(this.onChange=x.useDebounceFn((p,d)=>e.onChange(p,d),50))}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}isEnable(e){return c.isFunction(this.enable)?this.enable(e.getSearchObject()):this.enable}isDisabled(e){return c.isFunction(this.disabled)?this.disabled(e.getSearchObject()):this.disabled}}var H=Object.defineProperty,M=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,v=(r,e,t)=>M(r,typeof e!="symbol"?e+"":e,t);class g{constructor(e,t,s,i){v(this,"field"),v(this,"span"),v(this,"index"),v(this,"visible"),this.field=e,this.span=t,this.index=s,this.visible=i}static fromSearchItem(e,t){return new g(e.field,e.span,t??e.index,e.visible)}static formSearchConfig(e,t){var s,i;return new g(e.field,(s=e.span)!=null?s:P,t??e,(i=e.visible)!=null?i:!0)}static fromString(e){const[t,s,i,a]=e.split("_");return new g(s,Number(i),Number(t),a==="true")}toString(){return`${this.index}_${this.field}_${this.span}_${this.visible}`}merge(e){this.span=e.span,this.index=e.index,this.visible=e.visible}}const $=r=>`searches_layouts_${r}`;class W{constructor(e,t){v(this,"id"),v(this,"state"),v(this,"itemLayouts"),v(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=c.keyBy(e.items.map(g.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem($(this.id));e&&e.split(",").forEach(t=>{const s=g.fromString(t),i=this.itemLayouts[s.field];i&&i.merge(s)})}sync(e,t){if(e.length!==Object.keys(this.itemLayouts).length)throw new Error("同步布局字段数量不一致");e.forEach((s,i)=>{const a=this.itemLayouts[s];a.index=i,a.visible=t.has(s)})}persistent(){localStorage.setItem($(this.id),Object.values(this.itemLayouts).map(e=>e.toString()).join(",")),this.state.updateTags()}reset(){this.initialLayouts.forEach(e=>{const t=this.itemLayouts[e.field];t&&t.merge(e)})}}var K=Object.defineProperty,Y=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e,t)=>Y(r,typeof e!="symbol"?e+"":e,t);const z=[{isApply(r){return r.contains("el-radio-group")},getText(r){var e,t;return(t=(e=r.querySelector(".is-active"))==null?void 0:e.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-checkbox-group")},getText(r){var e;const t=Array.from((e=r.querySelectorAll(".el-checkbox__input.is-checked"))!=null?e:[]).map(s=>{var i;return(i=s.querySelector("input"))==null?void 0:i.value}).filter(s=>s);return t.length===1?t[0]:`${t[0]} 等${t.length}条`}},{isApply(r){return r.contains("el-input")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-input-number")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-select")},getText(r,e){var t;const s=r.querySelectorAll(".el-select__tags-text");return s.length>0?e.value.length>1?`${s[0].textContent} 等${e.value.length}条`:s[0].textContent:(t=r.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-cascader")},getText(r){var e;return(e=r.querySelector("input"))==null?void 0:e.value}},{isApply(r){return r.contains("el-switch")},getText(r){return r.querySelector(".is-active").innerHTML}},{isApply(r){return r.contains("el-slider")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-date-editor")},getText(r,e){return e.value?e.value.join(" ~ "):e.value}}];class D{constructor(e,t){_(this,"id"),_(this,"field"),_(this,"value"),_(this,"label"),_(this,"valueText"),_(this,"required"),_(this,"item"),_(this,"state");var s;this.id=`#${e.id}-${t.field}`,this.state=e,this.field=t.field,this.value=t.value,this.label=t.label,this.item=t,this.required=(s=t.required)!=null?s:!1,this.updateValueText()}static hasValue(e){return c.isNumber(e.value)||c.isBoolean(e.value)?!0:!c.isEmpty(e.value)}updateValueText(){const e=document.querySelector(this.id);if(!e)return;if(e.children.length!==1)throw new Error("holder children length is not 1");const t=e.children[0],s=z.find(i=>i.isApply(t.classList));s&&(this.valueText=s.getText(t,this))}async clean(){this.item.clean(),await this.state.doSearch()}}var G=Object.defineProperty,X=(r,e,t)=>e in r?G(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,m=(r,e,t)=>X(r,typeof e!="symbol"?e+"":e,t);class J{constructor(e,t,s){this.id=e,m(this,"items"),m(this,"config"),m(this,"searching"),m(this,"tags"),m(this,"searchCallback"),m(this,"sourceSearchable"),m(this,"_lastSearchObject",{time:0,data:null}),this.id=e,this.items=t.map((i,a)=>new I(i,a)),this.config=new W(this,t.map((i,a)=>g.formSearchConfig(i,a))),this.sourceSearchable=t,this.searching=!1,this.searchCallback=s,this.tags=[]}updateSearchTag(e){var t;(t=this.tags.find(s=>s.field===e))==null||t.updateValueText()}updateTags(){this.tags=this.items.filter(e=>e.tagFilter?e.tagFilter(e.value):D.hasValue(e)).map(e=>new D(this,e)).sort((e,t)=>this.config.itemLayouts[e.field].index-this.config.itemLayouts[t.field].index)}getSearchObject(e){const t=Date.now();return this._lastSearchObject.data&&t-this._lastSearchObject.time<50?this._lastSearchObject.data:(this._lastSearchObject={time:t,data:T.from(this.items).toCondition(e)},this._lastSearchObject.data)}async doSearch(){if(!this.searching)try{this.searching=!0,await this.searchCallback(this.getSearchObject()),this.updateTags()}finally{this.searching=!1}}async reset(e){this.items.forEach(t=>t.reset()),e&&await this.doSearch()}setSearchValue(e,t,s=i=>!0){const i=this.items.find(a=>a.field===e);i&&s&&s(i.value)&&(i.value=t)}}const Q={functional:!0,props:{search:{type:Object,required:!0},api:{type:Object}},render(r,e){var t;const{props:s}=e,i=s.search.render(s.search);if(i.componentOptions.propsData||(i.componentOptions.propsData={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),(t=i.data)!=null&&t.attrs||(i.data.attrs={}),i.data.attrs.labelChange=()=>{s.api.updateSearchTag(s.search.field)},i.componentOptions.listeners.input){const a=i.componentOptions.listeners.input;i.componentOptions.listeners.input=o=>{s.search.onChange&&s.search.onChange(o,s.api),a(o)}}return i.componentOptions.propsData.disabled=s.search.isDisabled(s.api),i}},Z=()=>{const r=n.shallowRef(),e=n.ref(),t=n.ref([]),s=n.ref(!1),i=n.ref(),a=n.ref([]),o=n.ref(300),p=l=>{r.value=l,t.value=[{label:"全部",id:"all",children:r.value.items.sort((u,C)=>l.config.itemLayouts[u.field].index-l.config.itemLayouts[C.field].index).map(u=>({label:u.label,id:u.field,disabled:!u.isEnable(l)}))}],i.value=c.chain(l.config.itemLayouts).pickBy(u=>u.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:i,drawerWidth:o,updateSnapshot:p,show:l=>{p(l),s.value=!0},save:()=>{r.value.config.sync(t.value[0].children.map(l=>l.id),new Set(e.value.getCheckedKeys())),r.value.config.persistent(),s.value=!1},reset:()=>{r.value.config.reset(),p(r.value)},keepSelection:()=>{a.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(a.value),a.value=[]},allowDrop:(l,u,C)=>C!=="inner",allowDrag:l=>!l.disabled}},U=n.defineComponent({__name:"SearchSettingsDrawer",setup(r,{expose:e}){const{treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:d,allowDrag:b,keepSelection:O,restoreSelection:S,save:y,reset:w}=Z();return e({show:p}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:d,allowDrag:b,keepSelection:O,restoreSelection:S,save:y,reset:w}}});var ee=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("el-drawer",{attrs:{size:s.drawerWidth,title:"搜索项配置",visible:s.visible},on:{"update:visible":function(i){s.visible=i}}},[t("div",{staticClass:"setting-container"},[t("el-tree",{ref:"treeRef",staticClass:"tree",attrs:{"default-expand-all":"","default-checked-keys":s.defaultCheckedKeys,"node-key":"id",draggable:"","show-checkbox":"",data:s.snapshot,"allow-drop":s.allowDrop,"allow-drag":s.allowDrag},on:{"node-drag-start":s.keepSelection,"node-drag-end":s.restoreSelection}}),t("div",{staticClass:"footer"},[t("el-button",{on:{click:s.reset}},[e._v("重置")]),t("el-button",{attrs:{type:"primary"},on:{click:s.save}},[e._v("保存")])],1)],1)])},te=[],se=L(U,ee,te,!1,null,null);const re=se.exports,ie=n.defineComponent({__name:"SettingButton",props:{state:null},setup(r){const e=r,t=n.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:re}}});var ae=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticStyle:{"margin-right":"10px"}},[t("el-button",{staticClass:"icon-button",staticStyle:{height:"100%"},on:{click:s.showSearchLayoutDialog}},[t("i",{staticClass:"el-icon-s-tools"})]),t(s.SearchSettingsDrawer,{ref:"searchSettingDialogRef"})],1)},ne=[],le=L(ie,ae,ne,!1,null,"61aa7563");const oe=le.exports,ce=n.defineComponent({__name:"SearchBar",props:{searches:null,id:null,onSearch:{type:Function},defaultSpan:{default:6},maxRows:{default:2},itemHeight:{default:67},resetAutoSearch:{type:Boolean,default:!0}},emits:["change"],setup(r,{expose:e,emit:t}){const s=r,i=n.reactive(new J(s.id,s.searches,s.onSearch)),a=n.ref(!1),o=n.ref();x.useMutationObserver(o,()=>{i.updateTags()},{childList:!0});const p=n.computed(()=>c.sum(Array.from(Object.values(i.config.itemLayouts)).filter(u=>u.visible).map(u=>u.span))/24>s.maxRows),d=n.ref([]);x.watchDebounced(()=>[i.items,i.config.itemLayouts],()=>{const l=[...i.items];d.value=l.sort((u,C)=>i.config.itemLayouts[u.field].index-i.config.itemLayouts[C.field].index).filter(u=>u.isEnable(i)),t("change",i.getSearchObject(),i)},{debounce:100,immediate:!0,deep:!0});const b=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),O=l=>i.config.itemLayouts[l.field],S=()=>i.items,y=()=>i.getSearchObject(),w=l=>{i.searching=l},A=()=>i.updateTags();return e({getSearchItems:S,getSearchObject:y,updateSearching:w,updateTags:A}),{__sfc:!0,props:s,state:i,expanded:a,itemContainerRef:o,isShowSpanIcon:p,sortedItems:d,emits:t,itemHeightStyle:b,getLayout:O,getSearchItems:S,getSearchObject:y,updateSearching:w,updateTags:A,SearchTagsRender:N,SearchItemRender:Q,SettingButton:oe}}});var ue=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"search-bar-container"},[t("el-row",{ref:"itemContainerRef",class:"search",staticStyle:{"flex-wrap":"wrap"},style:s.isShowSpanIcon&&!s.expanded?s.itemHeightStyle:{},attrs:{type:"flex",gutter:16}},e._l(s.sortedItems,function(i){return t("el-col",{directives:[{name:"show",rawName:"v-show",value:s.getLayout(i).visible,expression:"getLayout(item).visible"}],key:i.field,attrs:{span:s.getLayout(i).span}},[t("div",{staticClass:"search-item"},[t("div",{staticClass:"search-item-title"},[e._v(e._s(i.label))]),t("div",{staticClass:"search-item-content",attrs:{id:`${e.id}-${i.field}`}},[t(s.SearchItemRender,{attrs:{search:i,api:s.state}})],1)])])}),1),t("div",{staticClass:"search-bottom"},[s.state.tags.length>0?t(s.SearchTagsRender,{attrs:{tags:s.state.tags}}):e._e(),t("div",{staticClass:"actions"},[t("el-button",{directives:[{name:"show",rawName:"v-show",value:s.isShowSpanIcon,expression:"isShowSpanIcon"}],staticClass:"icon-button",staticStyle:{"margin-right":"10px"},on:{click:function(i){s.expanded=!s.expanded}}},[t("i",{class:[s.expanded?"el-icon-arrow-up":"el-icon-arrow-down"]})]),t(s.SettingButton,{attrs:{state:s.state}}),t("el-button",{attrs:{type:"primary",loading:s.state.searching,disabled:s.state.searching},on:{click:()=>s.state.doSearch()}},[e._v("查 询")]),t("el-button",{on:{click:()=>s.state.reset(e.resetAutoSearch)}},[e._v("重 置")])],1)],1)],1)},he=[],de=L(ce,ue,he,!1,null,null);const fe=de.exports;var pe=Object.defineProperty,ve=(r,e,t)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_e=(r,e,t)=>ve(r,e+"",t);const ge=r=>c.isEmpty(r),me=()=>!0,be=(r,e)=>{const t=r.getSearchObject();let s=!0;for(const[i,a]of Object.entries(e)){const o=t[i];s=a(o),s||(s=!1)}return()=>s},Se=(r,e,t)=>({refreshCallback:async s=>{const i=e.value.getSearchObject();try{return e.value.updateSearching(!0),await r(i,s)}finally{e.value.updateSearching(!1),e.value.updateTags()}},searchCallback:async()=>{var s;for(const i of t)await((s=i.value)==null?void 0:s.refresh())}});class T{constructor(e){_e(this,"record"),this.record=e}static from(e){const t=e.filter(s=>s.value===void 0?!1:Array.isArray(s.value)?s.value.length>0:!0).reduce((s,i)=>{const a=i.transform?i.transform(i.value):i.value;return{...s,...c.isPlainObject(a)?a:{[i.field]:a}}},{});return new T(t)}transform(e,t){const s=this.record[e],i=t(s);return delete this.record[e],this.record={...this.record,...i},this}toCondition(e){return{...this.record,...e}}}h.APPLY_ALWAYS=me,h.APPLY_WHEN_NOT_VALUE=ge,h.APPLY_WITH_MULTIPLE_VALUE=be,h.SearchBar=fe,h.Searches=T,h.useSearchProxy=Se,h.vModel=E,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("lodash-unified"),require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue","@vueuse/core"],c):(d=typeof globalThis<"u"?globalThis:d||self,c(d.ElementPlusSearch={},d.lodashUnified,d.vue,d.core))})(this,function(d,c,n,x){"use strict";const E=r=>({model:{value:c.get(r,"value"),callback:e=>{c.set(r,"value",e)}}}),F=n.defineComponent({name:"SearchTags"}),R=n.defineComponent({...F,props:{tags:null},setup(r){const e=r,t=n.ref(),s=()=>{t.value.scrollBy({left:-200,behavior:"smooth"})},i=()=>{t.value.scrollBy({left:200,behavior:"smooth"})},a=n.ref(!1),o=()=>{const h=Array.from(t.value.children);return c.sum(h.map(b=>b.getBoundingClientRect().width))},p=()=>t.value.getBoundingClientRect().width;return x.useMutationObserver(t,()=>{a.value=o()>p()},{subtree:!0,childList:!0,attributes:!0}),{__sfc:!0,props:e,scrollContainer:t,scrollLeft:s,scrollRight:i,showScrollBar:a,getTagsWidth:o,getContainerWidth:p}}});function L(r,e,t,s,i,a,o,p){var h=typeof r=="function"?r.options:r;return e&&(h.render=e,h.staticRenderFns=t,h._compiled=!0),a&&(h._scopeId="data-v-"+a),{exports:r,options:h}}var j=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"tags-scroll-container"},[t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-left-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollLeft}},[t("i",{staticClass:"el-icon-arrow-left"})]),t("div",{ref:"scrollContainer",staticClass:"search-tags"},e._l(e.tags,function(i){return t("el-tag",{key:i.field,staticClass:"search-tag",attrs:{"disable-transitions":"",closable:!i.required,type:i.required?"primary":"info"},on:{close:()=>i.clean()}},[t("span",[e._v(" "+e._s(i.label)+" ")]),e._v(": "),t("span",{domProps:{innerHTML:e._s(i.valueText)}})])}),1),t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-right-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollRight}},[t("i",{staticClass:"el-icon-arrow-right"})])],1)},B=[],q=L(R,j,B,!1,null,null);const N=q.exports;var k=Object.defineProperty,V=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,f=(r,e,t)=>V(r,typeof e!="symbol"?e+"":e,t);const P=6;class I{constructor(e,t){f(this,"field"),f(this,"label"),f(this,"value"),f(this,"required"),f(this,"index"),f(this,"visible"),f(this,"disabled"),f(this,"span"),f(this,"initValue"),f(this,"enable"),f(this,"tagFilter"),f(this,"render"),f(this,"transform"),f(this,"onChange");var s,i,a,o;this.field=e.field,this.label=e.label,this.value=e.initValue,this.required=e.required,this.initValue=e.initValue,this.index=t,this.visible=(s=e.visible)!=null?s:!0,this.span=(i=e.span)!=null?i:P,this.render=e.render,this.tagFilter=e.tagFilter,this.transform=e.transform,this.enable=(a=e.enable)!=null?a:!0,this.disabled=(o=e.disabled)!=null?o:!1,e.onChange&&(this.onChange=x.useDebounceFn((p,h)=>e.onChange(p,h),50))}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}isEnable(e){return c.isFunction(this.enable)?this.enable(e.getSearchObject()):this.enable}isDisabled(e){return c.isFunction(this.disabled)?this.disabled(e.getSearchObject()):this.disabled}}var M=Object.defineProperty,W=(r,e,t)=>e in r?M(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,v=(r,e,t)=>W(r,typeof e!="symbol"?e+"":e,t);class g{constructor(e,t,s,i){v(this,"field"),v(this,"span"),v(this,"index"),v(this,"visible"),this.field=e,this.span=t,this.index=s,this.visible=i}static fromSearchItem(e,t){return new g(e.field,e.span,t??e.index,e.visible)}static formSearchConfig(e,t){var s,i;return new g(e.field,(s=e.span)!=null?s:P,t??e,(i=e.visible)!=null?i:!0)}static fromString(e){const[t,s,i,a]=e.split("_");return new g(s,Number(i),Number(t),a==="true")}toString(){return`${this.index}_${this.field}_${this.span}_${this.visible}`}merge(e){this.span=e.span,this.index=e.index,this.visible=e.visible}}const $=r=>`searches_layouts_${r}`;class H{constructor(e,t){v(this,"id"),v(this,"state"),v(this,"itemLayouts"),v(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=c.keyBy(e.items.map(g.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem($(this.id));e&&e.split(",").forEach(t=>{const s=g.fromString(t),i=this.itemLayouts[s.field];i&&i.merge(s)})}sync(e,t){if(e.length!==Object.keys(this.itemLayouts).length)throw new Error("同步布局字段数量不一致");e.forEach((s,i)=>{const a=this.itemLayouts[s];a.index=i,a.visible=t.has(s)})}persistent(){localStorage.setItem($(this.id),Object.values(this.itemLayouts).map(e=>e.toString()).join(",")),this.state.updateTags()}reset(){this.initialLayouts.forEach(e=>{const t=this.itemLayouts[e.field];t&&t.merge(e)})}}var K=Object.defineProperty,Y=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e,t)=>Y(r,typeof e!="symbol"?e+"":e,t);const z=[{isApply(r){return r.contains("el-radio-group")},getText(r){var e,t;return(t=(e=r.querySelector(".is-active"))==null?void 0:e.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-checkbox-group")},getText(r){var e;const t=Array.from((e=r.querySelectorAll(".el-checkbox__input.is-checked"))!=null?e:[]).map(s=>{var i;return(i=s.querySelector("input"))==null?void 0:i.value}).filter(s=>s);return t.length===1?t[0]:`${t[0]} 等${t.length}条`}},{isApply(r){return r.contains("el-input")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-input-number")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-select")},getText(r,e){var t;const s=r.querySelectorAll(".el-select__tags-text");return s.length>0?e.value.length>1?`${s[0].textContent} 等${e.value.length}条`:s[0].textContent:(t=r.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-cascader")},getText(r){var e;return(e=r.querySelector("input"))==null?void 0:e.value}},{isApply(r){return r.contains("el-switch")},getText(r){return r.querySelector(".is-active").innerHTML}},{isApply(r){return r.contains("el-slider")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-date-editor")},getText(r,e){return e.value?e.value.join(" ~ "):e.value}}];class D{constructor(e,t){_(this,"id"),_(this,"field"),_(this,"value"),_(this,"label"),_(this,"valueText"),_(this,"required"),_(this,"item"),_(this,"state");var s;this.id=`#${e.id}-${t.field}`,this.state=e,this.field=t.field,this.value=t.value,this.label=t.label,this.item=t,this.required=(s=t.required)!=null?s:!1,this.updateValueText()}static hasValue(e){return c.isNumber(e.value)||c.isBoolean(e.value)?!0:!c.isEmpty(e.value)}updateValueText(){const e=document.querySelector(this.id);if(!e)return;if(e.children.length!==1)throw new Error("holder children length is not 1");const t=e.children[0],s=z.find(i=>i.isApply(t.classList));s&&(this.valueText=s.getText(t,this))}async clean(){this.item.clean(),await this.state.doSearch()}}var G=Object.defineProperty,X=(r,e,t)=>e in r?G(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,m=(r,e,t)=>X(r,typeof e!="symbol"?e+"":e,t);class J{constructor(e,t,s){this.id=e,m(this,"items"),m(this,"config"),m(this,"searching"),m(this,"tags"),m(this,"searchCallback"),m(this,"sourceSearchable"),m(this,"_lastSearchObject",{time:0,data:null}),this.id=e,this.items=t.map((i,a)=>new I(i,a)),this.config=new H(this,t.map((i,a)=>g.formSearchConfig(i,a))),this.sourceSearchable=t,this.searching=!1,this.searchCallback=s,this.tags=[]}updateSearchTag(e){var t;(t=this.tags.find(s=>s.field===e))==null||t.updateValueText()}updateTags(){this.tags=this.items.filter(e=>e.tagFilter?e.tagFilter(e.value):D.hasValue(e)).map(e=>new D(this,e)).sort((e,t)=>this.config.itemLayouts[e.field].index-this.config.itemLayouts[t.field].index)}getSearchObject(e){const t=Date.now();return this._lastSearchObject.data&&t-this._lastSearchObject.time<50?this._lastSearchObject.data:(this._lastSearchObject={time:t,data:T.from(this.items).toCondition(e)},this._lastSearchObject.data)}async doSearch(){if(!this.searching)try{this.searching=!0,await this.searchCallback(this.getSearchObject()),this.updateTags()}finally{this.searching=!1}}async reset(e){this.items.forEach(t=>t.reset()),e&&await this.doSearch()}setSearchValue(e,t,s=i=>!0){const i=this.items.find(a=>a.field===e);i&&s&&s(i.value)&&(i.value=t)}}const Q={functional:!0,props:{search:{type:Object,required:!0},api:{type:Object}},render(r,e){var t;const{props:s}=e,i=s.search.render(s.search);if(i.componentOptions.propsData||(i.componentOptions.propsData={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),(t=i.data)!=null&&t.attrs||(i.data.attrs={}),i.data.attrs.labelChange=()=>{s.api.updateSearchTag(s.search.field)},i.componentOptions.listeners.input){const a=i.componentOptions.listeners.input;i.componentOptions.listeners.input=o=>{s.search.onChange&&s.search.onChange(o,s.api),a(o)}}return i.componentOptions.propsData.disabled=s.search.isDisabled(s.api),i}},Z=()=>{const r=n.shallowRef(),e=n.ref(),t=n.ref([]),s=n.ref(!1),i=n.ref(),a=n.ref([]),o=n.ref(300),p=l=>{r.value=l,t.value=[{label:"全部",id:"all",children:r.value.items.sort((u,C)=>l.config.itemLayouts[u.field].index-l.config.itemLayouts[C.field].index).map(u=>({label:u.label,id:u.field,disabled:!u.isEnable(l)}))}],i.value=c.chain(l.config.itemLayouts).pickBy(u=>u.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:i,drawerWidth:o,updateSnapshot:p,show:l=>{p(l),s.value=!0},save:()=>{r.value.config.sync(t.value[0].children.map(l=>l.id),new Set(e.value.getCheckedKeys())),r.value.config.persistent(),s.value=!1},reset:()=>{r.value.config.reset(),p(r.value)},keepSelection:()=>{a.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(a.value),a.value=[]},allowDrop:(l,u,C)=>C!=="inner",allowDrag:l=>!l.disabled}},U=n.defineComponent({__name:"SearchSettingsDrawer",setup(r,{expose:e}){const{treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:h,allowDrag:b,keepSelection:O,restoreSelection:y,save:S,reset:w}=Z();return e({show:p}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:h,allowDrag:b,keepSelection:O,restoreSelection:y,save:S,reset:w}}});var ee=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("el-drawer",{attrs:{size:s.drawerWidth,title:"搜索项配置",visible:s.visible,"modal-append-to-body":!0,"append-to-body":!0},on:{"update:visible":function(i){s.visible=i}}},[t("div",{staticClass:"setting-container"},[t("el-tree",{ref:"treeRef",staticClass:"tree",attrs:{"default-expand-all":"","default-checked-keys":s.defaultCheckedKeys,"node-key":"id",draggable:"","show-checkbox":"",data:s.snapshot,"allow-drop":s.allowDrop,"allow-drag":s.allowDrag},on:{"node-drag-start":s.keepSelection,"node-drag-end":s.restoreSelection}}),t("div",{staticClass:"footer"},[t("el-button",{on:{click:s.reset}},[e._v("重置")]),t("el-button",{attrs:{type:"primary"},on:{click:s.save}},[e._v("保存")])],1)],1)])},te=[],se=L(U,ee,te,!1,null,null);const re=se.exports,ie=n.defineComponent({__name:"SettingButton",props:{state:null},setup(r){const e=r,t=n.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:re}}});var ae=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticStyle:{"margin-right":"10px"}},[t("el-tooltip",{attrs:{content:"搜索项设置"}},[t("el-button",{staticClass:"icon-button",staticStyle:{height:"100%"},on:{click:s.showSearchLayoutDialog}},[t("i",{staticClass:"el-icon-s-tools"})])],1),t(s.SearchSettingsDrawer,{ref:"searchSettingDialogRef"})],1)},ne=[],le=L(ie,ae,ne,!1,null,"b401b1ee");const oe=le.exports,ce=n.defineComponent({__name:"SearchBar",props:{searches:null,id:null,onSearch:{type:Function},defaultSpan:{default:6},maxRows:{default:2},itemHeight:{default:67},resetAutoSearch:{type:Boolean,default:!0}},emits:["change"],setup(r,{expose:e,emit:t}){const s=r,i=n.reactive(new J(s.id,s.searches,s.onSearch)),a=n.ref(!1),o=n.ref();x.useMutationObserver(o,()=>{i.updateTags()},{childList:!0});const p=n.computed(()=>c.sum(Array.from(Object.values(i.config.itemLayouts)).filter(u=>u.visible).map(u=>u.span))/24>s.maxRows),h=n.ref([]);x.watchDebounced(()=>[i.items,i.config.itemLayouts],()=>{const l=[...i.items];h.value=l.sort((u,C)=>i.config.itemLayouts[u.field].index-i.config.itemLayouts[C.field].index).filter(u=>u.isEnable(i)),t("change",i.getSearchObject(),i)},{debounce:100,immediate:!0,deep:!0});const b=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),O=l=>i.config.itemLayouts[l.field],y=()=>i.items,S=()=>i.getSearchObject(),w=l=>{i.searching=l},A=()=>i.updateTags();return e({getSearchItems:y,getSearchObject:S,updateSearching:w,updateTags:A}),{__sfc:!0,props:s,state:i,expanded:a,itemContainerRef:o,isShowSpanIcon:p,sortedItems:h,emits:t,itemHeightStyle:b,getLayout:O,getSearchItems:y,getSearchObject:S,updateSearching:w,updateTags:A,SearchTagsRender:N,SearchItemRender:Q,SettingButton:oe}}});var ue=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"search-bar-container"},[t("el-collapse-transition",[t("div",{directives:[{name:"show",rawName:"v-show",value:s.expanded,expression:"expanded"}]},[t("el-row",{ref:"itemContainerRef",class:"search",staticStyle:{"flex-wrap":"wrap"},attrs:{type:"flex",gutter:16}},e._l(s.sortedItems,function(i){return t("el-col",{directives:[{name:"show",rawName:"v-show",value:s.getLayout(i).visible,expression:"getLayout(item).visible"}],key:i.field,attrs:{span:s.getLayout(i).span}},[t("div",{staticClass:"search-item"},[t("div",{staticClass:"search-item-title"},[e._v(e._s(i.label))]),t("div",{staticClass:"search-item-content",attrs:{id:`${e.id}-${i.field}`}},[t(s.SearchItemRender,{attrs:{search:i,api:s.state}})],1)])])}),1)],1)]),t("div",{staticClass:"search-bottom"},[s.state.tags.length>0?t(s.SearchTagsRender,{attrs:{tags:s.state.tags}}):e._e(),t("div",{staticClass:"actions"},[t("el-tooltip",{attrs:{content:s.expanded?"收起":"更多搜索条件"}},[t("el-button",{staticClass:"icon-button",staticStyle:{"margin-right":"10px"},on:{click:function(i){s.expanded=!s.expanded}}},[t("i",{class:[s.expanded?"el-icon-arrow-up":"el-icon-arrow-down"]})])],1),t(s.SettingButton,{attrs:{state:s.state}}),t("el-button",{attrs:{type:"primary",loading:s.state.searching,disabled:s.state.searching},on:{click:()=>s.state.doSearch()}},[e._v("查 询")]),t("el-button",{on:{click:()=>s.state.reset(e.resetAutoSearch)}},[e._v("重 置")])],1)],1)],1)},de=[],he=L(ce,ue,de,!1,null,null);const fe=he.exports;var pe=Object.defineProperty,ve=(r,e,t)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_e=(r,e,t)=>ve(r,e+"",t);const ge=r=>c.isEmpty(r),me=()=>!0,be=(r,e)=>{const t=r.getSearchObject();let s=!0;for(const[i,a]of Object.entries(e)){const o=t[i];s=a(o),s||(s=!1)}return()=>s},ye=(r,e,t)=>({refreshCallback:async s=>{const i=e.value.getSearchObject();try{return e.value.updateSearching(!0),await r(i,s)}finally{e.value.updateSearching(!1),e.value.updateTags()}},searchCallback:async()=>{var s;for(const i of t)await((s=i.value)==null?void 0:s.refresh())}});class T{constructor(e){_e(this,"record"),this.record=e}static from(e){const t=e.filter(s=>s.value===void 0?!1:Array.isArray(s.value)?s.value.length>0:!0).reduce((s,i)=>{const a=i.transform?i.transform(i.value):i.value;return{...s,...c.isPlainObject(a)?a:{[i.field]:a}}},{});return new T(t)}transform(e,t){const s=this.record[e],i=t(s);return delete this.record[e],this.record={...this.record,...i},this}toCondition(e){return{...this.record,...e}}}d.APPLY_ALWAYS=me,d.APPLY_WHEN_NOT_VALUE=ge,d.APPLY_WITH_MULTIPLE_VALUE=be,d.SearchBar=fe,d.Searches=T,d.useSearchProxy=ye,d.vModel=E,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scvzerng/element-plus-search-vue2",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "scripts": {