@scvzerng/element-plus-search-vue2 0.0.2 → 0.0.3
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 +196 -173
- package/dist/ElementPlusSearch.umd.js +1 -1
- package/dist/style.css +1 -1
- package/dist/types/SearchBar.vue.d.ts +9 -2
- package/dist/types/SearchBarState.d.ts +2 -0
- package/dist/types/SearchItemRender.d.ts +6 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/model/SearchItem.d.ts +6 -1
- package/dist/types/setting/use-setting.d.ts +1 -0
- package/dist/types/types/Searchable.d.ts +7 -0
- package/package.json +1 -1
@@ -1,21 +1,22 @@
|
|
1
|
-
import { get as F, set as P, keyBy as R, isNumber as
|
2
|
-
import { defineComponent as
|
3
|
-
|
1
|
+
import { get as F, set as P, isFunction as L, keyBy as R, isNumber as q, isBoolean as k, isEmpty as E, chain as j, sum as B, isPlainObject as N } from "lodash-unified";
|
2
|
+
import { defineComponent as y, ref as h, shallowRef as V, reactive as I, computed as D } from "vue";
|
3
|
+
import { watchDebounced as K } from "@vueuse/core";
|
4
|
+
const Ae = (i) => ({
|
4
5
|
model: {
|
5
|
-
value: F(
|
6
|
+
value: F(i, "value"),
|
6
7
|
callback: (e) => {
|
7
|
-
P(
|
8
|
+
P(i, "value", e);
|
8
9
|
}
|
9
10
|
}
|
10
|
-
}),
|
11
|
+
}), H = y({
|
11
12
|
name: "SearchTags"
|
12
|
-
}),
|
13
|
-
...
|
13
|
+
}), z = /* @__PURE__ */ y({
|
14
|
+
...H,
|
14
15
|
props: {
|
15
16
|
tags: null
|
16
17
|
},
|
17
|
-
setup(
|
18
|
-
const e =
|
18
|
+
setup(i) {
|
19
|
+
const e = i, t = h();
|
19
20
|
return { __sfc: !0, props: e, scrollContainer: t, scrollLeft: () => {
|
20
21
|
t.value.scrollBy({ left: -200, behavior: "smooth" });
|
21
22
|
}, scrollRight: () => {
|
@@ -26,34 +27,34 @@ const Le = (r) => ({
|
|
26
27
|
} };
|
27
28
|
}
|
28
29
|
});
|
29
|
-
function
|
30
|
-
var
|
31
|
-
return e && (
|
32
|
-
exports:
|
33
|
-
options:
|
30
|
+
function x(i, e, t, s, r, a, d, c) {
|
31
|
+
var u = typeof i == "function" ? i.options : i;
|
32
|
+
return e && (u.render = e, u.staticRenderFns = t, u._compiled = !0), a && (u._scopeId = "data-v-" + a), {
|
33
|
+
exports: i,
|
34
|
+
options: u
|
34
35
|
};
|
35
36
|
}
|
36
|
-
var
|
37
|
+
var M = function() {
|
37
38
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
38
|
-
return t("div", { staticClass: "tags-scroll-container" }, [t("el-tag", { staticClass: "scroll-left-bar", attrs: { size: "medium", type: "info" }, on: { click: s.scrollLeft } }, [t("i", { staticClass: "el-icon-arrow-left" })]), t("div", { ref: "scrollContainer", staticClass: "search-tags" }, e._l(e.tags, function(
|
39
|
-
return t("el-tag", { key:
|
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(r) {
|
40
|
+
return t("el-tag", { key: r.field, staticClass: "search-tag", attrs: { size: "medium", closable: !r.required, type: r.required ? "primary" : "info" }, on: { close: () => r.clean() } }, [t("span", [e._v(" " + e._s(r.label) + " ")]), e._v(": "), t("span", { domProps: { innerHTML: e._s(r.valueText) } })]);
|
40
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);
|
41
|
-
},
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
}, W = [], G = /* @__PURE__ */ x(
|
43
|
+
z,
|
44
|
+
M,
|
45
|
+
W,
|
45
46
|
!1,
|
46
47
|
null,
|
47
48
|
null
|
48
49
|
);
|
49
|
-
const
|
50
|
-
var
|
50
|
+
const U = G.exports;
|
51
|
+
var X = Object.defineProperty, J = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, n = (i, e, t) => J(i, typeof e != "symbol" ? e + "" : e, t);
|
51
52
|
const A = 6;
|
52
|
-
class
|
53
|
+
class Q {
|
53
54
|
constructor(e, t) {
|
54
|
-
n(this, "field"), n(this, "label"), n(this, "value"), n(this, "required"), n(this, "index"), n(this, "visible"), n(this, "span"), n(this, "initValue"), n(this, "tagFilter"), n(this, "render"), n(this, "transform");
|
55
|
-
var s,
|
56
|
-
this.field = e.field, this.label = e.label, this.value = e.initValue, this.required = e.required, this.initValue = e.initValue, this.index = t, this.visible = (s = e.visible) != null ? s : !0, this.span = (
|
55
|
+
n(this, "field"), n(this, "label"), n(this, "value"), n(this, "required"), n(this, "index"), n(this, "visible"), n(this, "disabled"), n(this, "span"), n(this, "initValue"), n(this, "enable"), n(this, "tagFilter"), n(this, "render"), n(this, "transform");
|
56
|
+
var s, r, a, d;
|
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 = (r = e.span) != null ? r : A, this.render = e.render, this.tagFilter = e.tagFilter, this.transform = e.transform, this.enable = (a = e.enable) != null ? a : !0, this.disabled = (d = e.disabled) != null ? d : !1;
|
57
58
|
}
|
58
59
|
clean() {
|
59
60
|
Array.isArray(this.value) ? this.value = [] : this.value = void 0;
|
@@ -61,14 +62,20 @@ class U {
|
|
61
62
|
reset() {
|
62
63
|
this.value = this.initValue;
|
63
64
|
}
|
65
|
+
isEnable(e) {
|
66
|
+
return L(this.enable) ? this.enable(e.getSearchObject()) : this.enable;
|
67
|
+
}
|
68
|
+
isDisabled(e) {
|
69
|
+
return L(this.disabled) ? this.disabled(e.getSearchObject()) : this.disabled;
|
70
|
+
}
|
64
71
|
}
|
65
|
-
var
|
66
|
-
class
|
67
|
-
constructor(e, t, s,
|
68
|
-
|
72
|
+
var Y = Object.defineProperty, Z = (i, e, t) => e in i ? Y(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, v = (i, e, t) => Z(i, typeof e != "symbol" ? e + "" : e, t);
|
73
|
+
class g {
|
74
|
+
constructor(e, t, s, r) {
|
75
|
+
v(this, "field"), v(this, "span"), v(this, "index"), v(this, "visible"), this.field = e, this.span = t, this.index = s, this.visible = r;
|
69
76
|
}
|
70
77
|
static fromSearchItem(e, t) {
|
71
|
-
return new
|
78
|
+
return new g(
|
72
79
|
e.field,
|
73
80
|
e.span,
|
74
81
|
t ?? e.index,
|
@@ -76,18 +83,17 @@ class _ {
|
|
76
83
|
);
|
77
84
|
}
|
78
85
|
static formSearchConfig(e, t) {
|
79
|
-
var s,
|
80
|
-
return new
|
86
|
+
var s, r;
|
87
|
+
return new g(
|
81
88
|
e.field,
|
82
89
|
(s = e.span) != null ? s : A,
|
83
90
|
t ?? e,
|
84
|
-
(
|
91
|
+
(r = e.visible) != null ? r : !0
|
85
92
|
);
|
86
93
|
}
|
87
94
|
static fromString(e) {
|
88
|
-
|
89
|
-
|
90
|
-
return new _(i, Number(a), Number(s), (t = !!h) != null ? t : !0);
|
95
|
+
const [t, s, r, a] = e.split("_");
|
96
|
+
return new g(s, Number(r), Number(t), a === "true");
|
91
97
|
}
|
92
98
|
toString() {
|
93
99
|
return `${this.index}_${this.field}_${this.span}_${this.visible}`;
|
@@ -96,33 +102,33 @@ class _ {
|
|
96
102
|
this.span = e.span, this.index = e.index, this.visible = e.visible;
|
97
103
|
}
|
98
104
|
}
|
99
|
-
const
|
100
|
-
class
|
105
|
+
const T = (i) => `searches_layouts_${i}`;
|
106
|
+
class ee {
|
101
107
|
constructor(e, t) {
|
102
|
-
|
108
|
+
v(this, "id"), v(this, "state"), v(this, "itemLayouts"), v(this, "initialLayouts"), this.id = e.id, this.initialLayouts = t, this.state = e, this.itemLayouts = R(e.items.map(g.fromSearchItem), (s) => s.field), this.restoreCachedLayouts();
|
103
109
|
}
|
104
110
|
/**
|
105
111
|
* 恢复自缓存中的布局信息
|
106
112
|
* @private
|
107
113
|
*/
|
108
114
|
restoreCachedLayouts() {
|
109
|
-
const e = localStorage.getItem(
|
115
|
+
const e = localStorage.getItem(T(this.id));
|
110
116
|
e && e.split(",").forEach((t) => {
|
111
|
-
const s =
|
112
|
-
|
117
|
+
const s = g.fromString(t), r = this.itemLayouts[s.field];
|
118
|
+
r && r.merge(s);
|
113
119
|
});
|
114
120
|
}
|
115
121
|
sync(e, t) {
|
116
122
|
if (e.length !== Object.keys(this.itemLayouts).length)
|
117
123
|
throw new Error("同步布局字段数量不一致");
|
118
|
-
e.forEach((s,
|
124
|
+
e.forEach((s, r) => {
|
119
125
|
const a = this.itemLayouts[s];
|
120
|
-
a.index =
|
126
|
+
a.index = r, a.visible = t.has(s);
|
121
127
|
});
|
122
128
|
}
|
123
129
|
persistent() {
|
124
130
|
localStorage.setItem(
|
125
|
-
|
131
|
+
T(this.id),
|
126
132
|
Object.values(this.itemLayouts).map((e) => e.toString()).join(",")
|
127
133
|
), this.state.updateTags();
|
128
134
|
}
|
@@ -133,125 +139,126 @@ class Q {
|
|
133
139
|
});
|
134
140
|
}
|
135
141
|
}
|
136
|
-
var
|
137
|
-
const
|
142
|
+
var te = Object.defineProperty, se = (i, e, t) => e in i ? te(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => se(i, typeof e != "symbol" ? e + "" : e, t);
|
143
|
+
const ie = [
|
138
144
|
{
|
139
|
-
isApply(
|
140
|
-
return
|
145
|
+
isApply(i) {
|
146
|
+
return i.contains("el-radio-group");
|
141
147
|
},
|
142
|
-
getText(
|
148
|
+
getText(i) {
|
143
149
|
var e, t;
|
144
|
-
return (t = (e =
|
150
|
+
return (t = (e = i.querySelector(".is-active")) == null ? void 0 : e.querySelector("input")) == null ? void 0 : t.value;
|
145
151
|
}
|
146
152
|
},
|
147
153
|
{
|
148
|
-
isApply(
|
149
|
-
return
|
154
|
+
isApply(i) {
|
155
|
+
return i.contains("el-checkbox-group");
|
150
156
|
},
|
151
|
-
getText(
|
157
|
+
getText(i) {
|
152
158
|
var e;
|
153
|
-
const t = Array.from((e =
|
154
|
-
var
|
155
|
-
return (
|
159
|
+
const t = Array.from((e = i.querySelectorAll(".el-checkbox__input.is-checked")) != null ? e : []).map((s) => {
|
160
|
+
var r;
|
161
|
+
return (r = s.querySelector("input")) == null ? void 0 : r.value;
|
156
162
|
}).filter((s) => s);
|
157
163
|
return t.length === 1 ? t[0] : `${t[0]} 等${t.length}条`;
|
158
164
|
}
|
159
165
|
},
|
160
166
|
{
|
161
|
-
isApply(
|
162
|
-
return
|
167
|
+
isApply(i) {
|
168
|
+
return i.contains("el-input");
|
163
169
|
},
|
164
|
-
getText(
|
170
|
+
getText(i, e) {
|
165
171
|
return e.value;
|
166
172
|
}
|
167
173
|
},
|
168
174
|
{
|
169
|
-
isApply(
|
170
|
-
return
|
175
|
+
isApply(i) {
|
176
|
+
return i.contains("el-input-number");
|
171
177
|
},
|
172
|
-
getText(
|
178
|
+
getText(i, e) {
|
173
179
|
return e.value;
|
174
180
|
}
|
175
181
|
},
|
176
182
|
{
|
177
|
-
isApply(
|
178
|
-
return
|
183
|
+
isApply(i) {
|
184
|
+
return i.contains("el-select");
|
179
185
|
},
|
180
|
-
getText(
|
186
|
+
getText(i, e) {
|
181
187
|
var t;
|
182
|
-
const s =
|
183
|
-
return s.length > 0 ? e.value.length > 1 ? `${s[0].textContent} 等${e.value.length}条` : s[0].textContent : (t =
|
188
|
+
const s = i.querySelectorAll(".el-select__tags-text");
|
189
|
+
return s.length > 0 ? e.value.length > 1 ? `${s[0].textContent} 等${e.value.length}条` : s[0].textContent : (t = i.querySelector("input")) == null ? void 0 : t.value;
|
184
190
|
}
|
185
191
|
},
|
186
192
|
{
|
187
|
-
isApply(
|
188
|
-
return
|
193
|
+
isApply(i) {
|
194
|
+
return i.contains("el-cascader");
|
189
195
|
},
|
190
|
-
getText(
|
196
|
+
getText(i) {
|
191
197
|
var e;
|
192
|
-
return (e =
|
198
|
+
return (e = i.querySelector("input")) == null ? void 0 : e.value;
|
193
199
|
}
|
194
200
|
},
|
195
201
|
{
|
196
|
-
isApply(
|
197
|
-
return
|
202
|
+
isApply(i) {
|
203
|
+
return i.contains("el-switch");
|
198
204
|
},
|
199
|
-
getText(
|
200
|
-
return
|
205
|
+
getText(i) {
|
206
|
+
return i.querySelector(".is-active").innerHTML;
|
201
207
|
}
|
202
208
|
},
|
203
209
|
{
|
204
|
-
isApply(
|
205
|
-
return
|
210
|
+
isApply(i) {
|
211
|
+
return i.contains("el-slider");
|
206
212
|
},
|
207
|
-
getText(
|
213
|
+
getText(i, e) {
|
208
214
|
return e.value;
|
209
215
|
}
|
210
216
|
},
|
211
217
|
{
|
212
|
-
isApply(
|
213
|
-
return
|
218
|
+
isApply(i) {
|
219
|
+
return i.contains("el-date-editor");
|
214
220
|
},
|
215
|
-
getText(
|
221
|
+
getText(i, e) {
|
216
222
|
return e.value ? e.value.join(" ~ ") : e.value;
|
217
223
|
}
|
218
224
|
}
|
219
225
|
];
|
220
|
-
class
|
226
|
+
class O {
|
221
227
|
constructor(e, t) {
|
222
|
-
|
228
|
+
p(this, "id"), p(this, "field"), p(this, "value"), p(this, "label"), p(this, "valueText"), p(this, "required"), p(this, "item"), p(this, "state");
|
223
229
|
var s;
|
224
230
|
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();
|
225
231
|
}
|
226
232
|
static hasValue(e) {
|
227
|
-
return
|
233
|
+
return q(e.value) || k(e.value) ? !0 : !E(e.value);
|
228
234
|
}
|
229
235
|
updateValueText() {
|
230
236
|
const e = document.querySelector(this.id);
|
231
237
|
if (e.children.length !== 1)
|
232
238
|
throw new Error("holder children length is not 1");
|
233
|
-
const t = e.children[0], s =
|
239
|
+
const t = e.children[0], s = ie.find((r) => r.isApply(t.classList));
|
234
240
|
s && (this.valueText = s.getText(t, this));
|
235
241
|
}
|
236
242
|
async clean() {
|
237
243
|
this.item.clean(), await this.state.doSearch();
|
238
244
|
}
|
239
245
|
}
|
240
|
-
var
|
241
|
-
class
|
246
|
+
var re = Object.defineProperty, ae = (i, e, t) => e in i ? re(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, m = (i, e, t) => ae(i, typeof e != "symbol" ? e + "" : e, t);
|
247
|
+
class ne {
|
242
248
|
constructor(e, t, s) {
|
243
|
-
this.id = e, m(this, "items"), m(this, "config"), m(this, "searching"), m(this, "tags"), m(this, "searchCallback"), m(this, "sourceSearchable"), this.id = e, this.items = t.map((
|
249
|
+
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((r, a) => new Q(r, a)), this.config = new ee(
|
244
250
|
this,
|
245
|
-
t.map((
|
251
|
+
t.map((r, a) => g.formSearchConfig(r, a))
|
246
252
|
), this.sourceSearchable = t, this.searching = !1, this.searchCallback = s, this.tags = [];
|
247
253
|
}
|
248
254
|
updateTags() {
|
249
|
-
this.tags = this.items.filter((e) => e.tagFilter ? e.tagFilter(e.value) :
|
255
|
+
this.tags = this.items.filter((e) => e.tagFilter ? e.tagFilter(e.value) : O.hasValue(e)).map((e) => new O(this, e)).sort(
|
250
256
|
(e, t) => this.config.itemLayouts[e.field].index - this.config.itemLayouts[t.field].index
|
251
257
|
);
|
252
258
|
}
|
253
259
|
getSearchObject(e) {
|
254
|
-
|
260
|
+
const t = Date.now();
|
261
|
+
return this._lastSearchObject.data && t - this._lastSearchObject.time < 50 ? this._lastSearchObject.data : (this._lastSearchObject = { time: t, data: $.from(this.items).toCondition(e) }, this._lastSearchObject.data);
|
255
262
|
}
|
256
263
|
async doSearch() {
|
257
264
|
if (!this.searching)
|
@@ -264,52 +271,60 @@ class re {
|
|
264
271
|
async reset(e) {
|
265
272
|
this.items.forEach((t) => t.reset()), e && await this.doSearch();
|
266
273
|
}
|
274
|
+
setSearchValue(e, t) {
|
275
|
+
const s = this.items.find((r) => r.field === e);
|
276
|
+
s && (s.value = t);
|
277
|
+
}
|
267
278
|
}
|
268
|
-
const
|
279
|
+
const le = {
|
269
280
|
functional: !0,
|
270
281
|
props: {
|
271
282
|
search: {
|
272
283
|
type: Object,
|
273
284
|
required: !0
|
285
|
+
},
|
286
|
+
api: {
|
287
|
+
type: Object
|
274
288
|
}
|
275
289
|
},
|
276
|
-
render(
|
277
|
-
const { props: t } = e;
|
278
|
-
return t.search.
|
290
|
+
render(i, e) {
|
291
|
+
const { props: t } = e, s = t.search.render(t.search);
|
292
|
+
return s.componentOptions.propsData || (s.componentOptions.propsData = {}), s.componentOptions.propsData.disabled = t.search.isDisabled(t.api), s;
|
279
293
|
}
|
280
|
-
},
|
281
|
-
const
|
282
|
-
|
294
|
+
}, oe = () => {
|
295
|
+
const i = V(), e = h(), t = h([]), s = h(!1), r = h(), a = h([]), d = h(300), c = (o) => {
|
296
|
+
i.value = o, t.value = [
|
283
297
|
{
|
284
298
|
label: "全部",
|
285
299
|
id: "all",
|
286
|
-
children:
|
287
|
-
(
|
288
|
-
).map((
|
289
|
-
label:
|
290
|
-
id:
|
300
|
+
children: i.value.items.sort(
|
301
|
+
(f, C) => o.config.itemLayouts[f.field].index - o.config.itemLayouts[C.field].index
|
302
|
+
).map((f) => ({
|
303
|
+
label: f.label,
|
304
|
+
id: f.field,
|
305
|
+
disabled: !f.isEnable(o)
|
291
306
|
}))
|
292
307
|
}
|
293
|
-
],
|
308
|
+
], r.value = j(o.config.itemLayouts).pickBy((f) => f.visible).keys().value();
|
294
309
|
};
|
295
310
|
return {
|
296
311
|
treeRef: e,
|
297
312
|
visible: s,
|
298
313
|
snapshot: t,
|
299
|
-
defaultCheckedKeys:
|
300
|
-
drawerWidth:
|
301
|
-
updateSnapshot:
|
302
|
-
show: (
|
303
|
-
o
|
314
|
+
defaultCheckedKeys: r,
|
315
|
+
drawerWidth: d,
|
316
|
+
updateSnapshot: c,
|
317
|
+
show: (o) => {
|
318
|
+
c(o), s.value = !0;
|
304
319
|
},
|
305
320
|
save: () => {
|
306
|
-
|
307
|
-
t.value[0].children.map((
|
321
|
+
i.value.config.sync(
|
322
|
+
t.value[0].children.map((o) => o.id),
|
308
323
|
new Set(e.value.getCheckedKeys())
|
309
|
-
),
|
324
|
+
), i.value.config.persistent();
|
310
325
|
},
|
311
326
|
reset: () => {
|
312
|
-
|
327
|
+
i.value.config.reset(), c(i.value);
|
313
328
|
},
|
314
329
|
keepSelection: () => {
|
315
330
|
a.value = e.value.getCheckedKeys();
|
@@ -317,66 +332,68 @@ const ie = {
|
|
317
332
|
restoreSelection: () => {
|
318
333
|
e.value.setCheckedKeys(a.value), a.value = [];
|
319
334
|
},
|
320
|
-
allowDrop: (
|
335
|
+
allowDrop: (o, f, C) => C !== "inner",
|
336
|
+
allowDrag: (o) => !o.disabled
|
321
337
|
};
|
322
|
-
},
|
338
|
+
}, ce = /* @__PURE__ */ y({
|
323
339
|
__name: "SearchSettingsDrawer",
|
324
|
-
setup(
|
340
|
+
setup(i, { expose: e }) {
|
325
341
|
const {
|
326
342
|
treeRef: t,
|
327
343
|
visible: s,
|
328
|
-
snapshot:
|
344
|
+
snapshot: r,
|
329
345
|
drawerWidth: a,
|
330
|
-
defaultCheckedKeys:
|
331
|
-
show:
|
332
|
-
allowDrop:
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
346
|
+
defaultCheckedKeys: d,
|
347
|
+
show: c,
|
348
|
+
allowDrop: u,
|
349
|
+
allowDrag: S,
|
350
|
+
keepSelection: b,
|
351
|
+
restoreSelection: _,
|
352
|
+
save: l,
|
353
|
+
reset: w
|
354
|
+
} = oe();
|
338
355
|
return e({
|
339
|
-
show:
|
340
|
-
}), { __sfc: !0, treeRef: t, visible: s, snapshot:
|
356
|
+
show: c
|
357
|
+
}), { __sfc: !0, treeRef: t, visible: s, snapshot: r, drawerWidth: a, defaultCheckedKeys: d, show: c, allowDrop: u, allowDrag: S, keepSelection: b, restoreSelection: _, save: l, reset: w };
|
341
358
|
}
|
342
359
|
});
|
343
|
-
var
|
360
|
+
var ue = function() {
|
344
361
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
345
|
-
return t("el-drawer", { attrs: { size: s.drawerWidth, title: "搜索项配置", visible: s.visible }, on: { "update:visible": function(
|
346
|
-
s.visible =
|
347
|
-
} } }, [t("div", { staticClass: "setting-container" }, [t("el-tree", { ref: "treeRef", staticClass: "tree", attrs: { "default-expand-all": "", "default-checked-keys": s.defaultCheckedKeys, "node-key": "id", draggable: "", "show-checkbox": "", data: s.snapshot, "allow-drop": s.allowDrop }, on: { "node-drag-start": s.keepSelection, "node-drag-end": s.restoreSelection } }), t("div", { staticClass: "footer" }, [t("el-button", { on: { click: s.reset } }, [e._v("重置")]), t("el-button", { attrs: { type: "primary" }, on: { click: s.save } }, [e._v("保存")])], 1)], 1)]);
|
348
|
-
},
|
349
|
-
|
350
|
-
|
351
|
-
|
362
|
+
return t("el-drawer", { attrs: { size: s.drawerWidth, title: "搜索项配置", visible: s.visible }, on: { "update:visible": function(r) {
|
363
|
+
s.visible = r;
|
364
|
+
} } }, [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)]);
|
365
|
+
}, he = [], de = /* @__PURE__ */ x(
|
366
|
+
ce,
|
367
|
+
ue,
|
368
|
+
he,
|
352
369
|
!1,
|
353
370
|
null,
|
354
371
|
null
|
355
372
|
);
|
356
|
-
const
|
373
|
+
const fe = de.exports, pe = /* @__PURE__ */ y({
|
357
374
|
__name: "SettingButton",
|
358
375
|
props: {
|
359
376
|
state: null
|
360
377
|
},
|
361
|
-
setup(
|
362
|
-
const e =
|
378
|
+
setup(i) {
|
379
|
+
const e = i, t = h();
|
363
380
|
return { __sfc: !0, props: e, searchSettingDialogRef: t, showSearchLayoutDialog: () => {
|
364
381
|
t.value.show(e.state);
|
365
|
-
}, SearchSettingsDrawer:
|
382
|
+
}, SearchSettingsDrawer: fe };
|
366
383
|
}
|
367
384
|
});
|
368
|
-
var
|
385
|
+
var ve = function() {
|
369
386
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
370
387
|
return t("div", { staticStyle: { "margin-right": "10px" } }, [t("el-button", { staticClass: "icon-button", staticStyle: { height: "100%" }, on: { click: s.showSearchLayoutDialog } }, [t("i", { staticClass: "el-icon-s-tools" })]), t(s.SearchSettingsDrawer, { ref: "searchSettingDialogRef" })], 1);
|
371
|
-
},
|
372
|
-
|
373
|
-
|
374
|
-
|
388
|
+
}, _e = [], me = /* @__PURE__ */ x(
|
389
|
+
pe,
|
390
|
+
ve,
|
391
|
+
_e,
|
375
392
|
!1,
|
376
393
|
null,
|
377
394
|
"61aa7563"
|
378
395
|
);
|
379
|
-
const
|
396
|
+
const ge = me.exports, be = /* @__PURE__ */ y({
|
380
397
|
__name: "SearchBar",
|
381
398
|
props: {
|
382
399
|
searches: null,
|
@@ -387,44 +404,50 @@ const ve = pe.exports, _e = /* @__PURE__ */ S({
|
|
387
404
|
itemHeight: { default: 67 },
|
388
405
|
resetAutoSearch: { type: Boolean, default: !0 }
|
389
406
|
},
|
390
|
-
|
391
|
-
|
392
|
-
|
407
|
+
emits: ["change"],
|
408
|
+
setup(i, { expose: e, emit: t }) {
|
409
|
+
const s = i, r = I(new ne(s.id, s.searches, s.onSearch)), a = h(!1), d = D(() => B(Array.from(Object.values(r.config.itemLayouts)).filter((l) => l.visible).map((l) => l.span)) / 24 > s.maxRows), c = h([]);
|
410
|
+
K(() => r.items, () => {
|
411
|
+
const _ = [...r.items];
|
412
|
+
c.value = _.sort((l, w) => r.config.itemLayouts[l.field].index - r.config.itemLayouts[w.field].index).filter((l) => r.config.itemLayouts[l.field].visible).filter((l) => l.isEnable(r)), t("change", r.getSearchObject(), r);
|
413
|
+
}, { debounce: 100, immediate: !0, deep: !0 });
|
414
|
+
const u = D(() => ({
|
415
|
+
height: `${s.itemHeight * s.maxRows}px`,
|
393
416
|
overflow: "hidden"
|
394
|
-
})),
|
417
|
+
})), S = (_) => r.config.itemLayouts[_.field], b = () => r.items;
|
395
418
|
return e({
|
396
|
-
getSearchItems:
|
397
|
-
}), { __sfc: !0, props:
|
419
|
+
getSearchItems: b
|
420
|
+
}), { __sfc: !0, props: s, state: r, expanded: a, isShowSpanIcon: d, sortedItems: c, emits: t, itemHeightStyle: u, getLayout: S, getSearchItems: b, SearchTagsRender: U, SearchItemRender: le, SettingButton: ge };
|
398
421
|
}
|
399
422
|
});
|
400
|
-
var
|
423
|
+
var ye = function() {
|
401
424
|
var e = this, t = e._self._c, s = e._self._setupProxy;
|
402
|
-
return t("div", { staticClass: "search-bar-container" }, [t("el-row", { class: "search", style: s.isShowSpanIcon && !s.expanded ? s.itemHeightStyle : {}, attrs: { gutter: 16 } }, e._l(s.sortedItems, function(
|
403
|
-
return t("el-col", { directives: [{ name: "show", rawName: "v-show", value: s.getLayout(
|
404
|
-
}), 1), t("div", { staticClass: "search-bottom" }, [s.state.tags.length > 0 ? t(s.SearchTagsRender, { attrs: { tags: s.state.tags } }) : e._e(), t("div", { staticClass: "actions" }, [s.isShowSpanIcon ? t("el-button", { staticClass: "icon-button", staticStyle: { "margin-right": "10px" }, on: { click: function(
|
425
|
+
return t("div", { staticClass: "search-bar-container" }, [t("el-row", { class: "search", style: s.isShowSpanIcon && !s.expanded ? s.itemHeightStyle : {}, attrs: { gutter: 16 } }, e._l(s.sortedItems, function(r) {
|
426
|
+
return t("el-col", { directives: [{ name: "show", rawName: "v-show", value: s.getLayout(r).visible, expression: "getLayout(item).visible" }], key: r.field, attrs: { span: s.getLayout(r).span } }, [t("div", { staticClass: "search-item" }, [t("div", { staticClass: "search-item-title" }, [e._v(e._s(r.label))]), t("div", { staticClass: "search-item-content", attrs: { id: `${e.id}-${r.field}` } }, [t(s.SearchItemRender, { attrs: { search: r, api: s.state } })], 1)])]);
|
427
|
+
}), 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(r) {
|
405
428
|
s.expanded = !s.expanded;
|
406
429
|
} } }, [t("i", { class: [s.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"] })]) : e._e(), t(s.SettingButton, { attrs: { state: s.state } }), t("el-button", { on: { click: () => s.state.reset(e.resetAutoSearch) } }, [e._v("重 置")]), t("el-button", { attrs: { type: "primary", loading: s.state.searching, disabled: s.state.searching }, on: { click: () => s.state.doSearch() } }, [e._v("搜 索")])], 1)], 1)], 1);
|
407
|
-
},
|
408
|
-
|
409
|
-
|
410
|
-
|
430
|
+
}, Se = [], we = /* @__PURE__ */ x(
|
431
|
+
be,
|
432
|
+
ye,
|
433
|
+
Se,
|
411
434
|
!1,
|
412
435
|
null,
|
413
436
|
null
|
414
437
|
);
|
415
|
-
const
|
416
|
-
var
|
438
|
+
const Fe = we.exports;
|
439
|
+
var xe = Object.defineProperty, Ce = (i, e, t) => e in i ? xe(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, $e = (i, e, t) => Ce(i, e + "", t);
|
417
440
|
class $ {
|
418
441
|
constructor(e) {
|
419
|
-
|
442
|
+
$e(this, "record"), this.record = e;
|
420
443
|
}
|
421
444
|
static from(e) {
|
422
445
|
const t = e.filter((s) => s.value === void 0 ? !1 : Array.isArray(s.value) ? s.value.length > 0 : !0).reduce(
|
423
|
-
(s,
|
424
|
-
const a =
|
446
|
+
(s, r) => {
|
447
|
+
const a = r.transform ? r.transform(r.value) : r.value;
|
425
448
|
return {
|
426
449
|
...s,
|
427
|
-
...
|
450
|
+
...N(a) ? a : { [r.field]: a }
|
428
451
|
};
|
429
452
|
},
|
430
453
|
{}
|
@@ -432,15 +455,15 @@ class $ {
|
|
432
455
|
return new $(t);
|
433
456
|
}
|
434
457
|
transform(e, t) {
|
435
|
-
const s = this.record[e],
|
436
|
-
return delete this.record[e], this.record = { ...this.record, ...
|
458
|
+
const s = this.record[e], r = t(s);
|
459
|
+
return delete this.record[e], this.record = { ...this.record, ...r }, this;
|
437
460
|
}
|
438
461
|
toCondition(e) {
|
439
462
|
return { ...this.record, ...e };
|
440
463
|
}
|
441
464
|
}
|
442
465
|
export {
|
443
|
-
|
466
|
+
Fe as SearchBar,
|
444
467
|
$ as Searches,
|
445
|
-
|
468
|
+
Ae as vModel
|
446
469
|
};
|
@@ -1 +1 @@
|
|
1
|
-
(function(c,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("lodash-unified"),require("vue")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue"],l):(c=typeof globalThis<"u"?globalThis:c||self,l(c.ElementPlusSearch={},c.lodashUnified,c.vue))})(this,function(c,l,a){"use strict";const P=r=>({model:{value:l.get(r,"value"),callback:e=>{l.set(r,"value",e)}}}),F=a.defineComponent({name:"SearchTags"}),R=a.defineComponent({...F,props:{tags:null},setup(r){const e=r,t=a.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 w(r,e,t,s,i,n,_,h){var u=typeof r=="function"?r.options:r;return e&&(u.render=e,u.staticRenderFns=t,u._compiled=!0),n&&(u._scopeId="data-v-"+n),{exports:r,options:u}}var q=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)},D=[],k=w(R,q,D,!1,null,null);const B=k.exports;var O=Object.defineProperty,E=(r,e,t)=>e in r?O(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,o=(r,e,t)=>E(r,typeof e!="symbol"?e+"":e,t);const L=6;class N{constructor(e,t){o(this,"field"),o(this,"label"),o(this,"value"),o(this,"required"),o(this,"index"),o(this,"visible"),o(this,"span"),o(this,"initValue"),o(this,"tagFilter"),o(this,"render"),o(this,"transform");var s,i;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:L,this.render=e.render,this.tagFilter=e.tagFilter,this.transform=e.transform}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}}var I=Object.defineProperty,V=(r,e,t)=>e in r?I(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);class m{constructor(e,t,s,i){f(this,"field"),f(this,"span"),f(this,"index"),f(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:L,t??e,(i=e.visible)!=null?i:!0)}static fromString(e){var t;const[s,i,n,_]=e.split("_");return new m(i,Number(n),Number(s),(t=!!_)!=null?t:!0)}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 T=r=>`searches_layouts_${r}`;class K{constructor(e,t){f(this,"id"),f(this,"state"),f(this,"itemLayouts"),f(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=l.keyBy(e.items.map(m.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem(T(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 n=this.itemLayouts[s];n.index=i,n.visible=t.has(s)})}persistent(){localStorage.setItem(T(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 j=Object.defineProperty,H=(r,e,t)=>e in r?j(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,p=(r,e,t)=>H(r,typeof e!="symbol"?e+"":e,t);const M=[{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 A{constructor(e,t){p(this,"id"),p(this,"field"),p(this,"value"),p(this,"label"),p(this,"valueText"),p(this,"required"),p(this,"item"),p(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 l.isNumber(e.value)||l.isBoolean(e.value)?!0:!l.isEmpty(e.value)}updateValueText(){const e=document.querySelector(this.id);if(e.children.length!==1)throw new Error("holder children length is not 1");const t=e.children[0],s=M.find(i=>i.isApply(t.classList));s&&(this.valueText=s.getText(t,this))}async clean(){this.item.clean(),await this.state.doSearch()}}var z=Object.defineProperty,W=(r,e,t)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,y=(r,e,t)=>W(r,typeof e!="symbol"?e+"":e,t);class G{constructor(e,t,s){this.id=e,y(this,"items"),y(this,"config"),y(this,"searching"),y(this,"tags"),y(this,"searchCallback"),y(this,"sourceSearchable"),this.id=e,this.items=t.map((i,n)=>new N(i,n)),this.config=new K(this,t.map((i,n)=>m.formSearchConfig(i,n))),this.sourceSearchable=t,this.searching=!1,this.searchCallback=s,this.tags=[]}updateTags(){this.tags=this.items.filter(e=>e.tagFilter?e.tagFilter(e.value):A.hasValue(e)).map(e=>new A(this,e)).sort((e,t)=>this.config.itemLayouts[e.field].index-this.config.itemLayouts[t.field].index)}getSearchObject(e){return x.from(this.items).toCondition(e)}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()}}const X={functional:!0,props:{search:{type:Object,required:!0}},render(r,e){const{props:t}=e;return t.search.render(t.search)}},J=()=>{const r=a.shallowRef(),e=a.ref(),t=a.ref([]),s=a.ref(!1),i=a.ref(),n=a.ref([]),_=a.ref(300),h=d=>{r.value=d,t.value=[{label:"全部",id:"all",children:r.value.items.sort((g,$)=>d.config.itemLayouts[g.field].index-d.config.itemLayouts[$.field].index).map(g=>({label:g.label,id:g.field}))}],i.value=l.chain(d.config.itemLayouts).pickBy(g=>g.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:i,drawerWidth:_,updateSnapshot:h,show:d=>{h(d),s.value=!0},save:()=>{r.value.config.sync(t.value[0].children.map(d=>d.id),new Set(e.value.getCheckedKeys())),r.value.config.persistent()},reset:()=>{r.value.config.reset(),h(r.value)},keepSelection:()=>{n.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(n.value),n.value=[]},allowDrop:(d,g,$)=>$!=="inner"}},Q=a.defineComponent({__name:"SearchSettingsDrawer",setup(r,{expose:e}){const{treeRef:t,visible:s,snapshot:i,drawerWidth:n,defaultCheckedKeys:_,show:h,allowDrop:u,keepSelection:b,restoreSelection:S,save:v,reset:C}=J();return e({show:h}),{__sfc:!0,treeRef:t,visible:s,snapshot:i,drawerWidth:n,defaultCheckedKeys:_,show:h,allowDrop:u,keepSelection:b,restoreSelection:S,save:v,reset:C}}});var Y=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},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)])},Z=[],U=w(Q,Y,Z,!1,null,null);const ee=U.exports,te=a.defineComponent({__name:"SettingButton",props:{state:null},setup(r){const e=r,t=a.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:ee}}});var se=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)},re=[],ie=w(te,se,re,!1,null,"61aa7563");const ne=ie.exports,ae=a.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}},setup(r,{expose:e}){const t=r,s=a.reactive(new G(t.id,t.searches,t.onSearch)),i=a.ref(!1),n=a.computed(()=>l.sum(Array.from(Object.values(s.config.itemLayouts)).map(v=>v.span))/24>t.maxRows),_=a.computed(()=>[...s.items].sort((v,C)=>s.config.itemLayouts[v.field].index-s.config.itemLayouts[C.field].index).filter(v=>s.config.itemLayouts[v.field].visible)),h=a.computed(()=>({height:`${t.itemHeight*t.maxRows}px`,overflow:"hidden"})),u=S=>s.config.itemLayouts[S.field],b=()=>s.items;return e({getSearchItems:b}),{__sfc:!0,props:t,state:s,expanded:i,isShowSpanIcon:n,sortedItems:_,itemHeightStyle:h,getLayout:u,getSearchItems:b,SearchTagsRender:B,SearchItemRender:X,SettingButton:ne}}});var le=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"search-bar-container"},[t("el-row",{class:"search",style:s.isShowSpanIcon&&!s.expanded?s.itemHeightStyle:{},attrs:{gutter:16}},e._l(s.sortedItems,function(i){return t("el-col",{directives:[{name:"show",rawName:"v-show",value:s.getLayout(i).visible,expression:"getLayout(item).visible"}],key:i.field,attrs:{span:s.getLayout(i).span}},[t("div",{staticClass:"search-item"},[t("div",{staticClass:"search-item-title"},[e._v(e._s(i.label))]),t("div",{staticClass:"search-item-content",attrs:{id:`${e.id}-${i.field}`}},[t(s.SearchItemRender,{attrs:{search:i}})],1)])])}),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",{on:{click:()=>s.state.reset(e.resetAutoSearch)}},[e._v("重 置")]),t("el-button",{attrs:{type:"primary",loading:s.state.searching,disabled:s.state.searching},on:{click:()=>s.state.doSearch()}},[e._v("搜 索")])],1)],1)],1)},oe=[],ce=w(ae,le,oe,!1,null,null);const ue=ce.exports;var he=Object.defineProperty,de=(r,e,t)=>e in r?he(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,fe=(r,e,t)=>de(r,e+"",t);class x{constructor(e){fe(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 n=i.transform?i.transform(i.value):i.value;return{...s,...l.isPlainObject(n)?n:{[i.field]:n}}},{});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}}}c.SearchBar=ue,c.Searches=x,c.vModel=P,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
1
|
+
(function(d,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("lodash-unified"),require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","lodash-unified","vue","@vueuse/core"],l):(d=typeof globalThis<"u"?globalThis:d||self,l(d.ElementPlusSearch={},d.lodashUnified,d.vue,d.core))})(this,function(d,l,n,A){"use strict";const F=i=>({model:{value:l.get(i,"value"),callback:e=>{l.set(i,"value",e)}}}),P=n.defineComponent({name:"SearchTags"}),R=n.defineComponent({...P,props:{tags:null},setup(i){const e=i,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 w(i,e,t,s,r,a,p,h){var f=typeof i=="function"?i.options:i;return e&&(f.render=e,f.staticRenderFns=t,f._compiled=!0),a&&(f._scopeId="data-v-"+a),{exports:i,options:f}}var q=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(r){return t("el-tag",{key:r.field,staticClass:"search-tag",attrs:{size:"medium",closable:!r.required,type:r.required?"primary":"info"},on:{close:()=>r.clean()}},[t("span",[e._v(" "+e._s(r.label)+" ")]),e._v(": "),t("span",{domProps:{innerHTML:e._s(r.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)},j=[],k=w(R,q,j,!1,null,null);const E=k.exports;var B=Object.defineProperty,N=(i,e,t)=>e in i?B(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,o=(i,e,t)=>N(i,typeof e!="symbol"?e+"":e,t);const T=6;class V{constructor(e,t){o(this,"field"),o(this,"label"),o(this,"value"),o(this,"required"),o(this,"index"),o(this,"visible"),o(this,"disabled"),o(this,"span"),o(this,"initValue"),o(this,"enable"),o(this,"tagFilter"),o(this,"render"),o(this,"transform");var s,r,a,p;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=(r=e.span)!=null?r:T,this.render=e.render,this.tagFilter=e.tagFilter,this.transform=e.transform,this.enable=(a=e.enable)!=null?a:!0,this.disabled=(p=e.disabled)!=null?p:!1}clean(){Array.isArray(this.value)?this.value=[]:this.value=void 0}reset(){this.value=this.initValue}isEnable(e){return l.isFunction(this.enable)?this.enable(e.getSearchObject()):this.enable}isDisabled(e){return l.isFunction(this.disabled)?this.disabled(e.getSearchObject()):this.disabled}}var I=Object.defineProperty,K=(i,e,t)=>e in i?I(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,_=(i,e,t)=>K(i,typeof e!="symbol"?e+"":e,t);class g{constructor(e,t,s,r){_(this,"field"),_(this,"span"),_(this,"index"),_(this,"visible"),this.field=e,this.span=t,this.index=s,this.visible=r}static fromSearchItem(e,t){return new g(e.field,e.span,t??e.index,e.visible)}static formSearchConfig(e,t){var s,r;return new g(e.field,(s=e.span)!=null?s:T,t??e,(r=e.visible)!=null?r:!0)}static fromString(e){const[t,s,r,a]=e.split("_");return new g(s,Number(r),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 D=i=>`searches_layouts_${i}`;class H{constructor(e,t){_(this,"id"),_(this,"state"),_(this,"itemLayouts"),_(this,"initialLayouts"),this.id=e.id,this.initialLayouts=t,this.state=e,this.itemLayouts=l.keyBy(e.items.map(g.fromSearchItem),s=>s.field),this.restoreCachedLayouts()}restoreCachedLayouts(){const e=localStorage.getItem(D(this.id));e&&e.split(",").forEach(t=>{const s=g.fromString(t),r=this.itemLayouts[s.field];r&&r.merge(s)})}sync(e,t){if(e.length!==Object.keys(this.itemLayouts).length)throw new Error("同步布局字段数量不一致");e.forEach((s,r)=>{const a=this.itemLayouts[s];a.index=r,a.visible=t.has(s)})}persistent(){localStorage.setItem(D(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 M=Object.defineProperty,z=(i,e,t)=>e in i?M(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,v=(i,e,t)=>z(i,typeof e!="symbol"?e+"":e,t);const W=[{isApply(i){return i.contains("el-radio-group")},getText(i){var e,t;return(t=(e=i.querySelector(".is-active"))==null?void 0:e.querySelector("input"))==null?void 0:t.value}},{isApply(i){return i.contains("el-checkbox-group")},getText(i){var e;const t=Array.from((e=i.querySelectorAll(".el-checkbox__input.is-checked"))!=null?e:[]).map(s=>{var r;return(r=s.querySelector("input"))==null?void 0:r.value}).filter(s=>s);return t.length===1?t[0]:`${t[0]} 等${t.length}条`}},{isApply(i){return i.contains("el-input")},getText(i,e){return e.value}},{isApply(i){return i.contains("el-input-number")},getText(i,e){return e.value}},{isApply(i){return i.contains("el-select")},getText(i,e){var t;const s=i.querySelectorAll(".el-select__tags-text");return s.length>0?e.value.length>1?`${s[0].textContent} 等${e.value.length}条`:s[0].textContent:(t=i.querySelector("input"))==null?void 0:t.value}},{isApply(i){return i.contains("el-cascader")},getText(i){var e;return(e=i.querySelector("input"))==null?void 0:e.value}},{isApply(i){return i.contains("el-switch")},getText(i){return i.querySelector(".is-active").innerHTML}},{isApply(i){return i.contains("el-slider")},getText(i,e){return e.value}},{isApply(i){return i.contains("el-date-editor")},getText(i,e){return e.value?e.value.join(" ~ "):e.value}}];class O{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 l.isNumber(e.value)||l.isBoolean(e.value)?!0:!l.isEmpty(e.value)}updateValueText(){const e=document.querySelector(this.id);if(e.children.length!==1)throw new Error("holder children length is not 1");const t=e.children[0],s=W.find(r=>r.isApply(t.classList));s&&(this.valueText=s.getText(t,this))}async clean(){this.item.clean(),await this.state.doSearch()}}var G=Object.defineProperty,X=(i,e,t)=>e in i?G(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,b=(i,e,t)=>X(i,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((r,a)=>new V(r,a)),this.config=new H(this,t.map((r,a)=>g.formSearchConfig(r,a))),this.sourceSearchable=t,this.searching=!1,this.searchCallback=s,this.tags=[]}updateTags(){this.tags=this.items.filter(e=>e.tagFilter?e.tagFilter(e.value):O.hasValue(e)).map(e=>new O(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){const s=this.items.find(r=>r.field===e);s&&(s.value=t)}}const Q={functional:!0,props:{search:{type:Object,required:!0},api:{type:Object}},render(i,e){const{props:t}=e,s=t.search.render(t.search);return s.componentOptions.propsData||(s.componentOptions.propsData={}),s.componentOptions.propsData.disabled=t.search.isDisabled(t.api),s}},Y=()=>{const i=n.shallowRef(),e=n.ref(),t=n.ref([]),s=n.ref(!1),r=n.ref(),a=n.ref([]),p=n.ref(300),h=u=>{i.value=u,t.value=[{label:"全部",id:"all",children:i.value.items.sort((m,L)=>u.config.itemLayouts[m.field].index-u.config.itemLayouts[L.field].index).map(m=>({label:m.label,id:m.field,disabled:!m.isEnable(u)}))}],r.value=l.chain(u.config.itemLayouts).pickBy(m=>m.visible).keys().value()};return{treeRef:e,visible:s,snapshot:t,defaultCheckedKeys:r,drawerWidth:p,updateSnapshot:h,show:u=>{h(u),s.value=!0},save:()=>{i.value.config.sync(t.value[0].children.map(u=>u.id),new Set(e.value.getCheckedKeys())),i.value.config.persistent()},reset:()=>{i.value.config.reset(),h(i.value)},keepSelection:()=>{a.value=e.value.getCheckedKeys()},restoreSelection:()=>{e.value.setCheckedKeys(a.value),a.value=[]},allowDrop:(u,m,L)=>L!=="inner",allowDrag:u=>!u.disabled}},Z=n.defineComponent({__name:"SearchSettingsDrawer",setup(i,{expose:e}){const{treeRef:t,visible:s,snapshot:r,drawerWidth:a,defaultCheckedKeys:p,show:h,allowDrop:f,allowDrag:C,keepSelection:S,restoreSelection:y,save:c,reset:$}=Y();return e({show:h}),{__sfc:!0,treeRef:t,visible:s,snapshot:r,drawerWidth:a,defaultCheckedKeys:p,show:h,allowDrop:f,allowDrag:C,keepSelection:S,restoreSelection:y,save:c,reset:$}}});var U=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(r){s.visible=r}}},[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)])},ee=[],te=w(Z,U,ee,!1,null,null);const se=te.exports,ie=n.defineComponent({__name:"SettingButton",props:{state:null},setup(i){const e=i,t=n.ref();return{__sfc:!0,props:e,searchSettingDialogRef:t,showSearchLayoutDialog:()=>{t.value.show(e.state)},SearchSettingsDrawer:se}}});var re=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)},ae=[],ne=w(ie,re,ae,!1,null,"61aa7563");const le=ne.exports,oe=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(i,{expose:e,emit:t}){const s=i,r=n.reactive(new J(s.id,s.searches,s.onSearch)),a=n.ref(!1),p=n.computed(()=>l.sum(Array.from(Object.values(r.config.itemLayouts)).filter(c=>c.visible).map(c=>c.span))/24>s.maxRows),h=n.ref([]);A.watchDebounced(()=>r.items,()=>{const y=[...r.items];h.value=y.sort((c,$)=>r.config.itemLayouts[c.field].index-r.config.itemLayouts[$.field].index).filter(c=>r.config.itemLayouts[c.field].visible).filter(c=>c.isEnable(r)),t("change",r.getSearchObject(),r)},{debounce:100,immediate:!0,deep:!0});const f=n.computed(()=>({height:`${s.itemHeight*s.maxRows}px`,overflow:"hidden"})),C=y=>r.config.itemLayouts[y.field],S=()=>r.items;return e({getSearchItems:S}),{__sfc:!0,props:s,state:r,expanded:a,isShowSpanIcon:p,sortedItems:h,emits:t,itemHeightStyle:f,getLayout:C,getSearchItems:S,SearchTagsRender:E,SearchItemRender:Q,SettingButton:le}}});var ce=function(){var e=this,t=e._self._c,s=e._self._setupProxy;return t("div",{staticClass:"search-bar-container"},[t("el-row",{class:"search",style:s.isShowSpanIcon&&!s.expanded?s.itemHeightStyle:{},attrs:{gutter:16}},e._l(s.sortedItems,function(r){return t("el-col",{directives:[{name:"show",rawName:"v-show",value:s.getLayout(r).visible,expression:"getLayout(item).visible"}],key:r.field,attrs:{span:s.getLayout(r).span}},[t("div",{staticClass:"search-item"},[t("div",{staticClass:"search-item-title"},[e._v(e._s(r.label))]),t("div",{staticClass:"search-item-content",attrs:{id:`${e.id}-${r.field}`}},[t(s.SearchItemRender,{attrs:{search:r,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(r){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",{on:{click:()=>s.state.reset(e.resetAutoSearch)}},[e._v("重 置")]),t("el-button",{attrs:{type:"primary",loading:s.state.searching,disabled:s.state.searching},on:{click:()=>s.state.doSearch()}},[e._v("搜 索")])],1)],1)],1)},ue=[],de=w(oe,ce,ue,!1,null,null);const he=de.exports;var fe=Object.defineProperty,pe=(i,e,t)=>e in i?fe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,_e=(i,e,t)=>pe(i,e+"",t);class x{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,r)=>{const a=r.transform?r.transform(r.value):r.value;return{...s,...l.isPlainObject(a)?a:{[r.field]:a}}},{});return new x(t)}transform(e,t){const s=this.record[e],r=t(s);return delete this.record[e],this.record={...this.record,...r},this}toCondition(e){return{...this.record,...e}}}d.SearchBar=he,d.Searches=x,d.vModel=F,Object.defineProperty(d,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 .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:
|
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,3 +1,4 @@
|
|
1
|
+
import { SearchBarState } from './SearchBarState';
|
1
2
|
import { Searchable } from './types/Searchable';
|
2
3
|
type __VLS_Props = {
|
3
4
|
searches: Searchable[];
|
@@ -21,15 +22,21 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
21
22
|
required?: boolean | undefined;
|
22
23
|
index: number;
|
23
24
|
visible: boolean;
|
25
|
+
disabled: boolean | import("./index.js").PredicateCallback;
|
24
26
|
span: number;
|
25
27
|
initValue?: any;
|
28
|
+
enable: boolean | import("./index.js").PredicateCallback;
|
26
29
|
tagFilter?: ((value: any) => boolean) | undefined;
|
27
30
|
render: import("./model/SearchItem").SearchItemRender;
|
28
|
-
transform?: import("./
|
31
|
+
transform?: import("./index.js").TransformCallback<any> | undefined;
|
29
32
|
clean: () => void;
|
30
33
|
reset: () => void;
|
34
|
+
isEnable: (state: SearchBarState) => boolean;
|
35
|
+
isDisabled: (state: SearchBarState) => boolean;
|
31
36
|
}[];
|
32
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
37
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
38
|
+
change: (...args: any[]) => void;
|
39
|
+
}, string, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<__VLS_Props>, {
|
33
40
|
defaultSpan: number;
|
34
41
|
maxRows: number;
|
35
42
|
itemHeight: number;
|
@@ -10,9 +10,11 @@ export declare class SearchBarState {
|
|
10
10
|
tags: SearchTag[];
|
11
11
|
searchCallback: <T>(params: T) => Promise<void>;
|
12
12
|
sourceSearchable: Searchable[];
|
13
|
+
private _lastSearchObject;
|
13
14
|
constructor(id: string, searches: Searchable[], onSearch: (params: any) => Promise<void>);
|
14
15
|
updateTags(): void;
|
15
16
|
getSearchObject<T>(ext?: any): T;
|
16
17
|
doSearch(): Promise<void>;
|
17
18
|
reset(search?: boolean): Promise<void>;
|
19
|
+
setSearchValue(field: string, value: any): void;
|
18
20
|
}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { SearchItem } from './model/SearchItem';
|
2
2
|
import { PropType } from 'vue';
|
3
|
+
import { SearchBarState } from './SearchBarState';
|
3
4
|
declare const _default: {
|
4
5
|
functional: boolean;
|
5
6
|
props: {
|
@@ -7,11 +8,15 @@ declare const _default: {
|
|
7
8
|
type: PropType<SearchItem>;
|
8
9
|
required: boolean;
|
9
10
|
};
|
11
|
+
api: {
|
12
|
+
type: PropType<SearchBarState>;
|
13
|
+
};
|
10
14
|
};
|
11
15
|
render(h: any, context: {
|
12
16
|
props: {
|
13
17
|
search: SearchItem;
|
18
|
+
api: SearchBarState;
|
14
19
|
};
|
15
|
-
}): import("vue").VNode
|
20
|
+
}): import("vue").VNode;
|
16
21
|
};
|
17
22
|
export default _default;
|
package/dist/types/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { TransformCallback } from './types/Searchable';
|
2
2
|
import { SearchValueLike } from './types/SearchValueLike';
|
3
3
|
export * from "./helper/vModel";
|
4
|
+
export * from "./types/Searchable";
|
4
5
|
export { default as SearchBar } from './SearchBar.vue';
|
5
6
|
export type SearchBarInstance = {
|
6
7
|
getSearchItems(): SearchValueLike[];
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { VNode } from 'vue';
|
2
2
|
import { SearchValueLike } from '../types/SearchValueLike';
|
3
|
-
import { Searchable, TransformCallback } from '../types/Searchable';
|
3
|
+
import { PredicateCallback, Searchable, TransformCallback } from '../types/Searchable';
|
4
|
+
import { SearchBarState } from '../SearchBarState';
|
4
5
|
export declare const DEFAULT_SEARCH_SPAN = 6;
|
5
6
|
export type SearchItemRender = (value: SearchValueLike) => VNode | undefined;
|
6
7
|
export declare class SearchItem {
|
@@ -10,12 +11,16 @@ export declare class SearchItem {
|
|
10
11
|
required?: boolean;
|
11
12
|
index: number;
|
12
13
|
visible: boolean;
|
14
|
+
disabled: boolean | PredicateCallback;
|
13
15
|
span: number;
|
14
16
|
initValue?: any;
|
17
|
+
enable: boolean | PredicateCallback;
|
15
18
|
tagFilter?: (value: any) => boolean;
|
16
19
|
render: SearchItemRender;
|
17
20
|
transform?: TransformCallback<any>;
|
18
21
|
constructor(searchable: Searchable, index: number);
|
19
22
|
clean(): void;
|
20
23
|
reset(): void;
|
24
|
+
isEnable(state: SearchBarState): boolean;
|
25
|
+
isDisabled(state: SearchBarState): boolean;
|
21
26
|
}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import type { VNode } from 'vue';
|
2
2
|
import { SearchItem } from '../model/SearchItem';
|
3
|
+
import { SearchBarState } from '../SearchBarState';
|
3
4
|
export type TransformCallback<T> = (value: T) => Record<string, any>;
|
5
|
+
export type PredicateCallback = (value: SearchBarState) => boolean;
|
4
6
|
export interface Searchable {
|
5
7
|
/**
|
6
8
|
* 属性名
|
@@ -22,8 +24,13 @@ export interface Searchable {
|
|
22
24
|
* 搜索的tag标签是否可以关闭
|
23
25
|
*/
|
24
26
|
required?: boolean;
|
27
|
+
disabled?: boolean | PredicateCallback;
|
25
28
|
index?: number;
|
26
29
|
visible?: boolean;
|
30
|
+
/**
|
31
|
+
* 搜索项是否启用
|
32
|
+
*/
|
33
|
+
enable: boolean | PredicateCallback;
|
27
34
|
span?: number;
|
28
35
|
/**
|
29
36
|
* 渲染器
|