zartui 2.1.26 → 2.1.27

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.
@@ -41,6 +41,10 @@ var _default2 = exports.default = createComponent({
41
41
  return [];
42
42
  }
43
43
  },
44
+ filteredOptions: {
45
+ type: Array,
46
+ default: null
47
+ },
44
48
  toolbarPosition: {
45
49
  type: String,
46
50
  default: 'bottom'
@@ -64,6 +68,8 @@ var _default2 = exports.default = createComponent({
64
68
  }),
65
69
  data: function data() {
66
70
  return {
71
+ selectedValues: [],
72
+ // 基于值的选中状态,用于支持 options 动态变化
67
73
  currentIndexs: [],
68
74
  confirmIndexs: null
69
75
  };
@@ -71,29 +77,64 @@ var _default2 = exports.default = createComponent({
71
77
  watch: {
72
78
  options: {
73
79
  handler: function handler(newOptions) {
74
- // options 变化时,需要过滤掉无效的索引
75
- if (this.confirmIndexs) {
76
- var validIndexs = this.confirmIndexs.filter(function (index) {
77
- return index < newOptions.length;
80
+ var _this = this;
81
+ // options 变化时,基于 selectedValues 重新计算索引
82
+ if (this.selectedValues && this.selectedValues.length > 0) {
83
+ var newIndexs = [];
84
+ newOptions.forEach(function (option, index) {
85
+ var optionValue = _this.getOptionValue(option);
86
+ if (_this.selectedValues.includes(optionValue)) {
87
+ newIndexs.push(index);
88
+ }
78
89
  });
79
- this.confirmIndexs = validIndexs.length > 0 ? validIndexs : null;
80
- this.currentIndexs = validIndexs;
90
+ this.currentIndexs = newIndexs;
91
+ this.confirmIndexs = newIndexs.length > 0 ? newIndexs : null;
81
92
  }
82
93
  },
83
94
  immediate: false
84
95
  },
96
+ filteredOptions: {
97
+ handler: function handler() {
98
+ var _this2 = this;
99
+ // filteredOptions 变化时,需要基于 selectedValues 重新映射到 displayOptions 的索引
100
+ this.$nextTick(function () {
101
+ if (_this2.$refs.pickerOptions) {
102
+ var displayIndexs = [];
103
+ if (_this2.selectedValues && _this2.selectedValues.length > 0) {
104
+ _this2.displayOptions.forEach(function (option, index) {
105
+ var optionValue = _this2.getOptionValue(option);
106
+ if (_this2.selectedValues.includes(optionValue)) {
107
+ displayIndexs.push(index);
108
+ }
109
+ });
110
+ }
111
+ // 强制更新子组件,即使是空数组也要设置
112
+ _this2.$refs.pickerOptions.confirmed = false;
113
+ _this2.$refs.pickerOptions.setConfirmIndex(displayIndexs);
114
+ }
115
+ });
116
+ },
117
+ immediate: false
118
+ },
85
119
  showPicker: {
86
120
  handler: function handler(val) {
87
- var _this = this;
121
+ var _this3 = this;
88
122
  if (val) {
89
123
  this.$nextTick(function () {
90
- if (_this.$refs.pickerOptions && _this.confirmIndexs) {
91
- _this.$refs.pickerOptions.setConfirmIndex(_this.confirmIndexs);
92
- // 同步 currentIndexs 以更新底部全选和已选状态
93
- _this.currentIndexs = [].concat(_this.confirmIndexs);
94
- } else if (!_this.confirmIndexs && _this.defaultIndexs && _this.defaultIndexs.length === 0) {
95
- _this.$refs.pickerOptions.setConfirmIndex([]);
96
- _this.currentIndexs = [];
124
+ if (_this3.$refs.pickerOptions) {
125
+ // 基于 selectedValues 计算在 displayOptions 中的索引
126
+ var displayIndexs = [];
127
+ if (_this3.selectedValues && _this3.selectedValues.length > 0) {
128
+ _this3.displayOptions.forEach(function (option, index) {
129
+ var optionValue = _this3.getOptionValue(option);
130
+ if (_this3.selectedValues.includes(optionValue)) {
131
+ displayIndexs.push(index);
132
+ }
133
+ });
134
+ }
135
+ _this3.$refs.pickerOptions.setConfirmIndex(displayIndexs);
136
+ // 同步 currentIndexs(基于原始 options)
137
+ _this3.currentIndexs = _this3.confirmIndexs || [];
97
138
  }
98
139
  });
99
140
  }
@@ -102,11 +143,32 @@ var _default2 = exports.default = createComponent({
102
143
  }
103
144
  },
104
145
  computed: {
146
+ displayOptions: function displayOptions() {
147
+ return this.filteredOptions || this.options;
148
+ },
105
149
  isAllSelected: function isAllSelected() {
106
- return this.currentIndexs.length > 0 && this.currentIndexs.length === this.options.length;
150
+ var _this4 = this;
151
+ // 判断是否全选应该基于当前显示的 displayOptions
152
+ if (this.displayOptions.length === 0) return false;
153
+ var displayValues = this.displayOptions.map(function (opt) {
154
+ return _this4.getOptionValue(opt);
155
+ });
156
+ var selectedDisplayValues = this.selectedValues.filter(function (val) {
157
+ return displayValues.includes(val);
158
+ });
159
+ return selectedDisplayValues.length > 0 && selectedDisplayValues.length === this.displayOptions.length;
107
160
  },
108
161
  isIndeterminate: function isIndeterminate() {
109
- return this.currentIndexs.length > 0 && this.currentIndexs.length < this.options.length;
162
+ var _this5 = this;
163
+ // 判断半选状态也应该基于当前显示的 displayOptions
164
+ if (this.displayOptions.length === 0) return false;
165
+ var displayValues = this.displayOptions.map(function (opt) {
166
+ return _this5.getOptionValue(opt);
167
+ });
168
+ var selectedDisplayValues = this.selectedValues.filter(function (val) {
169
+ return displayValues.includes(val);
170
+ });
171
+ return selectedDisplayValues.length > 0 && selectedDisplayValues.length < this.displayOptions.length;
110
172
  },
111
173
  itemPxHeight: function itemPxHeight() {
112
174
  return this.itemHeight ? (0, _unit.unitToPx)(this.itemHeight) : _shared.DEFAULT_ITEM_HEIGHT;
@@ -121,21 +183,56 @@ var _default2 = exports.default = createComponent({
121
183
  emit: function emit(event) {
122
184
  this.$emit(event, this.getOptions());
123
185
  },
186
+ getOptionValue: function getOptionValue(option) {
187
+ if (typeof option === 'string' || typeof option === 'number') {
188
+ return option;
189
+ }
190
+ return option[this.valueKey] || JSON.stringify(option);
191
+ },
124
192
  getOptions: function getOptions() {
125
- var _this2 = this;
193
+ var _this6 = this;
126
194
  var indexs = this.$refs.pickerOptions.currentIndexs;
127
195
  var result = [];
196
+ // 从 displayOptions 中获取选中项
128
197
  indexs.forEach(function (index) {
129
- result.push((0, _extends2.default)({}, _this2.options[index], {
130
- initialIndex: index
131
- }));
198
+ var displayOption = _this6.displayOptions[index];
199
+ if (displayOption) {
200
+ // 查找在原始 options 中的索引
201
+ var originalIndex = _this6.options.findIndex(function (opt) {
202
+ return _this6.getOptionValue(opt) === _this6.getOptionValue(displayOption);
203
+ });
204
+ result.push((0, _extends2.default)({}, displayOption, {
205
+ initialIndex: originalIndex >= 0 ? originalIndex : index
206
+ }));
207
+ }
132
208
  });
133
209
  return result;
134
210
  },
135
211
  onChange: function onChange() {
212
+ var _this7 = this;
136
213
  // 同步 currentIndexs 以触发计算属性更新
137
214
  if (this.$refs.pickerOptions) {
138
- this.currentIndexs = [].concat(this.$refs.pickerOptions.currentIndexs);
215
+ // 实时更新 selectedValues,需要合并而不是覆盖
216
+ var displayOptions = this.getOptions();
217
+ var displayValues = displayOptions.map(function (v) {
218
+ return _this7.getOptionValue(v);
219
+ });
220
+ var displayAllValues = this.displayOptions.map(function (opt) {
221
+ return _this7.getOptionValue(opt);
222
+ });
223
+
224
+ // 移除当前显示列表中的所有值(无论是否选中),然后添加当前选中的值
225
+ this.selectedValues = [].concat(this.selectedValues.filter(function (val) {
226
+ return !displayAllValues.includes(val);
227
+ }), displayValues);
228
+
229
+ // 基于 selectedValues 更新 currentIndexs(用于显示已选数量)
230
+ this.currentIndexs = [];
231
+ this.options.forEach(function (option, index) {
232
+ if (_this7.selectedValues.includes(_this7.getOptionValue(option))) {
233
+ _this7.currentIndexs.push(index);
234
+ }
235
+ });
139
236
  }
140
237
  this.$emit('change', this.getOptions());
141
238
  },
@@ -144,32 +241,96 @@ var _default2 = exports.default = createComponent({
144
241
  this.emit('cancel');
145
242
  },
146
243
  confirm: function confirm() {
147
- var options = this.getOptions();
148
- this.confirmIndexs = options.map(function (v) {
244
+ var _this8 = this;
245
+ // 返回所有已选的数据,而不仅仅是当前显示的
246
+ var allSelectedOptions = [];
247
+ this.selectedValues.forEach(function (value) {
248
+ var option = _this8.options.find(function (opt) {
249
+ return _this8.getOptionValue(opt) === value;
250
+ });
251
+ if (option) {
252
+ var originalIndex = _this8.options.findIndex(function (opt) {
253
+ return _this8.getOptionValue(opt) === value;
254
+ });
255
+ allSelectedOptions.push((0, _extends2.default)({}, option, {
256
+ initialIndex: originalIndex
257
+ }));
258
+ }
259
+ });
260
+ this.confirmIndexs = allSelectedOptions.map(function (v) {
149
261
  return v.initialIndex;
150
262
  });
151
- this.emit('confirm', options);
263
+ this.$emit('confirm', allSelectedOptions);
152
264
  },
153
265
  handleSelectAll: function handleSelectAll() {
154
- var newIndexs = !this.isAllSelected ? this.options && this.options.map(function (_, index) {
155
- return index;
156
- }) : [];
157
- this.currentIndexs = newIndexs;
158
- if (this.$refs.pickerOptions) {
159
- this.$refs.pickerOptions.setConfirmIndex(newIndexs);
266
+ var _this9 = this;
267
+ // 全选应该基于当前显示的 displayOptions,只选中当前搜索结果
268
+ var displayValues = this.displayOptions.map(function (opt) {
269
+ return _this9.getOptionValue(opt);
270
+ });
271
+ if (!this.isAllSelected) {
272
+ // 全选:只选中当前显示的值,清除其他值
273
+ this.selectedValues = displayValues;
274
+
275
+ // 更新 currentIndexs(基于原始 options)
276
+ this.currentIndexs = [];
277
+ this.options.forEach(function (option, index) {
278
+ if (displayValues.includes(_this9.getOptionValue(option))) {
279
+ _this9.currentIndexs.push(index);
280
+ }
281
+ });
282
+
283
+ // 设置子组件索引(基于 displayOptions,全选所有显示项)
284
+ var displayIndexs = this.displayOptions.map(function (_, index) {
285
+ return index;
286
+ });
287
+ if (this.$refs.pickerOptions) {
288
+ this.$refs.pickerOptions.setConfirmIndex(displayIndexs);
289
+ }
290
+ } else {
291
+ // 取消全选:清空所有选中
292
+ this.selectedValues = [];
293
+ this.currentIndexs = [];
294
+ if (this.$refs.pickerOptions) {
295
+ this.$refs.pickerOptions.setConfirmIndex([]);
296
+ }
160
297
  }
161
298
  },
162
299
  onSelectOther: function onSelectOther() {
163
- var _this3 = this;
164
- var newIndexs = [];
165
- this.options && this.options.forEach(function (_, index) {
166
- if (!_this3.currentIndexs.includes(index)) {
167
- newIndexs.push(index);
300
+ var _this10 = this;
301
+ // 反选应该基于当前显示的 displayOptions,只操作当前搜索结果
302
+ var displayValues = this.displayOptions.map(function (opt) {
303
+ return _this10.getOptionValue(opt);
304
+ });
305
+
306
+ // 计算当前显示项中未选中的值
307
+ var displaySelectedValues = this.selectedValues.filter(function (val) {
308
+ return displayValues.includes(val);
309
+ });
310
+ var displayUnselectedValues = displayValues.filter(function (val) {
311
+ return !displaySelectedValues.includes(val);
312
+ });
313
+
314
+ // 只保留当前显示列表中未选中的项(反选逻辑)
315
+ this.selectedValues = displayUnselectedValues;
316
+
317
+ // 更新 currentIndexs(基于原始 options)
318
+ this.currentIndexs = [];
319
+ this.options.forEach(function (option, index) {
320
+ if (displayUnselectedValues.includes(_this10.getOptionValue(option))) {
321
+ _this10.currentIndexs.push(index);
322
+ }
323
+ });
324
+
325
+ // 映射到 displayOptions 的索引(反选后的状态)
326
+ var displayIndexs = [];
327
+ this.displayOptions.forEach(function (option, index) {
328
+ if (displayUnselectedValues.includes(_this10.getOptionValue(option))) {
329
+ displayIndexs.push(index);
168
330
  }
169
331
  });
170
- this.currentIndexs = newIndexs;
171
332
  if (this.$refs.pickerOptions) {
172
- this.$refs.pickerOptions.setConfirmIndex(newIndexs);
333
+ this.$refs.pickerOptions.setConfirmIndex(displayIndexs);
173
334
  }
174
335
  },
175
336
  genTitle: function genTitle() {
@@ -283,18 +444,19 @@ var _default2 = exports.default = createComponent({
283
444
  }, [this.genOptionItems()]);
284
445
  },
285
446
  genOptionItems: function genOptionItems() {
286
- var _this4 = this;
447
+ var _this11 = this;
287
448
  var h = this.$createElement;
288
449
  var formatOptions = [];
289
- if (this.options && this.options[0] && typeof this.options[0] !== 'object') {
290
- formatOptions = this.options.map(function (v) {
450
+ var sourceOptions = this.displayOptions;
451
+ if (sourceOptions && sourceOptions[0] && typeof sourceOptions[0] !== 'object') {
452
+ formatOptions = sourceOptions.map(function (v) {
291
453
  return {
292
454
  value: v,
293
455
  text: v
294
456
  };
295
457
  });
296
458
  } else {
297
- formatOptions = this.options;
459
+ formatOptions = sourceOptions;
298
460
  }
299
461
  return h(_MultiplePickerOptions.default, {
300
462
  "ref": "pickerOptions",
@@ -312,7 +474,7 @@ var _default2 = exports.default = createComponent({
312
474
  },
313
475
  "on": {
314
476
  "change": function change() {
315
- _this4.onChange();
477
+ _this11.onChange();
316
478
  }
317
479
  }
318
480
  });