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.
package/es/index.js CHANGED
@@ -76,7 +76,7 @@ import TextEllipsis from './text-ellipsis';
76
76
  import Timeline from './timeline';
77
77
  import Toast from './toast';
78
78
  import Uploader from './uploader';
79
- var version = '2.1.26';
79
+ var version = '2.1.28';
80
80
  function install(Vue) {
81
81
  var components = [ActionSheet, Area, Avatar, BackTop, Badge, Button, Calendar, Cascader, Cell, CellGroup, Checkbox, CheckboxGroup, Col, Collapse, CollapseItem, CountDown, DatetimePicker, Dialog, Divider, DropdownItem, DropdownMenu, Empty, Field, FoldDialog, Form, Grid, GridItem, HierarchySelect, Icon, Image, ImagePreview, IndexAnchor, IndexBar, Info, Lazyload, List, Loading, Locale, MediaPicker, MediaPlayer, MultiplePicker, NavBar, NoticeBar, NumberKeyboard, Overlay, PasswordInput, Picker, Popover, Popup, PullRefresh, Radio, RadioGroup, Rate, Row, Search, Signature, Skeleton, Slider, SpeechRecognizer, Step, Stepper, Steps, Sticky, Swipe, SwipeCell, SwipeItem, Switch, SwitchCell, Tab, Tabbar, TabbarItem, Table, Tabs, Tag, TextEllipsis, Timeline, Toast, Uploader];
82
82
  components.forEach(function (item) {
@@ -54,10 +54,19 @@ export default createComponent({
54
54
  methods: {
55
55
  setOptions: function setOptions(options) {
56
56
  if (JSON.stringify(options) !== JSON.stringify(this.options)) {
57
+ // 保存当前的 confirmed 状态
58
+ var wasConfirmed = this.confirmed;
57
59
  this.options = deepClone(options);
58
- // 当 options 变化时,需要重置 confirmed 状态,允许重新设置索引
59
- this.confirmed = false;
60
- this.setDefaultIndexs();
60
+
61
+ // 如果已经确认过选择,保持 confirmed 状态
62
+ if (wasConfirmed) {
63
+ // options 变化后,currentIndexs 会由父组件通过 setConfirmIndex 重新设置
64
+ // 这里不做任何操作,等待父组件更新
65
+ } else {
66
+ // 未确认时才重置状态
67
+ this.confirmed = false;
68
+ this.setDefaultIndexs();
69
+ }
61
70
  }
62
71
  },
63
72
  setDefaultIndexs: function setDefaultIndexs() {
@@ -34,6 +34,10 @@ export default createComponent({
34
34
  return [];
35
35
  }
36
36
  },
37
+ filteredOptions: {
38
+ type: Array,
39
+ default: null
40
+ },
37
41
  toolbarPosition: {
38
42
  type: String,
39
43
  default: 'bottom'
@@ -57,6 +61,10 @@ export default createComponent({
57
61
  }),
58
62
  data: function data() {
59
63
  return {
64
+ selectedValues: [],
65
+ // 基于值的选中状态,用于支持 options 动态变化
66
+ confirmedSelectedValues: [],
67
+ // 上次确认时的 selectedValues,用于取消时恢复
60
68
  currentIndexs: [],
61
69
  confirmIndexs: null
62
70
  };
@@ -64,29 +72,68 @@ export default createComponent({
64
72
  watch: {
65
73
  options: {
66
74
  handler: function handler(newOptions) {
67
- // options 变化时,需要过滤掉无效的索引
68
- if (this.confirmIndexs) {
69
- var validIndexs = this.confirmIndexs.filter(function (index) {
70
- return index < newOptions.length;
75
+ var _this = this;
76
+ // options 变化时,基于 selectedValues 重新计算索引
77
+ if (this.selectedValues && this.selectedValues.length > 0) {
78
+ var newIndexs = [];
79
+ newOptions.forEach(function (option, index) {
80
+ var optionValue = _this.getOptionValue(option);
81
+ if (_this.selectedValues.includes(optionValue)) {
82
+ newIndexs.push(index);
83
+ }
71
84
  });
72
- this.confirmIndexs = validIndexs.length > 0 ? validIndexs : null;
73
- this.currentIndexs = validIndexs;
85
+ this.currentIndexs = newIndexs;
86
+ this.confirmIndexs = newIndexs.length > 0 ? newIndexs : null;
74
87
  }
75
88
  },
76
89
  immediate: false
77
90
  },
91
+ filteredOptions: {
92
+ handler: function handler() {
93
+ var _this2 = this;
94
+ // filteredOptions 变化时,需要基于 selectedValues 重新映射到 displayOptions 的索引
95
+ this.$nextTick(function () {
96
+ if (_this2.$refs.pickerOptions) {
97
+ var displayIndexs = [];
98
+ if (_this2.selectedValues && _this2.selectedValues.length > 0) {
99
+ _this2.displayOptions.forEach(function (option, index) {
100
+ var optionValue = _this2.getOptionValue(option);
101
+ if (_this2.selectedValues.includes(optionValue)) {
102
+ displayIndexs.push(index);
103
+ }
104
+ });
105
+ }
106
+ // 强制更新子组件,即使是空数组也要设置
107
+ _this2.$refs.pickerOptions.confirmed = false;
108
+ _this2.$refs.pickerOptions.setConfirmIndex(displayIndexs);
109
+ }
110
+ });
111
+ },
112
+ immediate: false
113
+ },
78
114
  showPicker: {
79
115
  handler: function handler(val) {
80
- var _this = this;
116
+ var _this3 = this;
81
117
  if (val) {
82
118
  this.$nextTick(function () {
83
- if (_this.$refs.pickerOptions && _this.confirmIndexs) {
84
- _this.$refs.pickerOptions.setConfirmIndex(_this.confirmIndexs);
85
- // 同步 currentIndexs 以更新底部全选和已选状态
86
- _this.currentIndexs = [].concat(_this.confirmIndexs);
87
- } else if (!_this.confirmIndexs && _this.defaultIndexs && _this.defaultIndexs.length === 0) {
88
- _this.$refs.pickerOptions.setConfirmIndex([]);
89
- _this.currentIndexs = [];
119
+ if (_this3.$refs.pickerOptions) {
120
+ // 基于 selectedValues 计算在 displayOptions 中的索引
121
+ var displayIndexs = [];
122
+ if (_this3.selectedValues && _this3.selectedValues.length > 0) {
123
+ _this3.displayOptions.forEach(function (option, index) {
124
+ var optionValue = _this3.getOptionValue(option);
125
+ if (_this3.selectedValues.includes(optionValue)) {
126
+ displayIndexs.push(index);
127
+ }
128
+ });
129
+ }
130
+
131
+ // 弹出时直接设置 currentIndexs,不调用 setConfirmIndex,保持未确认状态
132
+ _this3.$refs.pickerOptions.confirmed = false;
133
+ _this3.$refs.pickerOptions.currentIndexs = displayIndexs;
134
+
135
+ // 同步 currentIndexs(基于原始 options)
136
+ _this3.currentIndexs = _this3.confirmIndexs || [];
90
137
  }
91
138
  });
92
139
  }
@@ -95,11 +142,32 @@ export default createComponent({
95
142
  }
96
143
  },
97
144
  computed: {
145
+ displayOptions: function displayOptions() {
146
+ return this.filteredOptions || this.options;
147
+ },
98
148
  isAllSelected: function isAllSelected() {
99
- return this.currentIndexs.length > 0 && this.currentIndexs.length === this.options.length;
149
+ var _this4 = this;
150
+ // 判断是否全选应该基于当前显示的 displayOptions
151
+ if (this.displayOptions.length === 0) return false;
152
+ var displayValues = this.displayOptions.map(function (opt) {
153
+ return _this4.getOptionValue(opt);
154
+ });
155
+ var selectedDisplayValues = this.selectedValues.filter(function (val) {
156
+ return displayValues.includes(val);
157
+ });
158
+ return selectedDisplayValues.length > 0 && selectedDisplayValues.length === this.displayOptions.length;
100
159
  },
101
160
  isIndeterminate: function isIndeterminate() {
102
- return this.currentIndexs.length > 0 && this.currentIndexs.length < this.options.length;
161
+ var _this5 = this;
162
+ // 判断半选状态也应该基于当前显示的 displayOptions
163
+ if (this.displayOptions.length === 0) return false;
164
+ var displayValues = this.displayOptions.map(function (opt) {
165
+ return _this5.getOptionValue(opt);
166
+ });
167
+ var selectedDisplayValues = this.selectedValues.filter(function (val) {
168
+ return displayValues.includes(val);
169
+ });
170
+ return selectedDisplayValues.length > 0 && selectedDisplayValues.length < this.displayOptions.length;
103
171
  },
104
172
  itemPxHeight: function itemPxHeight() {
105
173
  return this.itemHeight ? unitToPx(this.itemHeight) : DEFAULT_ITEM_HEIGHT;
@@ -114,55 +182,167 @@ export default createComponent({
114
182
  emit: function emit(event) {
115
183
  this.$emit(event, this.getOptions());
116
184
  },
185
+ getOptionValue: function getOptionValue(option) {
186
+ if (typeof option === 'string' || typeof option === 'number') {
187
+ return option;
188
+ }
189
+ return option[this.valueKey] || JSON.stringify(option);
190
+ },
117
191
  getOptions: function getOptions() {
118
- var _this2 = this;
192
+ var _this6 = this;
119
193
  var indexs = this.$refs.pickerOptions.currentIndexs;
120
194
  var result = [];
195
+ // 从 displayOptions 中获取选中项
121
196
  indexs.forEach(function (index) {
122
- result.push(_extends({}, _this2.options[index], {
123
- initialIndex: index
124
- }));
197
+ var displayOption = _this6.displayOptions[index];
198
+ if (displayOption) {
199
+ // 查找在原始 options 中的索引
200
+ var originalIndex = _this6.options.findIndex(function (opt) {
201
+ return _this6.getOptionValue(opt) === _this6.getOptionValue(displayOption);
202
+ });
203
+ result.push(_extends({}, displayOption, {
204
+ initialIndex: originalIndex >= 0 ? originalIndex : index
205
+ }));
206
+ }
125
207
  });
126
208
  return result;
127
209
  },
128
210
  onChange: function onChange() {
211
+ var _this7 = this;
129
212
  // 同步 currentIndexs 以触发计算属性更新
130
213
  if (this.$refs.pickerOptions) {
131
- this.currentIndexs = [].concat(this.$refs.pickerOptions.currentIndexs);
214
+ // 实时更新 selectedValues,需要合并而不是覆盖
215
+ var displayOptions = this.getOptions();
216
+ var displayValues = displayOptions.map(function (v) {
217
+ return _this7.getOptionValue(v);
218
+ });
219
+ var displayAllValues = this.displayOptions.map(function (opt) {
220
+ return _this7.getOptionValue(opt);
221
+ });
222
+
223
+ // 移除当前显示列表中的所有值(无论是否选中),然后添加当前选中的值
224
+ this.selectedValues = [].concat(this.selectedValues.filter(function (val) {
225
+ return !displayAllValues.includes(val);
226
+ }), displayValues);
227
+
228
+ // 基于 selectedValues 更新 currentIndexs(用于显示已选数量)
229
+ this.currentIndexs = [];
230
+ this.options.forEach(function (option, index) {
231
+ if (_this7.selectedValues.includes(_this7.getOptionValue(option))) {
232
+ _this7.currentIndexs.push(index);
233
+ }
234
+ });
132
235
  }
133
236
  this.$emit('change', this.getOptions());
134
237
  },
135
238
  cancel: function cancel() {
239
+ var _this8 = this;
240
+ // 取消时恢复到上次确认的状态
241
+ this.selectedValues = [].concat(this.confirmedSelectedValues);
242
+
243
+ // 重新计算 currentIndexs
244
+ this.currentIndexs = [];
245
+ this.options.forEach(function (option, index) {
246
+ if (_this8.selectedValues.includes(_this8.getOptionValue(option))) {
247
+ _this8.currentIndexs.push(index);
248
+ }
249
+ });
136
250
  this.$emit('update:showPicker', false);
137
251
  this.emit('cancel');
138
252
  },
139
253
  confirm: function confirm() {
140
- var options = this.getOptions();
141
- this.confirmIndexs = options.map(function (v) {
254
+ var _this9 = this;
255
+ // 返回所有已选的数据,而不仅仅是当前显示的
256
+ var allSelectedOptions = [];
257
+ this.selectedValues.forEach(function (value) {
258
+ var option = _this9.options.find(function (opt) {
259
+ return _this9.getOptionValue(opt) === value;
260
+ });
261
+ if (option) {
262
+ var originalIndex = _this9.options.findIndex(function (opt) {
263
+ return _this9.getOptionValue(opt) === value;
264
+ });
265
+ allSelectedOptions.push(_extends({}, option, {
266
+ initialIndex: originalIndex
267
+ }));
268
+ }
269
+ });
270
+ this.confirmIndexs = allSelectedOptions.map(function (v) {
142
271
  return v.initialIndex;
143
272
  });
144
- this.emit('confirm', options);
273
+ // 确认时保存当前的 selectedValues
274
+ this.confirmedSelectedValues = [].concat(this.selectedValues);
275
+ this.$emit('confirm', allSelectedOptions);
145
276
  },
146
277
  handleSelectAll: function handleSelectAll() {
147
- var newIndexs = !this.isAllSelected ? this.options && this.options.map(function (_, index) {
148
- return index;
149
- }) : [];
150
- this.currentIndexs = newIndexs;
151
- if (this.$refs.pickerOptions) {
152
- this.$refs.pickerOptions.setConfirmIndex(newIndexs);
278
+ var _this10 = this;
279
+ // 全选应该基于当前显示的 displayOptions,只选中当前搜索结果
280
+ var displayValues = this.displayOptions.map(function (opt) {
281
+ return _this10.getOptionValue(opt);
282
+ });
283
+ if (!this.isAllSelected) {
284
+ // 全选:只选中当前显示的值,清除其他值
285
+ this.selectedValues = displayValues;
286
+
287
+ // 更新 currentIndexs(基于原始 options)
288
+ this.currentIndexs = [];
289
+ this.options.forEach(function (option, index) {
290
+ if (displayValues.includes(_this10.getOptionValue(option))) {
291
+ _this10.currentIndexs.push(index);
292
+ }
293
+ });
294
+
295
+ // 设置子组件索引(基于 displayOptions,全选所有显示项)
296
+ var displayIndexs = this.displayOptions.map(function (_, index) {
297
+ return index;
298
+ });
299
+ if (this.$refs.pickerOptions) {
300
+ this.$refs.pickerOptions.setConfirmIndex(displayIndexs);
301
+ }
302
+ } else {
303
+ // 取消全选:清空所有选中
304
+ this.selectedValues = [];
305
+ this.currentIndexs = [];
306
+ if (this.$refs.pickerOptions) {
307
+ this.$refs.pickerOptions.setConfirmIndex([]);
308
+ }
153
309
  }
154
310
  },
155
311
  onSelectOther: function onSelectOther() {
156
- var _this3 = this;
157
- var newIndexs = [];
158
- this.options && this.options.forEach(function (_, index) {
159
- if (!_this3.currentIndexs.includes(index)) {
160
- newIndexs.push(index);
312
+ var _this11 = this;
313
+ // 反选应该基于当前显示的 displayOptions,只操作当前搜索结果
314
+ var displayValues = this.displayOptions.map(function (opt) {
315
+ return _this11.getOptionValue(opt);
316
+ });
317
+
318
+ // 计算当前显示项中未选中的值
319
+ var displaySelectedValues = this.selectedValues.filter(function (val) {
320
+ return displayValues.includes(val);
321
+ });
322
+ var displayUnselectedValues = displayValues.filter(function (val) {
323
+ return !displaySelectedValues.includes(val);
324
+ });
325
+
326
+ // 只保留当前显示列表中未选中的项(反选逻辑)
327
+ this.selectedValues = displayUnselectedValues;
328
+
329
+ // 更新 currentIndexs(基于原始 options)
330
+ this.currentIndexs = [];
331
+ this.options.forEach(function (option, index) {
332
+ if (displayUnselectedValues.includes(_this11.getOptionValue(option))) {
333
+ _this11.currentIndexs.push(index);
334
+ }
335
+ });
336
+
337
+ // 映射到 displayOptions 的索引(反选后的状态)
338
+ var displayIndexs = [];
339
+ this.displayOptions.forEach(function (option, index) {
340
+ if (displayUnselectedValues.includes(_this11.getOptionValue(option))) {
341
+ displayIndexs.push(index);
161
342
  }
162
343
  });
163
- this.currentIndexs = newIndexs;
164
344
  if (this.$refs.pickerOptions) {
165
- this.$refs.pickerOptions.setConfirmIndex(newIndexs);
345
+ this.$refs.pickerOptions.setConfirmIndex(displayIndexs);
166
346
  }
167
347
  },
168
348
  genTitle: function genTitle() {
@@ -276,18 +456,19 @@ export default createComponent({
276
456
  }, [this.genOptionItems()]);
277
457
  },
278
458
  genOptionItems: function genOptionItems() {
279
- var _this4 = this;
459
+ var _this12 = this;
280
460
  var h = this.$createElement;
281
461
  var formatOptions = [];
282
- if (this.options && this.options[0] && typeof this.options[0] !== 'object') {
283
- formatOptions = this.options.map(function (v) {
462
+ var sourceOptions = this.displayOptions;
463
+ if (sourceOptions && sourceOptions[0] && typeof sourceOptions[0] !== 'object') {
464
+ formatOptions = sourceOptions.map(function (v) {
284
465
  return {
285
466
  value: v,
286
467
  text: v
287
468
  };
288
469
  });
289
470
  } else {
290
- formatOptions = this.options;
471
+ formatOptions = sourceOptions;
291
472
  }
292
473
  return h(MultiplePickerOptions, {
293
474
  "ref": "pickerOptions",
@@ -305,7 +486,7 @@ export default createComponent({
305
486
  },
306
487
  "on": {
307
488
  "change": function change() {
308
- _this4.onChange();
489
+ _this12.onChange();
309
490
  }
310
491
  }
311
492
  });
package/lib/index.js CHANGED
@@ -161,7 +161,7 @@ var _toast = _interopRequireDefault(require("./toast"));
161
161
  exports.Toast = _toast.default;
162
162
  var _uploader = _interopRequireDefault(require("./uploader"));
163
163
  exports.Uploader = _uploader.default;
164
- var version = exports.version = '2.1.26';
164
+ var version = exports.version = '2.1.28';
165
165
  function install(Vue) {
166
166
  var components = [_actionSheet.default, _area.default, _avatar.default, _backTop.default, _badge.default, _button.default, _calendar.default, _cascader.default, _cell.default, _cellGroup.default, _checkbox.default, _checkboxGroup.default, _col.default, _collapse.default, _collapseItem.default, _countDown.default, _datetimePicker.default, _dialog.default, _divider.default, _dropdownItem.default, _dropdownMenu.default, _empty.default, _field.default, _foldDialog.default, _form.default, _grid.default, _gridItem.default, _hierarchySelect.default, _icon.default, _image.default, _imagePreview.default, _indexAnchor.default, _indexBar.default, _info.default, _lazyload.default, _list.default, _loading.default, _locale.default, _mediaPicker.default, _mediaPlayer.default, _multiplePicker.default, _navBar.default, _noticeBar.default, _numberKeyboard.default, _overlay.default, _passwordInput.default, _picker.default, _popover.default, _popup.default, _pullRefresh.default, _radio.default, _radioGroup.default, _rate.default, _row.default, _search.default, _signature.default, _skeleton.default, _slider.default, _speechRecognizer.default, _step.default, _stepper.default, _steps.default, _sticky.default, _swipe.default, _swipeCell.default, _swipeItem.default, _switch.default, _switchCell.default, _tab.default, _tabbar.default, _tabbarItem.default, _table.default, _tabs.default, _tag.default, _textEllipsis.default, _timeline.default, _toast.default, _uploader.default];
167
167
  components.forEach(function (item) {
@@ -59,10 +59,19 @@ var _default2 = exports.default = createComponent({
59
59
  methods: {
60
60
  setOptions: function setOptions(options) {
61
61
  if (JSON.stringify(options) !== JSON.stringify(this.options)) {
62
+ // 保存当前的 confirmed 状态
63
+ var wasConfirmed = this.confirmed;
62
64
  this.options = (0, _deepClone.deepClone)(options);
63
- // 当 options 变化时,需要重置 confirmed 状态,允许重新设置索引
64
- this.confirmed = false;
65
- this.setDefaultIndexs();
65
+
66
+ // 如果已经确认过选择,保持 confirmed 状态
67
+ if (wasConfirmed) {
68
+ // options 变化后,currentIndexs 会由父组件通过 setConfirmIndex 重新设置
69
+ // 这里不做任何操作,等待父组件更新
70
+ } else {
71
+ // 未确认时才重置状态
72
+ this.confirmed = false;
73
+ this.setDefaultIndexs();
74
+ }
66
75
  }
67
76
  },
68
77
  setDefaultIndexs: function setDefaultIndexs() {