完善临时运行命令时的逻辑

This commit is contained in:
fofolee 2025-01-26 15:26:27 +08:00
parent f1dd98624e
commit baf5217132
3 changed files with 52 additions and 35 deletions

View File

@ -192,14 +192,26 @@ export default defineComponent({
if (!this.localCommand.code) if (!this.localCommand.code)
return quickcommand.showMessageBox("请检查参数是否正确", "info"); return quickcommand.showMessageBox("请检查参数是否正确", "info");
// //
const outputVariable = this.getAvailableOutputVariable();
const tempCommand = { const tempCommand = {
...this.localCommand, ...this.localCommand,
outputVariable: { outputVariable,
name: `temp_${Date.now()}`,
...this.localCommand.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() { handleToggleCollapse() {
if (this.localCommand.isControlFlow) { if (this.localCommand.isControlFlow) {
@ -245,13 +257,33 @@ export default defineComponent({
this.localCommand.disabled = !this.localCommand.disabled; 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() { handleAddPrint() {
// //
this.localCommand.outputVariable = { const outputVariable = this.getAvailableOutputVariable();
name: `temp_${Date.now()}`, this.localCommand.outputVariable = outputVariable;
...this.localCommand.outputVariable, const consoleLogVars =
}; this.getAvailableOutputVariableName(outputVariable);
const printCommand = {
const consoleLogCommand = {
value: "console.log", value: "console.log",
label: "显示消息", label: "显示消息",
config: [ config: [
@ -261,10 +293,10 @@ export default defineComponent({
icon: "info", icon: "info",
}, },
], ],
argvs: [newVarInputVal("var", this.localCommand.outputVariable.name)], argvs: [newVarInputVal("var", consoleLogVars)],
}; };
this.$emit("add-command", { this.$emit("add-command", {
command: printCommand, command: consoleLogCommand,
type: "single", type: "single",
}); });
}, },

View File

@ -39,10 +39,10 @@
v-model="commands[index]" v-model="commands[index]"
:command-index="index" :command-index="index"
@remove="removeCommand(index)" @remove="removeCommand(index)"
@run="handleRunCommand" @run="$emit('action', 'run', $event)"
@add-branch="addBranch" @add-branch="addBranch"
@toggle-collapse="(event) => handleChainCollapse(event)" @toggle-collapse="handleChainCollapse"
@add-command="(event) => handleAddCommand(event, index)" @add-command="handleAddCommand($event, index)"
@toggle-chain-disable="handleToggleChainDisable" @toggle-chain-disable="handleToggleChainDisable"
/> />
</div> </div>
@ -336,23 +336,6 @@ export default defineComponent({
this.removeRangeCommand(index); 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) { findUniqueBranch(chainId, commandType) {
const uniqueBranch = ["default", "catch", "finally"]; const uniqueBranch = ["default", "catch", "finally"];

View File

@ -189,9 +189,11 @@ export default defineComponent({
} }
}, },
handleConfirm() { handleConfirm() {
const outputVariable = { const outputVariable = {};
name: this.simpleOutputVar,
}; if (this.simpleOutputVar) {
outputVariable.name = this.simpleOutputVar;
}
if (this.currentOutputs) { if (this.currentOutputs) {
const flatVars = {}; const flatVars = {};