zartui 2.1.25 → 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,23 +68,73 @@ 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
  };
70
76
  },
71
77
  watch: {
78
+ options: {
79
+ handler: function handler(newOptions) {
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
+ }
89
+ });
90
+ this.currentIndexs = newIndexs;
91
+ this.confirmIndexs = newIndexs.length > 0 ? newIndexs : null;
92
+ }
93
+ },
94
+ immediate: false
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
+ },
72
119
  showPicker: {
73
120
  handler: function handler(val) {
74
- var _this = this;
121
+ var _this3 = this;
75
122
  if (val) {
76
123
  this.$nextTick(function () {
77
- if (_this.$refs.pickerOptions && _this.confirmIndexs) {
78
- _this.$refs.pickerOptions.setConfirmIndex(_this.confirmIndexs);
79
- // 同步 currentIndexs 以更新底部全选和已选状态
80
- _this.currentIndexs = [].concat(_this.confirmIndexs);
81
- } else if (!_this.confirmIndexs && _this.defaultIndexs && _this.defaultIndexs.length === 0) {
82
- _this.$refs.pickerOptions.setConfirmIndex([]);
83
- _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 || [];
84
138
  }
85
139
  });
86
140
  }
@@ -89,11 +143,32 @@ var _default2 = exports.default = createComponent({
89
143
  }
90
144
  },
91
145
  computed: {
146
+ displayOptions: function displayOptions() {
147
+ return this.filteredOptions || this.options;
148
+ },
92
149
  isAllSelected: function isAllSelected() {
93
- 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;
94
160
  },
95
161
  isIndeterminate: function isIndeterminate() {
96
- 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;
97
172
  },
98
173
  itemPxHeight: function itemPxHeight() {
99
174
  return this.itemHeight ? (0, _unit.unitToPx)(this.itemHeight) : _shared.DEFAULT_ITEM_HEIGHT;
@@ -108,21 +183,56 @@ var _default2 = exports.default = createComponent({
108
183
  emit: function emit(event) {
109
184
  this.$emit(event, this.getOptions());
110
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
+ },
111
192
  getOptions: function getOptions() {
112
- var _this2 = this;
193
+ var _this6 = this;
113
194
  var indexs = this.$refs.pickerOptions.currentIndexs;
114
195
  var result = [];
196
+ // 从 displayOptions 中获取选中项
115
197
  indexs.forEach(function (index) {
116
- result.push((0, _extends2.default)({}, _this2.options[index], {
117
- initialIndex: index
118
- }));
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
+ }
119
208
  });
120
209
  return result;
121
210
  },
122
211
  onChange: function onChange() {
212
+ var _this7 = this;
123
213
  // 同步 currentIndexs 以触发计算属性更新
124
214
  if (this.$refs.pickerOptions) {
125
- 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
+ });
126
236
  }
127
237
  this.$emit('change', this.getOptions());
128
238
  },
@@ -131,32 +241,96 @@ var _default2 = exports.default = createComponent({
131
241
  this.emit('cancel');
132
242
  },
133
243
  confirm: function confirm() {
134
- var options = this.getOptions();
135
- 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) {
136
261
  return v.initialIndex;
137
262
  });
138
- this.emit('confirm', options);
263
+ this.$emit('confirm', allSelectedOptions);
139
264
  },
140
265
  handleSelectAll: function handleSelectAll() {
141
- var newIndexs = !this.isAllSelected ? this.options && this.options.map(function (_, index) {
142
- return index;
143
- }) : [];
144
- this.currentIndexs = newIndexs;
145
- if (this.$refs.pickerOptions) {
146
- 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
+ }
147
297
  }
148
298
  },
149
299
  onSelectOther: function onSelectOther() {
150
- var _this3 = this;
151
- var newIndexs = [];
152
- this.options && this.options.forEach(function (_, index) {
153
- if (!_this3.currentIndexs.includes(index)) {
154
- 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);
155
330
  }
156
331
  });
157
- this.currentIndexs = newIndexs;
158
332
  if (this.$refs.pickerOptions) {
159
- this.$refs.pickerOptions.setConfirmIndex(newIndexs);
333
+ this.$refs.pickerOptions.setConfirmIndex(displayIndexs);
160
334
  }
161
335
  },
162
336
  genTitle: function genTitle() {
@@ -270,18 +444,19 @@ var _default2 = exports.default = createComponent({
270
444
  }, [this.genOptionItems()]);
271
445
  },
272
446
  genOptionItems: function genOptionItems() {
273
- var _this4 = this;
447
+ var _this11 = this;
274
448
  var h = this.$createElement;
275
449
  var formatOptions = [];
276
- if (this.options && this.options[0] && typeof this.options[0] !== 'object') {
277
- 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) {
278
453
  return {
279
454
  value: v,
280
455
  text: v
281
456
  };
282
457
  });
283
458
  } else {
284
- formatOptions = this.options;
459
+ formatOptions = sourceOptions;
285
460
  }
286
461
  return h(_MultiplePickerOptions.default, {
287
462
  "ref": "pickerOptions",
@@ -299,7 +474,7 @@ var _default2 = exports.default = createComponent({
299
474
  },
300
475
  "on": {
301
476
  "change": function change() {
302
- _this4.onChange();
477
+ _this11.onChange();
303
478
  }
304
479
  }
305
480
  });