@94ai/nf-virtual-select 8.1.8 → 8.2.0

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.
@@ -2564,6 +2564,10 @@ const _sfc_main = {
2564
2564
  keywordLabelAlias: {
2565
2565
  type: String,
2566
2566
  default: "keywordHighlightLabel"
2567
+ },
2568
+ clearable: {
2569
+ type: Boolean,
2570
+ default: false
2567
2571
  }
2568
2572
  },
2569
2573
  data() {
@@ -2656,7 +2660,7 @@ const _sfc_main = {
2656
2660
  // 绑定属性
2657
2661
  bindProps() {
2658
2662
  let obj = {
2659
- clearable: true,
2663
+ clearable: this.clearable,
2660
2664
  ...this.itemOptions,
2661
2665
  ...this.$attrs,
2662
2666
  keywordHighlight: !!(this.keywordHighlight || this.itemOptions.keywordHighlight),
@@ -2717,6 +2721,13 @@ const _sfc_main = {
2717
2721
  nfVirtualSelect() {
2718
2722
  var _a, _b;
2719
2723
  return (_b = (_a = this.$refs.nfVirtualSelectContainer) == null ? void 0 : _a.$refs) == null ? void 0 : _b.nfVirtualSelect;
2724
+ },
2725
+ matchedCount() {
2726
+ const matchedNum = this.currentVal.filter((id) => {
2727
+ var _a;
2728
+ return (_a = this.selectArr) == null ? void 0 : _a.some((obj) => obj[this.keyValue[1]] === id);
2729
+ }).length || 0;
2730
+ return matchedNum;
2720
2731
  }
2721
2732
  },
2722
2733
  watch: {
@@ -2837,10 +2848,25 @@ const _sfc_main = {
2837
2848
  }));
2838
2849
  if (this.isKeywordHighlight) {
2839
2850
  if (this.keyword) {
2840
- selectArr = selectArr.filter((item) => {
2841
- var _a2;
2842
- return (_a2 = item[this.keyValue[0]]) == null ? void 0 : _a2.toLowerCase().includes(this.keyword.toLowerCase());
2843
- });
2851
+ const queryLower = this.keyword.toLowerCase().trim();
2852
+ const queryText = (this.keyword || "").replace(/\,/g, ",");
2853
+ let querySet = null;
2854
+ if (queryText.includes(",")) {
2855
+ querySet = new Set(queryText.split(","));
2856
+ }
2857
+ if (queryText.includes(",")) {
2858
+ selectArr = selectArr.filter((item) => {
2859
+ if (item[this.keyValue[0]]) {
2860
+ return querySet.has(item[this.keyValue[0]]);
2861
+ }
2862
+ });
2863
+ } else {
2864
+ selectArr = selectArr.filter((item) => {
2865
+ if (item[this.keyValue[0]]) {
2866
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
2867
+ }
2868
+ });
2869
+ }
2844
2870
  }
2845
2871
  this.keywordHighlightFn(selectArr);
2846
2872
  }
@@ -2856,11 +2882,26 @@ const _sfc_main = {
2856
2882
  await filterHandler(query);
2857
2883
  } else {
2858
2884
  this.reset();
2859
- const selectArr = this.optionsList.filter((item) => {
2860
- if (item[this.keyValue[0]]) {
2861
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
2862
- }
2863
- });
2885
+ const queryLower = query.toLowerCase().trim();
2886
+ const queryText = (query || "").replace(/\,/g, ",");
2887
+ let querySet = null;
2888
+ if (queryText.includes(",")) {
2889
+ querySet = new Set(queryText.split(","));
2890
+ }
2891
+ let selectArr = [];
2892
+ if (queryText.includes(",")) {
2893
+ selectArr = this.optionsList.filter((item) => {
2894
+ if (item[this.keyValue[0]]) {
2895
+ return querySet.has(item[this.keyValue[0]]);
2896
+ }
2897
+ });
2898
+ } else {
2899
+ selectArr = this.optionsList.filter((item) => {
2900
+ if (item[this.keyValue[0]]) {
2901
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
2902
+ }
2903
+ });
2904
+ }
2864
2905
  this.selectArr = (selectArr || []).map((it) => {
2865
2906
  return {
2866
2907
  [this.keyValue[0]]: it[this.keyValue[0]],
@@ -2923,6 +2964,15 @@ const _sfc_main = {
2923
2964
  list.forEach((item) => {
2924
2965
  item[this.keywordLabelAlias] = getHtmlLabel(this.keyword, item[this.keyValue[0]]);
2925
2966
  });
2967
+ },
2968
+ toggleCheckAll(check) {
2969
+ const checkList = this.selectArr.map((items) => items[this.keyValue[1]]);
2970
+ if (check) {
2971
+ this.currentVal = [.../* @__PURE__ */ new Set([...this.currentVal, ...checkList])];
2972
+ } else {
2973
+ const idSet = new Set(checkList);
2974
+ this.currentVal = this.currentVal.filter((item) => !idSet.has(item));
2975
+ }
2926
2976
  }
2927
2977
  },
2928
2978
  beforeDestroy() {
@@ -2938,7 +2988,7 @@ const _sfc_main = {
2938
2988
  }
2939
2989
  };
2940
2990
  var _sfc_render = function render2() {
2941
- var _a, _b, _c2, _d, _e, _f;
2991
+ var _a, _b, _c2, _d, _e, _f, _g;
2942
2992
  var _vm = this, _c = _vm._self._c;
2943
2993
  return _c("virtual-select-container", _vm._g({
2944
2994
  ref: "nfVirtualSelectContainer",
@@ -3011,20 +3061,17 @@ var _sfc_render = function render2() {
3011
3061
  "slot": "footer"
3012
3062
  }), _vm._t("header", null, {
3013
3063
  "slot": "header"
3014
- })], 2), _vm._t("default")] : [_vm._t("header"), _vm.bindProps.multiple && _vm.selectAll ? _c("div", {
3064
+ })], 2), _vm._t("default")] : [_vm._t("header"), _vm.bindProps.multiple && _vm.selectAll && ((_c2 = _vm.selectArr) == null ? void 0 : _c2.length) ? _c("div", {
3015
3065
  staticClass: "el-select-dropdown__item top-select-all",
3016
- class: ((_c2 = _vm.currentVal) == null ? void 0 : _c2.length) === ((_d = _vm.selectArr) == null ? void 0 : _d.length) ? "selected" : ""
3066
+ class: _vm.matchedCount === ((_d = _vm.selectArr) == null ? void 0 : _d.length) ? "selected" : ""
3017
3067
  }, [_c("el-checkbox", {
3018
3068
  attrs: {
3019
- "value": ((_e = _vm.currentVal) == null ? void 0 : _e.length) === ((_f = _vm.selectArr) == null ? void 0 : _f.length)
3069
+ "value": _vm.matchedCount === ((_e = _vm.selectArr) == null ? void 0 : _e.length)
3020
3070
  },
3021
3071
  on: {
3022
- "change": (check) => {
3023
- const checkList = check ? _vm.selectArr.map((items) => items[_vm.keyValue[1]]) : [];
3024
- _vm.currentVal = checkList;
3025
- }
3072
+ "change": _vm.toggleCheckAll
3026
3073
  }
3027
- }, [_vm._v(_vm._s(_vm.selectAllText))])], 1) : _vm._e(), _vm._l(_vm.selectArr, function(item, index2) {
3074
+ }, [_vm._v(_vm._s(_vm.selectAllText) + " "), ((_f = _vm.selectArr) == null ? void 0 : _f.length) ? _c("span", [_vm._v("(" + _vm._s(`${_vm.matchedCount}/${(_g = _vm.selectArr) == null ? void 0 : _g.length}`) + ")")]) : _vm._e()])], 1) : _vm._e(), _vm._l(_vm.selectArr, function(item, index2) {
3028
3075
  return _c("el-option", {
3029
3076
  key: item[_vm.keyValue[0]] + "_" + index2,
3030
3077
  attrs: {
@@ -2562,6 +2562,10 @@ const _sfc_main = {
2562
2562
  keywordLabelAlias: {
2563
2563
  type: String,
2564
2564
  default: "keywordHighlightLabel"
2565
+ },
2566
+ clearable: {
2567
+ type: Boolean,
2568
+ default: false
2565
2569
  }
2566
2570
  },
2567
2571
  data() {
@@ -2654,7 +2658,7 @@ const _sfc_main = {
2654
2658
  // 绑定属性
2655
2659
  bindProps() {
2656
2660
  let obj = {
2657
- clearable: true,
2661
+ clearable: this.clearable,
2658
2662
  ...this.itemOptions,
2659
2663
  ...this.$attrs,
2660
2664
  keywordHighlight: !!(this.keywordHighlight || this.itemOptions.keywordHighlight),
@@ -2715,6 +2719,13 @@ const _sfc_main = {
2715
2719
  nfVirtualSelect() {
2716
2720
  var _a, _b;
2717
2721
  return (_b = (_a = this.$refs.nfVirtualSelectContainer) == null ? void 0 : _a.$refs) == null ? void 0 : _b.nfVirtualSelect;
2722
+ },
2723
+ matchedCount() {
2724
+ const matchedNum = this.currentVal.filter((id) => {
2725
+ var _a;
2726
+ return (_a = this.selectArr) == null ? void 0 : _a.some((obj) => obj[this.keyValue[1]] === id);
2727
+ }).length || 0;
2728
+ return matchedNum;
2718
2729
  }
2719
2730
  },
2720
2731
  watch: {
@@ -2835,10 +2846,25 @@ const _sfc_main = {
2835
2846
  }));
2836
2847
  if (this.isKeywordHighlight) {
2837
2848
  if (this.keyword) {
2838
- selectArr = selectArr.filter((item) => {
2839
- var _a2;
2840
- return (_a2 = item[this.keyValue[0]]) == null ? void 0 : _a2.toLowerCase().includes(this.keyword.toLowerCase());
2841
- });
2849
+ const queryLower = this.keyword.toLowerCase().trim();
2850
+ const queryText = (this.keyword || "").replace(/\,/g, ",");
2851
+ let querySet = null;
2852
+ if (queryText.includes(",")) {
2853
+ querySet = new Set(queryText.split(","));
2854
+ }
2855
+ if (queryText.includes(",")) {
2856
+ selectArr = selectArr.filter((item) => {
2857
+ if (item[this.keyValue[0]]) {
2858
+ return querySet.has(item[this.keyValue[0]]);
2859
+ }
2860
+ });
2861
+ } else {
2862
+ selectArr = selectArr.filter((item) => {
2863
+ if (item[this.keyValue[0]]) {
2864
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
2865
+ }
2866
+ });
2867
+ }
2842
2868
  }
2843
2869
  this.keywordHighlightFn(selectArr);
2844
2870
  }
@@ -2854,11 +2880,26 @@ const _sfc_main = {
2854
2880
  await filterHandler(query);
2855
2881
  } else {
2856
2882
  this.reset();
2857
- const selectArr = this.optionsList.filter((item) => {
2858
- if (item[this.keyValue[0]]) {
2859
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1;
2860
- }
2861
- });
2883
+ const queryLower = query.toLowerCase().trim();
2884
+ const queryText = (query || "").replace(/\,/g, ",");
2885
+ let querySet = null;
2886
+ if (queryText.includes(",")) {
2887
+ querySet = new Set(queryText.split(","));
2888
+ }
2889
+ let selectArr = [];
2890
+ if (queryText.includes(",")) {
2891
+ selectArr = this.optionsList.filter((item) => {
2892
+ if (item[this.keyValue[0]]) {
2893
+ return querySet.has(item[this.keyValue[0]]);
2894
+ }
2895
+ });
2896
+ } else {
2897
+ selectArr = this.optionsList.filter((item) => {
2898
+ if (item[this.keyValue[0]]) {
2899
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
2900
+ }
2901
+ });
2902
+ }
2862
2903
  this.selectArr = (selectArr || []).map((it) => {
2863
2904
  return {
2864
2905
  [this.keyValue[0]]: it[this.keyValue[0]],
@@ -2921,6 +2962,15 @@ const _sfc_main = {
2921
2962
  list.forEach((item) => {
2922
2963
  item[this.keywordLabelAlias] = getHtmlLabel(this.keyword, item[this.keyValue[0]]);
2923
2964
  });
2965
+ },
2966
+ toggleCheckAll(check) {
2967
+ const checkList = this.selectArr.map((items) => items[this.keyValue[1]]);
2968
+ if (check) {
2969
+ this.currentVal = [.../* @__PURE__ */ new Set([...this.currentVal, ...checkList])];
2970
+ } else {
2971
+ const idSet = new Set(checkList);
2972
+ this.currentVal = this.currentVal.filter((item) => !idSet.has(item));
2973
+ }
2924
2974
  }
2925
2975
  },
2926
2976
  beforeDestroy() {
@@ -2936,7 +2986,7 @@ const _sfc_main = {
2936
2986
  }
2937
2987
  };
2938
2988
  var _sfc_render = function render2() {
2939
- var _a, _b, _c2, _d, _e, _f;
2989
+ var _a, _b, _c2, _d, _e, _f, _g;
2940
2990
  var _vm = this, _c = _vm._self._c;
2941
2991
  return _c("virtual-select-container", _vm._g({
2942
2992
  ref: "nfVirtualSelectContainer",
@@ -3009,20 +3059,17 @@ var _sfc_render = function render2() {
3009
3059
  "slot": "footer"
3010
3060
  }), _vm._t("header", null, {
3011
3061
  "slot": "header"
3012
- })], 2), _vm._t("default")] : [_vm._t("header"), _vm.bindProps.multiple && _vm.selectAll ? _c("div", {
3062
+ })], 2), _vm._t("default")] : [_vm._t("header"), _vm.bindProps.multiple && _vm.selectAll && ((_c2 = _vm.selectArr) == null ? void 0 : _c2.length) ? _c("div", {
3013
3063
  staticClass: "el-select-dropdown__item top-select-all",
3014
- class: ((_c2 = _vm.currentVal) == null ? void 0 : _c2.length) === ((_d = _vm.selectArr) == null ? void 0 : _d.length) ? "selected" : ""
3064
+ class: _vm.matchedCount === ((_d = _vm.selectArr) == null ? void 0 : _d.length) ? "selected" : ""
3015
3065
  }, [_c("el-checkbox", {
3016
3066
  attrs: {
3017
- "value": ((_e = _vm.currentVal) == null ? void 0 : _e.length) === ((_f = _vm.selectArr) == null ? void 0 : _f.length)
3067
+ "value": _vm.matchedCount === ((_e = _vm.selectArr) == null ? void 0 : _e.length)
3018
3068
  },
3019
3069
  on: {
3020
- "change": (check) => {
3021
- const checkList = check ? _vm.selectArr.map((items) => items[_vm.keyValue[1]]) : [];
3022
- _vm.currentVal = checkList;
3023
- }
3070
+ "change": _vm.toggleCheckAll
3024
3071
  }
3025
- }, [_vm._v(_vm._s(_vm.selectAllText))])], 1) : _vm._e(), _vm._l(_vm.selectArr, function(item, index2) {
3072
+ }, [_vm._v(_vm._s(_vm.selectAllText) + " "), ((_f = _vm.selectArr) == null ? void 0 : _f.length) ? _c("span", [_vm._v("(" + _vm._s(`${_vm.matchedCount}/${(_g = _vm.selectArr) == null ? void 0 : _g.length}`) + ")")]) : _vm._e()])], 1) : _vm._e(), _vm._l(_vm.selectArr, function(item, index2) {
3026
3073
  return _c("el-option", {
3027
3074
  key: item[_vm.keyValue[0]] + "_" + index2,
3028
3075
  attrs: {
@@ -59,17 +59,16 @@
59
59
  <template v-else>
60
60
  <slot name="header" />
61
61
  <div
62
- v-if="bindProps.multiple && selectAll"
62
+ v-if="bindProps.multiple && selectAll && selectArr?.length"
63
63
  class="el-select-dropdown__item top-select-all"
64
- :class="currentVal?.length === selectArr?.length ? 'selected' : ''"
64
+ :class="matchedCount === selectArr?.length ? 'selected' : ''"
65
65
  >
66
66
  <el-checkbox
67
- :value="currentVal?.length === selectArr?.length"
68
- @change="check => {
69
- const checkList = check ? selectArr.map(items => items[keyValue[1]]) : [];
70
- currentVal = checkList
71
- }"
72
- >{{selectAllText}}</el-checkbox>
67
+ :value="matchedCount === selectArr?.length"
68
+ @change="toggleCheckAll"
69
+ >{{selectAllText}}
70
+ <span v-if="selectArr?.length">({{`${matchedCount}/${selectArr?.length}`}})</span>
71
+ </el-checkbox>
73
72
  </div>
74
73
  <el-option
75
74
  v-for="(item, index) in selectArr"
@@ -314,7 +313,11 @@ export default {
314
313
  keywordLabelAlias: {
315
314
  type: String,
316
315
  default: 'keywordHighlightLabel'
317
- }
316
+ },
317
+ clearable: {
318
+ type: Boolean,
319
+ default: false
320
+ },
318
321
  },
319
322
  data() {
320
323
  const that = this
@@ -397,7 +400,7 @@ export default {
397
400
  // 绑定属性
398
401
  bindProps() {
399
402
  let obj = {
400
- clearable: true,
403
+ clearable: this.clearable,
401
404
  ...this.itemOptions,
402
405
  ...this.$attrs,
403
406
  keywordHighlight: !!(this.keywordHighlight || this.itemOptions.keywordHighlight),
@@ -453,6 +456,12 @@ export default {
453
456
  },
454
457
  nfVirtualSelect() {
455
458
  return this.$refs.nfVirtualSelectContainer?.$refs?.nfVirtualSelect
459
+ },
460
+ matchedCount() {
461
+ const matchedNum = this.currentVal.filter(id =>
462
+ this.selectArr?.some(obj => obj[this.keyValue[1]] === id)
463
+ ).length || 0;;
464
+ return matchedNum
456
465
  }
457
466
  },
458
467
  watch: {
@@ -575,7 +584,28 @@ export default {
575
584
  }))
576
585
  if (this.isKeywordHighlight) {
577
586
  if (this.keyword) {
578
- selectArr = selectArr.filter(item => item[this.keyValue[0]]?.toLowerCase().includes(this.keyword.toLowerCase()))
587
+ const queryLower = this.keyword.toLowerCase().trim();
588
+ const queryText = (this.keyword || '').replace(/\,/g, ',')
589
+ let querySet = null
590
+ if (queryText.includes(',')) {
591
+ querySet = new Set(queryText.split(","))
592
+ }
593
+
594
+ if (queryText.includes(',')) {
595
+ // 多个
596
+ selectArr = selectArr.filter(item => {
597
+ if (item[this.keyValue[0]]) {
598
+ return querySet.has(item[this.keyValue[0]]);
599
+ }
600
+ });
601
+ } else {
602
+ // 单个
603
+ selectArr = selectArr.filter(item => {
604
+ if (item[this.keyValue[0]]) {
605
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
606
+ }
607
+ });
608
+ }
579
609
  }
580
610
  this.keywordHighlightFn(selectArr)
581
611
  }
@@ -591,11 +621,28 @@ export default {
591
621
  await filterHandler(query)
592
622
  } else {
593
623
  this.reset()
594
- const selectArr = this.optionsList.filter(item => {
595
- if (item[this.keyValue[0]]) {
596
- return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
597
- }
598
- })
624
+ const queryLower = query.toLowerCase().trim();
625
+ const queryText = (query || '').replace(/\,/g, ',')
626
+ let querySet = null
627
+ if (queryText.includes(',')) {
628
+ querySet = new Set(queryText.split(","))
629
+ }
630
+ let selectArr = []
631
+ if (queryText.includes(',')) {
632
+ // 多个
633
+ selectArr = this.optionsList.filter(item => {
634
+ if (item[this.keyValue[0]]) {
635
+ return querySet.has(item[this.keyValue[0]]);
636
+ }
637
+ });
638
+ } else {
639
+ // 单个
640
+ selectArr = this.optionsList.filter(item => {
641
+ if (item[this.keyValue[0]]) {
642
+ return item[this.keyValue[0]].toLowerCase().indexOf(queryLower) > -1;
643
+ }
644
+ });
645
+ }
599
646
  this.selectArr = (selectArr || []).map(it => {
600
647
  return {
601
648
  [this.keyValue[0]]: it[this.keyValue[0]],
@@ -656,7 +703,15 @@ export default {
656
703
  item[this.keywordLabelAlias] = getHtmlLabel(this.keyword, item[this.keyValue[0]])
657
704
  })
658
705
  },
659
-
706
+ toggleCheckAll(check) {
707
+ const checkList = this.selectArr.map(items => items[this.keyValue[1]]);
708
+ if(check){
709
+ this.currentVal = [...new Set([...this.currentVal, ...checkList])]
710
+ } else {
711
+ const idSet = new Set(checkList);
712
+ this.currentVal = this.currentVal.filter(item => !idSet.has(item));
713
+ }
714
+ }
660
715
  },
661
716
  beforeDestroy() {
662
717
  this.reset()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "8.1.8",
3
+ "version": "8.2.0",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>,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": "^8.1.8",
18
- "@94ai/nf-theme-chalk": "^8.1.8",
17
+ "@94ai/common-utils": "^8.2.0",
18
+ "@94ai/nf-theme-chalk": "^8.2.0",
19
19
  "lodash-es": "^4.17.21",
20
20
  "sortablejs": "^1.15.3",
21
21
  "vue-demi": "^0.14.5",
@@ -34,5 +34,5 @@
34
34
  "types": "lib/index.d.ts",
35
35
  "main": "lib/nf-virtual-select.cjs.js",
36
36
  "module": "lib/nf-virtual-select.esm-bundler.js",
37
- "gitHead": "fef0a793a99381f252b7a22d48ac09d8c3fed698"
37
+ "gitHead": "2a8f23b9a3256ed3dc3303d38d2be483cf095e4d"
38
38
  }