sadais-piui 1.2.7-beta79 → 1.2.7-beta80

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.
@@ -101,7 +101,9 @@
101
101
  class="cascader-item"
102
102
  @tap="handleRemoveItem(id)"
103
103
  >
104
- <text class="pi-mg-right-12">{{ itemsMap[id][displayField] }}</text>
104
+ <text class="pi-mg-right-12">
105
+ {{ itemsMap && itemsMap[id] && itemsMap[id][displayField] }}
106
+ </text>
105
107
  <pi-icon name="close" />
106
108
  </view>
107
109
  </scroll-view>
@@ -154,7 +156,7 @@ export default {
154
156
  }
155
157
  },
156
158
  defaultValue: {
157
- type: Array,
159
+ type: [Array, String, Number],
158
160
  default: () => []
159
161
  },
160
162
  // 列表选项的唯一标识
@@ -181,6 +183,12 @@ export default {
181
183
  // false
182
184
  default: cascader.parentCanSelect
183
185
  },
186
+ // 是否单选(默认:'false')
187
+ isSingle: {
188
+ type: Boolean,
189
+ // false
190
+ default: cascader.isSingle
191
+ },
184
192
  // 弹窗选择参数设置
185
193
  popupSelect: {
186
194
  type: Object,
@@ -313,7 +321,7 @@ export default {
313
321
  defaultValue: {
314
322
  immediate: true,
315
323
  handler(vals) {
316
- this.selectedIds = [...vals]
324
+ this.selectedIds = this.isSingle ? [vals] : vals
317
325
  }
318
326
  }
319
327
  },
@@ -363,12 +371,19 @@ export default {
363
371
  this.innerItems = innerItems
364
372
  // 方便通过节点的id 为key快速定位到对应的节点dto
365
373
  this.itemsMap = itemsMap
374
+ if (this.currentItem[this.keyField] === ROOT_NODE) {
375
+ if (this.isSingle && this.defaultValue) {
376
+ this.currentItem = this.getItemByKeyField(this.defaultValue)
377
+ }
378
+ if (!this.isSingle && this.defaultValue.length > 0) {
379
+ this.currentItem = this.getItemByKeyField(this.defaultValue[0])
380
+ }
381
+ }
366
382
  },
367
383
  handleRemoveItem(id) {
368
384
  this.selectedIds = this.selectedIds.filter(i => i !== id)
369
385
  },
370
386
  handleClickItem(item) {
371
- console.log(item)
372
387
  // 点击全部
373
388
  if (item[this.keyField] === ROOT_NODE) {
374
389
  this.currentItem = cloneDeep(this.rootItem)
@@ -388,7 +403,11 @@ export default {
388
403
  this.handleRemoveItem(item[this.keyField])
389
404
  } else {
390
405
  // 选中
391
- this.selectedIds.push(item[this.keyField])
406
+ if (this.isSingle) {
407
+ this.selectedIds = [item[this.keyField]]
408
+ } else {
409
+ this.selectedIds.push(item[this.keyField])
410
+ }
392
411
  }
393
412
  }
394
413
  },
@@ -433,7 +452,7 @@ export default {
433
452
  */
434
453
  handleCancel() {
435
454
  this.$emit('cancel')
436
- this.selectedIds = [...this.defaultValue]
455
+ this.selectedIds = this.isSingle ? [this.defaultValue] : [...this.defaultValue]
437
456
  this.getPopupSelect.onCancelClose && this.handlePopupClose()
438
457
  },
439
458
  /**
@@ -441,7 +460,7 @@ export default {
441
460
  * 确认选择
442
461
  */
443
462
  handleConfirm() {
444
- this.$emit('confirm', this.selectedIds)
463
+ this.$emit('confirm', this.isSingle ? this.selectedIds[0] || '' : this.selectedIds)
445
464
  this.getPopupSelect.onConfirmClose && this.handlePopupClose()
446
465
  }
447
466
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta79",
3
+ "version": "1.2.7-beta80",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {