From baf521713231e9efd297ff0372c8e56c4c6eb46c Mon Sep 17 00:00:00 2001 From: fofolee Date: Sun, 26 Jan 2025 15:26:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=B8=B4=E6=97=B6=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=97=B6=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/composer/ComposerCard.vue | 56 +++++++++++++++---- src/components/composer/ComposerFlow.vue | 23 +------- src/components/composer/card/OutputEditor.vue | 8 ++- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/components/composer/ComposerCard.vue b/src/components/composer/ComposerCard.vue index baa6a31..fd9ce7f 100644 --- a/src/components/composer/ComposerCard.vue +++ b/src/components/composer/ComposerCard.vue @@ -192,14 +192,26 @@ export default defineComponent({ if (!this.localCommand.code) return quickcommand.showMessageBox("请检查参数是否正确", "info"); // 创建一个带临时变量的命令副本 + const outputVariable = this.getAvailableOutputVariable(); const tempCommand = { ...this.localCommand, - outputVariable: { - name: `temp_${Date.now()}`, - ...this.localCommand.outputVariable, - }, + outputVariable, }; - this.$emit("run", tempCommand); + const consoleLogVars = + this.getAvailableOutputVariableName(outputVariable); + const tempFlow = { + name: "main", + commands: [ + tempCommand, + { + //没有输出,则不打印 + code: `if(${consoleLogVars}!==undefined){ + console.log(${consoleLogVars}) + }`, + }, + ], + }; + this.$emit("run", tempFlow); }, handleToggleCollapse() { if (this.localCommand.isControlFlow) { @@ -245,13 +257,33 @@ export default defineComponent({ this.localCommand.disabled = !this.localCommand.disabled; } }, + getAvailableOutputVariable() { + let outputVariable = this.localCommand.outputVariable || {}; + if (!outputVariable.name && !outputVariable.details) { + outputVariable.name = `temp_${Date.now()}`; + } + return outputVariable; + }, + getAvailableOutputVariableName(outputVariable) { + const availableVars = [ + outputVariable.name, + ...Object.values(outputVariable.details || {}), + ].filter((v) => v); + + const finalVars = + availableVars.length > 1 + ? `{ ${availableVars.join(", ")} }` + : availableVars[0]; + return finalVars; + }, handleAddPrint() { // 创建一个打印命令 - this.localCommand.outputVariable = { - name: `temp_${Date.now()}`, - ...this.localCommand.outputVariable, - }; - const printCommand = { + const outputVariable = this.getAvailableOutputVariable(); + this.localCommand.outputVariable = outputVariable; + const consoleLogVars = + this.getAvailableOutputVariableName(outputVariable); + + const consoleLogCommand = { value: "console.log", label: "显示消息", config: [ @@ -261,10 +293,10 @@ export default defineComponent({ icon: "info", }, ], - argvs: [newVarInputVal("var", this.localCommand.outputVariable.name)], + argvs: [newVarInputVal("var", consoleLogVars)], }; this.$emit("add-command", { - command: printCommand, + command: consoleLogCommand, type: "single", }); }, diff --git a/src/components/composer/ComposerFlow.vue b/src/components/composer/ComposerFlow.vue index ee01eca..46d6537 100644 --- a/src/components/composer/ComposerFlow.vue +++ b/src/components/composer/ComposerFlow.vue @@ -39,10 +39,10 @@ v-model="commands[index]" :command-index="index" @remove="removeCommand(index)" - @run="handleRunCommand" + @run="$emit('action', 'run', $event)" @add-branch="addBranch" - @toggle-collapse="(event) => handleChainCollapse(event)" - @add-command="(event) => handleAddCommand(event, index)" + @toggle-collapse="handleChainCollapse" + @add-command="handleAddCommand($event, index)" @toggle-chain-disable="handleToggleChainDisable" /> @@ -336,23 +336,6 @@ export default defineComponent({ this.removeRangeCommand(index); } }, - handleRunCommand(command) { - // 创建一个临时的命令流程 - const tempFlow = { - name: "main", - commands: [ - command, - { - //没有输出,则不打印 - code: `if(${command.outputVariable.name}!==undefined){ - console.log(${command.outputVariable.name}) - }`, - }, - ], - }; - // 触发运行事件 - this.$emit("action", "run", tempFlow); - }, // 查找不可重复出现的分支 findUniqueBranch(chainId, commandType) { const uniqueBranch = ["default", "catch", "finally"]; diff --git a/src/components/composer/card/OutputEditor.vue b/src/components/composer/card/OutputEditor.vue index 9ea3ecb..20fab7d 100644 --- a/src/components/composer/card/OutputEditor.vue +++ b/src/components/composer/card/OutputEditor.vue @@ -189,9 +189,11 @@ export default defineComponent({ } }, handleConfirm() { - const outputVariable = { - name: this.simpleOutputVar, - }; + const outputVariable = {}; + + if (this.simpleOutputVar) { + outputVariable.name = this.simpleOutputVar; + } if (this.currentOutputs) { const flatVars = {};