@scvzerng/element-plus-search-vue2 0.0.1

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