vue2-client 1.6.4 → 1.6.5

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.
@@ -406,12 +406,22 @@ export default {
406
406
  if (this.attr.keyName && this.attr.keyName.indexOf('logic@') !== -1) {
407
407
  this.getData({}, res => {
408
408
  this.option = res
409
+ // 修改时恢复树形选择框选中状态
410
+ if (this.attr.type === 'treeSelect' && this.attr.queryType !== 'RIGHT_LIKE') {
411
+ const value = this.form[this.attr.model]
412
+ if (value) {
413
+ // 如果数据源中值含'-',代表是由多个数据源组成的树,需要重新组织新增/编辑时的表单值
414
+ if (this.option.length > 0 && this.option[0].value.indexOf('-') !== -1) {
415
+ this.treeSelectValue = this.attr.model + '-' + value
416
+ } else {
417
+ this.treeSelectValue = value
418
+ }
419
+ } else {
420
+ this.treeSelectValue = undefined
421
+ }
422
+ }
409
423
  })
410
424
  }
411
- // 修改时恢复树形选择框选中状态
412
- if (this.attr.type === 'treeSelect' && this.attr.queryType !== 'RIGHT_LIKE') {
413
- this.treeSelectValue = this.form[this.attr.model]
414
- }
415
425
  },
416
426
  openChangeOne (status) {
417
427
  if (status) {
@@ -503,8 +513,69 @@ export default {
503
513
  }
504
514
  this.form[this.attr.model] = label
505
515
  } else {
506
- this.form[this.attr.model] = value
516
+ // 如果选中值含'-',代表是由多个数据源组成的树,需要重新组织查询或新增/编辑时的表单
517
+ if ((value instanceof Array && value.length > 0 && value[0].indexOf('-') !== -1) || (value && value.indexOf('-') !== -1)) {
518
+ const treeDatas = {}
519
+ // 单选情况用于新增.修改表单场景,使用extra.triggerNode获取选中节点信息
520
+ if (!extra.allCheckedNodes) {
521
+ this.setNodeData(treeDatas, extra.triggerNode)
522
+ } else {
523
+ // 多选情况用于查询表单场景,使用extra.allCheckedNodes获取选中节点集合
524
+ const nodes = extra.allCheckedNodes
525
+ // 获取任意选中节点的叶子节点的字段名,用于查询时组织查询项的key
526
+ const name = this.getNodeDataProps(nodes[0])
527
+ // 获取所有选中节点的叶子节点的value,用于查询时组织查询项的value
528
+ const values = []
529
+ for (const node of nodes) {
530
+ const ref = this.setDataRef(node)
531
+ if (ref instanceof Array) {
532
+ for (const nodeRef of ref) {
533
+ const keyValue = nodeRef.node.key
534
+ values.push(keyValue.substring(keyValue.lastIndexOf('-') + 1))
535
+ }
536
+ } else {
537
+ const keyValue = ref.node.key
538
+ values.push(keyValue.substring(keyValue.lastIndexOf('-') + 1))
539
+ }
540
+ }
541
+ treeDatas[name] = values
542
+ }
543
+ // 移除默认的表单项,将组织好后的表单项合并进表单
544
+ this.form[this.attr.model] = undefined
545
+ Object.assign(this.form, treeDatas)
546
+ } else {
547
+ // 从单一数据源组成的树可以直接赋值
548
+ this.form[this.attr.model] = value
549
+ }
550
+ }
551
+ },
552
+ setDataRef (node) {
553
+ if (node.children) {
554
+ return this.setDataRef(node.children)
555
+ }
556
+ return node
557
+ },
558
+ /**
559
+ * 组织节点和每层父节点的数据,用于新增/修改时更新表单数据
560
+ * @param data 组织完成的数据
561
+ * @param node 节点
562
+ * @return 返回示例: { parentId: 1, childId: 2 }
563
+ */
564
+ setNodeData (data, node) {
565
+ if (node.value) {
566
+ const columnsName = node.dataRef['columns_name']
567
+ const value = node.value
568
+ data[columnsName] = value.substring(value.lastIndexOf('-') + 1)
569
+ if (node.$parent) {
570
+ this.setNodeData(data, node.$parent)
571
+ }
572
+ }
573
+ },
574
+ getNodeDataProps (node) {
575
+ if (node.children && node.children.length > 0) {
576
+ return this.getNodeDataProps(node.children[0])
507
577
  }
578
+ return node.node.data.props.columns_name
508
579
  }
509
580
  }
510
581
  }