@scvzerng/element-plus-search-vue2 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ElementPlusSearch.es.js +94 -83
- package/dist/ElementPlusSearch.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,46 +1,57 @@
|
|
|
1
|
-
import { get as
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
import {
|
|
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 R, chain as V, isPlainObject as I } from "lodash-unified";
|
|
2
|
+
import { defineComponent as w, ref as d, shallowRef as H, reactive as K, computed as $ } from "vue";
|
|
3
|
+
import { useMutationObserver as F, useDebounceFn as W, watchDebounced as M } from "@vueuse/core";
|
|
4
|
+
const Re = (r) => ({
|
|
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
|
+
}), U = w({
|
|
12
12
|
name: "SearchTags"
|
|
13
|
-
}),
|
|
14
|
-
...
|
|
13
|
+
}), z = /* @__PURE__ */ w({
|
|
14
|
+
...U,
|
|
15
15
|
props: {
|
|
16
16
|
tags: null
|
|
17
17
|
},
|
|
18
18
|
setup(r) {
|
|
19
|
-
const e = r, t = d()
|
|
20
|
-
return { __sfc: !0, props: e, scrollContainer: t, scrollLeft: () => {
|
|
19
|
+
const e = r, t = d(), s = () => {
|
|
21
20
|
t.value.scrollBy({ left: -200, behavior: "smooth" });
|
|
22
|
-
},
|
|
21
|
+
}, i = () => {
|
|
23
22
|
t.value.scrollBy({
|
|
24
23
|
left: 200,
|
|
25
24
|
behavior: "smooth"
|
|
26
25
|
});
|
|
27
|
-
}
|
|
26
|
+
}, a = d(!1), l = () => {
|
|
27
|
+
const c = Array.from(t.value.children);
|
|
28
|
+
return P(
|
|
29
|
+
c.map((g) => g.getBoundingClientRect().width)
|
|
30
|
+
);
|
|
31
|
+
}, u = () => t.value.getBoundingClientRect().width;
|
|
32
|
+
return F(
|
|
33
|
+
t,
|
|
34
|
+
() => {
|
|
35
|
+
a.value = l() > u();
|
|
36
|
+
},
|
|
37
|
+
{ subtree: !0, childList: !0, attributes: !0 }
|
|
38
|
+
), { __sfc: !0, props: e, scrollContainer: t, scrollLeft: s, scrollRight: i, showScrollBar: a, getTagsWidth: l, getContainerWidth: u };
|
|
28
39
|
}
|
|
29
40
|
});
|
|
30
|
-
function C(r, e, t, s, i, a,
|
|
31
|
-
var
|
|
32
|
-
return e && (
|
|
41
|
+
function C(r, e, t, s, i, a, l, u) {
|
|
42
|
+
var c = typeof r == "function" ? r.options : r;
|
|
43
|
+
return e && (c.render = e, c.staticRenderFns = t, c._compiled = !0), a && (c._scopeId = "data-v-" + a), {
|
|
33
44
|
exports: r,
|
|
34
|
-
options:
|
|
45
|
+
options: c
|
|
35
46
|
};
|
|
36
47
|
}
|
|
37
48
|
var Y = function() {
|
|
38
49
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
|
39
|
-
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) {
|
|
40
|
-
return t("el-tag", { key: i.field, staticClass: "search-tag", attrs: {
|
|
41
|
-
}), 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);
|
|
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
|
+
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
|
+
}), 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);
|
|
42
53
|
}, G = [], X = /* @__PURE__ */ C(
|
|
43
|
-
|
|
54
|
+
z,
|
|
44
55
|
Y,
|
|
45
56
|
G,
|
|
46
57
|
!1,
|
|
@@ -48,13 +59,13 @@ var Y = function() {
|
|
|
48
59
|
null
|
|
49
60
|
);
|
|
50
61
|
const J = X.exports;
|
|
51
|
-
var Q = Object.defineProperty, Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t,
|
|
52
|
-
const
|
|
62
|
+
var Q = Object.defineProperty, Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, h = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
|
|
63
|
+
const E = 6;
|
|
53
64
|
class ee {
|
|
54
65
|
constructor(e, t) {
|
|
55
|
-
|
|
56
|
-
var s, i, a,
|
|
57
|
-
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 :
|
|
66
|
+
h(this, "field"), h(this, "label"), h(this, "value"), h(this, "required"), h(this, "index"), h(this, "visible"), h(this, "disabled"), h(this, "span"), h(this, "initValue"), h(this, "enable"), h(this, "tagFilter"), h(this, "render"), h(this, "transform"), h(this, "onChange");
|
|
67
|
+
var s, i, a, l;
|
|
68
|
+
this.field = e.field, this.label = e.label, this.value = e.initValue, this.required = e.required, this.initValue = e.initValue, this.index = t, this.visible = (s = e.visible) != null ? s : !0, this.span = (i = e.span) != null ? i : E, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform, this.enable = (a = e.enable) != null ? a : !0, this.disabled = (l = e.disabled) != null ? l : !1, e.onChange && (this.onChange = W((u, c) => e.onChange(u, c), 50));
|
|
58
69
|
}
|
|
59
70
|
clean() {
|
|
60
71
|
Array.isArray(this.value) ? this.value = [] : this.value = void 0;
|
|
@@ -86,7 +97,7 @@ class _ {
|
|
|
86
97
|
var s, i;
|
|
87
98
|
return new _(
|
|
88
99
|
e.field,
|
|
89
|
-
(s = e.span) != null ? s :
|
|
100
|
+
(s = e.span) != null ? s : E,
|
|
90
101
|
t ?? e,
|
|
91
102
|
(i = e.visible) != null ? i : !0
|
|
92
103
|
);
|
|
@@ -105,7 +116,7 @@ class _ {
|
|
|
105
116
|
const A = (r) => `searches_layouts_${r}`;
|
|
106
117
|
class re {
|
|
107
118
|
constructor(e, t) {
|
|
108
|
-
p(this, "id"), p(this, "state"), p(this, "itemLayouts"), p(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts =
|
|
119
|
+
p(this, "id"), p(this, "state"), p(this, "itemLayouts"), p(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = k(e.items.map(_.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
|
|
109
120
|
}
|
|
110
121
|
/**
|
|
111
122
|
* 恢复自缓存中的布局信息
|
|
@@ -230,7 +241,7 @@ class D {
|
|
|
230
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();
|
|
231
242
|
}
|
|
232
243
|
static hasValue(e) {
|
|
233
|
-
return
|
|
244
|
+
return q(e.value) || N(e.value) ? !0 : !R(e.value);
|
|
234
245
|
}
|
|
235
246
|
updateValueText() {
|
|
236
247
|
const e = document.querySelector(this.id);
|
|
@@ -300,46 +311,46 @@ const ue = {
|
|
|
300
311
|
s.api.updateSearchTag(s.search.field);
|
|
301
312
|
}, i.componentOptions.listeners.input) {
|
|
302
313
|
const a = i.componentOptions.listeners.input;
|
|
303
|
-
i.componentOptions.listeners.input = (
|
|
304
|
-
s.search.onChange && s.search.onChange(
|
|
314
|
+
i.componentOptions.listeners.input = (l) => {
|
|
315
|
+
s.search.onChange && s.search.onChange(l, s.api), a(l);
|
|
305
316
|
};
|
|
306
317
|
}
|
|
307
318
|
return i.componentOptions.propsData.disabled = s.search.isDisabled(s.api), i;
|
|
308
319
|
}
|
|
309
320
|
}, he = () => {
|
|
310
|
-
const r =
|
|
321
|
+
const r = H(), e = d(), t = d([]), s = d(!1), i = d(), a = d([]), l = d(300), u = (n) => {
|
|
311
322
|
r.value = n, t.value = [
|
|
312
323
|
{
|
|
313
324
|
label: "全部",
|
|
314
325
|
id: "all",
|
|
315
326
|
children: r.value.items.sort(
|
|
316
|
-
(
|
|
317
|
-
).map((
|
|
318
|
-
label:
|
|
319
|
-
id:
|
|
320
|
-
disabled: !
|
|
327
|
+
(o, y) => n.config.itemLayouts[o.field].index - n.config.itemLayouts[y.field].index
|
|
328
|
+
).map((o) => ({
|
|
329
|
+
label: o.label,
|
|
330
|
+
id: o.field,
|
|
331
|
+
disabled: !o.isEnable(n)
|
|
321
332
|
}))
|
|
322
333
|
}
|
|
323
|
-
], i.value =
|
|
334
|
+
], i.value = V(n.config.itemLayouts).pickBy((o) => o.visible).keys().value();
|
|
324
335
|
};
|
|
325
336
|
return {
|
|
326
337
|
treeRef: e,
|
|
327
338
|
visible: s,
|
|
328
339
|
snapshot: t,
|
|
329
340
|
defaultCheckedKeys: i,
|
|
330
|
-
drawerWidth:
|
|
331
|
-
updateSnapshot:
|
|
341
|
+
drawerWidth: l,
|
|
342
|
+
updateSnapshot: u,
|
|
332
343
|
show: (n) => {
|
|
333
|
-
|
|
344
|
+
u(n), s.value = !0;
|
|
334
345
|
},
|
|
335
346
|
save: () => {
|
|
336
347
|
r.value.config.sync(
|
|
337
348
|
t.value[0].children.map((n) => n.id),
|
|
338
349
|
new Set(e.value.getCheckedKeys())
|
|
339
|
-
), r.value.config.persistent();
|
|
350
|
+
), r.value.config.persistent(), s.value = !1;
|
|
340
351
|
},
|
|
341
352
|
reset: () => {
|
|
342
|
-
r.value.config.reset(),
|
|
353
|
+
r.value.config.reset(), u(r.value);
|
|
343
354
|
},
|
|
344
355
|
keepSelection: () => {
|
|
345
356
|
a.value = e.value.getCheckedKeys();
|
|
@@ -347,10 +358,10 @@ const ue = {
|
|
|
347
358
|
restoreSelection: () => {
|
|
348
359
|
e.value.setCheckedKeys(a.value), a.value = [];
|
|
349
360
|
},
|
|
350
|
-
allowDrop: (n,
|
|
361
|
+
allowDrop: (n, o, y) => y !== "inner",
|
|
351
362
|
allowDrag: (n) => !n.disabled
|
|
352
363
|
};
|
|
353
|
-
}, de = /* @__PURE__ */
|
|
364
|
+
}, de = /* @__PURE__ */ w({
|
|
354
365
|
__name: "SearchSettingsDrawer",
|
|
355
366
|
setup(r, { expose: e }) {
|
|
356
367
|
const {
|
|
@@ -358,18 +369,18 @@ const ue = {
|
|
|
358
369
|
visible: s,
|
|
359
370
|
snapshot: i,
|
|
360
371
|
drawerWidth: a,
|
|
361
|
-
defaultCheckedKeys:
|
|
362
|
-
show:
|
|
363
|
-
allowDrop:
|
|
364
|
-
allowDrag:
|
|
372
|
+
defaultCheckedKeys: l,
|
|
373
|
+
show: u,
|
|
374
|
+
allowDrop: c,
|
|
375
|
+
allowDrag: g,
|
|
365
376
|
keepSelection: x,
|
|
366
|
-
restoreSelection:
|
|
367
|
-
save:
|
|
368
|
-
reset:
|
|
377
|
+
restoreSelection: m,
|
|
378
|
+
save: b,
|
|
379
|
+
reset: S
|
|
369
380
|
} = he();
|
|
370
381
|
return e({
|
|
371
|
-
show:
|
|
372
|
-
}), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys:
|
|
382
|
+
show: u
|
|
383
|
+
}), { __sfc: !0, treeRef: t, visible: s, snapshot: i, drawerWidth: a, defaultCheckedKeys: l, show: u, allowDrop: c, allowDrag: g, keepSelection: x, restoreSelection: m, save: b, reset: S };
|
|
373
384
|
}
|
|
374
385
|
});
|
|
375
386
|
var fe = function() {
|
|
@@ -385,7 +396,7 @@ var fe = function() {
|
|
|
385
396
|
null,
|
|
386
397
|
null
|
|
387
398
|
);
|
|
388
|
-
const _e = ve.exports, ge = /* @__PURE__ */
|
|
399
|
+
const _e = ve.exports, ge = /* @__PURE__ */ w({
|
|
389
400
|
__name: "SettingButton",
|
|
390
401
|
props: {
|
|
391
402
|
state: null
|
|
@@ -400,7 +411,7 @@ const _e = ve.exports, ge = /* @__PURE__ */ S({
|
|
|
400
411
|
var me = function() {
|
|
401
412
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
|
402
413
|
return t("div", { staticStyle: { "margin-right": "10px" } }, [t("el-button", { staticClass: "icon-button", staticStyle: { height: "100%" }, on: { click: s.showSearchLayoutDialog } }, [t("i", { staticClass: "el-icon-s-tools" })]), t(s.SearchSettingsDrawer, { ref: "searchSettingDialogRef" })], 1);
|
|
403
|
-
}, be = [],
|
|
414
|
+
}, be = [], Se = /* @__PURE__ */ C(
|
|
404
415
|
ge,
|
|
405
416
|
me,
|
|
406
417
|
be,
|
|
@@ -408,7 +419,7 @@ var me = function() {
|
|
|
408
419
|
null,
|
|
409
420
|
"61aa7563"
|
|
410
421
|
);
|
|
411
|
-
const
|
|
422
|
+
const ye = Se.exports, we = /* @__PURE__ */ w({
|
|
412
423
|
__name: "SearchBar",
|
|
413
424
|
props: {
|
|
414
425
|
searches: null,
|
|
@@ -421,40 +432,40 @@ const Se = ye.exports, we = /* @__PURE__ */ S({
|
|
|
421
432
|
},
|
|
422
433
|
emits: ["change"],
|
|
423
434
|
setup(r, { expose: e, emit: t }) {
|
|
424
|
-
const s = r, i =
|
|
425
|
-
|
|
426
|
-
|
|
435
|
+
const s = r, i = K(new ce(s.id, s.searches, s.onSearch)), a = d(!1), l = d();
|
|
436
|
+
F(
|
|
437
|
+
l,
|
|
427
438
|
() => {
|
|
428
439
|
i.updateTags();
|
|
429
440
|
},
|
|
430
441
|
{ childList: !0 }
|
|
431
442
|
);
|
|
432
|
-
const
|
|
433
|
-
|
|
443
|
+
const u = $(() => P(Array.from(Object.values(i.config.itemLayouts)).filter((o) => o.visible).map((o) => o.span)) / 24 > s.maxRows), c = d([]);
|
|
444
|
+
M(() => [i.items, i.config.itemLayouts], () => {
|
|
434
445
|
const n = [...i.items];
|
|
435
|
-
|
|
446
|
+
c.value = n.sort((o, y) => i.config.itemLayouts[o.field].index - i.config.itemLayouts[y.field].index).filter((o) => o.isEnable(i)), t("change", i.getSearchObject(), i);
|
|
436
447
|
}, { debounce: 100, immediate: !0, deep: !0 });
|
|
437
|
-
const
|
|
448
|
+
const g = $(() => ({
|
|
438
449
|
height: `${s.itemHeight * s.maxRows}px`,
|
|
439
450
|
overflow: "hidden"
|
|
440
|
-
})), x = (n) => i.config.itemLayouts[n.field],
|
|
451
|
+
})), x = (n) => i.config.itemLayouts[n.field], m = () => i.items, b = () => i.getSearchObject(), S = (n) => {
|
|
441
452
|
i.searching = n;
|
|
442
453
|
}, L = () => i.updateTags();
|
|
443
454
|
return e({
|
|
444
|
-
getSearchItems:
|
|
445
|
-
getSearchObject:
|
|
446
|
-
updateSearching:
|
|
455
|
+
getSearchItems: m,
|
|
456
|
+
getSearchObject: b,
|
|
457
|
+
updateSearching: S,
|
|
447
458
|
updateTags: L
|
|
448
|
-
}), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef:
|
|
459
|
+
}), { __sfc: !0, props: s, state: i, expanded: a, itemContainerRef: l, isShowSpanIcon: u, sortedItems: c, emits: t, itemHeightStyle: g, getLayout: x, getSearchItems: m, getSearchObject: b, updateSearching: S, updateTags: L, SearchTagsRender: J, SearchItemRender: ue, SettingButton: ye };
|
|
449
460
|
}
|
|
450
461
|
});
|
|
451
462
|
var xe = function() {
|
|
452
463
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
|
453
464
|
return t("div", { staticClass: "search-bar-container" }, [t("el-row", { ref: "itemContainerRef", class: "search", staticStyle: { "flex-wrap": "wrap" }, style: s.isShowSpanIcon && !s.expanded ? s.itemHeightStyle : {}, attrs: { type: "flex", gutter: 16 } }, e._l(s.sortedItems, function(i) {
|
|
454
465
|
return t("el-col", { directives: [{ name: "show", rawName: "v-show", value: s.getLayout(i).visible, expression: "getLayout(item).visible" }], key: i.field, attrs: { span: s.getLayout(i).span } }, [t("div", { staticClass: "search-item" }, [t("div", { staticClass: "search-item-title" }, [e._v(e._s(i.label))]), t("div", { staticClass: "search-item-content", attrs: { id: `${e.id}-${i.field}` } }, [t(s.SearchItemRender, { attrs: { search: i, api: s.state } })], 1)])]);
|
|
455
|
-
}), 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" }, [
|
|
466
|
+
}), 1), t("div", { staticClass: "search-bottom" }, [s.state.tags.length > 0 ? t(s.SearchTagsRender, { attrs: { tags: s.state.tags } }) : e._e(), t("div", { staticClass: "actions" }, [t("el-button", { directives: [{ name: "show", rawName: "v-show", value: s.isShowSpanIcon, expression: "isShowSpanIcon" }], staticClass: "icon-button", staticStyle: { "margin-right": "10px" }, on: { click: function(i) {
|
|
456
467
|
s.expanded = !s.expanded;
|
|
457
|
-
} } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })])
|
|
468
|
+
} } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })]), t(s.SettingButton, { attrs: { state: s.state } }), t("el-button", { attrs: { type: "primary", loading: s.state.searching, disabled: s.state.searching }, on: { click: () => s.state.doSearch() } }, [e._v("查 询")]), t("el-button", { on: { click: () => s.state.reset(e.resetAutoSearch) } }, [e._v("重 置")])], 1)], 1)], 1);
|
|
458
469
|
}, Ce = [], Le = /* @__PURE__ */ C(
|
|
459
470
|
we,
|
|
460
471
|
xe,
|
|
@@ -463,17 +474,17 @@ var xe = function() {
|
|
|
463
474
|
null,
|
|
464
475
|
null
|
|
465
476
|
);
|
|
466
|
-
const
|
|
477
|
+
const Fe = Le.exports;
|
|
467
478
|
var Oe = Object.defineProperty, Te = (r, e, t) => e in r ? Oe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, $e = (r, e, t) => Te(r, e + "", t);
|
|
468
|
-
const
|
|
479
|
+
const Ee = (r) => R(r), je = () => !0, Be = (r, e) => {
|
|
469
480
|
const t = r.getSearchObject();
|
|
470
481
|
let s = !0;
|
|
471
482
|
for (const [i, a] of Object.entries(e)) {
|
|
472
|
-
const
|
|
473
|
-
s = a(
|
|
483
|
+
const l = t[i];
|
|
484
|
+
s = a(l), s || (s = !1);
|
|
474
485
|
}
|
|
475
486
|
return () => s;
|
|
476
|
-
},
|
|
487
|
+
}, ke = (r, e, t) => ({
|
|
477
488
|
/**
|
|
478
489
|
* 数据刷新回调代理
|
|
479
490
|
*
|
|
@@ -509,7 +520,7 @@ class O {
|
|
|
509
520
|
const a = i.transform ? i.transform(i.value) : i.value;
|
|
510
521
|
return {
|
|
511
522
|
...s,
|
|
512
|
-
...
|
|
523
|
+
...I(a) ? a : { [i.field]: a }
|
|
513
524
|
};
|
|
514
525
|
},
|
|
515
526
|
{}
|
|
@@ -525,11 +536,11 @@ class O {
|
|
|
525
536
|
}
|
|
526
537
|
}
|
|
527
538
|
export {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
539
|
+
je as APPLY_ALWAYS,
|
|
540
|
+
Ee as APPLY_WHEN_NOT_VALUE,
|
|
541
|
+
Be as APPLY_WITH_MULTIPLE_VALUE,
|
|
542
|
+
Fe as SearchBar,
|
|
532
543
|
O as Searches,
|
|
533
|
-
|
|
534
|
-
|
|
544
|
+
ke as useSearchProxy,
|
|
545
|
+
Re as vModel
|
|
535
546
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("lodash-unified"),require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue","@vueuse/core"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.ElementPlusSearch={},u.lodashUnified,u.vue,u.core))})(this,function(u,o,n,O){"use strict";const E=r=>({model:{value:o.get(r,"value"),callback:e=>{o.set(r,"value",e)}}}),F=n.defineComponent({name:"SearchTags"}),R=n.defineComponent({...F,props:{tags:null},setup(r){const e=r,t=n.ref();return{__sfc:!0,props:e,scrollContainer:t,scrollLeft:()=>{t.value.scrollBy({left:-200,behavior:"smooth"})},scrollRight:()=>{t.value.scrollBy({left:200,behavior:"smooth"})}}}});function C(r,e,t,s,i,a,h,p){var f=typeof r=="function"?r.options:r;return e&&(f.render=e,f.staticRenderFns=t,f._compiled=!0),a&&(f._scopeId="data-v-"+a),{exports:r,options:f}}var j=function(){var e=this,t=e._self._c,s=e._self._setupProxy;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){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)}})])}),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)},q=[],k=C(R,j,q,!1,null,null);const N=k.exports;var B=Object.defineProperty,V=(r,e,t)=>e in r?B(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,d=(r,e,t)=>V(r,typeof e!="symbol"?e+"":e,t);const A=6;class I{constructor(e,t){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");var s,i,a,h;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,this.enable=(a=e.enable)!=null?a:!0,this.disabled=(h=e.disabled)!=null?h:!1,e.onChange&&(this.onChange=O.useDebounceFn((p,f)=>e.onChange(p,f),50))}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}isEnable(e){return o.isFunction(this.enable)?this.enable(e.getSearchObject()):this.enable}isDisabled(e){return o.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,_=(r,e,t)=>M(r,typeof e!="symbol"?e+"":e,t);class g{constructor(e,t,s,i){_(this,"field"),_(this,"span"),_(this,"index"),_(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:A,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){_(this,"id"),_(this,"state"),_(this,"itemLayouts"),_(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=o.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,v=(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){v(this,"id"),v(this,"field"),v(this,"value"),v(this,"label"),v(this,"valueText"),v(this,"required"),v(this,"item"),v(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 o.isNumber(e.value)||o.isBoolean(e.value)?!0:!o.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:x.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=h=>{s.search.onChange&&s.search.onChange(h,s.api),a(h)}}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([]),h=n.ref(300),p=l=>{r.value=l,t.value=[{label:"全部",id:"all",children:r.value.items.sort((c,w)=>l.config.itemLayouts[c.field].index-l.config.itemLayouts[w.field].index).map(c=>({label:c.label,id:c.field,disabled:!c.isEnable(l)}))}],i.value=o.chain(l.config.itemLayouts).pickBy(c=>c.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:i,drawerWidth:h,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()},reset:()=>{r.value.config.reset(),p(r.value)},keepSelection:()=>{a.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(a.value),a.value=[]},allowDrop:(l,c,w)=>w!=="inner",allowDrag:l=>!l.disabled}},U=n.defineComponent({__name:"SearchSettingsDrawer",setup(r,{expose:e}){const{treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:h,show:p,allowDrop:f,allowDrag:L,keepSelection:T,restoreSelection:b,save:y,reset:S}=Z();return e({show:p}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:h,show:p,allowDrop:f,allowDrag:L,keepSelection:T,restoreSelection:b,save:y,reset:S}}});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=C(U,ee,te,!1,null,null);const re=se.exports,ie=n.defineComponent({__name:"SettingButton",props:{state:null},setup(r){const e=r,t=n.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:re}}});var ae=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticStyle:{"margin-right":"10px"}},[t("el-button",{staticClass:"icon-button",staticStyle:{height:"100%"},on:{click:s.showSearchLayoutDialog}},[t("i",{staticClass:"el-icon-s-tools"})]),t(s.SearchSettingsDrawer,{ref:"searchSettingDialogRef"})],1)},ne=[],le=C(ie,ae,ne,!1,null,"61aa7563");const oe=le.exports,ce=n.defineComponent({__name:"SearchBar",props:{searches:null,id:null,onSearch:{type:Function},defaultSpan:{default:6},maxRows:{default:2},itemHeight:{default:67},resetAutoSearch:{type:Boolean,default:!0}},emits:["change"],setup(r,{expose:e,emit:t}){const s=r,i=n.reactive(new J(s.id,s.searches,s.onSearch)),a=n.ref(!1),h=n.ref();O.useMutationObserver(h,()=>{i.updateTags()},{childList:!0});const p=n.computed(()=>o.sum(Array.from(Object.values(i.config.itemLayouts)).filter(c=>c.visible).map(c=>c.span))/24>s.maxRows),f=n.ref([]);O.watchDebounced(()=>[i.items,i.config.itemLayouts],()=>{const l=[...i.items];f.value=l.sort((c,w)=>i.config.itemLayouts[c.field].index-i.config.itemLayouts[w.field].index).filter(c=>c.isEnable(i)),t("change",i.getSearchObject(),i)},{debounce:100,immediate:!0,deep:!0});const L=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),T=l=>i.config.itemLayouts[l.field],b=()=>i.items,y=()=>i.getSearchObject(),S=l=>{i.searching=l},P=()=>i.updateTags();return e({getSearchItems:b,getSearchObject:y,updateSearching:S,updateTags:P}),{__sfc:!0,props:s,state:i,expanded:a,itemContainerRef:h,isShowSpanIcon:p,sortedItems:f,emits:t,itemHeightStyle:L,getLayout:T,getSearchItems:b,getSearchObject:y,updateSearching:S,updateTags:P,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"},[s.isShowSpanIcon?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"]})]):e._e(),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=C(ce,ue,he,!1,null,null);const fe=de.exports;var pe=Object.defineProperty,_e=(r,e,t)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ve=(r,e,t)=>_e(r,e+"",t);const ge=r=>o.isEmpty(r),me=()=>!0,be=(r,e)=>{const t=r.getSearchObject();let s=!0;for(const[i,a]of Object.entries(e)){const h=t[i];s=a(h),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 x{constructor(e){ve(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,...o.isPlainObject(a)?a:{[i.field]:a}}},{});return new x(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}}}u.APPLY_ALWAYS=me,u.APPLY_WHEN_NOT_VALUE=ge,u.APPLY_WITH_MULTIPLE_VALUE=be,u.SearchBar=fe,u.Searches=x,u.useSearchProxy=ye,u.vModel=E,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("lodash-unified"),require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue","@vueuse/core"],c):(h=typeof globalThis<"u"?globalThis:h||self,c(h.ElementPlusSearch={},h.lodashUnified,h.vue,h.core))})(this,function(h,c,n,x){"use strict";const E=r=>({model:{value:c.get(r,"value"),callback:e=>{c.set(r,"value",e)}}}),F=n.defineComponent({name:"SearchTags"}),R=n.defineComponent({...F,props:{tags:null},setup(r){const e=r,t=n.ref(),s=()=>{t.value.scrollBy({left:-200,behavior:"smooth"})},i=()=>{t.value.scrollBy({left:200,behavior:"smooth"})},a=n.ref(!1),o=()=>{const d=Array.from(t.value.children);return c.sum(d.map(b=>b.getBoundingClientRect().width))},p=()=>t.value.getBoundingClientRect().width;return x.useMutationObserver(t,()=>{a.value=o()>p()},{subtree:!0,childList:!0,attributes:!0}),{__sfc:!0,props:e,scrollContainer:t,scrollLeft:s,scrollRight:i,showScrollBar:a,getTagsWidth:o,getContainerWidth:p}}});function L(r,e,t,s,i,a,o,p){var d=typeof r=="function"?r.options:r;return e&&(d.render=e,d.staticRenderFns=t,d._compiled=!0),a&&(d._scopeId="data-v-"+a),{exports:r,options:d}}var j=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"tags-scroll-container"},[t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-left-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollLeft}},[t("i",{staticClass:"el-icon-arrow-left"})]),t("div",{ref:"scrollContainer",staticClass:"search-tags"},e._l(e.tags,function(i){return t("el-tag",{key:i.field,staticClass:"search-tag",attrs:{"disable-transitions":"",closable:!i.required,type:i.required?"primary":"info"},on:{close:()=>i.clean()}},[t("span",[e._v(" "+e._s(i.label)+" ")]),e._v(": "),t("span",{domProps:{innerHTML:e._s(i.valueText)}})])}),1),t("el-tag",{directives:[{name:"show",rawName:"v-show",value:s.showScrollBar,expression:"showScrollBar"}],staticClass:"scroll-right-bar",attrs:{"disable-transitions":"",size:"medium",type:"info"},on:{click:s.scrollRight}},[t("i",{staticClass:"el-icon-arrow-right"})])],1)},B=[],q=L(R,j,B,!1,null,null);const N=q.exports;var k=Object.defineProperty,V=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,f=(r,e,t)=>V(r,typeof e!="symbol"?e+"":e,t);const P=6;class I{constructor(e,t){f(this,"field"),f(this,"label"),f(this,"value"),f(this,"required"),f(this,"index"),f(this,"visible"),f(this,"disabled"),f(this,"span"),f(this,"initValue"),f(this,"enable"),f(this,"tagFilter"),f(this,"render"),f(this,"transform"),f(this,"onChange");var s,i,a,o;this.field=e.field,this.label=e.label,this.value=e.initValue,this.required=e.required,this.initValue=e.initValue,this.index=t,this.visible=(s=e.visible)!=null?s:!0,this.span=(i=e.span)!=null?i:P,this.render=e.render,this.tagFilter=e.tagFilter,this.transform=e.transform,this.enable=(a=e.enable)!=null?a:!0,this.disabled=(o=e.disabled)!=null?o:!1,e.onChange&&(this.onChange=x.useDebounceFn((p,d)=>e.onChange(p,d),50))}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}isEnable(e){return c.isFunction(this.enable)?this.enable(e.getSearchObject()):this.enable}isDisabled(e){return c.isFunction(this.disabled)?this.disabled(e.getSearchObject()):this.disabled}}var H=Object.defineProperty,M=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,v=(r,e,t)=>M(r,typeof e!="symbol"?e+"":e,t);class g{constructor(e,t,s,i){v(this,"field"),v(this,"span"),v(this,"index"),v(this,"visible"),this.field=e,this.span=t,this.index=s,this.visible=i}static fromSearchItem(e,t){return new g(e.field,e.span,t??e.index,e.visible)}static formSearchConfig(e,t){var s,i;return new g(e.field,(s=e.span)!=null?s:P,t??e,(i=e.visible)!=null?i:!0)}static fromString(e){const[t,s,i,a]=e.split("_");return new g(s,Number(i),Number(t),a==="true")}toString(){return`${this.index}_${this.field}_${this.span}_${this.visible}`}merge(e){this.span=e.span,this.index=e.index,this.visible=e.visible}}const $=r=>`searches_layouts_${r}`;class W{constructor(e,t){v(this,"id"),v(this,"state"),v(this,"itemLayouts"),v(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=c.keyBy(e.items.map(g.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem($(this.id));e&&e.split(",").forEach(t=>{const s=g.fromString(t),i=this.itemLayouts[s.field];i&&i.merge(s)})}sync(e,t){if(e.length!==Object.keys(this.itemLayouts).length)throw new Error("同步布局字段数量不一致");e.forEach((s,i)=>{const a=this.itemLayouts[s];a.index=i,a.visible=t.has(s)})}persistent(){localStorage.setItem($(this.id),Object.values(this.itemLayouts).map(e=>e.toString()).join(",")),this.state.updateTags()}reset(){this.initialLayouts.forEach(e=>{const t=this.itemLayouts[e.field];t&&t.merge(e)})}}var K=Object.defineProperty,Y=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e,t)=>Y(r,typeof e!="symbol"?e+"":e,t);const z=[{isApply(r){return r.contains("el-radio-group")},getText(r){var e,t;return(t=(e=r.querySelector(".is-active"))==null?void 0:e.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-checkbox-group")},getText(r){var e;const t=Array.from((e=r.querySelectorAll(".el-checkbox__input.is-checked"))!=null?e:[]).map(s=>{var i;return(i=s.querySelector("input"))==null?void 0:i.value}).filter(s=>s);return t.length===1?t[0]:`${t[0]} 等${t.length}条`}},{isApply(r){return r.contains("el-input")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-input-number")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-select")},getText(r,e){var t;const s=r.querySelectorAll(".el-select__tags-text");return s.length>0?e.value.length>1?`${s[0].textContent} 等${e.value.length}条`:s[0].textContent:(t=r.querySelector("input"))==null?void 0:t.value}},{isApply(r){return r.contains("el-cascader")},getText(r){var e;return(e=r.querySelector("input"))==null?void 0:e.value}},{isApply(r){return r.contains("el-switch")},getText(r){return r.querySelector(".is-active").innerHTML}},{isApply(r){return r.contains("el-slider")},getText(r,e){return e.value}},{isApply(r){return r.contains("el-date-editor")},getText(r,e){return e.value?e.value.join(" ~ "):e.value}}];class D{constructor(e,t){_(this,"id"),_(this,"field"),_(this,"value"),_(this,"label"),_(this,"valueText"),_(this,"required"),_(this,"item"),_(this,"state");var s;this.id=`#${e.id}-${t.field}`,this.state=e,this.field=t.field,this.value=t.value,this.label=t.label,this.item=t,this.required=(s=t.required)!=null?s:!1,this.updateValueText()}static hasValue(e){return c.isNumber(e.value)||c.isBoolean(e.value)?!0:!c.isEmpty(e.value)}updateValueText(){const e=document.querySelector(this.id);if(!e)return;if(e.children.length!==1)throw new Error("holder children length is not 1");const t=e.children[0],s=z.find(i=>i.isApply(t.classList));s&&(this.valueText=s.getText(t,this))}async clean(){this.item.clean(),await this.state.doSearch()}}var G=Object.defineProperty,X=(r,e,t)=>e in r?G(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,m=(r,e,t)=>X(r,typeof e!="symbol"?e+"":e,t);class J{constructor(e,t,s){this.id=e,m(this,"items"),m(this,"config"),m(this,"searching"),m(this,"tags"),m(this,"searchCallback"),m(this,"sourceSearchable"),m(this,"_lastSearchObject",{time:0,data:null}),this.id=e,this.items=t.map((i,a)=>new I(i,a)),this.config=new W(this,t.map((i,a)=>g.formSearchConfig(i,a))),this.sourceSearchable=t,this.searching=!1,this.searchCallback=s,this.tags=[]}updateSearchTag(e){var t;(t=this.tags.find(s=>s.field===e))==null||t.updateValueText()}updateTags(){this.tags=this.items.filter(e=>e.tagFilter?e.tagFilter(e.value):D.hasValue(e)).map(e=>new D(this,e)).sort((e,t)=>this.config.itemLayouts[e.field].index-this.config.itemLayouts[t.field].index)}getSearchObject(e){const t=Date.now();return this._lastSearchObject.data&&t-this._lastSearchObject.time<50?this._lastSearchObject.data:(this._lastSearchObject={time:t,data:T.from(this.items).toCondition(e)},this._lastSearchObject.data)}async doSearch(){if(!this.searching)try{this.searching=!0,await this.searchCallback(this.getSearchObject()),this.updateTags()}finally{this.searching=!1}}async reset(e){this.items.forEach(t=>t.reset()),e&&await this.doSearch()}setSearchValue(e,t,s=i=>!0){const i=this.items.find(a=>a.field===e);i&&s&&s(i.value)&&(i.value=t)}}const Q={functional:!0,props:{search:{type:Object,required:!0},api:{type:Object}},render(r,e){var t;const{props:s}=e,i=s.search.render(s.search);if(i.componentOptions.propsData||(i.componentOptions.propsData={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),i.componentOptions.listeners||(i.componentOptions.listeners={}),(t=i.data)!=null&&t.attrs||(i.data.attrs={}),i.data.attrs.labelChange=()=>{s.api.updateSearchTag(s.search.field)},i.componentOptions.listeners.input){const a=i.componentOptions.listeners.input;i.componentOptions.listeners.input=o=>{s.search.onChange&&s.search.onChange(o,s.api),a(o)}}return i.componentOptions.propsData.disabled=s.search.isDisabled(s.api),i}},Z=()=>{const r=n.shallowRef(),e=n.ref(),t=n.ref([]),s=n.ref(!1),i=n.ref(),a=n.ref([]),o=n.ref(300),p=l=>{r.value=l,t.value=[{label:"全部",id:"all",children:r.value.items.sort((u,C)=>l.config.itemLayouts[u.field].index-l.config.itemLayouts[C.field].index).map(u=>({label:u.label,id:u.field,disabled:!u.isEnable(l)}))}],i.value=c.chain(l.config.itemLayouts).pickBy(u=>u.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:i,drawerWidth:o,updateSnapshot:p,show:l=>{p(l),s.value=!0},save:()=>{r.value.config.sync(t.value[0].children.map(l=>l.id),new Set(e.value.getCheckedKeys())),r.value.config.persistent(),s.value=!1},reset:()=>{r.value.config.reset(),p(r.value)},keepSelection:()=>{a.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(a.value),a.value=[]},allowDrop:(l,u,C)=>C!=="inner",allowDrag:l=>!l.disabled}},U=n.defineComponent({__name:"SearchSettingsDrawer",setup(r,{expose:e}){const{treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:d,allowDrag:b,keepSelection:O,restoreSelection:S,save:y,reset:w}=Z();return e({show:p}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:a,defaultCheckedKeys:o,show:p,allowDrop:d,allowDrag:b,keepSelection:O,restoreSelection:S,save:y,reset:w}}});var ee=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("el-drawer",{attrs:{size:s.drawerWidth,title:"搜索项配置",visible:s.visible},on:{"update:visible":function(i){s.visible=i}}},[t("div",{staticClass:"setting-container"},[t("el-tree",{ref:"treeRef",staticClass:"tree",attrs:{"default-expand-all":"","default-checked-keys":s.defaultCheckedKeys,"node-key":"id",draggable:"","show-checkbox":"",data:s.snapshot,"allow-drop":s.allowDrop,"allow-drag":s.allowDrag},on:{"node-drag-start":s.keepSelection,"node-drag-end":s.restoreSelection}}),t("div",{staticClass:"footer"},[t("el-button",{on:{click:s.reset}},[e._v("重置")]),t("el-button",{attrs:{type:"primary"},on:{click:s.save}},[e._v("保存")])],1)],1)])},te=[],se=L(U,ee,te,!1,null,null);const re=se.exports,ie=n.defineComponent({__name:"SettingButton",props:{state:null},setup(r){const e=r,t=n.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:re}}});var ae=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticStyle:{"margin-right":"10px"}},[t("el-button",{staticClass:"icon-button",staticStyle:{height:"100%"},on:{click:s.showSearchLayoutDialog}},[t("i",{staticClass:"el-icon-s-tools"})]),t(s.SearchSettingsDrawer,{ref:"searchSettingDialogRef"})],1)},ne=[],le=L(ie,ae,ne,!1,null,"61aa7563");const oe=le.exports,ce=n.defineComponent({__name:"SearchBar",props:{searches:null,id:null,onSearch:{type:Function},defaultSpan:{default:6},maxRows:{default:2},itemHeight:{default:67},resetAutoSearch:{type:Boolean,default:!0}},emits:["change"],setup(r,{expose:e,emit:t}){const s=r,i=n.reactive(new J(s.id,s.searches,s.onSearch)),a=n.ref(!1),o=n.ref();x.useMutationObserver(o,()=>{i.updateTags()},{childList:!0});const p=n.computed(()=>c.sum(Array.from(Object.values(i.config.itemLayouts)).filter(u=>u.visible).map(u=>u.span))/24>s.maxRows),d=n.ref([]);x.watchDebounced(()=>[i.items,i.config.itemLayouts],()=>{const l=[...i.items];d.value=l.sort((u,C)=>i.config.itemLayouts[u.field].index-i.config.itemLayouts[C.field].index).filter(u=>u.isEnable(i)),t("change",i.getSearchObject(),i)},{debounce:100,immediate:!0,deep:!0});const b=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),O=l=>i.config.itemLayouts[l.field],S=()=>i.items,y=()=>i.getSearchObject(),w=l=>{i.searching=l},A=()=>i.updateTags();return e({getSearchItems:S,getSearchObject:y,updateSearching:w,updateTags:A}),{__sfc:!0,props:s,state:i,expanded:a,itemContainerRef:o,isShowSpanIcon:p,sortedItems:d,emits:t,itemHeightStyle:b,getLayout:O,getSearchItems:S,getSearchObject:y,updateSearching:w,updateTags:A,SearchTagsRender:N,SearchItemRender:Q,SettingButton:oe}}});var ue=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"search-bar-container"},[t("el-row",{ref:"itemContainerRef",class:"search",staticStyle:{"flex-wrap":"wrap"},style:s.isShowSpanIcon&&!s.expanded?s.itemHeightStyle:{},attrs:{type:"flex",gutter:16}},e._l(s.sortedItems,function(i){return t("el-col",{directives:[{name:"show",rawName:"v-show",value:s.getLayout(i).visible,expression:"getLayout(item).visible"}],key:i.field,attrs:{span:s.getLayout(i).span}},[t("div",{staticClass:"search-item"},[t("div",{staticClass:"search-item-title"},[e._v(e._s(i.label))]),t("div",{staticClass:"search-item-content",attrs:{id:`${e.id}-${i.field}`}},[t(s.SearchItemRender,{attrs:{search:i,api:s.state}})],1)])])}),1),t("div",{staticClass:"search-bottom"},[s.state.tags.length>0?t(s.SearchTagsRender,{attrs:{tags:s.state.tags}}):e._e(),t("div",{staticClass:"actions"},[t("el-button",{directives:[{name:"show",rawName:"v-show",value:s.isShowSpanIcon,expression:"isShowSpanIcon"}],staticClass:"icon-button",staticStyle:{"margin-right":"10px"},on:{click:function(i){s.expanded=!s.expanded}}},[t("i",{class:[s.expanded?"el-icon-arrow-up":"el-icon-arrow-down"]})]),t(s.SettingButton,{attrs:{state:s.state}}),t("el-button",{attrs:{type:"primary",loading:s.state.searching,disabled:s.state.searching},on:{click:()=>s.state.doSearch()}},[e._v("查 询")]),t("el-button",{on:{click:()=>s.state.reset(e.resetAutoSearch)}},[e._v("重 置")])],1)],1)],1)},he=[],de=L(ce,ue,he,!1,null,null);const fe=de.exports;var pe=Object.defineProperty,ve=(r,e,t)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_e=(r,e,t)=>ve(r,e+"",t);const ge=r=>c.isEmpty(r),me=()=>!0,be=(r,e)=>{const t=r.getSearchObject();let s=!0;for(const[i,a]of Object.entries(e)){const o=t[i];s=a(o),s||(s=!1)}return()=>s},Se=(r,e,t)=>({refreshCallback:async s=>{const i=e.value.getSearchObject();try{return e.value.updateSearching(!0),await r(i,s)}finally{e.value.updateSearching(!1),e.value.updateTags()}},searchCallback:async()=>{var s;for(const i of t)await((s=i.value)==null?void 0:s.refresh())}});class T{constructor(e){_e(this,"record"),this.record=e}static from(e){const t=e.filter(s=>s.value===void 0?!1:Array.isArray(s.value)?s.value.length>0:!0).reduce((s,i)=>{const a=i.transform?i.transform(i.value):i.value;return{...s,...c.isPlainObject(a)?a:{[i.field]:a}}},{});return new T(t)}transform(e,t){const s=this.record[e],i=t(s);return delete this.record[e],this.record={...this.record,...i},this}toCondition(e){return{...this.record,...e}}}h.APPLY_ALWAYS=me,h.APPLY_WHEN_NOT_VALUE=ge,h.APPLY_WITH_MULTIPLE_VALUE=be,h.SearchBar=fe,h.Searches=T,h.useSearchProxy=Se,h.vModel=E,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/dist/style.css
CHANGED
|
@@ -1 +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}.setting-container{display:flex;flex-direction:column;height:100%}.setting-container .tree{flex:1;overflow-y:auto}.setting-container div[aria-disabled=true]{display:none}.setting-container .footer{margin-top:auto;margin-left:auto;padding:10px 15px;display:flex;gap:10px}.setting-container .footer .el-button{width:90px}.search-bar-container{font-size:14px;width:100%;display:flex;flex-direction:column}.search-bar-container .search,.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 .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{display:flex;margin-left:auto}.search-bar-container .search-bottom .actions .el-button{width:90px}.search-bar-container .search-bottom .actions .icon-button{padding:0 8px;width:34px;font-size:larger}.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}
|
|
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;margin-top:2px}.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}.setting-container{display:flex;flex-direction:column;height:100%}.setting-container .tree{flex:1;overflow-y:auto}.setting-container div[aria-disabled=true]{display:none}.setting-container .footer{margin-top:auto;margin-left:auto;padding:10px 15px;display:flex;gap:10px}.setting-container .footer .el-button{width:90px}.search-bar-container{font-size:14px;width:100%;display:flex;flex-direction:column}.search-bar-container .search,.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 .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{display:flex;margin-left:auto}.search-bar-container .search-bottom .actions .el-button{width:90px}.search-bar-container .search-bottom .actions .icon-button{padding:0 8px;width:34px;font-size:larger}.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}
|