@94ai/nf-virtual-select 3.2.75 → 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,6 +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
+ require("vue-demi");
6
7
  const _sfc_main$1 = {
7
8
  name: "ItemComponent",
8
9
  props: {
@@ -288,15 +289,16 @@ const _sfc_main = {
288
289
  }
289
290
  }
290
291
  },
291
- isVirtualSelect() {
292
- return this.virtualList || this.itemOptions.virtualList;
293
- },
294
292
  // 绑定属性
295
293
  bindProps() {
296
294
  let obj = {
297
295
  clearable: true,
296
+ ...this.itemOptions,
298
297
  ...this.$attrs,
299
- ...this.formatItemOptions
298
+ virtualList: this.isVirtualSelect,
299
+ placeholder: this.placeholderDesc,
300
+ multiple: this.isMultipleSelect,
301
+ options: this.optionsList
300
302
  };
301
303
  if (obj.element === "custom-select" || obj.element === "el-select") {
302
304
  if (obj.multiple) {
@@ -319,26 +321,25 @@ const _sfc_main = {
319
321
  if (events == null ? void 0 : events.change) {
320
322
  delete events.change;
321
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
+ }
322
330
  if ((events == null ? void 0 : events["visible-change"]) && (this.virtualList || ((_a = this.itemOptions) == null ? void 0 : _a.virtualList))) {
323
331
  delete events["visible-change"];
324
332
  }
325
333
  return events || {};
326
334
  },
327
- formatItemOptions() {
328
- const that = this;
329
- return {
330
- ...this.itemOptions,
331
- ...this.$attrs,
332
- virtualList: this.itemOptions.virtualList || this.virtualList,
333
- placeholder: this.itemOptions.placeholder || this.placeholder,
334
- multiple: this.itemOptions.multiple || this.multiple,
335
- options: this.optionsList,
336
- events: {
337
- change(val) {
338
- that.$emit("change", val);
339
- }
340
- }
341
- };
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;
342
343
  },
343
344
  optionsList() {
344
345
  var _a;
@@ -352,7 +353,7 @@ const _sfc_main = {
352
353
  }
353
354
  },
354
355
  watch: {
355
- options(newVal, value) {
356
+ optionsList(newVal, value) {
356
357
  if (!lodashEs.isEqual(newVal, value)) {
357
358
  this.init();
358
359
  }
@@ -375,7 +376,19 @@ const _sfc_main = {
375
376
  this.$refs.virtualSelectList.scrollToBottom();
376
377
  },
377
378
  scrollToIndex(index) {
378
- 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
+ }
379
392
  },
380
393
  scrollToOffset(offset) {
381
394
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -390,7 +403,8 @@ const _sfc_main = {
390
403
  return this.$refs.virtualSelectList.getScrollSize();
391
404
  },
392
405
  updatePageModeFront() {
393
- this.$refs.virtualSelectList.updatePageModeFront();
406
+ var _a;
407
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
394
408
  },
395
409
  scroll(event) {
396
410
  var _a;
@@ -425,73 +439,56 @@ const _sfc_main = {
425
439
  }
426
440
  },
427
441
  init() {
428
- this.$nextTick(() => {
429
- var _a;
430
- if (this.isVirtualSelect) {
431
- this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
432
- [this.keyValue[0]]: it[this.keyValue[0]],
433
- [this.keyValue[1]]: it[this.keyValue[1]],
434
- [this.dataKey]: it[this.keyValue[1]],
435
- disabled: it["disabled"] ?? false
436
- }))) ?? [];
437
- if (this.currentVal) {
438
- if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
439
- const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
440
- this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
441
- } else {
442
- const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
443
- if (index !== -1) {
444
- const obj = this.selectArr.splice(index, 1)[0];
445
- this.selectArr.unshift(obj);
446
- }
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);
447
459
  }
448
460
  }
449
- } else {
450
- this.selectArr = (this.optionsList || []).map((it) => ({
451
- [this.keyValue[0]]: it[this.keyValue[0]],
452
- [this.keyValue[1]]: it[this.keyValue[1]],
453
- disabled: it["disabled"] ?? false
454
- }));
455
461
  }
456
- });
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
+ }
457
469
  },
458
470
  // 搜索
459
471
  async filterMethod(query) {
460
472
  const filterHandler = this.bindProps["filter-method"];
461
473
  if (query !== "") {
462
- this.$refs.virtualSelectList.scrollToIndex(0);
463
- let timer = setTimeout(async () => {
464
- var _a, _b, _c;
465
- clearTimeout(timer);
466
- timer = null;
467
- if (filterHandler) {
468
- await filterHandler(query);
469
- } else {
470
- 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 : [];
471
- const selectArr = arr.filter((item) => {
472
- if (item[this.keyValue[0]]) {
473
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
474
- }
475
- });
476
- this.selectArr = (selectArr || []).map((it) => {
477
- return {
478
- [this.keyValue[0]]: it[this.keyValue[0]],
479
- [this.keyValue[1]]: it[this.keyValue[1]],
480
- [this.dataKey]: it[this.keyValue[1]],
481
- disabled: it["disabled"] ? it["disabled"] : false,
482
- slotContent: (it == null ? void 0 : it.slotContent) || {}
483
- };
484
- });
485
- }
486
- }, 100);
487
- this.$once("hook:beforeDestroy", () => {
488
- clearTimeout(timer);
489
- timer = null;
490
- });
491
- this.$once("hook:deactivated", () => {
492
- clearTimeout(timer);
493
- timer = null;
494
- });
474
+ if (filterHandler) {
475
+ await filterHandler(query);
476
+ } else {
477
+ this.reset();
478
+ const selectArr = this.optionsList.filter((item) => {
479
+ if (item[this.keyValue[0]]) {
480
+ return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
481
+ }
482
+ });
483
+ this.selectArr = (selectArr || []).map((it) => {
484
+ return {
485
+ [this.keyValue[0]]: it[this.keyValue[0]],
486
+ [this.keyValue[1]]: it[this.keyValue[1]],
487
+ [this.dataKey]: it[this.keyValue[1]],
488
+ disabled: it["disabled"] ? it["disabled"] : false
489
+ };
490
+ });
491
+ }
495
492
  } else if (filterHandler) {
496
493
  await filterHandler(query);
497
494
  } else {
@@ -513,9 +510,6 @@ const _sfc_main = {
513
510
  this.reset();
514
511
  this.init();
515
512
  }
516
- if (!events["visible-change"]) {
517
- this.$emit("visible-change", bool);
518
- }
519
513
  }
520
514
  },
521
515
  beforeDestroy() {
@@ -1,6 +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 "vue-demi";
4
5
  const _sfc_main$1 = {
5
6
  name: "ItemComponent",
6
7
  props: {
@@ -286,15 +287,16 @@ const _sfc_main = {
286
287
  }
287
288
  }
288
289
  },
289
- isVirtualSelect() {
290
- return this.virtualList || this.itemOptions.virtualList;
291
- },
292
290
  // 绑定属性
293
291
  bindProps() {
294
292
  let obj = {
295
293
  clearable: true,
294
+ ...this.itemOptions,
296
295
  ...this.$attrs,
297
- ...this.formatItemOptions
296
+ virtualList: this.isVirtualSelect,
297
+ placeholder: this.placeholderDesc,
298
+ multiple: this.isMultipleSelect,
299
+ options: this.optionsList
298
300
  };
299
301
  if (obj.element === "custom-select" || obj.element === "el-select") {
300
302
  if (obj.multiple) {
@@ -317,26 +319,25 @@ const _sfc_main = {
317
319
  if (events == null ? void 0 : events.change) {
318
320
  delete events.change;
319
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
+ }
320
328
  if ((events == null ? void 0 : events["visible-change"]) && (this.virtualList || ((_a = this.itemOptions) == null ? void 0 : _a.virtualList))) {
321
329
  delete events["visible-change"];
322
330
  }
323
331
  return events || {};
324
332
  },
325
- formatItemOptions() {
326
- const that = this;
327
- return {
328
- ...this.itemOptions,
329
- ...this.$attrs,
330
- virtualList: this.itemOptions.virtualList || this.virtualList,
331
- placeholder: this.itemOptions.placeholder || this.placeholder,
332
- multiple: this.itemOptions.multiple || this.multiple,
333
- options: this.optionsList,
334
- events: {
335
- change(val) {
336
- that.$emit("change", val);
337
- }
338
- }
339
- };
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;
340
341
  },
341
342
  optionsList() {
342
343
  var _a;
@@ -350,7 +351,7 @@ const _sfc_main = {
350
351
  }
351
352
  },
352
353
  watch: {
353
- options(newVal, value) {
354
+ optionsList(newVal, value) {
354
355
  if (!isEqual(newVal, value)) {
355
356
  this.init();
356
357
  }
@@ -373,7 +374,19 @@ const _sfc_main = {
373
374
  this.$refs.virtualSelectList.scrollToBottom();
374
375
  },
375
376
  scrollToIndex(index) {
376
- 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
+ }
377
390
  },
378
391
  scrollToOffset(offset) {
379
392
  this.$refs.virtualSelectList.scrollToOffset(offset);
@@ -388,7 +401,8 @@ const _sfc_main = {
388
401
  return this.$refs.virtualSelectList.getScrollSize();
389
402
  },
390
403
  updatePageModeFront() {
391
- this.$refs.virtualSelectList.updatePageModeFront();
404
+ var _a;
405
+ (_a = this.$refs.virtualSelectList) == null ? void 0 : _a.updatePageModeFront();
392
406
  },
393
407
  scroll(event) {
394
408
  var _a;
@@ -423,73 +437,56 @@ const _sfc_main = {
423
437
  }
424
438
  },
425
439
  init() {
426
- this.$nextTick(() => {
427
- var _a;
428
- if (this.isVirtualSelect) {
429
- this.selectArr = ((_a = this.optionsList) == null ? void 0 : _a.map((it) => ({
430
- [this.keyValue[0]]: it[this.keyValue[0]],
431
- [this.keyValue[1]]: it[this.keyValue[1]],
432
- [this.dataKey]: it[this.keyValue[1]],
433
- disabled: it["disabled"] ?? false
434
- }))) ?? [];
435
- if (this.currentVal) {
436
- if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
437
- const multiple_elements = this.selectArr.filter((item) => this.currentVal.includes(item[this.keyValue[1]]));
438
- this.selectArr = [...multiple_elements, ...this.selectArr.filter((item) => !multiple_elements.includes(item))];
439
- } else {
440
- const index = this.selectArr.findIndex((item) => item.value === this.currentVal);
441
- if (index !== -1) {
442
- const obj = this.selectArr.splice(index, 1)[0];
443
- this.selectArr.unshift(obj);
444
- }
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);
445
457
  }
446
458
  }
447
- } else {
448
- this.selectArr = (this.optionsList || []).map((it) => ({
449
- [this.keyValue[0]]: it[this.keyValue[0]],
450
- [this.keyValue[1]]: it[this.keyValue[1]],
451
- disabled: it["disabled"] ?? false
452
- }));
453
459
  }
454
- });
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
+ }
455
467
  },
456
468
  // 搜索
457
469
  async filterMethod(query) {
458
470
  const filterHandler = this.bindProps["filter-method"];
459
471
  if (query !== "") {
460
- this.$refs.virtualSelectList.scrollToIndex(0);
461
- let timer = setTimeout(async () => {
462
- var _a, _b, _c;
463
- clearTimeout(timer);
464
- timer = null;
465
- if (filterHandler) {
466
- await filterHandler(query);
467
- } else {
468
- 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 : [];
469
- const selectArr = arr.filter((item) => {
470
- if (item[this.keyValue[0]]) {
471
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
472
- }
473
- });
474
- this.selectArr = (selectArr || []).map((it) => {
475
- return {
476
- [this.keyValue[0]]: it[this.keyValue[0]],
477
- [this.keyValue[1]]: it[this.keyValue[1]],
478
- [this.dataKey]: it[this.keyValue[1]],
479
- disabled: it["disabled"] ? it["disabled"] : false,
480
- slotContent: (it == null ? void 0 : it.slotContent) || {}
481
- };
482
- });
483
- }
484
- }, 100);
485
- this.$once("hook:beforeDestroy", () => {
486
- clearTimeout(timer);
487
- timer = null;
488
- });
489
- this.$once("hook:deactivated", () => {
490
- clearTimeout(timer);
491
- timer = null;
492
- });
472
+ if (filterHandler) {
473
+ await filterHandler(query);
474
+ } else {
475
+ this.reset();
476
+ const selectArr = this.optionsList.filter((item) => {
477
+ if (item[this.keyValue[0]]) {
478
+ return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
479
+ }
480
+ });
481
+ this.selectArr = (selectArr || []).map((it) => {
482
+ return {
483
+ [this.keyValue[0]]: it[this.keyValue[0]],
484
+ [this.keyValue[1]]: it[this.keyValue[1]],
485
+ [this.dataKey]: it[this.keyValue[1]],
486
+ disabled: it["disabled"] ? it["disabled"] : false
487
+ };
488
+ });
489
+ }
493
490
  } else if (filterHandler) {
494
491
  await filterHandler(query);
495
492
  } else {
@@ -511,9 +508,6 @@ const _sfc_main = {
511
508
  this.reset();
512
509
  this.init();
513
510
  }
514
- if (!events["visible-change"]) {
515
- this.$emit("visible-change", bool);
516
- }
517
511
  }
518
512
  },
519
513
  beforeDestroy() {
@@ -1,4 +1,4 @@
1
- declare const _default: import("vue").DefineComponent<{
1
+ declare const _default: import("vue-demi").DefineComponent<{
2
2
  offset: {
3
3
  type: NumberConstructor;
4
4
  default: number;
@@ -155,12 +155,13 @@ declare const _default: import("vue").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
- }, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {}, string, Readonly<import("vue").ExtractPropTypes<{
164
+ }, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {}, string, Readonly<import("vue-demi").ExtractPropTypes<{
164
165
  offset: {
165
166
  type: NumberConstructor;
166
167
  default: number;
@@ -313,7 +314,6 @@ declare const _default: import("vue").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").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>
@@ -94,6 +94,8 @@
94
94
  import virtualList from 'vue-virtual-scroll-list'
95
95
  import ElOptionNode from './el-option-node.vue'
96
96
  import { isEqual } from 'lodash-es'
97
+ import { nextTick } from 'vue-demi'
98
+
97
99
  export default {
98
100
  name: 'nf-virtual-select',
99
101
  components: { 'virtual-list': virtualList },
@@ -134,7 +136,7 @@ export default {
134
136
  type: String,
135
137
  default: 'div'
136
138
  },
137
- wrapStyle: {
139
+ wrapStyle: {
138
140
  type: Object,
139
141
  default: () => {
140
142
  return {}
@@ -149,7 +151,7 @@ export default {
149
151
  default: ''
150
152
  },
151
153
  itemClassAdd: {
152
- type: Function,
154
+ type: Function
153
155
  },
154
156
  itemStyle: {
155
157
  type: Object,
@@ -208,10 +210,10 @@ export default {
208
210
  })
209
211
  },
210
212
  dataComponent: {
211
- type: Object,
213
+ type: Object
212
214
  },
213
215
  dataKey: {
214
- type: [String , Function],
216
+ type: [String, Function],
215
217
  default: 'templateId'
216
218
  },
217
219
  /**
@@ -243,7 +245,7 @@ export default {
243
245
  default() {
244
246
  return {
245
247
  options: [],
246
- virtualList: false
248
+ virtualList: false,
247
249
  }
248
250
  }
249
251
  },
@@ -255,7 +257,6 @@ export default {
255
257
  type: Array,
256
258
  default: () => []
257
259
  },
258
-
259
260
  placeholder: {
260
261
  type: String,
261
262
  default: '请选择'
@@ -299,9 +300,9 @@ export default {
299
300
  value: that.keyValue[1],
300
301
  showTip: that.showTip,
301
302
  source: this.source,
302
- index: this.index,
303
- },
304
- });
303
+ index: this.index
304
+ }
305
+ })
305
306
  }
306
307
  }
307
308
  return {
@@ -323,15 +324,16 @@ export default {
323
324
  }
324
325
  }
325
326
  },
326
- isVirtualSelect() {
327
- return this.virtualList || this.itemOptions.virtualList
328
- },
329
327
  // 绑定属性
330
328
  bindProps() {
331
329
  let obj = {
332
330
  clearable: true,
331
+ ...this.itemOptions,
333
332
  ...this.$attrs,
334
- ...this.formatItemOptions
333
+ virtualList: this.isVirtualSelect,
334
+ placeholder: this.placeholderDesc,
335
+ multiple: this.isMultipleSelect,
336
+ options: this.optionsList
335
337
  }
336
338
  if (obj.element === 'custom-select' || (obj.element === 'el-select')) {
337
339
  if (obj.multiple) {
@@ -350,39 +352,38 @@ export default {
350
352
  if (events?.change) {
351
353
  delete events.change
352
354
  }
355
+ if (events?.input) {
356
+ delete events.input
357
+ }
358
+ if (events?.['update:value']) {
359
+ delete events['update:value']
360
+ }
353
361
  if (events?.['visible-change'] && (this.virtualList || this.itemOptions?.virtualList)) {
354
362
  delete events['visible-change']
355
363
  }
356
364
  return events || {}
357
365
  },
358
- formatItemOptions() {
359
- const that = this
360
- return {
361
- ...this.itemOptions,
362
- ...this.$attrs,
363
- virtualList: this.itemOptions.virtualList || this.virtualList,
364
- placeholder: this.itemOptions.placeholder || this.placeholder,
365
- multiple: this.itemOptions.multiple || this.multiple,
366
- options: this.optionsList,
367
- events: {
368
- change(val) {
369
- that.$emit('change', val)
370
- }
371
- }
372
- }
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
373
374
  },
374
375
  optionsList() {
375
376
  if (this.options.length) {
376
- return this.options;
377
+ return this.options
377
378
  } else if (this.itemOptions.options?.length) {
378
- return this.itemOptions.options;
379
+ return this.itemOptions.options
379
380
  } else {
380
- return [];
381
+ return []
381
382
  }
382
383
  }
383
384
  },
384
385
  watch: {
385
- options(newVal, value) {
386
+ optionsList(newVal, value) {
386
387
  if (!isEqual(newVal, value)) {
387
388
  this.init()
388
389
  }
@@ -404,7 +405,18 @@ export default {
404
405
  this.$refs.virtualSelectList.scrollToBottom()
405
406
  },
406
407
  scrollToIndex(index) {
407
- 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
+ }
408
420
  },
409
421
  scrollToOffset(offset) {
410
422
  this.$refs.virtualSelectList.scrollToOffset(offset)
@@ -419,12 +431,12 @@ export default {
419
431
  return this.$refs.virtualSelectList.getScrollSize()
420
432
  },
421
433
  updatePageModeFront() {
422
- this.$refs.virtualSelectList.updatePageModeFront()
434
+ this.$refs.virtualSelectList?.updatePageModeFront()
423
435
  },
424
436
  scroll(event) {
425
437
  if (this.itemOptions.events?.scroll) {
426
438
  this.itemOptions.events.scroll(event, this)
427
- }else{
439
+ } else {
428
440
  // @scroll 事件
429
441
  this.$emit('scroll', event)
430
442
  }
@@ -432,7 +444,7 @@ export default {
432
444
  totop(event) {
433
445
  if (this.itemOptions.events?.totop) {
434
446
  this.itemOptions.events.totop(event, this)
435
- }else{
447
+ } else {
436
448
  // @totop 事件
437
449
  this.$emit('totop', event)
438
450
  }
@@ -440,7 +452,7 @@ export default {
440
452
  tobottom(event) {
441
453
  if (this.itemOptions.events?.tobottom) {
442
454
  this.itemOptions.events.tobottom(event, this)
443
- }else{
455
+ } else {
444
456
  // @tobottom 事件
445
457
  this.$emit('tobottom', event)
446
458
  }
@@ -448,14 +460,13 @@ export default {
448
460
  resized(event) {
449
461
  if (this.itemOptions.events?.resized) {
450
462
  this.itemOptions.events.resized(event, this)
451
- }else{
463
+ } else {
452
464
  // @resized 事件
453
465
  this.$emit('resized', event)
454
466
  }
455
467
  },
456
468
  init() {
457
- this.$nextTick(() => {
458
- if ((this.isVirtualSelect)) {
469
+ if ((this.isVirtualSelect)) {
459
470
  // 虚拟
460
471
  // 无回显值
461
472
  this.selectArr = this.optionsList?.map(it => ({
@@ -463,19 +474,19 @@ export default {
463
474
  [this.keyValue[1]]: it[this.keyValue[1]],
464
475
  [this.dataKey]: it[this.keyValue[1]],
465
476
  disabled: it['disabled'] ?? false
466
- })) ?? [];
477
+ })) ?? []
467
478
  if (this.currentVal) {
468
479
  // 有回显值
469
480
  if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
470
481
  // 多选
471
482
  const multiple_elements = this.selectArr.filter(item => this.currentVal.includes(item[this.keyValue[1]]))
472
- 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))]
473
484
  } else {
474
485
  // 单选
475
- const index = this.selectArr.findIndex(item => item.value === this.currentVal);
486
+ const index = this.selectArr.findIndex(item => item.value === this.currentVal)
476
487
  if (index !== -1) {
477
- const obj = this.selectArr.splice(index, 1)[0];
478
- this.selectArr.unshift(obj);
488
+ const obj = this.selectArr.splice(index, 1)[0]
489
+ this.selectArr.unshift(obj)
479
490
  }
480
491
  }
481
492
  }
@@ -487,44 +498,29 @@ export default {
487
498
  disabled: it['disabled'] ?? false
488
499
  }))
489
500
  }
490
- })
491
501
  },
492
502
  // 搜索
493
503
  async filterMethod(query) {
494
504
  const filterHandler = this.bindProps['filter-method']
495
505
  if (query !== '') {
496
- this.$refs.virtualSelectList.scrollToIndex(0)// 滚动到顶部
497
- let timer = setTimeout(async () => {
498
- clearTimeout(timer)
499
- timer = null
500
- if (filterHandler) {
501
- await filterHandler(query)
502
- } else {
503
- const arr = this.itemOptions?.options?.length ? this.itemOptions.options : this.options?.length ? this.options : []
504
- const selectArr = arr.filter(item => {
505
- if (item[this.keyValue[0]]) {
506
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
507
- }
508
- })
509
- this.selectArr = (selectArr || []).map(it => {
510
- return {
511
- [this.keyValue[0]]: it[this.keyValue[0]],
512
- [this.keyValue[1]]: it[this.keyValue[1]],
513
- [this.dataKey]: it[this.keyValue[1]],
514
- disabled: it['disabled'] ? it['disabled'] : false,
515
- slotContent: it?.slotContent || {}
516
- }
517
- })
518
- }
519
- }, 100)
520
- this.$once('hook:beforeDestroy', () => {
521
- clearTimeout(timer)
522
- timer = null
523
- })
524
- this.$once('hook:deactivated', () => {
525
- clearTimeout(timer)
526
- timer = null
527
- })
506
+ if (filterHandler) {
507
+ await filterHandler(query)
508
+ } else {
509
+ this.reset()
510
+ const selectArr = this.optionsList.filter(item => {
511
+ if (item[this.keyValue[0]]) {
512
+ return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
513
+ }
514
+ })
515
+ this.selectArr = (selectArr || []).map(it => {
516
+ return {
517
+ [this.keyValue[0]]: it[this.keyValue[0]],
518
+ [this.keyValue[1]]: it[this.keyValue[1]],
519
+ [this.dataKey]: it[this.keyValue[1]],
520
+ disabled: it['disabled'] ? it['disabled'] : false,
521
+ }
522
+ })
523
+ }
528
524
  } else if (filterHandler) {
529
525
  await filterHandler(query)
530
526
  } else {
@@ -534,7 +530,7 @@ export default {
534
530
  async visibleChange(bool) {
535
531
  const events = { ...(this.$listeners || {}), ...this.itemOptions.events }
536
532
  if (events['visible-change']) {
537
- const go = await (events['visible-change'])(bool)
533
+ const go = await (events['visible-change'])(bool)
538
534
  if (go === 'break') {
539
535
  return go
540
536
  }
@@ -543,9 +539,6 @@ export default {
543
539
  this.reset()
544
540
  this.init()
545
541
  }
546
- if (!events['visible-change']) {
547
- this.$emit('visible-change', bool)
548
- }
549
542
  }
550
543
  },
551
544
  beforeDestroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "3.2.75",
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.75",
18
- "@94ai/nf-theme-chalk": "^3.2.75",
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": "3e303fef4a30e065979f80c4df5000243b57d652"
36
+ "gitHead": "c83df2f1fd663fdab0735f187aeab554cb743512"
37
37
  }