完善执行命令功能 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

@ -358,6 +358,16 @@ let parseItem = item => {
return item.toString() return item.toString()
} }
convertFilePathToUtoolsPayload = files => files.map(file => {
let isFile = fs.statSync(file).isFile()
return {
isFile: isFile,
isDirectory: !isFile,
name: path.basename(file),
path: file
}
})
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n") let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
VmEval = (cmd, sandbox = {}) => new VM({ VmEval = (cmd, sandbox = {}) => new VM({
@ -503,7 +513,7 @@ getQuickcommandTempFile = ext => {
return path.join(os.tmpdir(), `quickcommandTempFile.${ext}`) return path.join(os.tmpdir(), `quickcommandTempFile.${ext}`)
} }
getBase64Ico = async filepath => { getBase64Ico = async (filepath, compressed = true) => {
let sourceImage, ext = path.extname(filepath).slice(1) let sourceImage, ext = path.extname(filepath).slice(1)
if (['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'].includes(ext)) { if (['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'].includes(ext)) {
if (ext == 'svg') ext = 'svg+xml' if (ext == 'svg') ext = 'svg+xml'
@ -513,6 +523,7 @@ getBase64Ico = async filepath => {
sourceImage = utools.getFileIcon(filepath) sourceImage = utools.getFileIcon(filepath)
return sourceImage return sourceImage
} }
if (!compressed) return sourceImage
let compressedImage = await getCompressedIco(sourceImage) let compressedImage = await getCompressedIco(sourceImage)
return compressedImage return compressedImage
} }

View File

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

View File

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

View File

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

View File

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

View File

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