@scvzerng/element-plus-search-vue2 0.0.2 → 0.0.4

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,59 +1,99 @@
1
- import { get as F, set as P, keyBy as R, isNumber as D, isBoolean as q, isEmpty as k, chain as B, sum as O, isPlainObject as E } from "lodash-unified";
2
- import { defineComponent as S, ref as u, shallowRef as N, reactive as I, computed as C } from "vue";
3
- const Le = (r) => ({
4
- model: {
5
- value: F(r, "value"),
6
- callback: (e) => {
7
- P(r, "value", e);
8
- }
9
- }
10
- }), V = S({
11
- name: "SearchTags"
12
- }), K = /* @__PURE__ */ S({
13
- ...V,
1
+ import { isFunction as V, keyBy as M, isNumber as z, isBoolean as P, isEmpty as U, chain as G, sum as W, isPlainObject as X } from "lodash-unified";
2
+ import { defineComponent as D, ref as y, resolveComponent as g, createElementBlock as A, openBlock as f, createVNode as o, createElementVNode as b, withCtx as c, unref as u, Fragment as N, renderList as B, createBlock as w, createTextVNode as L, toDisplayString as F, reactive as H, shallowRef as J, isRef as Q, computed as j, normalizeStyle as Y, normalizeClass as Z, withDirectives as ee, vShow as te, createCommentVNode as q } from "vue";
3
+ import { ArrowLeft as se, ArrowRight as ie, ArrowDown as re, ArrowUp as ne } from "@element-plus/icons-vue";
4
+ import { Setting as le } from "@scvzerng/icons";
5
+ import { watchDebounced as ae } from "@vueuse/core";
6
+ const oe = { class: "tags-scroll-container" }, ce = ["innerHTML"], ue = /* @__PURE__ */ D({
7
+ name: "SearchTags",
8
+ __name: "SearchTagsRender",
14
9
  props: {
15
- tags: null
10
+ tags: {}
16
11
  },
17
- setup(r) {
18
- const e = r, t = u();
19
- return { __sfc: !0, props: e, scrollContainer: t, scrollLeft: () => {
20
- t.value.scrollBy({ left: -200, behavior: "smooth" });
21
- }, scrollRight: () => {
22
- t.value.scrollBy({
12
+ setup(s) {
13
+ const e = y(), t = () => {
14
+ e.value.scrollBy({ left: -200, behavior: "smooth" });
15
+ }, r = () => {
16
+ e.value.scrollBy({
23
17
  left: 200,
24
18
  behavior: "smooth"
25
19
  });
26
- } };
27
- }
28
- });
29
- function w(r, e, t, s, i, a, h, o) {
30
- var l = typeof r == "function" ? r.options : r;
31
- return e && (l.render = e, l.staticRenderFns = t, l._compiled = !0), a && (l._scopeId = "data-v-" + a), {
32
- exports: r,
33
- options: l
34
- };
35
- }
36
- var H = function() {
37
- var e = this, t = e._self._c, s = e._self._setupProxy;
38
- return t("div", { staticClass: "tags-scroll-container" }, [t("el-tag", { staticClass: "scroll-left-bar", attrs: { 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) {
39
- return t("el-tag", { key: i.field, staticClass: "search-tag", attrs: { size: "medium", 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) } })]);
40
- }), 1), t("el-tag", { staticClass: "scroll-right-bar", attrs: { size: "medium", type: "info" }, on: { click: s.scrollRight } }, [t("i", { staticClass: "el-icon-arrow-right" })])], 1);
41
- }, j = [], z = /* @__PURE__ */ w(
42
- K,
43
- H,
44
- j,
45
- !1,
46
- null,
47
- null
48
- );
49
- const M = z.exports;
50
- var W = Object.defineProperty, G = (r, e, t) => e in r ? W(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, n = (r, e, t) => G(r, typeof e != "symbol" ? e + "" : e, t);
51
- const A = 6;
52
- class U {
20
+ };
21
+ return (i, n) => {
22
+ const p = g("el-icon"), d = g("el-tag");
23
+ return f(), A("div", oe, [
24
+ o(d, {
25
+ type: "info",
26
+ class: "scroll-left-bar",
27
+ onClick: t
28
+ }, {
29
+ default: c(() => [
30
+ o(p, null, {
31
+ default: c(() => [
32
+ o(u(se))
33
+ ]),
34
+ _: 1
35
+ }),
36
+ n[0] || (n[0] = b("i", { class: "el-icon-arrow-left" }, null, -1))
37
+ ]),
38
+ _: 1
39
+ }),
40
+ b("div", {
41
+ ref_key: "scrollContainer",
42
+ ref: e,
43
+ class: "search-tags"
44
+ }, [
45
+ (f(!0), A(N, null, B(s.tags, (m) => (f(), w(d, {
46
+ class: "search-tag",
47
+ onClose: () => m.clean(),
48
+ closable: !m.required,
49
+ type: m.required ? "primary" : "info",
50
+ key: m.field
51
+ }, {
52
+ default: c(() => [
53
+ b("span", null, F(m.label), 1),
54
+ n[1] || (n[1] = L(": ", -1)),
55
+ b("span", {
56
+ innerHTML: m.valueText
57
+ }, null, 8, ce)
58
+ ]),
59
+ _: 2
60
+ }, 1032, ["onClose", "closable", "type"]))), 128))
61
+ ], 512),
62
+ o(d, {
63
+ type: "info",
64
+ class: "scroll-right-bar",
65
+ onClick: r
66
+ }, {
67
+ default: c(() => [
68
+ o(p, null, {
69
+ default: c(() => [
70
+ o(u(ie))
71
+ ]),
72
+ _: 1
73
+ })
74
+ ]),
75
+ _: 1
76
+ })
77
+ ]);
78
+ };
79
+ }
80
+ }), K = 6;
81
+ class de {
82
+ field;
83
+ label;
84
+ value;
85
+ required;
86
+ index;
87
+ visible;
88
+ disabled;
89
+ span;
90
+ initValue;
91
+ enable;
92
+ tagFilter;
93
+ render;
94
+ transform;
53
95
  constructor(e, t) {
54
- n(this, "field"), n(this, "label"), n(this, "value"), n(this, "required"), n(this, "index"), n(this, "visible"), n(this, "span"), n(this, "initValue"), n(this, "tagFilter"), n(this, "render"), n(this, "transform");
55
- var s, i;
56
- 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 : A, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform;
96
+ 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 = e.visible ?? !0, this.span = e.span ?? K, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform, this.enable = e.enable ?? !0, this.disabled = e.disabled ?? !1;
57
97
  }
58
98
  clean() {
59
99
  Array.isArray(this.value) ? this.value = [] : this.value = void 0;
@@ -61,14 +101,23 @@ class U {
61
101
  reset() {
62
102
  this.value = this.initValue;
63
103
  }
104
+ isEnable(e) {
105
+ return V(this.enable) ? this.enable(e.getSearchObject()) : this.enable;
106
+ }
107
+ isDisabled(e) {
108
+ return V(this.disabled) ? this.disabled(e.getSearchObject()) : this.disabled;
109
+ }
64
110
  }
65
- var X = Object.defineProperty, J = (r, e, t) => e in r ? X(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => J(r, typeof e != "symbol" ? e + "" : e, t);
66
- class _ {
67
- constructor(e, t, s, i) {
68
- p(this, "field"), p(this, "span"), p(this, "index"), p(this, "visible"), this.field = e, this.span = t, this.index = s, this.visible = i;
111
+ class x {
112
+ field;
113
+ span;
114
+ index;
115
+ visible;
116
+ constructor(e, t, r, i) {
117
+ this.field = e, this.span = t, this.index = r, this.visible = i;
69
118
  }
70
119
  static fromSearchItem(e, t) {
71
- return new _(
120
+ return new x(
72
121
  e.field,
73
122
  e.span,
74
123
  t ?? e.index,
@@ -76,18 +125,16 @@ class _ {
76
125
  );
77
126
  }
78
127
  static formSearchConfig(e, t) {
79
- var s, i;
80
- return new _(
128
+ return new x(
81
129
  e.field,
82
- (s = e.span) != null ? s : A,
130
+ e.span ?? K,
83
131
  t ?? e,
84
- (i = e.visible) != null ? i : !0
132
+ e.visible ?? !0
85
133
  );
86
134
  }
87
135
  static fromString(e) {
88
- var t;
89
- const [s, i, a, h] = e.split("_");
90
- return new _(i, Number(a), Number(s), (t = !!h) != null ? t : !0);
136
+ const [t, r, i, n] = e.split("_");
137
+ return new x(r, Number(i), Number(t), n === "true");
91
138
  }
92
139
  toString() {
93
140
  return `${this.index}_${this.field}_${this.span}_${this.visible}`;
@@ -96,33 +143,37 @@ class _ {
96
143
  this.span = e.span, this.index = e.index, this.visible = e.visible;
97
144
  }
98
145
  }
99
- const L = (r) => `searches_layouts_${r}`;
100
- class Q {
146
+ const O = (s) => `searches_layouts_${s}`;
147
+ class he {
148
+ id;
149
+ state;
150
+ itemLayouts;
151
+ initialLayouts;
101
152
  constructor(e, t) {
102
- p(this, "id"), p(this, "state"), p(this, "itemLayouts"), p(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = R(e.items.map(_.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
153
+ this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = M(e.items.map(x.fromSearchItem), (r) => r.field), this.restoreCachedLayouts();
103
154
  }
104
155
  /**
105
156
  * 恢复自缓存中的布局信息
106
157
  * @private
107
158
  */
108
159
  restoreCachedLayouts() {
109
- const e = localStorage.getItem(L(this.id));
160
+ const e = localStorage.getItem(O(this.id));
110
161
  e && e.split(",").forEach((t) => {
111
- const s = _.fromString(t), i = this.itemLayouts[s.field];
112
- i && i.merge(s);
162
+ const r = x.fromString(t), i = this.itemLayouts[r.field];
163
+ i && i.merge(r);
113
164
  });
114
165
  }
115
166
  sync(e, t) {
116
167
  if (e.length !== Object.keys(this.itemLayouts).length)
117
168
  throw new Error("同步布局字段数量不一致");
118
- e.forEach((s, i) => {
119
- const a = this.itemLayouts[s];
120
- a.index = i, a.visible = t.has(s);
169
+ e.forEach((r, i) => {
170
+ const n = this.itemLayouts[r];
171
+ n.index = i, n.visible = t.has(r);
121
172
  });
122
173
  }
123
174
  persistent() {
124
175
  localStorage.setItem(
125
- L(this.id),
176
+ O(this.id),
126
177
  Object.values(this.itemLayouts).map((e) => e.toString()).join(",")
127
178
  ), this.state.updateTags();
128
179
  }
@@ -133,125 +184,132 @@ class Q {
133
184
  });
134
185
  }
135
186
  }
136
- var Y = Object.defineProperty, Z = (r, e, t) => e in r ? Y(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
137
- const ee = [
187
+ const fe = [
138
188
  {
139
- isApply(r) {
140
- return r.contains("el-radio-group");
189
+ isApply(s) {
190
+ return s.contains("el-radio-group");
141
191
  },
142
- getText(r) {
143
- var e, t;
144
- return (t = (e = r.querySelector(".is-active")) == null ? void 0 : e.querySelector("input")) == null ? void 0 : t.value;
192
+ getText(s) {
193
+ return s.querySelector(".is-active")?.querySelector("input")?.value;
145
194
  }
146
195
  },
147
196
  {
148
- isApply(r) {
149
- return r.contains("el-checkbox-group");
197
+ isApply(s) {
198
+ return s.contains("el-checkbox-group");
150
199
  },
151
- getText(r) {
152
- var e;
153
- const t = Array.from((e = r.querySelectorAll(".el-checkbox__input.is-checked")) != null ? e : []).map((s) => {
154
- var i;
155
- return (i = s.querySelector("input")) == null ? void 0 : i.value;
156
- }).filter((s) => s);
157
- return t.length === 1 ? t[0] : `${t[0]} 等${t.length}条`;
200
+ getText(s) {
201
+ const e = Array.from(s.querySelectorAll(".el-checkbox__input.is-checked") ?? []).map((t) => t.querySelector("input")?.value).filter((t) => t);
202
+ return e.length === 1 ? e[0] : `${e[0]} 等${e.length}条`;
158
203
  }
159
204
  },
160
205
  {
161
- isApply(r) {
162
- return r.contains("el-input");
206
+ isApply(s) {
207
+ return s.contains("el-input");
163
208
  },
164
- getText(r, e) {
209
+ getText(s, e) {
165
210
  return e.value;
166
211
  }
167
212
  },
168
213
  {
169
- isApply(r) {
170
- return r.contains("el-input-number");
214
+ isApply(s) {
215
+ return s.contains("el-input-number");
171
216
  },
172
- getText(r, e) {
217
+ getText(s, e) {
173
218
  return e.value;
174
219
  }
175
220
  },
176
221
  {
177
- isApply(r) {
178
- return r.contains("el-select");
222
+ isApply(s) {
223
+ return s.contains("el-select");
179
224
  },
180
- getText(r, e) {
181
- var t;
182
- const s = r.querySelectorAll(".el-select__tags-text");
183
- 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;
225
+ getText(s, e) {
226
+ const t = s.querySelectorAll(".el-select__tags-text");
227
+ return t.length > 0 ? e.value.length > 1 ? `${t[0].textContent} 等${e.value.length}条` : t[0].textContent : s.querySelector(".el-select__placeholder")?.innerHTML;
184
228
  }
185
229
  },
186
230
  {
187
- isApply(r) {
188
- return r.contains("el-cascader");
231
+ isApply(s) {
232
+ return s.contains("el-cascader");
189
233
  },
190
- getText(r) {
191
- var e;
192
- return (e = r.querySelector("input")) == null ? void 0 : e.value;
234
+ getText(s) {
235
+ return s.querySelector("input")?.value;
193
236
  }
194
237
  },
195
238
  {
196
- isApply(r) {
197
- return r.contains("el-switch");
239
+ isApply(s) {
240
+ return s.contains("el-switch");
198
241
  },
199
- getText(r) {
200
- return r.querySelector(".is-active").innerHTML;
242
+ getText(s) {
243
+ return s.querySelector(".is-active").innerHTML;
201
244
  }
202
245
  },
203
246
  {
204
- isApply(r) {
205
- return r.contains("el-slider");
247
+ isApply(s) {
248
+ return s.contains("el-slider");
206
249
  },
207
- getText(r, e) {
250
+ getText(s, e) {
208
251
  return e.value;
209
252
  }
210
253
  },
211
254
  {
212
- isApply(r) {
213
- return r.contains("el-date-editor");
255
+ isApply(s) {
256
+ return s.contains("el-date-editor");
214
257
  },
215
- getText(r, e) {
258
+ getText(s, e) {
216
259
  return e.value ? e.value.join(" ~ ") : e.value;
217
260
  }
218
261
  }
219
262
  ];
220
- class T {
263
+ class R {
264
+ id;
265
+ field;
266
+ value;
267
+ label;
268
+ valueText;
269
+ required;
270
+ item;
271
+ state;
221
272
  constructor(e, t) {
222
- f(this, "id"), f(this, "field"), f(this, "value"), f(this, "label"), f(this, "valueText"), f(this, "required"), f(this, "item"), f(this, "state");
223
- var s;
224
- 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();
273
+ 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 = t.required ?? !1, this.updateValueText();
225
274
  }
226
275
  static hasValue(e) {
227
- return D(e.value) || q(e.value) ? !0 : !k(e.value);
276
+ return z(e.value) || P(e.value) ? !0 : !U(e.value);
228
277
  }
229
278
  updateValueText() {
230
279
  const e = document.querySelector(this.id);
231
280
  if (e.children.length !== 1)
232
281
  throw new Error("holder children length is not 1");
233
- const t = e.children[0], s = ee.find((i) => i.isApply(t.classList));
234
- s && (this.valueText = s.getText(t, this));
282
+ const t = e.children[0], r = fe.find((i) => i.isApply(t.classList));
283
+ r && (this.valueText = r.getText(t, this));
235
284
  }
236
285
  async clean() {
237
286
  this.item.clean(), await this.state.doSearch();
238
287
  }
239
288
  }
240
- 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, m = (r, e, t) => se(r, typeof e != "symbol" ? e + "" : e, t);
241
- class re {
242
- constructor(e, t, s) {
243
- this.id = e, m(this, "items"), m(this, "config"), m(this, "searching"), m(this, "tags"), m(this, "searchCallback"), m(this, "sourceSearchable"), this.id = e, this.items = t.map((i, a) => new U(i, a)), this.config = new Q(
244
- this,
245
- t.map((i, a) => _.formSearchConfig(i, a))
246
- ), this.sourceSearchable = t, this.searching = !1, this.searchCallback = s, this.tags = [];
247
- }
289
+ class pe {
290
+ constructor(e, t, r) {
291
+ this.id = e, this.id = e, this.items = t.map((i, n) => new de(i, n)), this.config = H(
292
+ new he(
293
+ this,
294
+ t.map((i, n) => x.formSearchConfig(i, n))
295
+ )
296
+ ), this.sourceSearchable = t, this.searching = !1, this.searchCallback = r, this.tags = [];
297
+ }
298
+ items;
299
+ config;
300
+ searching;
301
+ tags;
302
+ searchCallback;
303
+ sourceSearchable;
304
+ _lastSearchObject = { time: 0, data: null };
248
305
  updateTags() {
249
- this.tags = this.items.filter((e) => e.tagFilter ? e.tagFilter(e.value) : T.hasValue(e)).map((e) => new T(this, e)).sort(
306
+ this.tags = this.items.filter((e) => e.tagFilter ? e.tagFilter(e.value) : R.hasValue(e)).map((e) => new R(this, e)).sort(
250
307
  (e, t) => this.config.itemLayouts[e.field].index - this.config.itemLayouts[t.field].index
251
308
  );
252
309
  }
253
310
  getSearchObject(e) {
254
- return $.from(this.items).toCondition(e);
311
+ const t = Date.now();
312
+ return this._lastSearchObject.data && t - this._lastSearchObject.time < 50 ? this._lastSearchObject.data : (this._lastSearchObject = { time: t, data: E.from(this.items).toCondition(e) }, this._lastSearchObject.data);
255
313
  }
256
314
  async doSearch() {
257
315
  if (!this.searching)
@@ -264,175 +322,280 @@ class re {
264
322
  async reset(e) {
265
323
  this.items.forEach((t) => t.reset()), e && await this.doSearch();
266
324
  }
267
- }
268
- const ie = {
269
- functional: !0,
270
- props: {
271
- search: {
272
- type: Object,
273
- required: !0
274
- }
275
- },
276
- render(r, e) {
277
- const { props: t } = e;
278
- return t.search.render(t.search);
325
+ setSearchValue(e, t) {
326
+ const r = this.items.find((i) => i.field === e);
327
+ r && (r.value = t);
279
328
  }
280
- }, ae = () => {
281
- const r = N(), e = u(), t = u([]), s = u(!1), i = u(), a = u([]), h = u(300), o = (c) => {
282
- r.value = c, t.value = [
329
+ }
330
+ const me = ({ search: s, api: e }) => {
331
+ const t = s.render(s);
332
+ return t.props || (t.props = {}), s.isDisabled(e) && (t.props.disabled = !0), t;
333
+ }, ge = () => {
334
+ const s = J(), e = y(), t = y([]), r = y(!1), i = y(), n = y([]), p = y(300), d = (a) => {
335
+ s.value = a, t.value = [
283
336
  {
284
337
  label: "全部",
285
338
  id: "all",
286
- children: r.value.items.sort(
287
- (v, x) => c.config.itemLayouts[v.field].index - c.config.itemLayouts[x.field].index
288
- ).map((v) => ({
289
- label: v.label,
290
- id: v.field
339
+ children: s.value.items.sort(
340
+ (h, v) => a.config.itemLayouts[h.field].index - a.config.itemLayouts[v.field].index
341
+ ).map((h) => ({
342
+ label: h.label,
343
+ id: h.field,
344
+ disabled: !h.isEnable(a)
291
345
  }))
292
346
  }
293
- ], i.value = B(c.config.itemLayouts).pickBy((v) => v.visible).keys().value();
347
+ ], i.value = G(a.config.itemLayouts).pickBy((h) => h.visible).keys().value();
294
348
  };
295
349
  return {
296
350
  treeRef: e,
297
- visible: s,
351
+ visible: r,
298
352
  snapshot: t,
299
353
  defaultCheckedKeys: i,
300
- drawerWidth: h,
301
- updateSnapshot: o,
302
- show: (c) => {
303
- o(c), s.value = !0;
354
+ drawerWidth: p,
355
+ updateSnapshot: d,
356
+ show: (a) => {
357
+ d(a), r.value = !0;
304
358
  },
305
359
  save: () => {
306
- r.value.config.sync(
307
- t.value[0].children.map((c) => c.id),
360
+ s.value.config.sync(
361
+ t.value[0].children.map((a) => a.id),
308
362
  new Set(e.value.getCheckedKeys())
309
- ), r.value.config.persistent();
363
+ ), s.value.config.persistent();
310
364
  },
311
365
  reset: () => {
312
- r.value.config.reset(), o(r.value);
366
+ s.value.config.reset(), d(s.value);
313
367
  },
314
368
  keepSelection: () => {
315
- a.value = e.value.getCheckedKeys();
369
+ n.value = e.value.getCheckedKeys();
316
370
  },
317
371
  restoreSelection: () => {
318
- e.value.setCheckedKeys(a.value), a.value = [];
372
+ e.value.setCheckedKeys(n.value), n.value = [];
319
373
  },
320
- allowDrop: (c, v, x) => x !== "inner"
374
+ allowDrop: (a, h, v) => v !== "inner",
375
+ allowDrag: (a) => !a.disabled
321
376
  };
322
- }, ne = /* @__PURE__ */ S({
377
+ }, ve = /* @__PURE__ */ D({
323
378
  __name: "SearchSettingsDrawer",
324
- setup(r, { expose: e }) {
379
+ setup(s, { expose: e }) {
325
380
  const {
326
381
  treeRef: t,
327
- visible: s,
382
+ visible: r,
328
383
  snapshot: i,
329
- drawerWidth: a,
330
- defaultCheckedKeys: h,
331
- show: o,
332
- allowDrop: l,
333
- keepSelection: y,
334
- restoreSelection: g,
335
- save: d,
336
- reset: b
337
- } = ae();
384
+ drawerWidth: n,
385
+ defaultCheckedKeys: p,
386
+ show: d,
387
+ allowDrop: m,
388
+ allowDrag: T,
389
+ keepSelection: k,
390
+ restoreSelection: $,
391
+ save: S,
392
+ reset: l
393
+ } = ge();
338
394
  return e({
339
- show: o
340
- }), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: h, show: o, allowDrop: l, keepSelection: y, restoreSelection: g, save: d, reset: b };
341
- }
342
- });
343
- var le = function() {
344
- var e = this, t = e._self._c, s = e._self._setupProxy;
345
- return t("el-drawer", { attrs: { size: s.drawerWidth, title: "搜索项配置", visible: s.visible }, on: { "update:visible": function(i) {
346
- s.visible = i;
347
- } } }, [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 }, 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)]);
348
- }, oe = [], ce = /* @__PURE__ */ w(
349
- ne,
350
- le,
351
- oe,
352
- !1,
353
- null,
354
- null
355
- );
356
- const ue = ce.exports, he = /* @__PURE__ */ S({
395
+ show: d
396
+ }), (C, a) => {
397
+ const h = g("el-tree"), v = g("el-button"), _ = g("el-drawer");
398
+ return f(), w(_, {
399
+ class: "search-setting",
400
+ size: u(n),
401
+ title: "搜索项配置",
402
+ modelValue: u(r),
403
+ "onUpdate:modelValue": a[0] || (a[0] = (I) => Q(r) ? r.value = I : null)
404
+ }, {
405
+ footer: c(() => [
406
+ o(v, { onClick: u(l) }, {
407
+ default: c(() => [...a[1] || (a[1] = [
408
+ L("重置", -1)
409
+ ])]),
410
+ _: 1
411
+ }, 8, ["onClick"]),
412
+ o(v, {
413
+ type: "primary",
414
+ onClick: u(S)
415
+ }, {
416
+ default: c(() => [...a[2] || (a[2] = [
417
+ L("保存", -1)
418
+ ])]),
419
+ _: 1
420
+ }, 8, ["onClick"])
421
+ ]),
422
+ default: c(() => [
423
+ o(h, {
424
+ class: "tree",
425
+ "default-expand-all": "",
426
+ "default-checked-keys": u(p),
427
+ "node-key": "id",
428
+ ref_key: "treeRef",
429
+ ref: t,
430
+ draggable: "",
431
+ "show-checkbox": "",
432
+ data: u(i),
433
+ onNodeDragStart: u(k),
434
+ onNodeDragEnd: u($),
435
+ "allow-drop": u(m),
436
+ "allow-drag": u(T)
437
+ }, null, 8, ["default-checked-keys", "data", "onNodeDragStart", "onNodeDragEnd", "allow-drop", "allow-drag"])
438
+ ]),
439
+ _: 1
440
+ }, 8, ["size", "modelValue"]);
441
+ };
442
+ }
443
+ }), ye = /* @__PURE__ */ D({
357
444
  __name: "SettingButton",
358
445
  props: {
359
- state: null
446
+ state: {}
360
447
  },
361
- setup(r) {
362
- const e = r, t = u();
363
- return { __sfc: !0, props: e, searchSettingDialogRef: t, showSearchLayoutDialog: () => {
448
+ setup(s) {
449
+ const e = s, t = y(), r = () => {
364
450
  t.value.show(e.state);
365
- }, SearchSettingsDrawer: ue };
451
+ };
452
+ return (i, n) => {
453
+ const p = g("el-icon"), d = g("el-button");
454
+ return f(), w(d, {
455
+ class: "icon-button",
456
+ onClick: r
457
+ }, {
458
+ default: c(() => [
459
+ o(p, null, {
460
+ default: c(() => [
461
+ o(u(le))
462
+ ]),
463
+ _: 1
464
+ }),
465
+ o(ve, {
466
+ ref_key: "searchSettingDialogRef",
467
+ ref: t
468
+ }, null, 512)
469
+ ]),
470
+ _: 1
471
+ });
472
+ };
366
473
  }
367
- });
368
- var de = function() {
369
- var e = this, t = e._self._c, s = e._self._setupProxy;
370
- 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);
371
- }, fe = [], pe = /* @__PURE__ */ w(
372
- he,
373
- de,
374
- fe,
375
- !1,
376
- null,
377
- "61aa7563"
378
- );
379
- const ve = pe.exports, _e = /* @__PURE__ */ S({
474
+ }), _e = { class: "search-bar-container" }, be = { class: "search-item" }, Se = { class: "search-item-title" }, we = ["id"], xe = { class: "search-bottom" }, ke = { class: "actions" }, $e = /* @__PURE__ */ D({
380
475
  __name: "SearchBar",
381
476
  props: {
382
- searches: null,
383
- id: null,
384
- onSearch: { type: Function },
477
+ searches: {},
478
+ id: {},
479
+ onSearch: {},
385
480
  defaultSpan: { default: 6 },
386
481
  maxRows: { default: 2 },
387
482
  itemHeight: { default: 67 },
388
483
  resetAutoSearch: { type: Boolean, default: !0 }
389
484
  },
390
- setup(r, { expose: e }) {
391
- const t = r, s = I(new re(t.id, t.searches, t.onSearch)), i = u(!1), a = C(() => O(Array.from(Object.values(s.config.itemLayouts)).map((d) => d.span)) / 24 > t.maxRows), h = C(() => [...s.items].sort((d, b) => s.config.itemLayouts[d.field].index - s.config.itemLayouts[b.field].index).filter((d) => s.config.itemLayouts[d.field].visible)), o = C(() => ({
392
- height: `${t.itemHeight * t.maxRows}px`,
485
+ emits: ["change"],
486
+ setup(s, { expose: e, emit: t }) {
487
+ const r = s, i = H(new pe(r.id, r.searches, r.onSearch)), n = y(!1), p = j(() => W(Array.from(Object.values(i.config.itemLayouts)).filter((l) => l.visible).map((l) => l.span)) / 24 > r.maxRows), d = y([]), m = t;
488
+ ae(() => i.items, () => {
489
+ const S = [...i.items];
490
+ d.value = S.sort((l, C) => i.config.itemLayouts[l.field].index - i.config.itemLayouts[C.field].index).filter((l) => i.config.itemLayouts[l.field].visible).filter((l) => l.isEnable(i)), m("change", i.getSearchObject(), i);
491
+ }, { debounce: 100, immediate: !0, deep: !0 });
492
+ const T = j(() => ({
493
+ height: `${r.itemHeight * r.maxRows}px`,
393
494
  overflow: "hidden"
394
- })), l = (g) => s.config.itemLayouts[g.field], y = () => s.items;
495
+ })), k = (S) => i.config.itemLayouts[S.field];
395
496
  return e({
396
- getSearchItems: y
397
- }), { __sfc: !0, props: t, state: s, expanded: i, isShowSpanIcon: a, sortedItems: h, itemHeightStyle: o, getLayout: l, getSearchItems: y, SearchTagsRender: M, SearchItemRender: ie, SettingButton: ve };
497
+ getSearchItems: () => i.items
498
+ }), (S, l) => {
499
+ const C = g("el-col"), a = g("el-row"), h = g("el-icon"), v = g("el-button");
500
+ return f(), A("div", _e, [
501
+ o(a, {
502
+ class: Z("search"),
503
+ style: Y(p.value && !n.value ? T.value : {}),
504
+ gutter: 16
505
+ }, {
506
+ default: c(() => [
507
+ (f(!0), A(N, null, B(d.value, (_) => ee((f(), w(C, {
508
+ span: k(_).span,
509
+ key: _.field
510
+ }, {
511
+ default: c(() => [
512
+ b("div", be, [
513
+ b("div", Se, F(_.label), 1),
514
+ b("div", {
515
+ id: `${s.id}-${_.field}`,
516
+ class: "search-item-content"
517
+ }, [
518
+ o(u(me), {
519
+ search: _,
520
+ api: i
521
+ }, null, 8, ["search", "api"])
522
+ ], 8, we)
523
+ ])
524
+ ]),
525
+ _: 2
526
+ }, 1032, ["span"])), [
527
+ [te, k(_).visible]
528
+ ])), 128))
529
+ ]),
530
+ _: 1
531
+ }, 8, ["style"]),
532
+ b("div", xe, [
533
+ i.tags.length > 0 ? (f(), w(ue, {
534
+ key: 0,
535
+ tags: i.tags
536
+ }, null, 8, ["tags"])) : q("", !0),
537
+ b("div", ke, [
538
+ p.value ? (f(), w(v, {
539
+ key: 0,
540
+ class: "icon-button",
541
+ onClick: l[0] || (l[0] = (_) => n.value = !n.value)
542
+ }, {
543
+ default: c(() => [
544
+ o(h, null, {
545
+ default: c(() => [
546
+ n.value ? (f(), w(u(ne), { key: 1 })) : (f(), w(u(re), { key: 0 }))
547
+ ]),
548
+ _: 1
549
+ })
550
+ ]),
551
+ _: 1
552
+ })) : q("", !0),
553
+ o(ye, { state: i }, null, 8, ["state"]),
554
+ o(v, {
555
+ onClick: l[1] || (l[1] = () => i.reset(s.resetAutoSearch))
556
+ }, {
557
+ default: c(() => [...l[3] || (l[3] = [
558
+ L("重 置", -1)
559
+ ])]),
560
+ _: 1
561
+ }),
562
+ o(v, {
563
+ type: "primary",
564
+ loading: i.searching,
565
+ disabled: i.searching,
566
+ onClick: l[2] || (l[2] = () => i.doSearch())
567
+ }, {
568
+ default: c(() => [...l[4] || (l[4] = [
569
+ L("搜 索", -1)
570
+ ])]),
571
+ _: 1
572
+ }, 8, ["loading", "disabled"])
573
+ ])
574
+ ])
575
+ ]);
576
+ };
398
577
  }
399
578
  });
400
- var ge = function() {
401
- var e = this, t = e._self._c, s = e._self._setupProxy;
402
- return t("div", { staticClass: "search-bar-container" }, [t("el-row", { class: "search", style: s.isShowSpanIcon && !s.expanded ? s.itemHeightStyle : {}, attrs: { gutter: 16 } }, e._l(s.sortedItems, function(i) {
403
- 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 } })], 1)])]);
404
- }), 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" }, [s.isShowSpanIcon ? t("el-button", { staticClass: "icon-button", staticStyle: { "margin-right": "10px" }, on: { click: function(i) {
405
- s.expanded = !s.expanded;
406
- } } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })]) : e._e(), t(s.SettingButton, { attrs: { state: s.state } }), t("el-button", { on: { click: () => s.state.reset(e.resetAutoSearch) } }, [e._v("重 置")]), t("el-button", { attrs: { type: "primary", loading: s.state.searching, disabled: s.state.searching }, on: { click: () => s.state.doSearch() } }, [e._v("搜 索")])], 1)], 1)], 1);
407
- }, me = [], ye = /* @__PURE__ */ w(
408
- _e,
409
- ge,
410
- me,
411
- !1,
412
- null,
413
- null
414
- );
415
- const Te = ye.exports;
416
- var Se = Object.defineProperty, be = (r, e, t) => e in r ? Se(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, we = (r, e, t) => be(r, e + "", t);
417
- class $ {
579
+ class E {
580
+ record;
418
581
  constructor(e) {
419
- we(this, "record"), this.record = e;
582
+ this.record = e;
420
583
  }
421
584
  static from(e) {
422
- const t = e.filter((s) => s.value === void 0 ? !1 : Array.isArray(s.value) ? s.value.length > 0 : !0).reduce(
423
- (s, i) => {
424
- const a = i.transform ? i.transform(i.value) : i.value;
585
+ const t = e.filter((r) => r.value === void 0 ? !1 : Array.isArray(r.value) ? r.value.length > 0 : !0).reduce(
586
+ (r, i) => {
587
+ const n = i.transform ? i.transform(i.value) : i.value;
425
588
  return {
426
- ...s,
427
- ...E(a) ? a : { [i.field]: a }
589
+ ...r,
590
+ ...X(n) ? n : { [i.field]: n }
428
591
  };
429
592
  },
430
593
  {}
431
594
  );
432
- return new $(t);
595
+ return new E(t);
433
596
  }
434
597
  transform(e, t) {
435
- const s = this.record[e], i = t(s);
598
+ const r = this.record[e], i = t(r);
436
599
  return delete this.record[e], this.record = { ...this.record, ...i }, this;
437
600
  }
438
601
  toCondition(e) {
@@ -440,7 +603,6 @@ class $ {
440
603
  }
441
604
  }
442
605
  export {
443
- Te as SearchBar,
444
- $ as Searches,
445
- Le as vModel
606
+ $e as SearchBar,
607
+ E as Searches
446
608
  };