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

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
  }
@@ -369,14 +369,22 @@ const _sfc_main = {
369
369
  },
370
370
  methods: {
371
371
  reset() {
372
- var _a;
373
- (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.reset();
372
+ var _a, _b, _c, _d, _e;
373
+ if (this.isVirtualSelect) {
374
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.reset();
375
+ } else {
376
+ 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");
377
+ if (container) {
378
+ container.scrollTop = 0;
379
+ }
380
+ }
374
381
  },
375
382
  scrollToBottom() {
376
383
  this.$refs.virtualSelectList.scrollToBottom();
377
384
  },
378
385
  scrollToIndex(index) {
379
- this.$refs.virtualSelectList.scrollToIndex(index);
386
+ var _a;
387
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.scrollToIndex(index);
380
388
  },
381
389
  scrollToOffset(offset) {
382
390
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -391,7 +399,8 @@ const _sfc_main = {
391
399
  return this.$refs.virtualSelectList.getScrollSize();
392
400
  },
393
401
  updatePageModeFront() {
394
- this.$refs.virtualSelectList.updatePageModeFront();
402
+ var _a;
403
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
395
404
  },
396
405
  scroll(event) {
397
406
  var _a;
@@ -426,55 +435,43 @@ const _sfc_main = {
426
435
  }
427
436
  },
428
437
  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
- }
438
+ var _a;
439
+ if (this.isVirtualSelect) {
440
+ this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
441
+ [this.keyValue[0]]: it[this.keyValue[0]],
442
+ [this.keyValue[1]]: it[this.keyValue[1]],
443
+ [this.dataKey]: it[this.keyValue[1]],
444
+ disabled: it["disabled"] ?? false
445
+ }))) ?? [];
446
+ if (this.currentVal) {
447
+ if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
448
+ const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
449
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
450
+ } else {
451
+ const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
452
+ if (index !== -1) {
453
+ const obj = this.selectArr.splice(index, 1)[0];
454
+ this.selectArr.unshift(obj);
448
455
  }
449
456
  }
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
457
  }
457
- });
458
+ } else {
459
+ this.selectArr = (this.optionsList || []).map((it) => ({
460
+ [this.keyValue[0]]: it[this.keyValue[0]],
461
+ [this.keyValue[1]]: it[this.keyValue[1]],
462
+ disabled: it["disabled"] ?? false
463
+ }));
464
+ }
458
465
  },
459
466
  // 搜索
460
467
  async filterMethod(query) {
461
- var _a, _b, _c;
462
468
  const filterHandler = this.bindProps["filter-method"];
463
469
  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
470
  if (filterHandler) {
474
471
  await filterHandler(query);
475
472
  } 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) => {
473
+ this.reset();
474
+ const selectArr = this.optionsList.filter((item) => {
478
475
  if (item[this.keyValue[0]]) {
479
476
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
480
477
  }
@@ -484,8 +481,7 @@ const _sfc_main = {
484
481
  [this.keyValue[0]]: it[this.keyValue[0]],
485
482
  [this.keyValue[1]]: it[this.keyValue[1]],
486
483
  [this.dataKey]: it[this.keyValue[1]],
487
- disabled: it["disabled"] ? it["disabled"] : false,
488
- slotContent: (it == null ? void 0 : it.slotContent) || {}
484
+ disabled: it["disabled"] ? it["disabled"] : false
489
485
  };
490
486
  });
491
487
  }
@@ -510,9 +506,6 @@ const _sfc_main = {
510
506
  this.reset();
511
507
  this.init();
512
508
  }
513
- if (!events["visible-change"]) {
514
- this.$emit("visible-change", bool);
515
- }
516
509
  }
517
510
  },
518
511
  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
  }
@@ -367,14 +367,22 @@ const _sfc_main = {
367
367
  },
368
368
  methods: {
369
369
  reset() {
370
- var _a;
371
- (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.reset();
370
+ var _a, _b, _c, _d, _e;
371
+ if (this.isVirtualSelect) {
372
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.reset();
373
+ } else {
374
+ 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");
375
+ if (container) {
376
+ container.scrollTop = 0;
377
+ }
378
+ }
372
379
  },
373
380
  scrollToBottom() {
374
381
  this.$refs.virtualSelectList.scrollToBottom();
375
382
  },
376
383
  scrollToIndex(index) {
377
- this.$refs.virtualSelectList.scrollToIndex(index);
384
+ var _a;
385
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.scrollToIndex(index);
378
386
  },
379
387
  scrollToOffset(offset) {
380
388
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -389,7 +397,8 @@ const _sfc_main = {
389
397
  return this.$refs.virtualSelectList.getScrollSize();
390
398
  },
391
399
  updatePageModeFront() {
392
- this.$refs.virtualSelectList.updatePageModeFront();
400
+ var _a;
401
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
393
402
  },
394
403
  scroll(event) {
395
404
  var _a;
@@ -424,55 +433,43 @@ const _sfc_main = {
424
433
  }
425
434
  },
426
435
  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
- }
436
+ var _a;
437
+ if (this.isVirtualSelect) {
438
+ this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
439
+ [this.keyValue[0]]: it[this.keyValue[0]],
440
+ [this.keyValue[1]]: it[this.keyValue[1]],
441
+ [this.dataKey]: it[this.keyValue[1]],
442
+ disabled: it["disabled"] ?? false
443
+ }))) ?? [];
444
+ if (this.currentVal) {
445
+ if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
446
+ const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
447
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
448
+ } else {
449
+ const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
450
+ if (index !== -1) {
451
+ const obj = this.selectArr.splice(index, 1)[0];
452
+ this.selectArr.unshift(obj);
446
453
  }
447
454
  }
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
455
  }
455
- });
456
+ } else {
457
+ this.selectArr = (this.optionsList || []).map((it) => ({
458
+ [this.keyValue[0]]: it[this.keyValue[0]],
459
+ [this.keyValue[1]]: it[this.keyValue[1]],
460
+ disabled: it["disabled"] ?? false
461
+ }));
462
+ }
456
463
  },
457
464
  // 搜索
458
465
  async filterMethod(query) {
459
- var _a, _b, _c;
460
466
  const filterHandler = this.bindProps["filter-method"];
461
467
  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
468
  if (filterHandler) {
472
469
  await filterHandler(query);
473
470
  } 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) => {
471
+ this.reset();
472
+ const selectArr = this.optionsList.filter((item) => {
476
473
  if (item[this.keyValue[0]]) {
477
474
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
478
475
  }
@@ -482,8 +479,7 @@ const _sfc_main = {
482
479
  [this.keyValue[0]]: it[this.keyValue[0]],
483
480
  [this.keyValue[1]]: it[this.keyValue[1]],
484
481
  [this.dataKey]: it[this.keyValue[1]],
485
- disabled: it["disabled"] ? it["disabled"] : false,
486
- slotContent: (it == null ? void 0 : it.slotContent) || {}
482
+ disabled: it["disabled"] ? it["disabled"] : false
487
483
  };
488
484
  });
489
485
  }
@@ -508,9 +504,6 @@ const _sfc_main = {
508
504
  this.reset();
509
505
  this.init();
510
506
  }
511
- if (!events["visible-change"]) {
512
- this.$emit("visible-change", bool);
513
- }
514
507
  }
515
508
  },
516
509
  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
  }
@@ -399,13 +399,20 @@ export default {
399
399
  },
400
400
  methods: {
401
401
  reset() {
402
- this.$refs.virtualSelectList?.reset()
402
+ if (this.isVirtualSelect) {
403
+ this.$refs.virtualSelectList?.reset()
404
+ } else {
405
+ const container = this.$refs.nfVirtualSelect?.$refs?.popper?.$el?.querySelector('.el-select-dropdown__wrap')
406
+ if (container) {
407
+ container.scrollTop = 0
408
+ }
409
+ }
403
410
  },
404
411
  scrollToBottom() {
405
412
  this.$refs.virtualSelectList.scrollToBottom()
406
413
  },
407
414
  scrollToIndex(index) {
408
- this.$refs.virtualSelectList.scrollToIndex(index)
415
+ this.$refs.virtualSelectList?.scrollToIndex(index)
409
416
  },
410
417
  scrollToOffset(offset) {
411
418
  this.$refs.virtualSelectList.scrollToOffset(offset)
@@ -420,12 +427,12 @@ export default {
420
427
  return this.$refs.virtualSelectList.getScrollSize()
421
428
  },
422
429
  updatePageModeFront() {
423
- this.$refs.virtualSelectList.updatePageModeFront()
430
+ this.$refs.virtualSelectList?.updatePageModeFront()
424
431
  },
425
432
  scroll(event) {
426
433
  if (this.itemOptions.events?.scroll) {
427
434
  this.itemOptions.events.scroll(event, this)
428
- }else{
435
+ } else {
429
436
  // @scroll 事件
430
437
  this.$emit('scroll', event)
431
438
  }
@@ -433,7 +440,7 @@ export default {
433
440
  totop(event) {
434
441
  if (this.itemOptions.events?.totop) {
435
442
  this.itemOptions.events.totop(event, this)
436
- }else{
443
+ } else {
437
444
  // @totop 事件
438
445
  this.$emit('totop', event)
439
446
  }
@@ -441,7 +448,7 @@ export default {
441
448
  tobottom(event) {
442
449
  if (this.itemOptions.events?.tobottom) {
443
450
  this.itemOptions.events.tobottom(event, this)
444
- }else{
451
+ } else {
445
452
  // @tobottom 事件
446
453
  this.$emit('tobottom', event)
447
454
  }
@@ -449,14 +456,13 @@ export default {
449
456
  resized(event) {
450
457
  if (this.itemOptions.events?.resized) {
451
458
  this.itemOptions.events.resized(event, this)
452
- }else{
459
+ } else {
453
460
  // @resized 事件
454
461
  this.$emit('resized', event)
455
462
  }
456
463
  },
457
464
  init() {
458
- this.$nextTick(() => {
459
- if ((this.isVirtualSelect)) {
465
+ if ((this.isVirtualSelect)) {
460
466
  // 虚拟
461
467
  // 无回显值
462
468
  this.selectArr = this.optionsList?.map(it => ({
@@ -464,19 +470,19 @@ export default {
464
470
  [this.keyValue[1]]: it[this.keyValue[1]],
465
471
  [this.dataKey]: it[this.keyValue[1]],
466
472
  disabled: it['disabled'] ?? false
467
- })) ?? [];
473
+ })) ?? []
468
474
  if (this.currentVal) {
469
475
  // 有回显值
470
476
  if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
471
477
  // 多选
472
478
  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))];
479
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter(item => !multiple_elements.includes(item))]
474
480
  } else {
475
481
  // 单选
476
- const index = this.selectArr.findIndex(item => item.value === this.currentVal);
482
+ const index = this.selectArr.findIndex(item => item.value === this.currentVal)
477
483
  if (index !== -1) {
478
- const obj = this.selectArr.splice(index, 1)[0];
479
- this.selectArr.unshift(obj);
484
+ const obj = this.selectArr.splice(index, 1)[0]
485
+ this.selectArr.unshift(obj)
480
486
  }
481
487
  }
482
488
  }
@@ -488,26 +494,16 @@ export default {
488
494
  disabled: it['disabled'] ?? false
489
495
  }))
490
496
  }
491
- })
492
497
  },
493
498
  // 搜索
494
499
  async filterMethod(query) {
495
500
  const filterHandler = this.bindProps['filter-method']
496
501
  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
502
  if (filterHandler) {
507
503
  await filterHandler(query)
508
504
  } else {
509
- const arr = this.itemOptions?.options?.length ? this.itemOptions.options : this.options?.length ? this.options : []
510
- const selectArr = arr.filter(item => {
505
+ this.reset()
506
+ const selectArr = this.optionsList.filter(item => {
511
507
  if (item[this.keyValue[0]]) {
512
508
  return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
513
509
  }
@@ -518,7 +514,6 @@ export default {
518
514
  [this.keyValue[1]]: it[this.keyValue[1]],
519
515
  [this.dataKey]: it[this.keyValue[1]],
520
516
  disabled: it['disabled'] ? it['disabled'] : false,
521
- slotContent: it?.slotContent || {}
522
517
  }
523
518
  })
524
519
  }
@@ -531,7 +526,7 @@ export default {
531
526
  async visibleChange(bool) {
532
527
  const events = { ...(this.$listeners || {}), ...this.itemOptions.events }
533
528
  if (events['visible-change']) {
534
- const go = await (events['visible-change'])(bool)
529
+ const go = await (events['visible-change'])(bool)
535
530
  if (go === 'break') {
536
531
  return go
537
532
  }
@@ -540,9 +535,6 @@ export default {
540
535
  this.reset()
541
536
  this.init()
542
537
  }
543
- if (!events['visible-change']) {
544
- this.$emit('visible-change', bool)
545
- }
546
538
  }
547
539
  },
548
540
  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.78",
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.78",
18
+ "@94ai/nf-theme-chalk": "^3.2.78",
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": "9d94e59c7927e55f42ea0964f349121b0cadfcee"
37
37
  }