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