完善执行命令功能 80%

This commit is contained in:
fofolee 2022-04-09 16:27:55 +08:00
parent b36248c9bc
commit 94b19dce5d
4 changed files with 102 additions and 56 deletions

View File

@ -473,8 +473,8 @@ getNodeJsCommand = () => {
return obj return obj
} }
htmlEncode = (value, raw = true) => { htmlEncode = (value) => {
return raw ? String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;") : value return String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;")
} }
hexEncode = text => Buffer.from(text, 'utf8').toString('hex') hexEncode = text => Buffer.from(text, 'utf8').toString('hex')

View File

@ -352,7 +352,9 @@ export default {
}, },
// //
runCurrentCommand() { runCurrentCommand() {
this.quickcommandInfo.output = this.$refs.menu?.currentCommand.output; // action run text
this.quickcommandInfo.output =
this.$refs.menu?.currentCommand.output || "text";
this.$refs.result.runCurrentCommand(this.quickcommandInfo); this.$refs.result.runCurrentCommand(this.quickcommandInfo);
}, },
}, },

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<div v-if="action.type === 'inPlugin'"> <div v-if="!fromUtools">
<q-dialog v-model="isResultShow" @hide="runResult = ''" position="bottom"> <q-dialog v-model="isResultShow" @hide="runResult = ''" position="bottom">
<q-card style="width: 90vh"> <q-card style="width: 90vh">
<q-toolbar> <q-toolbar>
@ -28,18 +28,23 @@
</q-dialog> </q-dialog>
</div> </div>
<div v-else> <div v-else>
<q-card> <div
<pre v-show="!!runResult"
:class="runResultStatus ? '' : 'text-red'" :class="{
'text-red': !runResultStatus,
'q-pa-md': 1,
}"
style="white-space: pre"
v-html="runResult" v-html="runResult"
></pre> ></div>
</q-card>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import outputTypes from "../js/options/outputTypes.js";
export default { export default {
data() { data() {
return { return {
@ -54,28 +59,31 @@ export default {
mounted() { mounted() {
window.runResult = this; window.runResult = this;
}, },
computed: {
fromUtools() {
return this.action.type !== "inPlugin";
},
},
methods: { methods: {
// //
async runCurrentCommand(currentCommand) { async runCurrentCommand(currentCommand) {
currentCommand.cmd = window.special(currentCommand.cmd); currentCommand.cmd = window.special(currentCommand.cmd);
currentCommand.cmd = await this.replaceTempInputVals(currentCommand.cmd); currentCommand.cmd = await this.replaceTempInputVals(currentCommand.cmd);
let terminal = false; let { hideWindow, outPlugin, action } =
let raw = true; outputTypes[currentCommand.output];
switch (currentCommand.output) { //
case "html": hideWindow && utools.hideMainWindow();
raw = false; // 退
break; // 退
case "terminal": this.fromUtools &&
terminal = true; outPlugin &&
break; setTimeout(() => {
case "ignore": utools.outPlugin();
utools.hideMainWindow(); }, 500);
break;
}
if (currentCommand.program === "quickcommand") { if (currentCommand.program === "quickcommand") {
window.runCodeInVm(currentCommand.cmd, (stdout, stderr) => { window.runCodeInVm(currentCommand.cmd, (stdout, stderr) => {
if (stderr) return this.showRunResult(stderr, raw, false); if (stderr) return this.showRunResult(stderr, false, action);
this.showRunResult(stdout, raw, true); this.showRunResult(stdout, true, action);
}); });
} else { } else {
let option = this.$programmings[currentCommand.program]; let option = this.$programmings[currentCommand.program];
@ -86,11 +94,10 @@ export default {
window.runCodeFile( window.runCodeFile(
currentCommand.cmd, currentCommand.cmd,
option, option,
terminal, currentCommand.output === "terminal",
(stdout, stderr) => { (stdout, stderr) => {
if (terminal) return; if (stderr) return this.showRunResult(stderr, false, action);
if (stderr) return this.showRunResult(stderr, raw, false); this.showRunResult(stdout, true, action);
this.showRunResult(stdout, raw, true);
} }
); );
} }
@ -122,7 +129,7 @@ export default {
return cmd; return cmd;
}, },
// //
showRunResult(content, raw, isSuccess) { showRunResult(content, isSuccess, action) {
this.isResultShow = true; this.isResultShow = true;
this.runResultStatus = isSuccess; this.runResultStatus = isSuccess;
let contlength = content.length; let contlength = content.length;
@ -133,7 +140,24 @@ export default {
contlength - this.resultMaxLength - 100 contlength - this.resultMaxLength - 100
} 字省略\n...\n\n` + } 字省略\n...\n\n` +
content.slice(contlength - 100); content.slice(contlength - 100);
this.runResult += htmlEncode(content, raw); let pretreatment = action(content);
pretreatment && (this.runResult += pretreatment);
this.fromUtools &&
this.$nextTick(() => {
this.outputAutoHeight();
});
},
// utools
outputAutoHeight(autoScroll = true, autoHeight = true) {
let clientHeight = document.body.clientHeight;
let pluginHeight = clientHeight < 600 ? clientHeight : 600;
autoHeight && utools.setExpendHeight(pluginHeight);
autoScroll &&
window.scroll({
top: clientHeight,
left: 0,
behavior: "smooth",
});
}, },
}, },
}; };

View File

@ -6,42 +6,62 @@ const outputTypes = {
ignore: { ignore: {
name: "ignore", name: "ignore",
label: "忽略输出并隐藏", label: "忽略输出并隐藏",
icon: "more_horiz" icon: "more_horiz",
hideWindow: true,
outPlugin: true,
action: result => null
}, },
nothing: { nothing: {
name: "nothing", name: "nothing",
label: "忽略输出且不隐藏", label: "忽略输出且不隐藏",
icon: "blur_linear" icon: "blur_linear",
outPlugin: true,
action: result => null
}, },
text: { text: {
name: "text", name: "text",
label: "纯文本输出", label: "纯文本输出",
icon: "text_snippet" icon: "text_snippet",
action: result => window.htmlEncode(result)
}, },
html: { html: {
name: "html", name: "html",
label: "html格式输出", label: "html格式输出",
icon: "html" icon: "html",
action: result => result
}, },
terminal: { terminal: {
name: "terminal", name: "terminal",
label: "在终端显示", label: "在终端显示",
icon: "terminal" icon: "terminal",
hideWindow: true,
outPlugin: true,
action: result => null
}, },
clip: { clip: {
name: "clip", name: "clip",
label: "复制到剪贴板", label: "复制到剪贴板",
icon: "content_paste" icon: "content_paste",
hideWindow: true,
outPlugin: true,
action: result => window.copyTo(result)
}, },
send: { send: {
name: "send", name: "send",
label: "发送到活动窗口", label: "发送到活动窗口",
icon: "web_asset" icon: "web_asset",
hideWindow: true,
outPlugin: true,
action: result => window.send(result)
}, },
notice: { notice: {
name: "notice", name: "notice",
label: "发送系统通知", label: "发送系统通知",
icon: "sms" icon: "sms",
hideWindow: true,
outPlugin: true,
action: result => window.message(result)
}, },
}; };