完善执行命令功能 99%

This commit is contained in:
fofolee
2022-04-10 14:06:21 +08:00
parent c78581bc76
commit a4179cb9d8
6 changed files with 73 additions and 44 deletions

View File

@@ -146,7 +146,7 @@
}"
/>
<!-- 运行结果 -->
<CommandRunResult :action="runResultAction" ref="result"></CommandRunResult>
<CommandRunResult :action="action" ref="result"></CommandRunResult>
</div>
</template>
@@ -182,10 +182,6 @@ export default {
isRunCodePage: this.action.type === "run",
parent: this.$parent.$parent.$parent.$parent,
commandString: this.$q.platform.is.mac ? "⌘" : "ctrl",
runResultAction: {
type: "inPlugin",
data: {},
},
};
},
props: {

View File

@@ -16,10 +16,11 @@
>
</q-toolbar>
<q-card-section class="row items-center">
<pre
<div
style="white-space: pre"
:class="runResultStatus ? '' : 'text-red'"
v-html="runResult"
></pre>
></div>
</q-card-section>
<q-card-actions align="right">
<q-btn
@@ -51,6 +52,7 @@
<script>
import outputTypes from "../js/options/outputTypes.js";
import specialVars from "../js/options/specialVars.js";
import commandTypes from "../js/options/commandTypes.js";
export default {
data() {
@@ -62,6 +64,13 @@ export default {
};
},
props: {
/**
* run 「RunCode界面」 无侧栏,运行结果弹窗显示,保存命令历史
* edit 「编辑命令界面』 有侧栏,运行结果弹窗显示
* new 『新建命令界面」 有侧栏,运行结果弹窗显示
* config 「配置界面』 运行结果弹窗显示需要对payload临时赋值
* input 『主输入框进入」 运行结果直接展示,动态调整窗体高度
*/
action: Object,
},
mounted() {
@@ -69,19 +78,22 @@ export default {
},
computed: {
fromUtools() {
return this.action.type !== "inPlugin";
return this.action.type === "input";
},
needTempPayload() {
return this.action.type === "config";
},
},
methods: {
// 运行命令
runCurrentCommand(currentCommand) {
async runCurrentCommand(currentCommand) {
await this.getTempPayload(currentCommand);
if (currentCommand.cmd.includes("{{subinput"))
return this.setSubInput(currentCommand);
this.fire(currentCommand);
},
async fire(currentCommand) {
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
// currentCommand.cmd = await this.replaceTempInputVars(currentCommand.cmd);
let { hideWindow, outPlugin, action } =
outputTypes[currentCommand.output];
// 需要隐藏的提前隐藏窗口
@@ -150,31 +162,15 @@ export default {
};
document.addEventListener("keydown", this.$profile.tmp.handleEnter);
},
// 替换特殊变量
async replaceTempInputVars(cmd) {
let tempInputVals = [];
let needInputVal = [
"input",
"subinput",
"pwd",
// "SelectFile",
"WindowInfo",
"MatchedFiles",
];
needInputVal.forEach((x) => {
let m = cmd.match(new RegExp("{{" + x + ".*?}}", "g"));
m &&
m.forEach((y) => tempInputVals.includes(y) || tempInputVals.push(y));
});
if (!tempInputVals.length) return cmd;
let inputs = await quickcommand.showInputBox(
tempInputVals,
"需要临时为以下变量赋值"
);
tempInputVals.forEach((t, n) => {
cmd = cmd.replace(new RegExp(t, "g"), inputs[n]);
});
return cmd;
// payload 临时赋值
async getTempPayload(currentCommand) {
if (!this.needTempPayload) return;
let cmd = currentCommand.features.cmds[0];
let type = cmd.type;
quickcommand.enterData = {
type: cmd.type || "text",
payload: (await commandTypes[type]?.tempPayload?.()) || cmd,
};
},
// 显示运行结果
showRunResult(content, isSuccess, action) {

View File

@@ -2,6 +2,8 @@
* 所有的匹配类型
*/
const jsonSample = [
"关键词",
{
@@ -72,7 +74,11 @@ const commandTypes = {
match: rules,
minNum: 1,
}, ],
verify: rules => !!rules > 0 || "正则不能为空"
verify: rules => !!rules > 0 || "正则不能为空",
tempPayload: async() => {
let values = await quickcommand.showInputBox(["需要处理的文本"])
return values[0]
}
},
over: {
name: "over",
@@ -87,7 +93,11 @@ const commandTypes = {
type: "over",
minNum: 1,
}],
verify: rules => true
verify: rules => true,
tempPayload: async() => {
let values = await quickcommand.showInputBox(["需要处理的文本"])
return values[0]
}
},
window: {
name: "window",
@@ -104,21 +114,33 @@ const commandTypes = {
"app": rules
}
}],
verify: rules => !_.isEmpty(rules) || "进程名不能为空"
verify: rules => !_.isEmpty(rules) || "进程名不能为空",
},
img: {
name: "img",
label: "图片",
matchLabel: "无需配置",
icon: "panorama",
desc: "匹配主输入框或超级面板选中的图片,并返回图片的 base64",
desc: "匹配主输入框或超级面板选中的图片,并返回图片的 DataUrl",
valueType: null,
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
matchToCmds: (rules, desc) => [{
label: desc,
type: "img",
}],
verify: rules => true
verify: rules => true,
tempPayload: () => window.getBase64Ico(utools.showOpenDialog({
title: "需要处理的文件",
filters: [{
name: 'Images',
extensions: ['png',
'jpg',
'jpeg',
'bmp',
'gif',
]
}]
})[0])
},
files: {
name: "files",
@@ -134,7 +156,11 @@ const commandTypes = {
match: rules,
"minLength": 1,
}, ],
verify: rules => !!rules > 0 || "正则不能为空"
verify: rules => !!rules > 0 || "正则不能为空",
tempPayload: () => window.convertFilePathToUtoolsPayload(utools.showOpenDialog({
title: "需要处理的文件",
properties: ['openFile', 'openDirectory', 'multiSelections']
}))
},
professional: {

View File

@@ -12,7 +12,7 @@ export default {
data() {
return {
action: {
type: "fromUtools",
type: "input",
data: {},
},
featureCode: this.$route.path.slice(1),

View File

@@ -188,7 +188,7 @@
</q-card>
</q-dialog>
<CommandRunResult
:action="{ type: 'inPlugin' }"
:action="{ type: 'config' }"
ref="result"
></CommandRunResult>
</div>