@94ai/nf-virtual-select 3.2.76 → 3.2.77

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/lib/index.d.ts CHANGED
@@ -304,7 +304,6 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
304
304
  value: string | number | unknown[];
305
305
  showTip: boolean;
306
306
  placeholder: string;
307
- options: unknown[];
308
307
  offset: number;
309
308
  start: number;
310
309
  pageMode: boolean;
@@ -331,6 +330,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
331
330
  keyValue: unknown[];
332
331
  itemOptions: Record<string, any>;
333
332
  virtualList: boolean;
333
+ options: unknown[];
334
334
  multiple: boolean;
335
335
  width: string;
336
336
  maxWidth: string;
@@ -492,10 +492,11 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
492
492
  get(): any;
493
493
  set(v: any): void;
494
494
  };
495
- isVirtualSelect(): any;
496
495
  bindProps(): any;
497
496
  bindEvents(): any;
498
- formatItemOptions(): any;
497
+ isVirtualSelect(): any;
498
+ isMultipleSelect(): any;
499
+ placeholderDesc(): any;
499
500
  optionsList(): any;
500
501
  }> & import("vue-demi").ComponentCustomProperties & Readonly<import("vue-demi").ExtractPropTypes<{
501
502
  offset: {
@@ -803,16 +804,16 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
803
804
  get(): any;
804
805
  set(v: any): void;
805
806
  };
806
- isVirtualSelect(): any;
807
807
  bindProps(): any;
808
808
  bindEvents(): any;
809
- formatItemOptions(): any;
809
+ isVirtualSelect(): any;
810
+ isMultipleSelect(): any;
811
+ placeholderDesc(): any;
810
812
  optionsList(): any;
811
813
  }, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {}, string, {
812
814
  value: string | number | unknown[];
813
815
  showTip: boolean;
814
816
  placeholder: string;
815
- options: unknown[];
816
817
  offset: number;
817
818
  start: number;
818
819
  pageMode: boolean;
@@ -839,6 +840,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
839
840
  keyValue: unknown[];
840
841
  itemOptions: Record<string, any>;
841
842
  virtualList: boolean;
843
+ options: unknown[];
842
844
  multiple: boolean;
843
845
  width: string;
844
846
  maxWidth: string;
@@ -3,7 +3,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
3
3
  const virtualList = require("vue-virtual-scroll-list");
4
4
  const vue2RuntimeHelpers = require("@94ai/vue2-runtime-helpers");
5
5
  const lodashEs = require("lodash-es");
6
- const vueDemi = require("vue-demi");
6
+ require("vue-demi");
7
7
  const _sfc_main$1 = {
8
8
  name: "ItemComponent",
9
9
  props: {
@@ -289,15 +289,16 @@ const _sfc_main = {
289
289
  }
290
290
  }
291
291
  },
292
- isVirtualSelect() {
293
- return this.virtualList || this.itemOptions.virtualList;
294
- },
295
292
  // 绑定属性
296
293
  bindProps() {
297
294
  let obj = {
298
295
  clearable: true,
296
+ ...this.itemOptions,
299
297
  ...this.$attrs,
300
- ...this.formatItemOptions
298
+ virtualList: this.isVirtualSelect,
299
+ placeholder: this.placeholderDesc,
300
+ multiple: this.isMultipleSelect,
301
+ options: this.optionsList
301
302
  };
302
303
  if (obj.element === "custom-select" || obj.element === "el-select") {
303
304
  if (obj.multiple) {
@@ -320,26 +321,25 @@ const _sfc_main = {
320
321
  if (events == null ? void 0 : events.change) {
321
322
  delete events.change;
322
323
  }
324
+ if (events == null ? void 0 : events.input) {
325
+ delete events.input;
326
+ }
327
+ if (events == null ? void 0 : events["update:value"]) {
328
+ delete events["update:value"];
329
+ }
323
330
  if ((events == null ? void 0 : events["visible-change"]) && (this.virtualList || ((_a = this.itemOptions) == null ? void 0 : _a.virtualList))) {
324
331
  delete events["visible-change"];
325
332
  }
326
333
  return events || {};
327
334
  },
328
- formatItemOptions() {
329
- const that = this;
330
- return {
331
- ...this.itemOptions,
332
- ...this.$attrs,
333
- virtualList: this.itemOptions.virtualList || this.virtualList,
334
- placeholder: this.itemOptions.placeholder || this.placeholder,
335
- multiple: this.itemOptions.multiple || this.multiple,
336
- options: this.optionsList,
337
- events: {
338
- change(val) {
339
- that.$emit("change", val);
340
- }
341
- }
342
- };
335
+ isVirtualSelect() {
336
+ return this.virtualList || this.itemOptions.virtualList;
337
+ },
338
+ isMultipleSelect() {
339
+ return this.multiple || this.itemOptions.multiple;
340
+ },
341
+ placeholderDesc() {
342
+ return this.itemOptions.placeholder || this.placeholder;
343
343
  },
344
344
  optionsList() {
345
345
  var _a;
@@ -353,7 +353,7 @@ const _sfc_main = {
353
353
  }
354
354
  },
355
355
  watch: {
356
- options(newVal, value) {
356
+ optionsList(newVal, value) {
357
357
  if (!lodashEs.isEqual(newVal, value)) {
358
358
  this.init();
359
359
  }
@@ -376,7 +376,19 @@ const _sfc_main = {
376
376
  this.$refs.virtualSelectList.scrollToBottom();
377
377
  },
378
378
  scrollToIndex(index) {
379
- this.$refs.virtualSelectList.scrollToIndex(index);
379
+ var _a, _b, _c, _d, _e;
380
+ try {
381
+ if (this.isVirtualSelect) {
382
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.scrollToIndex(index);
383
+ } else {
384
+ const container = (_e = (_d = (_c = (_b = this.$refs.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");
385
+ if (container) {
386
+ container.scrollTop = 0;
387
+ }
388
+ }
389
+ } catch (e) {
390
+ console.log(e);
391
+ }
380
392
  },
381
393
  scrollToOffset(offset) {
382
394
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -391,7 +403,8 @@ const _sfc_main = {
391
403
  return this.$refs.virtualSelectList.getScrollSize();
392
404
  },
393
405
  updatePageModeFront() {
394
- this.$refs.virtualSelectList.updatePageModeFront();
406
+ var _a;
407
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
395
408
  },
396
409
  scroll(event) {
397
410
  var _a;
@@ -426,55 +439,43 @@ const _sfc_main = {
426
439
  }
427
440
  },
428
441
  init() {
429
- this.$nextTick(() => {
430
- var _a;
431
- if (this.isVirtualSelect) {
432
- this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
433
- [this.keyValue[0]]: it[this.keyValue[0]],
434
- [this.keyValue[1]]: it[this.keyValue[1]],
435
- [this.dataKey]: it[this.keyValue[1]],
436
- disabled: it["disabled"] ?? false
437
- }))) ?? [];
438
- if (this.currentVal) {
439
- if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
440
- const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
441
- this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
442
- } else {
443
- const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
444
- if (index !== -1) {
445
- const obj = this.selectArr.splice(index, 1)[0];
446
- this.selectArr.unshift(obj);
447
- }
442
+ var _a;
443
+ if (this.isVirtualSelect) {
444
+ this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
445
+ [this.keyValue[0]]: it[this.keyValue[0]],
446
+ [this.keyValue[1]]: it[this.keyValue[1]],
447
+ [this.dataKey]: it[this.keyValue[1]],
448
+ disabled: it["disabled"] ?? false
449
+ }))) ?? [];
450
+ if (this.currentVal) {
451
+ if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
452
+ const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
453
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
454
+ } else {
455
+ const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
456
+ if (index !== -1) {
457
+ const obj = this.selectArr.splice(index, 1)[0];
458
+ this.selectArr.unshift(obj);
448
459
  }
449
460
  }
450
- } else {
451
- this.selectArr = (this.optionsList || []).map((it) => ({
452
- [this.keyValue[0]]: it[this.keyValue[0]],
453
- [this.keyValue[1]]: it[this.keyValue[1]],
454
- disabled: it["disabled"] ?? false
455
- }));
456
461
  }
457
- });
462
+ } else {
463
+ this.selectArr = (this.optionsList || []).map((it) => ({
464
+ [this.keyValue[0]]: it[this.keyValue[0]],
465
+ [this.keyValue[1]]: it[this.keyValue[1]],
466
+ disabled: it["disabled"] ?? false
467
+ }));
468
+ }
458
469
  },
459
470
  // 搜索
460
471
  async filterMethod(query) {
461
- var _a, _b, _c;
462
472
  const filterHandler = this.bindProps["filter-method"];
463
473
  if (query !== "") {
464
- this.$refs.virtualSelectList.scrollToIndex(0);
465
- await vueDemi.nextTick();
466
- await new Promise((resolve) => {
467
- let timer = setTimeout(() => {
468
- clearTimeout(timer);
469
- timer = void 0;
470
- resolve(true);
471
- }, 30);
472
- });
473
474
  if (filterHandler) {
474
475
  await filterHandler(query);
475
476
  } else {
476
- const arr = ((_b = (_a = this.itemOptions) == null ? void 0 : _a.options) == null ? void 0 : _b.length) ? this.itemOptions.options : ((_c = this.options) == null ? void 0 : _c.length) ? this.options : [];
477
- const selectArr = arr.filter((item) => {
477
+ this.reset();
478
+ const selectArr = this.optionsList.filter((item) => {
478
479
  if (item[this.keyValue[0]]) {
479
480
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
480
481
  }
@@ -484,8 +485,7 @@ const _sfc_main = {
484
485
  [this.keyValue[0]]: it[this.keyValue[0]],
485
486
  [this.keyValue[1]]: it[this.keyValue[1]],
486
487
  [this.dataKey]: it[this.keyValue[1]],
487
- disabled: it["disabled"] ? it["disabled"] : false,
488
- slotContent: (it == null ? void 0 : it.slotContent) || {}
488
+ disabled: it["disabled"] ? it["disabled"] : false
489
489
  };
490
490
  });
491
491
  }
@@ -510,9 +510,6 @@ const _sfc_main = {
510
510
  this.reset();
511
511
  this.init();
512
512
  }
513
- if (!events["visible-change"]) {
514
- this.$emit("visible-change", bool);
515
- }
516
513
  }
517
514
  },
518
515
  beforeDestroy() {
@@ -1,7 +1,7 @@
1
1
  import virtualList from "vue-virtual-scroll-list";
2
2
  import { normalizeComponent } from "@94ai/vue2-runtime-helpers";
3
3
  import { isEqual } from "lodash-es";
4
- import { nextTick } from "vue-demi";
4
+ import "vue-demi";
5
5
  const _sfc_main$1 = {
6
6
  name: "ItemComponent",
7
7
  props: {
@@ -287,15 +287,16 @@ const _sfc_main = {
287
287
  }
288
288
  }
289
289
  },
290
- isVirtualSelect() {
291
- return this.virtualList || this.itemOptions.virtualList;
292
- },
293
290
  // 绑定属性
294
291
  bindProps() {
295
292
  let obj = {
296
293
  clearable: true,
294
+ ...this.itemOptions,
297
295
  ...this.$attrs,
298
- ...this.formatItemOptions
296
+ virtualList: this.isVirtualSelect,
297
+ placeholder: this.placeholderDesc,
298
+ multiple: this.isMultipleSelect,
299
+ options: this.optionsList
299
300
  };
300
301
  if (obj.element === "custom-select" || obj.element === "el-select") {
301
302
  if (obj.multiple) {
@@ -318,26 +319,25 @@ const _sfc_main = {
318
319
  if (events == null ? void 0 : events.change) {
319
320
  delete events.change;
320
321
  }
322
+ if (events == null ? void 0 : events.input) {
323
+ delete events.input;
324
+ }
325
+ if (events == null ? void 0 : events["update:value"]) {
326
+ delete events["update:value"];
327
+ }
321
328
  if ((events == null ? void 0 : events["visible-change"]) && (this.virtualList || ((_a = this.itemOptions) == null ? void 0 : _a.virtualList))) {
322
329
  delete events["visible-change"];
323
330
  }
324
331
  return events || {};
325
332
  },
326
- formatItemOptions() {
327
- const that = this;
328
- return {
329
- ...this.itemOptions,
330
- ...this.$attrs,
331
- virtualList: this.itemOptions.virtualList || this.virtualList,
332
- placeholder: this.itemOptions.placeholder || this.placeholder,
333
- multiple: this.itemOptions.multiple || this.multiple,
334
- options: this.optionsList,
335
- events: {
336
- change(val) {
337
- that.$emit("change", val);
338
- }
339
- }
340
- };
333
+ isVirtualSelect() {
334
+ return this.virtualList || this.itemOptions.virtualList;
335
+ },
336
+ isMultipleSelect() {
337
+ return this.multiple || this.itemOptions.multiple;
338
+ },
339
+ placeholderDesc() {
340
+ return this.itemOptions.placeholder || this.placeholder;
341
341
  },
342
342
  optionsList() {
343
343
  var _a;
@@ -351,7 +351,7 @@ const _sfc_main = {
351
351
  }
352
352
  },
353
353
  watch: {
354
- options(newVal, value) {
354
+ optionsList(newVal, value) {
355
355
  if (!isEqual(newVal, value)) {
356
356
  this.init();
357
357
  }
@@ -374,7 +374,19 @@ const _sfc_main = {
374
374
  this.$refs.virtualSelectList.scrollToBottom();
375
375
  },
376
376
  scrollToIndex(index) {
377
- this.$refs.virtualSelectList.scrollToIndex(index);
377
+ var _a, _b, _c, _d, _e;
378
+ try {
379
+ if (this.isVirtualSelect) {
380
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.scrollToIndex(index);
381
+ } else {
382
+ const container = (_e = (_d = (_c = (_b = this.$refs.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");
383
+ if (container) {
384
+ container.scrollTop = 0;
385
+ }
386
+ }
387
+ } catch (e) {
388
+ console.log(e);
389
+ }
378
390
  },
379
391
  scrollToOffset(offset) {
380
392
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -389,7 +401,8 @@ const _sfc_main = {
389
401
  return this.$refs.virtualSelectList.getScrollSize();
390
402
  },
391
403
  updatePageModeFront() {
392
- this.$refs.virtualSelectList.updatePageModeFront();
404
+ var _a;
405
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
393
406
  },
394
407
  scroll(event) {
395
408
  var _a;
@@ -424,55 +437,43 @@ const _sfc_main = {
424
437
  }
425
438
  },
426
439
  init() {
427
- this.$nextTick(() => {
428
- var _a;
429
- if (this.isVirtualSelect) {
430
- this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
431
- [this.keyValue[0]]: it[this.keyValue[0]],
432
- [this.keyValue[1]]: it[this.keyValue[1]],
433
- [this.dataKey]: it[this.keyValue[1]],
434
- disabled: it["disabled"] ?? false
435
- }))) ?? [];
436
- if (this.currentVal) {
437
- if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
438
- const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
439
- this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
440
- } else {
441
- const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
442
- if (index !== -1) {
443
- const obj = this.selectArr.splice(index, 1)[0];
444
- this.selectArr.unshift(obj);
445
- }
440
+ var _a;
441
+ if (this.isVirtualSelect) {
442
+ this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
443
+ [this.keyValue[0]]: it[this.keyValue[0]],
444
+ [this.keyValue[1]]: it[this.keyValue[1]],
445
+ [this.dataKey]: it[this.keyValue[1]],
446
+ disabled: it["disabled"] ?? false
447
+ }))) ?? [];
448
+ if (this.currentVal) {
449
+ if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
450
+ const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
451
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
452
+ } else {
453
+ const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
454
+ if (index !== -1) {
455
+ const obj = this.selectArr.splice(index, 1)[0];
456
+ this.selectArr.unshift(obj);
446
457
  }
447
458
  }
448
- } else {
449
- this.selectArr = (this.optionsList || []).map((it) => ({
450
- [this.keyValue[0]]: it[this.keyValue[0]],
451
- [this.keyValue[1]]: it[this.keyValue[1]],
452
- disabled: it["disabled"] ?? false
453
- }));
454
459
  }
455
- });
460
+ } else {
461
+ this.selectArr = (this.optionsList || []).map((it) => ({
462
+ [this.keyValue[0]]: it[this.keyValue[0]],
463
+ [this.keyValue[1]]: it[this.keyValue[1]],
464
+ disabled: it["disabled"] ?? false
465
+ }));
466
+ }
456
467
  },
457
468
  // 搜索
458
469
  async filterMethod(query) {
459
- var _a, _b, _c;
460
470
  const filterHandler = this.bindProps["filter-method"];
461
471
  if (query !== "") {
462
- this.$refs.virtualSelectList.scrollToIndex(0);
463
- await nextTick();
464
- await new Promise((resolve) => {
465
- let timer = setTimeout(() => {
466
- clearTimeout(timer);
467
- timer = void 0;
468
- resolve(true);
469
- }, 30);
470
- });
471
472
  if (filterHandler) {
472
473
  await filterHandler(query);
473
474
  } else {
474
- const arr = ((_b = (_a = this.itemOptions) == null ? void 0 : _a.options) == null ? void 0 : _b.length) ? this.itemOptions.options : ((_c = this.options) == null ? void 0 : _c.length) ? this.options : [];
475
- const selectArr = arr.filter((item) => {
475
+ this.reset();
476
+ const selectArr = this.optionsList.filter((item) => {
476
477
  if (item[this.keyValue[0]]) {
477
478
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
478
479
  }
@@ -482,8 +483,7 @@ const _sfc_main = {
482
483
  [this.keyValue[0]]: it[this.keyValue[0]],
483
484
  [this.keyValue[1]]: it[this.keyValue[1]],
484
485
  [this.dataKey]: it[this.keyValue[1]],
485
- disabled: it["disabled"] ? it["disabled"] : false,
486
- slotContent: (it == null ? void 0 : it.slotContent) || {}
486
+ disabled: it["disabled"] ? it["disabled"] : false
487
487
  };
488
488
  });
489
489
  }
@@ -508,9 +508,6 @@ const _sfc_main = {
508
508
  this.reset();
509
509
  this.init();
510
510
  }
511
- if (!events["visible-change"]) {
512
- this.$emit("visible-change", bool);
513
- }
514
511
  }
515
512
  },
516
513
  beforeDestroy() {
@@ -155,10 +155,11 @@ declare const _default: import("vue-demi").DefineComponent<{
155
155
  get(): any;
156
156
  set(v: any): void;
157
157
  };
158
- isVirtualSelect(): any;
159
158
  bindProps(): any;
160
159
  bindEvents(): any;
161
- formatItemOptions(): any;
160
+ isVirtualSelect(): any;
161
+ isMultipleSelect(): any;
162
+ placeholderDesc(): any;
162
163
  optionsList(): any;
163
164
  }, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {}, string, Readonly<import("vue-demi").ExtractPropTypes<{
164
165
  offset: {
@@ -313,7 +314,6 @@ declare const _default: import("vue-demi").DefineComponent<{
313
314
  value: string | number | unknown[];
314
315
  showTip: boolean;
315
316
  placeholder: string;
316
- options: unknown[];
317
317
  offset: number;
318
318
  start: number;
319
319
  pageMode: boolean;
@@ -340,6 +340,7 @@ declare const _default: import("vue-demi").DefineComponent<{
340
340
  keyValue: unknown[];
341
341
  itemOptions: Record<string, any>;
342
342
  virtualList: boolean;
343
+ options: unknown[];
343
344
  multiple: boolean;
344
345
  width: string;
345
346
  maxWidth: string;
@@ -1,59 +1,59 @@
1
1
  <template>
2
2
  <div class="nf-virtual-select">
3
3
  <el-select
4
- v-if="isVirtualSelect"
5
- v-model="currentVal"
6
- v-on="bindEvents"
7
- v-bind="bindProps"
8
- ref="nfVirtualSelect"
9
- :class="['nf-virtual-select-el-select', bindProps['collapse-tags'] ? 'nf-virtual-select-collapse-tags' : '']"
10
- popper-class="nf-virtual-select-virtual-list-popper"
11
- filterable
12
- :filter-method="filterMethod"
13
- @visible-change="visibleChange"
4
+ v-if="isVirtualSelect"
5
+ v-model="currentVal"
6
+ v-on="bindEvents"
7
+ v-bind="bindProps"
8
+ ref="nfVirtualSelect"
9
+ :class="['nf-virtual-select-el-select', bindProps['collapse-tags'] ? 'nf-virtual-select-collapse-tags' : '']"
10
+ popper-class="nf-virtual-select-virtual-list-popper"
11
+ filterable
12
+ :filter-method="filterMethod"
13
+ @visible-change="visibleChange"
14
+ >
15
+ <slot name="prefix" slot="prefix" />
16
+ <slot name="empty" slot="empty" />
17
+ <virtual-list
18
+ :offset="offset"
19
+ :start="start"
20
+ :page-mode="pageMode"
21
+ :direction="direction"
22
+ :top-threshold="topThreshold"
23
+ :bottom-threshold="bottomThreshold"
24
+ :root-tag="rootTag"
25
+ :wrap-tag="wrapTag"
26
+ :wrap-style="wrapStyle"
27
+ :item-tag="itemTag"
28
+ :item-class="itemClass"
29
+ :item-class-add="itemClassAdd"
30
+ :item-style="itemStyle"
31
+ :item-scoped-slots="itemScopedSlots"
32
+ :header-tag="headerTag"
33
+ :header-class="headeClass"
34
+ :header-style="headerStyle"
35
+ :footer-tag="footerTag"
36
+ :footer-class="footerClass"
37
+ :footer-style="footerStyle"
38
+ :extra-props="extraProps"
39
+ :data-component="itemComponent"
40
+ :data-sources="selectArr"
41
+ :data-key="dataKey"
42
+ :estimate-size="estimateSize"
43
+ :keeps="keeps"
44
+ ref="virtualSelectList"
45
+ class="nf-virtual-select-list"
46
+ @scroll="scroll"
47
+ @totop="totop"
48
+ @tobottom="tobottom"
49
+ @resized="resized"
50
+ :style="`max-height: ${height};min-width: ${width};max-width: ${maxWidth};`"
14
51
  >
15
- <slot name="prefix" slot="prefix" />
16
- <slot name="empty" slot="empty" />
17
- <virtual-list
18
- :offset="offset"
19
- :start="start"
20
- :page-mode="pageMode"
21
- :direction="direction"
22
- :top-threshold="topThreshold"
23
- :bottom-threshold="bottomThreshold"
24
- :root-tag="rootTag"
25
- :wrap-tag="wrapTag"
26
- :wrap-style="wrapStyle"
27
- :item-tag="itemTag"
28
- :item-class="itemClass"
29
- :item-class-add="itemClassAdd"
30
- :item-style="itemStyle"
31
- :item-scoped-slots="itemScopedSlots"
32
- :header-tag="headerTag"
33
- :header-class="headeClass"
34
- :header-style="headerStyle"
35
- :footer-tag="footerTag"
36
- :footer-class="footerClass"
37
- :footer-style="footerStyle"
38
- :extra-props="extraProps"
39
- :data-component="itemComponent"
40
- :data-sources="selectArr"
41
- :data-key="dataKey"
42
- :estimate-size="estimateSize"
43
- :keeps="keeps"
44
- ref="virtualSelectList"
45
- class="nf-virtual-select-list"
46
- @scroll="scroll"
47
- @totop="totop"
48
- @tobottom="tobottom"
49
- @resized="resized"
50
- :style="`max-height: ${height};min-width: ${width};max-width: ${maxWidth};`"
51
- >
52
- <slot slot="footer" name="footer" />
53
- <slot slot="header" name="header" />
54
- </virtual-list>
55
- <slot/>
56
- </el-select>
52
+ <slot slot="footer" name="footer" />
53
+ <slot slot="header" name="header" />
54
+ </virtual-list>
55
+ <slot />
56
+ </el-select>
57
57
  <el-select
58
58
  v-else
59
59
  v-model="currentVal"
@@ -84,8 +84,8 @@
84
84
  {{ item[keyValue[0]] }}
85
85
  </span>
86
86
  </el-option>
87
- <slot/>
88
- <slot name="footer"/>
87
+ <slot />
88
+ <slot name="footer" />
89
89
  </el-select>
90
90
  </div>
91
91
  </template>
@@ -95,6 +95,7 @@ import virtualList from 'vue-virtual-scroll-list'
95
95
  import ElOptionNode from './el-option-node.vue'
96
96
  import { isEqual } from 'lodash-es'
97
97
  import { nextTick } from 'vue-demi'
98
+
98
99
  export default {
99
100
  name: 'nf-virtual-select',
100
101
  components: { 'virtual-list': virtualList },
@@ -135,7 +136,7 @@ export default {
135
136
  type: String,
136
137
  default: 'div'
137
138
  },
138
- wrapStyle: {
139
+ wrapStyle: {
139
140
  type: Object,
140
141
  default: () => {
141
142
  return {}
@@ -150,7 +151,7 @@ export default {
150
151
  default: ''
151
152
  },
152
153
  itemClassAdd: {
153
- type: Function,
154
+ type: Function
154
155
  },
155
156
  itemStyle: {
156
157
  type: Object,
@@ -209,10 +210,10 @@ export default {
209
210
  })
210
211
  },
211
212
  dataComponent: {
212
- type: Object,
213
+ type: Object
213
214
  },
214
215
  dataKey: {
215
- type: [String , Function],
216
+ type: [String, Function],
216
217
  default: 'templateId'
217
218
  },
218
219
  /**
@@ -244,7 +245,7 @@ export default {
244
245
  default() {
245
246
  return {
246
247
  options: [],
247
- virtualList: false
248
+ virtualList: false,
248
249
  }
249
250
  }
250
251
  },
@@ -256,7 +257,6 @@ export default {
256
257
  type: Array,
257
258
  default: () => []
258
259
  },
259
-
260
260
  placeholder: {
261
261
  type: String,
262
262
  default: '请选择'
@@ -300,9 +300,9 @@ export default {
300
300
  value: that.keyValue[1],
301
301
  showTip: that.showTip,
302
302
  source: this.source,
303
- index: this.index,
304
- },
305
- });
303
+ index: this.index
304
+ }
305
+ })
306
306
  }
307
307
  }
308
308
  return {
@@ -324,15 +324,16 @@ export default {
324
324
  }
325
325
  }
326
326
  },
327
- isVirtualSelect() {
328
- return this.virtualList || this.itemOptions.virtualList
329
- },
330
327
  // 绑定属性
331
328
  bindProps() {
332
329
  let obj = {
333
330
  clearable: true,
331
+ ...this.itemOptions,
334
332
  ...this.$attrs,
335
- ...this.formatItemOptions
333
+ virtualList: this.isVirtualSelect,
334
+ placeholder: this.placeholderDesc,
335
+ multiple: this.isMultipleSelect,
336
+ options: this.optionsList
336
337
  }
337
338
  if (obj.element === 'custom-select' || (obj.element === 'el-select')) {
338
339
  if (obj.multiple) {
@@ -351,39 +352,38 @@ export default {
351
352
  if (events?.change) {
352
353
  delete events.change
353
354
  }
355
+ if (events?.input) {
356
+ delete events.input
357
+ }
358
+ if (events?.['update:value']) {
359
+ delete events['update:value']
360
+ }
354
361
  if (events?.['visible-change'] && (this.virtualList || this.itemOptions?.virtualList)) {
355
362
  delete events['visible-change']
356
363
  }
357
364
  return events || {}
358
365
  },
359
- formatItemOptions() {
360
- const that = this
361
- return {
362
- ...this.itemOptions,
363
- ...this.$attrs,
364
- virtualList: this.itemOptions.virtualList || this.virtualList,
365
- placeholder: this.itemOptions.placeholder || this.placeholder,
366
- multiple: this.itemOptions.multiple || this.multiple,
367
- options: this.optionsList,
368
- events: {
369
- change(val) {
370
- that.$emit('change', val)
371
- }
372
- }
373
- }
366
+ isVirtualSelect() {
367
+ return this.virtualList || this.itemOptions.virtualList
368
+ },
369
+ isMultipleSelect() {
370
+ return this.multiple || this.itemOptions.multiple
371
+ },
372
+ placeholderDesc() {
373
+ return this.itemOptions.placeholder || this.placeholder
374
374
  },
375
375
  optionsList() {
376
376
  if (this.options.length) {
377
- return this.options;
377
+ return this.options
378
378
  } else if (this.itemOptions.options?.length) {
379
- return this.itemOptions.options;
379
+ return this.itemOptions.options
380
380
  } else {
381
- return [];
381
+ return []
382
382
  }
383
383
  }
384
384
  },
385
385
  watch: {
386
- options(newVal, value) {
386
+ optionsList(newVal, value) {
387
387
  if (!isEqual(newVal, value)) {
388
388
  this.init()
389
389
  }
@@ -405,7 +405,18 @@ export default {
405
405
  this.$refs.virtualSelectList.scrollToBottom()
406
406
  },
407
407
  scrollToIndex(index) {
408
- this.$refs.virtualSelectList.scrollToIndex(index)
408
+ try {
409
+ if (this.isVirtualSelect) {
410
+ this.$refs.virtualSelectList?.scrollToIndex(index)
411
+ } else {
412
+ const container = this.$refs.nfVirtualSelect?.$refs?.popper?.$el?.querySelector('.el-select-dropdown__wrap')
413
+ if (container) {
414
+ container.scrollTop = 0
415
+ }
416
+ }
417
+ } catch (e) {
418
+ console.log(e)
419
+ }
409
420
  },
410
421
  scrollToOffset(offset) {
411
422
  this.$refs.virtualSelectList.scrollToOffset(offset)
@@ -420,12 +431,12 @@ export default {
420
431
  return this.$refs.virtualSelectList.getScrollSize()
421
432
  },
422
433
  updatePageModeFront() {
423
- this.$refs.virtualSelectList.updatePageModeFront()
434
+ this.$refs.virtualSelectList?.updatePageModeFront()
424
435
  },
425
436
  scroll(event) {
426
437
  if (this.itemOptions.events?.scroll) {
427
438
  this.itemOptions.events.scroll(event, this)
428
- }else{
439
+ } else {
429
440
  // @scroll 事件
430
441
  this.$emit('scroll', event)
431
442
  }
@@ -433,7 +444,7 @@ export default {
433
444
  totop(event) {
434
445
  if (this.itemOptions.events?.totop) {
435
446
  this.itemOptions.events.totop(event, this)
436
- }else{
447
+ } else {
437
448
  // @totop 事件
438
449
  this.$emit('totop', event)
439
450
  }
@@ -441,7 +452,7 @@ export default {
441
452
  tobottom(event) {
442
453
  if (this.itemOptions.events?.tobottom) {
443
454
  this.itemOptions.events.tobottom(event, this)
444
- }else{
455
+ } else {
445
456
  // @tobottom 事件
446
457
  this.$emit('tobottom', event)
447
458
  }
@@ -449,14 +460,13 @@ export default {
449
460
  resized(event) {
450
461
  if (this.itemOptions.events?.resized) {
451
462
  this.itemOptions.events.resized(event, this)
452
- }else{
463
+ } else {
453
464
  // @resized 事件
454
465
  this.$emit('resized', event)
455
466
  }
456
467
  },
457
468
  init() {
458
- this.$nextTick(() => {
459
- if ((this.isVirtualSelect)) {
469
+ if ((this.isVirtualSelect)) {
460
470
  // 虚拟
461
471
  // 无回显值
462
472
  this.selectArr = this.optionsList?.map(it => ({
@@ -464,19 +474,19 @@ export default {
464
474
  [this.keyValue[1]]: it[this.keyValue[1]],
465
475
  [this.dataKey]: it[this.keyValue[1]],
466
476
  disabled: it['disabled'] ?? false
467
- })) ?? [];
477
+ })) ?? []
468
478
  if (this.currentVal) {
469
479
  // 有回显值
470
480
  if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
471
481
  // 多选
472
482
  const multiple_elements = this.selectArr.filter(item => this.currentVal.includes(item[this.keyValue[1]]))
473
- this.selectArr = [...multiple_elements, ...this.selectArr.filter(item => !multiple_elements.includes(item))];
483
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter(item => !multiple_elements.includes(item))]
474
484
  } else {
475
485
  // 单选
476
- const index = this.selectArr.findIndex(item => item.value === this.currentVal);
486
+ const index = this.selectArr.findIndex(item => item.value === this.currentVal)
477
487
  if (index !== -1) {
478
- const obj = this.selectArr.splice(index, 1)[0];
479
- this.selectArr.unshift(obj);
488
+ const obj = this.selectArr.splice(index, 1)[0]
489
+ this.selectArr.unshift(obj)
480
490
  }
481
491
  }
482
492
  }
@@ -488,26 +498,16 @@ export default {
488
498
  disabled: it['disabled'] ?? false
489
499
  }))
490
500
  }
491
- })
492
501
  },
493
502
  // 搜索
494
503
  async filterMethod(query) {
495
504
  const filterHandler = this.bindProps['filter-method']
496
505
  if (query !== '') {
497
- this.$refs.virtualSelectList.scrollToIndex(0)// 滚动到顶部
498
- await nextTick()
499
- await new Promise((resolve) => {
500
- let timer = setTimeout(() => {
501
- clearTimeout(timer)
502
- timer = undefined
503
- resolve(true)
504
- }, 30)
505
- })
506
506
  if (filterHandler) {
507
507
  await filterHandler(query)
508
508
  } else {
509
- const arr = this.itemOptions?.options?.length ? this.itemOptions.options : this.options?.length ? this.options : []
510
- const selectArr = arr.filter(item => {
509
+ this.reset()
510
+ const selectArr = this.optionsList.filter(item => {
511
511
  if (item[this.keyValue[0]]) {
512
512
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
513
513
  }
@@ -518,7 +518,6 @@ export default {
518
518
  [this.keyValue[1]]: it[this.keyValue[1]],
519
519
  [this.dataKey]: it[this.keyValue[1]],
520
520
  disabled: it['disabled'] ? it['disabled'] : false,
521
- slotContent: it?.slotContent || {}
522
521
  }
523
522
  })
524
523
  }
@@ -531,7 +530,7 @@ export default {
531
530
  async visibleChange(bool) {
532
531
  const events = { ...(this.$listeners || {}), ...this.itemOptions.events }
533
532
  if (events['visible-change']) {
534
- const go = await (events['visible-change'])(bool)
533
+ const go = await (events['visible-change'])(bool)
535
534
  if (go === 'break') {
536
535
  return go
537
536
  }
@@ -540,9 +539,6 @@ export default {
540
539
  this.reset()
541
540
  this.init()
542
541
  }
543
- if (!events['visible-change']) {
544
- this.$emit('visible-change', bool)
545
- }
546
542
  }
547
543
  },
548
544
  beforeDestroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "3.2.76",
3
+ "version": "3.2.77",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "DESKTOP-1EDDQ79\\dev026 <liuxiangxiang@94ai.com>",
@@ -14,8 +14,8 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/common-utils": "^3.2.76",
18
- "@94ai/nf-theme-chalk": "^3.2.76",
17
+ "@94ai/common-utils": "^3.2.77",
18
+ "@94ai/nf-theme-chalk": "^3.2.77",
19
19
  "lodash-es": "^4.17.21",
20
20
  "vue-demi": "^0.14.5",
21
21
  "vue-virtual-scroll-list": "^2.3.5"
@@ -33,5 +33,5 @@
33
33
  "types": "lib/index.d.ts",
34
34
  "main": "lib/nf-virtual-select.cjs.js",
35
35
  "module": "lib/nf-virtual-select.esm-bundler.js",
36
- "gitHead": "07f6d8aca65e93849c2f70cf0b83fdf2ae2cc0f1"
36
+ "gitHead": "c83df2f1fd663fdab0735f187aeab554cb743512"
37
37
  }