zartui 2.1.26 → 2.1.28

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