From 9cdf9d3e9370418f83f4923139baace0cebe6919 Mon Sep 17 00:00:00 2001 From: Feynman Date: Thu, 26 Oct 2023 14:54:27 +0800 Subject: [PATCH 1/2] refactor: update setSelected logic --- .../src/components/async-select/AsyncSelect.vue | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/form/src/components/async-select/AsyncSelect.vue b/packages/form/src/components/async-select/AsyncSelect.vue index 62a9732fd3..a0a91f028f 100644 --- a/packages/form/src/components/async-select/AsyncSelect.vue +++ b/packages/form/src/components/async-select/AsyncSelect.vue @@ -421,16 +421,7 @@ export default { async setSelected() { if (!this.multiple) { let option = await this.getOption(this.value) - // 不添加!this.lazy 会导致 onSetSelected 的参数为 { value: this.value, currentLabel: this.currentLabel} - // 防止开启了lazy 同时设置了currentLabel,进入这个判断 - if (this.currentLabel && !this.lazy) { - option = { - value: this.value, - currentLabel: this.currentLabel - } - } else { - option = await this.getOption(this.value) - } + if (this.onSetSelected && ~this.hoverIndex) { if (!option.$el) { this.onSetSelected(option) @@ -448,6 +439,10 @@ export default { this.selectedLabel = option.currentLabel this.selected = option if (this.filterable) this.query = this.selectedLabel + + if (option.currentLabel === option.value && this.itemType === 'object' && this.currentLabel) { + this.selectedLabel = this.currentLabel + } return } let result = [] From 453d3b7d6e602c5c25a3dc1987a6e499a7b1ab2b Mon Sep 17 00:00:00 2001 From: Feynman Date: Thu, 26 Oct 2023 14:54:37 +0800 Subject: [PATCH 2/2] refactor: update materialized view schema tree logic display all inputs field with targetPath --- .../materialized-view/MaterializedView.vue | 6 +- .../src/components/materialized-view/Node.vue | 125 ++++++++++++------ 2 files changed, 88 insertions(+), 43 deletions(-) diff --git a/packages/dag/src/components/materialized-view/MaterializedView.vue b/packages/dag/src/components/materialized-view/MaterializedView.vue index 2e71fe3a53..d0ad119c49 100644 --- a/packages/dag/src/components/materialized-view/MaterializedView.vue +++ b/packages/dag/src/components/materialized-view/MaterializedView.vue @@ -294,6 +294,10 @@ export default { const indexOfParent = parentNode.children.findIndex(n => n.id === id) ~indexOfParent && parentNode.children.splice(indexOfParent, 1) parentNode.children.push(...childrenNodes) + + // 从父节点的输入上删除 + const oldIndex = this.inputsMap[parentNode.id].indexOf(id) + this.inputsMap[parentNode.id].splice(oldIndex, 1) } else { const { mergeProperties } = this.activeNode const index = mergeProperties.findIndex(n => n.id === id) @@ -647,7 +651,7 @@ export default { if (this.targetNode?.id) { // 更新目标节点schema await this.afterTaskSaved() - await this.loadNodeSchema(this.targetNode.id) + await this.onLoadTargetSchema(this.targetNode.id) } }, diff --git a/packages/dag/src/components/materialized-view/Node.vue b/packages/dag/src/components/materialized-view/Node.vue index 36c2fe7044..7f41acc200 100644 --- a/packages/dag/src/components/materialized-view/Node.vue +++ b/packages/dag/src/components/materialized-view/Node.vue @@ -303,51 +303,29 @@ export default { }, treeData() { - // console.log('computed:treeData') - let { schema } = this + let schema = this.schema ? [...this.schema] : [] if (!schema) return [] - const richFields = (inputs, targetPath) => { - let arr = [] - for (const input of inputs) { - const inputNode = this.nodeMap[input] - let fields = this.nodeSchemaMap[input] - if (!fields) continue + const inputs = this.inputsMap?.[this.node.id] - let nodeTargetPath = inputNode.targetPath - if (nodeTargetPath && targetPath) { - nodeTargetPath = nodeTargetPath.replace(new RegExp(`${targetPath}?.`), '') - } + if (inputs?.length) { + const { targetPath } = this.node + let mergedFields = this.richFields(this.inputsMap[this.node.id], this.node.targetPath) + + if (targetPath) { + mergedFields = mergedFields + .map(field => { + return { + ...field, + field_name: field.field_name.replace(new RegExp(`^${targetPath}\\.|^${targetPath}$`), '') + } + }) + .filter(field => !!field.field_name) - if (this.inputsMap[input]?.length) { - arr = unionBy(arr, fields, richFields(this.inputsMap[input], nodeTargetPath), 'field_name') - } else { - // if (nodeTargetPath && targetPath) { - // nodeTargetPath.replace(new RegExp(`${targetPath}?.`), '') - // } - - if (nodeTargetPath) { - fields = fields.map(field => { - return { - ...field, - field_name: `${nodeTargetPath}.${field.field_name}` - } - }) - fields.unshift({ - field_name: nodeTargetPath, - dataType: 'DOCUMENT' - }) - } - arr = unionBy(arr, fields) - } + console.log('mergedFields', mergedFields) } - return arr - } - const inputs = this.inputsMap?.[this.node.id] - if (inputs?.length) { - const mergedFields = richFields(this.inputsMap[this.node.id], this.node.targetPath) schema = unionBy(schema, mergedFields, 'field_name') schema.sort((a, b) => { let aVal, bVal @@ -366,12 +344,9 @@ export default { return aVal - bVal }) - console.log('schema', schema) } - const treeData = this.createTree(schema) - - return treeData + return this.createTree(schema) }, sourceNodes() { @@ -813,6 +788,8 @@ export default { Object.keys(nodeAttrs).forEach(key => { this.$set(this.dagNode.attrs, key, nodeAttrs[key]) }) + + console.log('this.dagNode.attrs', this.dagNode.attrs.connectionName, connection) }, async onChangeConnection() { @@ -866,6 +843,70 @@ export default { } animationId = requestAnimationFrame(revalidate) + }, + + /** + * 根据写入路径,收集上游字段 + * @param inputs + * @param targetPath + * @returns {*[]} + */ + richFields(inputs, targetPath) { + let arr = [] + + for (const input of inputs) { + const inputNode = this.nodeMap[input] + let fields = this.nodeSchemaMap[input] + + if (!fields) continue + + let nodeTargetPath = inputNode.targetPath + + /*if (nodeTargetPath && targetPath) { + nodeTargetPath = nodeTargetPath.replace(new RegExp(`^${targetPath}\\.|^${targetPath}$`), '') + }*/ + + if (this.isMainTable) { + console.log('path', targetPath, nodeTargetPath, inputNode.targetPath) + } + + if (this.inputsMap[input]?.length) { + if (nodeTargetPath /* && inputNode.targetPath === nodeTargetPath*/) { + fields = fields.map(field => { + return { + ...field, + field_name: `${nodeTargetPath}.${field.field_name}` + } + }) + + fields.unshift({ + field_name: nodeTargetPath, + dataType: 'DOCUMENT' + }) + } + + const newFields = this.richFields(this.inputsMap[input], nodeTargetPath) + + arr = unionBy(arr, fields, newFields, 'field_name') + } else { + if (nodeTargetPath) { + fields = fields.map(field => { + return { + ...field, + field_name: `${nodeTargetPath}.${field.field_name}` + } + }) + + fields.unshift({ + field_name: nodeTargetPath, + dataType: 'DOCUMENT' + }) + } + arr = unionBy(arr, fields) + } + } + + return arr } } }