@94ai/nf-virtual-select 3.1.13
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/.eslintrc.cjs +49 -0
- package/README.md +16 -0
- package/components.d.ts +8 -0
- package/lib/el-option-node.vue.d.ts +47 -0
- package/lib/index.d.ts +1056 -0
- package/lib/nf-virtual-select-container.vue.d.ts +32 -0
- package/lib/nf-virtual-select.cjs.js +701 -0
- package/lib/nf-virtual-select.esm-bundler.js +701 -0
- package/lib/nf-virtual-select.vue.d.ts +369 -0
- package/lib/style/css.d.ts +1 -0
- package/lib/style/css.js +1 -0
- package/lib/style/index.d.ts +1 -0
- package/lib/style/index.js +1 -0
- package/package/el-option-node.vue +48 -0
- package/package/index.ts +8 -0
- package/package/nf-virtual-select-container.vue +68 -0
- package/package/nf-virtual-select.vue +571 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package.json +37 -0
- package/postcss.config.js +8 -0
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import virtualList from "vue-virtual-scroll-list";
|
|
2
|
+
import { normalizeComponent } from "@94ai/vue2-runtime-helpers";
|
|
3
|
+
import { isEqual } from "lodash-es";
|
|
4
|
+
import { defineComponent, h } from "vue-demi";
|
|
5
|
+
const _sfc_main$2 = {
|
|
6
|
+
name: "ItemComponent",
|
|
7
|
+
props: {
|
|
8
|
+
index: {
|
|
9
|
+
// 每一行的索引
|
|
10
|
+
type: Number,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
source: {
|
|
14
|
+
// 每一行的内容
|
|
15
|
+
type: Object,
|
|
16
|
+
default() {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
label: {
|
|
21
|
+
// 要显示的名称
|
|
22
|
+
type: String,
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
value: {
|
|
26
|
+
// 绑定的值
|
|
27
|
+
type: [String, Number, Array],
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
showTip: {
|
|
31
|
+
// 提示
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var _sfc_render$2 = function render() {
|
|
38
|
+
var _vm = this, _c = _vm._self._c;
|
|
39
|
+
return _c("el-option", {
|
|
40
|
+
key: _vm.index,
|
|
41
|
+
attrs: {
|
|
42
|
+
"label": _vm.source[_vm.label],
|
|
43
|
+
"value": _vm.source[_vm.value],
|
|
44
|
+
"disabled": _vm.source["disabled"]
|
|
45
|
+
}
|
|
46
|
+
}, [_vm.showTip ? _c("el-tooltip", {
|
|
47
|
+
attrs: {
|
|
48
|
+
"content": _vm.source[_vm.label],
|
|
49
|
+
"open-delay": 1e3,
|
|
50
|
+
"effect": "dark",
|
|
51
|
+
"placement": "left"
|
|
52
|
+
}
|
|
53
|
+
}, [_c("span", [_vm._v(_vm._s(_vm.source[_vm.label]))])]) : _c("span", [_vm._v(_vm._s(_vm.source[_vm.label]))])], 1);
|
|
54
|
+
};
|
|
55
|
+
var _sfc_staticRenderFns$2 = [];
|
|
56
|
+
var __component__$2 = /* @__PURE__ */ normalizeComponent(_sfc_main$2, _sfc_render$2, _sfc_staticRenderFns$2, false, null, null, null, null);
|
|
57
|
+
const ElOptionNode = __component__$2.exports;
|
|
58
|
+
const _sfc_main$1 = defineComponent({
|
|
59
|
+
name: "nf-virtual-select-container",
|
|
60
|
+
props: {
|
|
61
|
+
/**
|
|
62
|
+
* 指定容器类型
|
|
63
|
+
*/
|
|
64
|
+
tag: {
|
|
65
|
+
type: String,
|
|
66
|
+
default: "el-select"
|
|
67
|
+
},
|
|
68
|
+
value: {
|
|
69
|
+
type: [String, Number, Array],
|
|
70
|
+
default: () => ""
|
|
71
|
+
},
|
|
72
|
+
config: {
|
|
73
|
+
type: Object,
|
|
74
|
+
default: () => ({})
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
render() {
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
79
|
+
const Tag = this.tag;
|
|
80
|
+
const on = this.$listeners;
|
|
81
|
+
return h(Tag, {
|
|
82
|
+
"ref": "nfVirtualSelect",
|
|
83
|
+
"props": {
|
|
84
|
+
...{
|
|
85
|
+
...this.config,
|
|
86
|
+
value: this.value
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"on": {
|
|
90
|
+
...{
|
|
91
|
+
...on,
|
|
92
|
+
input: (val) => {
|
|
93
|
+
if (this.tag === "el-select" || this.tag === "custom-select-dropdown") {
|
|
94
|
+
this.$emit("update:value", val);
|
|
95
|
+
this.$emit("change", val);
|
|
96
|
+
this.$emit("input", val);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, [(_b = (_a = this.$scopedSlots).default) == null ? void 0 : _b.call(_a, {}), h("template", {
|
|
102
|
+
"slot": "prefix"
|
|
103
|
+
}, [(_d = (_c = this.$scopedSlots).prefix) == null ? void 0 : _d.call(_c, {})]), h("template", {
|
|
104
|
+
"slot": "empty"
|
|
105
|
+
}, [(_f = (_e = this.$scopedSlots).empty) == null ? void 0 : _f.call(_e, {})]), h("template", {
|
|
106
|
+
"slot": "footer"
|
|
107
|
+
}, [(_h = (_g = this.$scopedSlots).footer) == null ? void 0 : _h.call(_g, {})]), h("template", {
|
|
108
|
+
"slot": "header"
|
|
109
|
+
}, [(_j = (_i = this.$scopedSlots).header) == null ? void 0 : _j.call(_i, {})])]);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const _sfc_render$1 = null;
|
|
113
|
+
const _sfc_staticRenderFns$1 = null;
|
|
114
|
+
var __component__$1 = /* @__PURE__ */ normalizeComponent(_sfc_main$1, _sfc_render$1, _sfc_staticRenderFns$1, false, null, null, null, null);
|
|
115
|
+
const VirtualSelectContainer = __component__$1.exports;
|
|
116
|
+
const _sfc_main = {
|
|
117
|
+
name: "nf-virtual-select",
|
|
118
|
+
components: {
|
|
119
|
+
"virtual-list": virtualList,
|
|
120
|
+
"virtual-select-container": VirtualSelectContainer
|
|
121
|
+
},
|
|
122
|
+
inheritAttrs: false,
|
|
123
|
+
props: {
|
|
124
|
+
tag: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: "el-select"
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* 虚拟滚动属性
|
|
130
|
+
*/
|
|
131
|
+
offset: {
|
|
132
|
+
type: Number,
|
|
133
|
+
default: 0
|
|
134
|
+
},
|
|
135
|
+
start: {
|
|
136
|
+
type: Number,
|
|
137
|
+
default: 0
|
|
138
|
+
},
|
|
139
|
+
pageMode: {
|
|
140
|
+
type: Boolean,
|
|
141
|
+
default: false
|
|
142
|
+
},
|
|
143
|
+
direction: {
|
|
144
|
+
type: String,
|
|
145
|
+
default: "vertical"
|
|
146
|
+
},
|
|
147
|
+
topThreshold: {
|
|
148
|
+
type: Number,
|
|
149
|
+
default: 0
|
|
150
|
+
},
|
|
151
|
+
bottomThreshold: {
|
|
152
|
+
type: Number,
|
|
153
|
+
default: 0
|
|
154
|
+
},
|
|
155
|
+
rootTag: {
|
|
156
|
+
type: String,
|
|
157
|
+
default: "div"
|
|
158
|
+
},
|
|
159
|
+
wrapTag: {
|
|
160
|
+
type: String,
|
|
161
|
+
default: "div"
|
|
162
|
+
},
|
|
163
|
+
wrapStyle: {
|
|
164
|
+
type: Object,
|
|
165
|
+
default: () => {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
itemTag: {
|
|
170
|
+
type: String,
|
|
171
|
+
default: "div"
|
|
172
|
+
},
|
|
173
|
+
itemClass: {
|
|
174
|
+
type: String,
|
|
175
|
+
default: ""
|
|
176
|
+
},
|
|
177
|
+
itemClassAdd: {
|
|
178
|
+
type: Function
|
|
179
|
+
},
|
|
180
|
+
itemStyle: {
|
|
181
|
+
type: Object,
|
|
182
|
+
default: () => {
|
|
183
|
+
return {};
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
itemScopedSlots: {
|
|
187
|
+
type: Object,
|
|
188
|
+
default: () => {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
headerTag: {
|
|
193
|
+
type: String,
|
|
194
|
+
default: "div"
|
|
195
|
+
},
|
|
196
|
+
headeClass: {
|
|
197
|
+
type: String,
|
|
198
|
+
default: ""
|
|
199
|
+
},
|
|
200
|
+
headerStyle: {
|
|
201
|
+
type: Object,
|
|
202
|
+
default: () => {
|
|
203
|
+
return {};
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
footerTag: {
|
|
207
|
+
type: String,
|
|
208
|
+
default: "span"
|
|
209
|
+
},
|
|
210
|
+
footerClass: {
|
|
211
|
+
type: String,
|
|
212
|
+
default: ""
|
|
213
|
+
},
|
|
214
|
+
footerStyle: {
|
|
215
|
+
type: Object,
|
|
216
|
+
default: () => {
|
|
217
|
+
return {};
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
keeps: {
|
|
221
|
+
type: Number,
|
|
222
|
+
default: 30
|
|
223
|
+
},
|
|
224
|
+
// 每个项目的估计大小,如果它更接近平均大小,滚动条长度看起来更准确。建议指定自己计算的平均值。
|
|
225
|
+
estimateSize: {
|
|
226
|
+
type: Number,
|
|
227
|
+
default: 50
|
|
228
|
+
},
|
|
229
|
+
echoValueTop: {
|
|
230
|
+
// 处理当回显值在虚拟滚动渲染外不能正确回显问题
|
|
231
|
+
type: Boolean,
|
|
232
|
+
default: true
|
|
233
|
+
},
|
|
234
|
+
extraProps: {
|
|
235
|
+
type: Object,
|
|
236
|
+
default: () => ({
|
|
237
|
+
label: "label",
|
|
238
|
+
value: "value"
|
|
239
|
+
})
|
|
240
|
+
},
|
|
241
|
+
dataComponent: {
|
|
242
|
+
type: Object
|
|
243
|
+
},
|
|
244
|
+
dataKey: {
|
|
245
|
+
type: [String, Function],
|
|
246
|
+
default: "templateId"
|
|
247
|
+
},
|
|
248
|
+
/**
|
|
249
|
+
* 选中值
|
|
250
|
+
*/
|
|
251
|
+
value: {
|
|
252
|
+
type: [String, Number, Array],
|
|
253
|
+
default: () => {
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
/**
|
|
258
|
+
* 开启tooltip
|
|
259
|
+
*/
|
|
260
|
+
showTip: {
|
|
261
|
+
type: Boolean,
|
|
262
|
+
default: true
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* keyValue别名
|
|
266
|
+
*/
|
|
267
|
+
keyValue: {
|
|
268
|
+
type: Array,
|
|
269
|
+
default: () => ["label", "value"]
|
|
270
|
+
},
|
|
271
|
+
itemOptions: {
|
|
272
|
+
type: Object,
|
|
273
|
+
default() {
|
|
274
|
+
return {
|
|
275
|
+
options: [],
|
|
276
|
+
virtualList: false
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
virtualList: {
|
|
281
|
+
type: Boolean,
|
|
282
|
+
default: false
|
|
283
|
+
},
|
|
284
|
+
options: {
|
|
285
|
+
type: Array,
|
|
286
|
+
default: () => []
|
|
287
|
+
},
|
|
288
|
+
placeholder: {
|
|
289
|
+
type: String,
|
|
290
|
+
default: "请选择"
|
|
291
|
+
},
|
|
292
|
+
multiple: {
|
|
293
|
+
type: Boolean,
|
|
294
|
+
default: false
|
|
295
|
+
},
|
|
296
|
+
width: {
|
|
297
|
+
type: String,
|
|
298
|
+
default: "100%"
|
|
299
|
+
},
|
|
300
|
+
maxWidth: {
|
|
301
|
+
type: String,
|
|
302
|
+
default: void 0
|
|
303
|
+
},
|
|
304
|
+
height: {
|
|
305
|
+
type: String,
|
|
306
|
+
default: "245px"
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
data() {
|
|
310
|
+
const that = this;
|
|
311
|
+
const ElOption = {
|
|
312
|
+
props: {
|
|
313
|
+
index: {
|
|
314
|
+
// 每一行的索引
|
|
315
|
+
type: Number,
|
|
316
|
+
required: true
|
|
317
|
+
},
|
|
318
|
+
source: {
|
|
319
|
+
// 每一行的内容
|
|
320
|
+
type: Object,
|
|
321
|
+
default() {
|
|
322
|
+
return {};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
render(h2) {
|
|
327
|
+
return h2(ElOptionNode, {
|
|
328
|
+
attrs: {
|
|
329
|
+
label: that.keyValue[0],
|
|
330
|
+
value: that.keyValue[1],
|
|
331
|
+
showTip: that.showTip,
|
|
332
|
+
source: this.source,
|
|
333
|
+
index: this.index
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
return {
|
|
339
|
+
itemComponent: this.dataComponent ?? ElOption,
|
|
340
|
+
selectArr: []
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
computed: {
|
|
344
|
+
config() {
|
|
345
|
+
const configData = {
|
|
346
|
+
...this.bindProps,
|
|
347
|
+
"popper-class": (this.bindProps.popperClass || "") + ` ${this.isVirtualSelect ? "nf-virtual-select-virtual-list-popper" : "nf-virtual-select-el-select-popper"}`
|
|
348
|
+
};
|
|
349
|
+
if (this.isVirtualSelect) {
|
|
350
|
+
return {
|
|
351
|
+
...configData,
|
|
352
|
+
"filter-method": this.filterMethod,
|
|
353
|
+
filterable: true
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
return configData;
|
|
357
|
+
},
|
|
358
|
+
currentVal: {
|
|
359
|
+
get() {
|
|
360
|
+
return this.value;
|
|
361
|
+
},
|
|
362
|
+
set(v) {
|
|
363
|
+
var _a;
|
|
364
|
+
this.$emit("input", v);
|
|
365
|
+
this.$emit("change", v);
|
|
366
|
+
this.$emit("update:value", v);
|
|
367
|
+
if ((_a = this.itemOptions.events) == null ? void 0 : _a.change) {
|
|
368
|
+
this.itemOptions.events.change(v, this);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
// 绑定属性
|
|
373
|
+
bindProps() {
|
|
374
|
+
let obj = {
|
|
375
|
+
clearable: true,
|
|
376
|
+
...this.itemOptions,
|
|
377
|
+
...this.$attrs,
|
|
378
|
+
virtualList: this.isVirtualSelect,
|
|
379
|
+
placeholder: this.placeholderDesc,
|
|
380
|
+
multiple: this.isMultipleSelect,
|
|
381
|
+
options: this.optionsList
|
|
382
|
+
};
|
|
383
|
+
if (obj.element === "custom-select" || obj.element === "el-select") {
|
|
384
|
+
if (obj.multiple) {
|
|
385
|
+
obj = {
|
|
386
|
+
"collapse-tags": true,
|
|
387
|
+
...obj
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
delete obj.options;
|
|
391
|
+
}
|
|
392
|
+
return obj;
|
|
393
|
+
},
|
|
394
|
+
// 绑定方法
|
|
395
|
+
bindEvents() {
|
|
396
|
+
const events = {
|
|
397
|
+
...this.$listeners || {},
|
|
398
|
+
...this.itemOptions.events
|
|
399
|
+
};
|
|
400
|
+
if (events == null ? void 0 : events.change) {
|
|
401
|
+
delete events.change;
|
|
402
|
+
}
|
|
403
|
+
if (events == null ? void 0 : events.input) {
|
|
404
|
+
delete events.input;
|
|
405
|
+
}
|
|
406
|
+
if (events == null ? void 0 : events["update:value"]) {
|
|
407
|
+
delete events["update:value"];
|
|
408
|
+
}
|
|
409
|
+
if (events == null ? void 0 : events["visible-change"]) {
|
|
410
|
+
delete events["visible-change"];
|
|
411
|
+
}
|
|
412
|
+
return events || {};
|
|
413
|
+
},
|
|
414
|
+
isVirtualSelect() {
|
|
415
|
+
return this.virtualList || this.itemOptions.virtualList;
|
|
416
|
+
},
|
|
417
|
+
isMultipleSelect() {
|
|
418
|
+
return this.multiple || this.itemOptions.multiple;
|
|
419
|
+
},
|
|
420
|
+
placeholderDesc() {
|
|
421
|
+
return this.itemOptions.placeholder || this.placeholder;
|
|
422
|
+
},
|
|
423
|
+
optionsList() {
|
|
424
|
+
var _a;
|
|
425
|
+
if (this.options.length) {
|
|
426
|
+
return this.options;
|
|
427
|
+
} else if ((_a = this.itemOptions.options) == null ? void 0 : _a.length) {
|
|
428
|
+
return this.itemOptions.options;
|
|
429
|
+
} else {
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
nfVirtualSelect() {
|
|
434
|
+
var _a, _b;
|
|
435
|
+
return (_b = (_a = this.$refs.nfVirtualSelectContainer) == null ? void 0 : _a.$refs) == null ? void 0 : _b.nfVirtualSelect;
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
watch: {
|
|
439
|
+
optionsList(newVal, value) {
|
|
440
|
+
if (!isEqual(newVal, value)) {
|
|
441
|
+
this.init();
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
currentVal: {
|
|
445
|
+
handler(newVal, value) {
|
|
446
|
+
this.init();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
mounted() {
|
|
451
|
+
this.init();
|
|
452
|
+
},
|
|
453
|
+
methods: {
|
|
454
|
+
reset() {
|
|
455
|
+
var _a, _b, _c, _d, _e;
|
|
456
|
+
if (this.isVirtualSelect) {
|
|
457
|
+
(_a = this.$refs.virtualSelectList) == null ? void 0 : _a.reset();
|
|
458
|
+
} else {
|
|
459
|
+
const container = (_e = (_d = (_c = (_b = this.nfVirtualSelect) == null ? void 0 : _b.$refs) == null ? void 0 : _c.popper) == null ? void 0 : _d.$el) == null ? void 0 : _e.querySelector(".el-select-dropdown__wrap");
|
|
460
|
+
if (container) {
|
|
461
|
+
container.scrollTop = 0;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
scrollToBottom() {
|
|
466
|
+
this.$refs.virtualSelectList.scrollToBottom();
|
|
467
|
+
},
|
|
468
|
+
scrollToIndex(index) {
|
|
469
|
+
var _a;
|
|
470
|
+
(_a = this.$refs.virtualSelectList) == null ? void 0 : _a.scrollToIndex(index);
|
|
471
|
+
},
|
|
472
|
+
scrollToOffset(offset) {
|
|
473
|
+
this.$refs.virtualSelectList.scrollToOffset(offset);
|
|
474
|
+
},
|
|
475
|
+
getSize(id) {
|
|
476
|
+
return this.$refs.virtualSelectList.getSize(id);
|
|
477
|
+
},
|
|
478
|
+
getClientSize() {
|
|
479
|
+
return this.$refs.virtualSelectList.getClientSize();
|
|
480
|
+
},
|
|
481
|
+
getScrollSize() {
|
|
482
|
+
return this.$refs.virtualSelectList.getScrollSize();
|
|
483
|
+
},
|
|
484
|
+
updatePageModeFront() {
|
|
485
|
+
var _a;
|
|
486
|
+
(_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
|
|
487
|
+
},
|
|
488
|
+
scroll(event) {
|
|
489
|
+
var _a;
|
|
490
|
+
if ((_a = this.itemOptions.events) == null ? void 0 : _a.scroll) {
|
|
491
|
+
this.itemOptions.events.scroll(event, this);
|
|
492
|
+
} else {
|
|
493
|
+
this.$emit("scroll", event);
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
totop(event) {
|
|
497
|
+
var _a;
|
|
498
|
+
if ((_a = this.itemOptions.events) == null ? void 0 : _a.totop) {
|
|
499
|
+
this.itemOptions.events.totop(event, this);
|
|
500
|
+
} else {
|
|
501
|
+
this.$emit("totop", event);
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
tobottom(event) {
|
|
505
|
+
var _a;
|
|
506
|
+
if ((_a = this.itemOptions.events) == null ? void 0 : _a.tobottom) {
|
|
507
|
+
this.itemOptions.events.tobottom(event, this);
|
|
508
|
+
} else {
|
|
509
|
+
this.$emit("tobottom", event);
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
resized(event) {
|
|
513
|
+
var _a;
|
|
514
|
+
if ((_a = this.itemOptions.events) == null ? void 0 : _a.resized) {
|
|
515
|
+
this.itemOptions.events.resized(event, this);
|
|
516
|
+
} else {
|
|
517
|
+
this.$emit("resized", event);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
init() {
|
|
521
|
+
var _a;
|
|
522
|
+
if (this.isVirtualSelect) {
|
|
523
|
+
this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
|
|
524
|
+
[this.keyValue[0]]: it[this.keyValue[0]],
|
|
525
|
+
[this.keyValue[1]]: it[this.keyValue[1]],
|
|
526
|
+
[this.dataKey]: it[this.keyValue[1]],
|
|
527
|
+
disabled: it["disabled"] ?? false
|
|
528
|
+
}))) ?? [];
|
|
529
|
+
if (this.currentVal && this.echoValueTop) {
|
|
530
|
+
if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
|
|
531
|
+
const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
|
|
532
|
+
this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
|
|
533
|
+
} else {
|
|
534
|
+
const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
|
|
535
|
+
if (index !== -1) {
|
|
536
|
+
const obj = this.selectArr.splice(index, 1)[0];
|
|
537
|
+
this.selectArr.unshift(obj);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
} else {
|
|
542
|
+
this.selectArr = (this.optionsList || []).map((it) => ({
|
|
543
|
+
[this.keyValue[0]]: it[this.keyValue[0]],
|
|
544
|
+
[this.keyValue[1]]: it[this.keyValue[1]],
|
|
545
|
+
disabled: it["disabled"] ?? false
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
// 搜索
|
|
550
|
+
async filterMethod(query) {
|
|
551
|
+
const filterHandler = this.bindProps["filter-method"];
|
|
552
|
+
if (query !== "") {
|
|
553
|
+
if (filterHandler) {
|
|
554
|
+
await filterHandler(query);
|
|
555
|
+
} else {
|
|
556
|
+
this.reset();
|
|
557
|
+
const selectArr = this.optionsList.filter((item) => {
|
|
558
|
+
if (item[this.keyValue[0]]) {
|
|
559
|
+
return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
this.selectArr = (selectArr || []).map((it) => {
|
|
563
|
+
return {
|
|
564
|
+
[this.keyValue[0]]: it[this.keyValue[0]],
|
|
565
|
+
[this.keyValue[1]]: it[this.keyValue[1]],
|
|
566
|
+
[this.dataKey]: it[this.keyValue[1]],
|
|
567
|
+
disabled: it["disabled"] ? it["disabled"] : false
|
|
568
|
+
};
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
} else if (filterHandler) {
|
|
572
|
+
await filterHandler(query);
|
|
573
|
+
} else {
|
|
574
|
+
this.init();
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
async visibleChange(bool) {
|
|
578
|
+
const events = {
|
|
579
|
+
...this.$listeners || {},
|
|
580
|
+
...this.itemOptions.events
|
|
581
|
+
};
|
|
582
|
+
const fn = events["visible-change"];
|
|
583
|
+
if (fn) {
|
|
584
|
+
let go = fn(bool);
|
|
585
|
+
if (Promise.resolve(go) === go) {
|
|
586
|
+
go = await go;
|
|
587
|
+
}
|
|
588
|
+
if (go === "break") {
|
|
589
|
+
return go;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (!bool && this.isVirtualSelect) {
|
|
593
|
+
this.reset();
|
|
594
|
+
this.init();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
beforeDestroy() {
|
|
599
|
+
this.reset();
|
|
600
|
+
this.selectArr = [];
|
|
601
|
+
},
|
|
602
|
+
activated() {
|
|
603
|
+
this.init();
|
|
604
|
+
},
|
|
605
|
+
deactivated() {
|
|
606
|
+
this.reset();
|
|
607
|
+
this.selectArr = [];
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var _sfc_render = function render2() {
|
|
611
|
+
var _vm = this, _c = _vm._self._c;
|
|
612
|
+
return _c("virtual-select-container", _vm._g({
|
|
613
|
+
ref: "nfVirtualSelectContainer",
|
|
614
|
+
class: ["nf-virtual-select nf-virtual-select-el-select", _vm.bindProps["collapse-tags"] ? "nf-virtual-select-collapse-tags" : ""],
|
|
615
|
+
attrs: {
|
|
616
|
+
"config": _vm.config,
|
|
617
|
+
"tag": _vm.tag
|
|
618
|
+
},
|
|
619
|
+
on: {
|
|
620
|
+
"visible-change": _vm.visibleChange
|
|
621
|
+
},
|
|
622
|
+
model: {
|
|
623
|
+
value: _vm.currentVal,
|
|
624
|
+
callback: function($$v) {
|
|
625
|
+
_vm.currentVal = $$v;
|
|
626
|
+
},
|
|
627
|
+
expression: "currentVal"
|
|
628
|
+
}
|
|
629
|
+
}, _vm.bindEvents), [_vm.isVirtualSelect ? [_vm._t("prefix", null, {
|
|
630
|
+
"slot": "prefix"
|
|
631
|
+
}), _vm._t("empty", null, {
|
|
632
|
+
"slot": "empty"
|
|
633
|
+
}), _c("virtual-list", {
|
|
634
|
+
ref: "virtualSelectList",
|
|
635
|
+
staticClass: "nf-virtual-select-list",
|
|
636
|
+
style: `max-height: ${_vm.height};min-width: ${_vm.width};max-width: ${_vm.maxWidth};`,
|
|
637
|
+
attrs: {
|
|
638
|
+
"offset": _vm.offset,
|
|
639
|
+
"start": _vm.start,
|
|
640
|
+
"page-mode": _vm.pageMode,
|
|
641
|
+
"direction": _vm.direction,
|
|
642
|
+
"top-threshold": _vm.topThreshold,
|
|
643
|
+
"bottom-threshold": _vm.bottomThreshold,
|
|
644
|
+
"root-tag": _vm.rootTag,
|
|
645
|
+
"wrap-tag": _vm.wrapTag,
|
|
646
|
+
"wrap-style": _vm.wrapStyle,
|
|
647
|
+
"item-tag": _vm.itemTag,
|
|
648
|
+
"item-class": _vm.itemClass,
|
|
649
|
+
"item-class-add": _vm.itemClassAdd,
|
|
650
|
+
"item-style": _vm.itemStyle,
|
|
651
|
+
"item-scoped-slots": _vm.itemScopedSlots,
|
|
652
|
+
"header-tag": _vm.headerTag,
|
|
653
|
+
"header-class": _vm.headeClass,
|
|
654
|
+
"header-style": _vm.headerStyle,
|
|
655
|
+
"footer-tag": _vm.footerTag,
|
|
656
|
+
"footer-class": _vm.footerClass,
|
|
657
|
+
"footer-style": _vm.footerStyle,
|
|
658
|
+
"extra-props": _vm.extraProps,
|
|
659
|
+
"data-component": _vm.itemComponent,
|
|
660
|
+
"data-sources": _vm.selectArr,
|
|
661
|
+
"data-key": _vm.dataKey,
|
|
662
|
+
"estimate-size": _vm.estimateSize,
|
|
663
|
+
"keeps": _vm.keeps
|
|
664
|
+
},
|
|
665
|
+
on: {
|
|
666
|
+
"scroll": _vm.scroll,
|
|
667
|
+
"totop": _vm.totop,
|
|
668
|
+
"tobottom": _vm.tobottom,
|
|
669
|
+
"resized": _vm.resized
|
|
670
|
+
}
|
|
671
|
+
}, [_vm._t("footer", null, {
|
|
672
|
+
"slot": "footer"
|
|
673
|
+
}), _vm._t("header", null, {
|
|
674
|
+
"slot": "header"
|
|
675
|
+
})], 2), _vm._t("default")] : [_vm._t("header"), _vm._l(_vm.selectArr, function(item, index) {
|
|
676
|
+
return _c("el-option", {
|
|
677
|
+
key: item[_vm.keyValue[0]] + "_" + index,
|
|
678
|
+
attrs: {
|
|
679
|
+
"label": item[_vm.keyValue[0]],
|
|
680
|
+
"value": item[_vm.keyValue[1]],
|
|
681
|
+
"disabled": item.disabled
|
|
682
|
+
}
|
|
683
|
+
}, [_vm.showTip ? _c("el-tooltip", {
|
|
684
|
+
attrs: {
|
|
685
|
+
"content": item[_vm.keyValue[0]],
|
|
686
|
+
"open-delay": 1e3,
|
|
687
|
+
"effect": "dark",
|
|
688
|
+
"placement": "left"
|
|
689
|
+
}
|
|
690
|
+
}, [_c("span", [_vm._v(_vm._s(item[_vm.keyValue[0]]))])]) : _c("span", [_vm._v(" " + _vm._s(item[_vm.keyValue[0]]) + " ")])], 1);
|
|
691
|
+
}), _vm._t("default"), _vm._t("footer")]], 2);
|
|
692
|
+
};
|
|
693
|
+
var _sfc_staticRenderFns = [];
|
|
694
|
+
var __component__ = /* @__PURE__ */ normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null, null, null);
|
|
695
|
+
const NfVirtualSelect = __component__.exports;
|
|
696
|
+
NfVirtualSelect.install = (app) => {
|
|
697
|
+
app.component("nf-virtual-select", NfVirtualSelect);
|
|
698
|
+
};
|
|
699
|
+
export {
|
|
700
|
+
NfVirtualSelect as default
|
|
701
|
+
};
|