@scvzerng/element-plus-search-vue2 0.0.13 → 0.0.15
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,32 +1,32 @@
|
|
|
1
|
-
import { get as
|
|
2
|
-
import { defineComponent as w, ref as
|
|
3
|
-
import { useMutationObserver as E, useDebounceFn as
|
|
4
|
-
const
|
|
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 F, isPlainObject as V } from "lodash-unified";
|
|
2
|
+
import { defineComponent as w, ref as h, shallowRef as I, reactive as H, computed as $ } from "vue";
|
|
3
|
+
import { useMutationObserver as E, useDebounceFn as K, watchDebounced as W } from "@vueuse/core";
|
|
4
|
+
const Pe = (r) => ({
|
|
5
5
|
model: {
|
|
6
|
-
value:
|
|
6
|
+
value: j(r, "value"),
|
|
7
7
|
callback: (e) => {
|
|
8
|
-
|
|
8
|
+
B(r, "value", e);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
}),
|
|
11
|
+
}), M = w({
|
|
12
12
|
name: "SearchTags"
|
|
13
|
-
}),
|
|
14
|
-
...
|
|
13
|
+
}), U = /* @__PURE__ */ w({
|
|
14
|
+
...M,
|
|
15
15
|
props: {
|
|
16
16
|
tags: null
|
|
17
17
|
},
|
|
18
18
|
setup(r) {
|
|
19
|
-
const e = r, t =
|
|
19
|
+
const e = r, t = h(), s = () => {
|
|
20
20
|
t.value.scrollBy({ left: -200, behavior: "smooth" });
|
|
21
21
|
}, i = () => {
|
|
22
22
|
t.value.scrollBy({
|
|
23
23
|
left: 200,
|
|
24
24
|
behavior: "smooth"
|
|
25
25
|
});
|
|
26
|
-
}, a =
|
|
26
|
+
}, a = h(!1), l = () => {
|
|
27
27
|
const c = Array.from(t.value.children);
|
|
28
28
|
return P(
|
|
29
|
-
c.map((
|
|
29
|
+
c.map((m) => m.getBoundingClientRect().width)
|
|
30
30
|
);
|
|
31
31
|
}, u = () => t.value.getBoundingClientRect().width;
|
|
32
32
|
return E(
|
|
@@ -45,27 +45,27 @@ function C(r, e, t, s, i, a, l, u) {
|
|
|
45
45
|
options: c
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
var
|
|
48
|
+
var z = function() {
|
|
49
49
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
|
50
50
|
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) {
|
|
51
51
|
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) } })]);
|
|
52
52
|
}), 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);
|
|
53
|
-
},
|
|
53
|
+
}, Y = [], G = /* @__PURE__ */ C(
|
|
54
|
+
U,
|
|
54
55
|
z,
|
|
55
56
|
Y,
|
|
56
|
-
G,
|
|
57
57
|
!1,
|
|
58
58
|
null,
|
|
59
59
|
null
|
|
60
60
|
);
|
|
61
|
-
const
|
|
62
|
-
var
|
|
61
|
+
const X = G.exports;
|
|
62
|
+
var J = Object.defineProperty, Q = (r, e, t) => e in r ? J(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e, t) => Q(r, typeof e != "symbol" ? e + "" : e, t);
|
|
63
63
|
const R = 6;
|
|
64
|
-
class
|
|
64
|
+
class Z {
|
|
65
65
|
constructor(e, t) {
|
|
66
|
-
|
|
66
|
+
d(this, "field"), d(this, "label"), d(this, "value"), d(this, "required"), d(this, "index"), d(this, "visible"), d(this, "disabled"), d(this, "span"), d(this, "initValue"), d(this, "enable"), d(this, "tagFilter"), d(this, "render"), d(this, "transform"), d(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 : 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 =
|
|
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 = K((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,13 +80,13 @@ class ee {
|
|
|
80
80
|
return T(this.disabled) ? this.disabled(e.getSearchObject()) : this.disabled;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
var
|
|
84
|
-
class
|
|
83
|
+
var ee = Object.defineProperty, te = (r, e, t) => e in r ? ee(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, v = (r, e, t) => te(r, typeof e != "symbol" ? e + "" : e, t);
|
|
84
|
+
class g {
|
|
85
85
|
constructor(e, t, s, i) {
|
|
86
|
-
|
|
86
|
+
v(this, "field"), v(this, "span"), v(this, "index"), v(this, "visible"), this.field = e, this.span = t, this.index = s, this.visible = i;
|
|
87
87
|
}
|
|
88
88
|
static fromSearchItem(e, t) {
|
|
89
|
-
return new
|
|
89
|
+
return new g(
|
|
90
90
|
e.field,
|
|
91
91
|
e.span,
|
|
92
92
|
t ?? e.index,
|
|
@@ -95,7 +95,7 @@ class _ {
|
|
|
95
95
|
}
|
|
96
96
|
static formSearchConfig(e, t) {
|
|
97
97
|
var s, i;
|
|
98
|
-
return new
|
|
98
|
+
return new g(
|
|
99
99
|
e.field,
|
|
100
100
|
(s = e.span) != null ? s : R,
|
|
101
101
|
t ?? e,
|
|
@@ -104,7 +104,7 @@ class _ {
|
|
|
104
104
|
}
|
|
105
105
|
static fromString(e) {
|
|
106
106
|
const [t, s, i, a] = e.split("_");
|
|
107
|
-
return new
|
|
107
|
+
return new g(s, Number(i), Number(t), a === "true");
|
|
108
108
|
}
|
|
109
109
|
toString() {
|
|
110
110
|
return `${this.index}_${this.field}_${this.span}_${this.visible}`;
|
|
@@ -114,9 +114,9 @@ class _ {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
const A = (r) => `searches_layouts_${r}`;
|
|
117
|
-
class
|
|
117
|
+
class se {
|
|
118
118
|
constructor(e, t) {
|
|
119
|
-
|
|
119
|
+
v(this, "id"), v(this, "state"), v(this, "itemLayouts"), v(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = k(e.items.map(g.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* 恢复自缓存中的布局信息
|
|
@@ -125,7 +125,7 @@ class re {
|
|
|
125
125
|
restoreCachedLayouts() {
|
|
126
126
|
const e = localStorage.getItem(A(this.id));
|
|
127
127
|
e && e.split(",").forEach((t) => {
|
|
128
|
-
const s =
|
|
128
|
+
const s = g.fromString(t), i = this.itemLayouts[s.field];
|
|
129
129
|
i && i.merge(s);
|
|
130
130
|
});
|
|
131
131
|
}
|
|
@@ -150,8 +150,8 @@ class re {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
var
|
|
154
|
-
const
|
|
153
|
+
var re = Object.defineProperty, ie = (r, e, t) => e in r ? re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => ie(r, typeof e != "symbol" ? e + "" : e, t);
|
|
154
|
+
const ae = [
|
|
155
155
|
{
|
|
156
156
|
isApply(r) {
|
|
157
157
|
return r.contains("el-radio-group");
|
|
@@ -236,7 +236,7 @@ const ne = [
|
|
|
236
236
|
];
|
|
237
237
|
class D {
|
|
238
238
|
constructor(e, t) {
|
|
239
|
-
|
|
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
|
}
|
|
@@ -249,19 +249,19 @@ class D {
|
|
|
249
249
|
return;
|
|
250
250
|
if (e.children.length !== 1)
|
|
251
251
|
throw new Error("holder children length is not 1");
|
|
252
|
-
const t = e.children[0], s =
|
|
252
|
+
const t = e.children[0], s = ae.find((i) => i.isApply(t.classList));
|
|
253
253
|
s && (this.valueText = s.getText(t, this));
|
|
254
254
|
}
|
|
255
255
|
async clean() {
|
|
256
256
|
this.item.clean(), await this.state.doSearch();
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
var
|
|
260
|
-
class
|
|
259
|
+
var ne = Object.defineProperty, le = (r, e, t) => e in r ? ne(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, _ = (r, e, t) => le(r, typeof e != "symbol" ? e + "" : e, t);
|
|
260
|
+
class oe {
|
|
261
261
|
constructor(e, t, s) {
|
|
262
|
-
this.id = e,
|
|
262
|
+
this.id = e, _(this, "items"), _(this, "config"), _(this, "searching"), _(this, "tags"), _(this, "searchCallback"), _(this, "sourceSearchable"), _(this, "_lastSearchObject", { time: 0, data: null }), this.id = e, this.items = t.map((i, a) => new Z(i, a)), this.config = new se(
|
|
263
263
|
this,
|
|
264
|
-
t.map((i, a) =>
|
|
264
|
+
t.map((i, a) => g.formSearchConfig(i, a))
|
|
265
265
|
), this.sourceSearchable = t, this.searching = !1, this.searchCallback = s, this.tags = [];
|
|
266
266
|
}
|
|
267
267
|
updateSearchTag(e) {
|
|
@@ -293,7 +293,7 @@ class ce {
|
|
|
293
293
|
i && s && s(i.value) && (i.value = t);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
const
|
|
296
|
+
const ce = {
|
|
297
297
|
functional: !0,
|
|
298
298
|
props: {
|
|
299
299
|
search: {
|
|
@@ -317,21 +317,26 @@ const ue = {
|
|
|
317
317
|
}
|
|
318
318
|
return i.componentOptions.propsData.disabled = s.search.isDisabled(s.api), i;
|
|
319
319
|
}
|
|
320
|
-
},
|
|
321
|
-
const r =
|
|
320
|
+
}, ue = () => {
|
|
321
|
+
const r = I(), e = h(), t = h([]), s = h(!1), i = h(), a = h([]), l = h(300), u = (n) => {
|
|
322
322
|
r.value = n, t.value = [
|
|
323
323
|
{
|
|
324
324
|
label: "全部",
|
|
325
325
|
id: "all",
|
|
326
326
|
children: r.value.items.sort(
|
|
327
|
-
(o,
|
|
327
|
+
(o, f) => n.config.itemLayouts[o.field].index - n.config.itemLayouts[f.field].index
|
|
328
328
|
).map((o) => ({
|
|
329
329
|
label: o.label,
|
|
330
330
|
id: o.field,
|
|
331
331
|
disabled: !o.isEnable(n)
|
|
332
332
|
}))
|
|
333
333
|
}
|
|
334
|
-
], i.value =
|
|
334
|
+
], i.value = Object.keys(n.config.itemLayouts).filter(
|
|
335
|
+
(o) => {
|
|
336
|
+
var f;
|
|
337
|
+
return (f = n.config.itemLayouts[o]) == null ? void 0 : f.visible;
|
|
338
|
+
}
|
|
339
|
+
);
|
|
335
340
|
};
|
|
336
341
|
return {
|
|
337
342
|
treeRef: e,
|
|
@@ -358,7 +363,7 @@ const ue = {
|
|
|
358
363
|
restoreSelection: () => {
|
|
359
364
|
e.value.setCheckedKeys(a.value), a.value = [];
|
|
360
365
|
},
|
|
361
|
-
allowDrop: (n, o,
|
|
366
|
+
allowDrop: (n, o, f) => f !== "inner",
|
|
362
367
|
allowDrag: (n) => !n.disabled
|
|
363
368
|
};
|
|
364
369
|
}, de = /* @__PURE__ */ w({
|
|
@@ -372,54 +377,54 @@ const ue = {
|
|
|
372
377
|
defaultCheckedKeys: l,
|
|
373
378
|
show: u,
|
|
374
379
|
allowDrop: c,
|
|
375
|
-
allowDrag:
|
|
380
|
+
allowDrag: m,
|
|
376
381
|
keepSelection: x,
|
|
377
|
-
restoreSelection:
|
|
378
|
-
save:
|
|
382
|
+
restoreSelection: b,
|
|
383
|
+
save: y,
|
|
379
384
|
reset: S
|
|
380
|
-
} =
|
|
385
|
+
} = ue();
|
|
381
386
|
return e({
|
|
382
387
|
show: u
|
|
383
|
-
}), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: l, show: u, allowDrop: c, allowDrag:
|
|
388
|
+
}), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: l, show: u, allowDrop: c, allowDrag: m, keepSelection: x, restoreSelection: b, save: y, reset: S };
|
|
384
389
|
}
|
|
385
390
|
});
|
|
386
|
-
var
|
|
391
|
+
var he = function() {
|
|
387
392
|
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) {
|
|
393
|
+
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
394
|
s.visible = i;
|
|
390
395
|
} } }, [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
|
-
},
|
|
396
|
+
}, fe = [], pe = /* @__PURE__ */ C(
|
|
392
397
|
de,
|
|
398
|
+
he,
|
|
393
399
|
fe,
|
|
394
|
-
pe,
|
|
395
400
|
!1,
|
|
396
401
|
null,
|
|
397
402
|
null
|
|
398
403
|
);
|
|
399
|
-
const
|
|
404
|
+
const ve = pe.exports, _e = /* @__PURE__ */ w({
|
|
400
405
|
__name: "SettingButton",
|
|
401
406
|
props: {
|
|
402
407
|
state: null
|
|
403
408
|
},
|
|
404
409
|
setup(r) {
|
|
405
|
-
const e = r, t =
|
|
410
|
+
const e = r, t = h();
|
|
406
411
|
return { __sfc: !0, props: e, searchSettingDialogRef: t, showSearchLayoutDialog: () => {
|
|
407
412
|
t.value.show(e.state);
|
|
408
|
-
}, SearchSettingsDrawer:
|
|
413
|
+
}, SearchSettingsDrawer: ve };
|
|
409
414
|
}
|
|
410
415
|
});
|
|
411
|
-
var
|
|
416
|
+
var ge = function() {
|
|
412
417
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
|
413
418
|
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
|
-
},
|
|
419
|
+
}, me = [], be = /* @__PURE__ */ C(
|
|
420
|
+
_e,
|
|
415
421
|
ge,
|
|
416
422
|
me,
|
|
417
|
-
be,
|
|
418
423
|
!1,
|
|
419
424
|
null,
|
|
420
425
|
"b401b1ee"
|
|
421
426
|
);
|
|
422
|
-
const ye =
|
|
427
|
+
const ye = be.exports, Se = /* @__PURE__ */ w({
|
|
423
428
|
__name: "SearchBar",
|
|
424
429
|
props: {
|
|
425
430
|
searches: null,
|
|
@@ -432,7 +437,7 @@ const ye = Se.exports, we = /* @__PURE__ */ w({
|
|
|
432
437
|
},
|
|
433
438
|
emits: ["change"],
|
|
434
439
|
setup(r, { expose: e, emit: t }) {
|
|
435
|
-
const s = r, i =
|
|
440
|
+
const s = r, i = H(new oe(s.id, s.searches, s.onSearch)), a = h(!1), l = h();
|
|
436
441
|
E(
|
|
437
442
|
l,
|
|
438
443
|
() => {
|
|
@@ -440,43 +445,43 @@ const ye = Se.exports, we = /* @__PURE__ */ w({
|
|
|
440
445
|
},
|
|
441
446
|
{ childList: !0 }
|
|
442
447
|
);
|
|
443
|
-
const u = $(() => P(Array.from(Object.values(i.config.itemLayouts)).filter((o) => o.visible).map((o) => o.span)) / 24 > s.maxRows), c =
|
|
444
|
-
|
|
448
|
+
const u = $(() => P(Array.from(Object.values(i.config.itemLayouts)).filter((o) => o.visible).map((o) => o.span)) / 24 > s.maxRows), c = h([]);
|
|
449
|
+
W(() => [i.items, i.config.itemLayouts], () => {
|
|
445
450
|
const n = [...i.items];
|
|
446
|
-
c.value = n.sort((o,
|
|
451
|
+
c.value = n.sort((o, f) => i.config.itemLayouts[o.field].index - i.config.itemLayouts[f.field].index).filter((o) => o.isEnable(i)), t("change", i.getSearchObject(), i);
|
|
447
452
|
}, { debounce: 100, immediate: !0, deep: !0 });
|
|
448
|
-
const
|
|
453
|
+
const m = $(() => ({
|
|
449
454
|
height: `${s.itemHeight * s.maxRows}px`,
|
|
450
455
|
overflow: "hidden"
|
|
451
|
-
})), x = (n) => i.config.itemLayouts[n.field],
|
|
456
|
+
})), x = (n) => i.config.itemLayouts[n.field], b = () => i.items, y = () => i.getSearchObject(), S = (n) => {
|
|
452
457
|
i.searching = n;
|
|
453
458
|
}, L = () => i.updateTags();
|
|
454
459
|
return e({
|
|
455
|
-
getSearchItems:
|
|
456
|
-
getSearchObject:
|
|
460
|
+
getSearchItems: b,
|
|
461
|
+
getSearchObject: y,
|
|
457
462
|
updateSearching: S,
|
|
458
463
|
updateTags: L
|
|
459
|
-
}), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef: l, isShowSpanIcon: u, sortedItems: c, emits: t, itemHeightStyle:
|
|
464
|
+
}), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef: l, isShowSpanIcon: u, sortedItems: c, emits: t, itemHeightStyle: m, getLayout: x, getSearchItems: b, getSearchObject: y, updateSearching: S, updateTags: L, SearchTagsRender: X, SearchItemRender: ce, SettingButton: ye };
|
|
460
465
|
}
|
|
461
466
|
});
|
|
462
|
-
var
|
|
467
|
+
var we = function() {
|
|
463
468
|
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" },
|
|
469
|
+
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
470
|
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-tooltip", { attrs: { content: s.expanded ? "收起" : "更多搜索条件" } }, [t("el-button", {
|
|
471
|
+
}), 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
472
|
s.expanded = !s.expanded;
|
|
468
473
|
} } }, [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
|
-
},
|
|
474
|
+
}, xe = [], Ce = /* @__PURE__ */ C(
|
|
475
|
+
Se,
|
|
470
476
|
we,
|
|
471
477
|
xe,
|
|
472
|
-
Ce,
|
|
473
478
|
!1,
|
|
474
479
|
null,
|
|
475
480
|
null
|
|
476
481
|
);
|
|
477
|
-
const
|
|
478
|
-
var
|
|
479
|
-
const
|
|
482
|
+
const Fe = Ce.exports;
|
|
483
|
+
var Le = Object.defineProperty, Oe = (r, e, t) => e in r ? Le(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Te = (r, e, t) => Oe(r, e + "", t);
|
|
484
|
+
const Ee = (r) => F(r), Re = () => !0, je = (r, e) => {
|
|
480
485
|
const t = r.getSearchObject();
|
|
481
486
|
let s = !0;
|
|
482
487
|
for (const [i, a] of Object.entries(e)) {
|
|
@@ -484,7 +489,7 @@ const Re = (r) => F(r), Be = () => !0, je = (r, e) => {
|
|
|
484
489
|
s = a(l), s || (s = !1);
|
|
485
490
|
}
|
|
486
491
|
return () => s;
|
|
487
|
-
},
|
|
492
|
+
}, Be = (r, e, t) => ({
|
|
488
493
|
/**
|
|
489
494
|
* 数据刷新回调代理
|
|
490
495
|
*
|
|
@@ -512,7 +517,7 @@ const Re = (r) => F(r), Be = () => !0, je = (r, e) => {
|
|
|
512
517
|
});
|
|
513
518
|
class O {
|
|
514
519
|
constructor(e) {
|
|
515
|
-
|
|
520
|
+
Te(this, "record"), this.record = e;
|
|
516
521
|
}
|
|
517
522
|
static from(e) {
|
|
518
523
|
const t = e.filter((s) => s.value === void 0 ? !1 : Array.isArray(s.value) ? s.value.length > 0 : !0).reduce(
|
|
@@ -520,7 +525,7 @@ class O {
|
|
|
520
525
|
const a = i.transform ? i.transform(i.value) : i.value;
|
|
521
526
|
return {
|
|
522
527
|
...s,
|
|
523
|
-
...
|
|
528
|
+
...V(a) ? a : { [i.field]: a }
|
|
524
529
|
};
|
|
525
530
|
},
|
|
526
531
|
{}
|
|
@@ -536,11 +541,11 @@ class O {
|
|
|
536
541
|
}
|
|
537
542
|
}
|
|
538
543
|
export {
|
|
539
|
-
|
|
540
|
-
|
|
544
|
+
Re as APPLY_ALWAYS,
|
|
545
|
+
Ee as APPLY_WHEN_NOT_VALUE,
|
|
541
546
|
je as APPLY_WITH_MULTIPLE_VALUE,
|
|
542
|
-
|
|
547
|
+
Fe as SearchBar,
|
|
543
548
|
O as Searches,
|
|
544
|
-
|
|
545
|
-
|
|
549
|
+
Be as useSearchProxy,
|
|
550
|
+
Pe as vModel
|
|
546
551
|
};
|
|
@@ -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-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),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-tooltip",{attrs:{content:s.expanded?"收起":"更多搜索条件"}},[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"]})])],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)},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(y=>y.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 m{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 m(e.field,e.span,t??e.index,e.visible)}static formSearchConfig(e,t){var s,i;return new m(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 m(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(m.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem($(this.id));e&&e.split(",").forEach(t=>{const s=m.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,b=(r,e,t)=>X(r,typeof e!="symbol"?e+"":e,t);class J{constructor(e,t,s){this.id=e,b(this,"items"),b(this,"config"),b(this,"searching"),b(this,"tags"),b(this,"searchCallback"),b(this,"sourceSearchable"),b(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)=>m.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,g)=>l.config.itemLayouts[u.field].index-l.config.itemLayouts[g.field].index).map(u=>({label:u.label,id:u.field,disabled:!u.isEnable(l)}))}],i.value=Object.keys(l.config.itemLayouts).filter(u=>{var g;return(g=l.config.itemLayouts[u])==null?void 0:g.visible})};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,g)=>g!=="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:y,keepSelection:O,restoreSelection:S,save:w,reset:C}=Z();return e({show:p}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:h,allowDrag:y,keepSelection:O,restoreSelection:S,save:w,reset:C}}});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,g)=>i.config.itemLayouts[u.field].index-i.config.itemLayouts[g.field].index).filter(u=>u.isEnable(i)),t("change",i.getSearchObject(),i)},{debounce:100,immediate:!0,deep:!0});const y=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),O=l=>i.config.itemLayouts[l.field],S=()=>i.items,w=()=>i.getSearchObject(),C=l=>{i.searching=l},A=()=>i.updateTags();return e({getSearchItems:S,getSearchObject:w,updateSearching:C,updateTags:A}),{__sfc:!0,props:s,state:i,expanded:a,itemContainerRef:o,isShowSpanIcon:p,sortedItems:h,emits:t,itemHeightStyle:y,getLayout:O,getSearchItems:S,getSearchObject:w,updateSearching:C,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"})});
|