ct-component-plus 2.2.11 → 2.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # v2.2.11版本更新内容:
1
+ # v2.2.13版本更新内容:
2
+
3
+ 1. 分页下拉组件添加补充项配置
4
+
5
+ # v2.2.12版本更新内容:
2
6
 
3
7
  1. 优化分页下拉组件搜索相关逻辑
4
8
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ct-component-plus",
3
3
  "private": false,
4
- "version": "2.2.11",
4
+ "version": "2.2.13",
5
5
  "type": "module",
6
6
  "main": "packages/components/index.js",
7
7
  "files": [
@@ -7,6 +7,12 @@ export const selectProps = {
7
7
  ...searchComponentProps,
8
8
  modelValue: [String, Number, Array, Boolean],
9
9
  multiple: Boolean,
10
+ options: {
11
+ type: Array,
12
+ default() {
13
+ return [];
14
+ },
15
+ },
10
16
  filterable: Boolean,
11
17
  api: String,
12
18
  serviceMethod: String,
@@ -7,7 +7,7 @@
7
7
  collapse-tags
8
8
  v-bind="rawAttr"
9
9
  :multiple="multiple"
10
- :filterable="filterable"
10
+ :filterable="filterable && !multiple"
11
11
  :filter-method="filterMethod"
12
12
  :clear-icon="clearIcon"
13
13
  :suffix-icon="suffixIcon"
@@ -17,7 +17,7 @@
17
17
  @focus="showSearchPrefix"
18
18
  @blur="hideSearchPrefix"
19
19
  @click="focusSearchInput"
20
- @visible-change="handleListSort"
20
+ @visible-change="handleVisibleChange"
21
21
  >
22
22
  <template #prefix>
23
23
  <div
@@ -63,25 +63,19 @@
63
63
  }}</span>
64
64
  </slot>
65
65
  </el-option>
66
+ <el-option
67
+ v-if="multiple && noFilterOptions"
68
+ :key="'__ct_paging_select_empty__'"
69
+ :label="''"
70
+ :value="'__ct_paging_select_empty__'"
71
+ disabled
72
+ style="display: none"
73
+ >
74
+ </el-option>
66
75
  </slot>
67
76
  </div>
68
77
  <Empty :text="emptyText" v-if="multiple && noFilterOptions" />
69
78
  <template #empty>
70
- <div :class="[ns.e('top')]" v-if="multiple">
71
- <div :class="[ns.e('filter')]">
72
- <el-input v-model="keyword" ref="filterInput" @input="changeKeyword">
73
- <template #prefix>
74
- <ct-icon name="search_line"></ct-icon>
75
- </template>
76
- </el-input>
77
- </div>
78
- <div :class="[ns.e('select')]" v-if="!rawAttr.multipleLimit">
79
- <span :class="[ns.e('select-title')]">
80
- <span v-if="!keyword">已选{{ selectLength }}项</span>
81
- <span v-else>检索结果</span>
82
- </span>
83
- </div>
84
- </div>
85
79
  <slot name="empty">
86
80
  <Empty :text="emptyText" />
87
81
  </slot>
@@ -113,8 +107,23 @@ const attrs = useAttrs();
113
107
 
114
108
  const ns = useNamespace("paging-select");
115
109
  const optionsByApi = ref([]);
110
+ const extraOptions = computed(() => {
111
+ return props.options && Array.isArray(props.options) ? props.options : [];
112
+ });
113
+
116
114
  const showOptions = computed(() => {
117
- return optionsByApi.value;
115
+ const map = new Map();
116
+ (extraOptions.value || []).forEach((item) => {
117
+ if (!item || item.value === undefined || item.value === null) return;
118
+ map.set(item.value, item);
119
+ });
120
+ (optionsByApi.value || []).forEach((item) => {
121
+ if (!item || item.value === undefined || item.value === null) return;
122
+ if (!map.has(item.value)) {
123
+ map.set(item.value, item);
124
+ }
125
+ });
126
+ return Array.from(map.values());
118
127
  });
119
128
  const valueModel = computed({
120
129
  get() {
@@ -203,8 +212,8 @@ watch(
203
212
  selectRef.value.selectedLabel = newVal;
204
213
  },
205
214
  );
206
- watch(optionsByApi, () => {
207
- const arr = optionsByApi.value || [];
215
+ watch(showOptions, () => {
216
+ const arr = showOptions.value || [];
208
217
  if (arr.length) {
209
218
  filterOptions.value = arr;
210
219
  noFilterOptions.value = false;
@@ -235,6 +244,11 @@ const handleListSort = (val) => {
235
244
  }
236
245
  }
237
246
  };
247
+ const dropdownVisible = ref(false);
248
+ const handleVisibleChange = (visible) => {
249
+ dropdownVisible.value = visible;
250
+ handleListSort(visible);
251
+ };
238
252
  const watchServiceHandle = async (reset = false) => {
239
253
  // 通过api获取数据,会监听api以及serviceParams的改变(收集到的依赖改变)都会触发重新查询
240
254
  const cbs = props.cbs || {};
@@ -386,10 +400,15 @@ useBuriedParams(props, emit, {
386
400
  });
387
401
 
388
402
  function filterMethod(val) {
389
- if (props.multiple) {
390
- return; //多选走原有搜索逻辑
391
- }
392
- keyword.value = val;
403
+ if (props.multiple) return; //多选走原有搜索逻辑
404
+ const next = typeof val === "string" ? val : "";
405
+ const nextTrim = next.trim();
406
+ if (!dropdownVisible.value && !nextTrim) return;
407
+ //单选开启 filterable 时, el-select 内部有一套“输入查询”的状态。
408
+ // 下拉收起(点击别处/blur)时,Element Plus 往往会把内部 query 清空,并触发一次 filter-method,
409
+ // 所以这里优化了下拉收起时的查询
410
+ if (nextTrim === keyword.value) return;
411
+ keyword.value = nextTrim;
393
412
  changeKeyword();
394
413
  }
395
414