mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
完善临时运行命令时的逻辑
This commit is contained in:
parent
f1dd98624e
commit
baf5217132
@ -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",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -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"];
|
||||||
|
@ -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 = {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user