mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-11 08:04:05 +08:00
完善新建和编辑命令功能
This commit is contained in:
parent
fa7fcd216b
commit
ee7d965826
@ -276,7 +276,17 @@ export default {
|
|||||||
},
|
},
|
||||||
// 编辑命令
|
// 编辑命令
|
||||||
editCommand() {
|
editCommand() {
|
||||||
console.log(this.commandInfo);
|
let routeData = {
|
||||||
|
from: "configuration",
|
||||||
|
action: "edit",
|
||||||
|
data: this.commandInfo,
|
||||||
|
};
|
||||||
|
this.$router.push({
|
||||||
|
name: "code",
|
||||||
|
params: {
|
||||||
|
data: JSON.stringify(routeData),
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
// 运行命令
|
// 运行命令
|
||||||
runCommand() {
|
runCommand() {
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
transition-show="jump-down"
|
transition-show="jump-down"
|
||||||
transition-hide="jump-up"
|
transition-hide="jump-up"
|
||||||
label-color="teal"
|
label-color="teal"
|
||||||
v-model="program"
|
v-model="quickcommandInfo.program"
|
||||||
:options="options"
|
:options="options"
|
||||||
label="编程语言"
|
label="编程语言"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<q-avatar rounded>
|
<q-avatar rounded>
|
||||||
<img :src="'/logo/' + program + '.png'" />
|
<img :src="'/logo/' + quickcommandInfo.program + '.png'" />
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:option="scope">
|
<template v-slot:option="scope">
|
||||||
@ -33,12 +33,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="row q-gutter-sm" v-show="program === 'custom'">
|
<div
|
||||||
|
class="row q-gutter-sm"
|
||||||
|
v-show="quickcommandInfo.program === 'custom'"
|
||||||
|
>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
color="teal"
|
color="teal"
|
||||||
v-model="customOptions.bin"
|
v-model="quickcommandInfo.customOptions.bin"
|
||||||
stack-label
|
stack-label
|
||||||
label="解释器路径"
|
label="解释器路径"
|
||||||
/>
|
/>
|
||||||
@ -47,7 +50,7 @@
|
|||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
color="teal"
|
color="teal"
|
||||||
v-model="customOptions.argv"
|
v-model="quickcommandInfo.customOptions.argv"
|
||||||
stack-label
|
stack-label
|
||||||
label="解释器参数"
|
label="解释器参数"
|
||||||
/>
|
/>
|
||||||
@ -56,7 +59,7 @@
|
|||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
color="teal"
|
color="teal"
|
||||||
v-model="customOptions.ext"
|
v-model="quickcommandInfo.customOptions.ext"
|
||||||
@blur="matchLanguage"
|
@blur="matchLanguage"
|
||||||
label="后缀,不含."
|
label="后缀,不含."
|
||||||
stack-label
|
stack-label
|
||||||
@ -71,9 +74,9 @@
|
|||||||
outlined
|
outlined
|
||||||
color="teal"
|
color="teal"
|
||||||
input-style="width: 120px;"
|
input-style="width: 120px;"
|
||||||
v-model="scptarg"
|
v-model="quickcommandInfo.scptarg"
|
||||||
label="脚本参数"
|
label="脚本参数"
|
||||||
v-show="program !== 'quickcommand'"
|
v-show="quickcommandInfo.program !== 'quickcommand'"
|
||||||
/>
|
/>
|
||||||
<q-btn-group>
|
<q-btn-group>
|
||||||
<q-btn
|
<q-btn
|
||||||
@ -82,7 +85,7 @@
|
|||||||
flat
|
flat
|
||||||
icon="description"
|
icon="description"
|
||||||
@click="showHelp"
|
@click="showHelp"
|
||||||
v-show="program === 'quickcommand'"
|
v-show="quickcommandInfo.program === 'quickcommand'"
|
||||||
><q-tooltip>查看文档</q-tooltip></q-btn
|
><q-tooltip>查看文档</q-tooltip></q-btn
|
||||||
>
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
@ -91,7 +94,7 @@
|
|||||||
flat
|
flat
|
||||||
icon="format_size"
|
icon="format_size"
|
||||||
@click="showCodingPage()"
|
@click="showCodingPage()"
|
||||||
v-show="program !== 'quickcommand'"
|
v-show="quickcommandInfo.program !== 'quickcommand'"
|
||||||
><q-tooltip>脚本及输出编码设置</q-tooltip></q-btn
|
><q-tooltip>脚本及输出编码设置</q-tooltip></q-btn
|
||||||
>
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
@ -156,55 +159,79 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
options: Object.keys(this.$programmings),
|
options: Object.keys(this.$programmings),
|
||||||
program: "quickcommand",
|
quickcommandInfo: {
|
||||||
customOptions: { bin: "", argv: "", ext: "" },
|
features: {
|
||||||
scptarg: "",
|
explain: "",
|
||||||
scriptCode: "",
|
cmds: [],
|
||||||
outputCode: "",
|
platform: [],
|
||||||
output: "",
|
},
|
||||||
|
program: "quickcommand",
|
||||||
|
cmd: "",
|
||||||
|
output: "",
|
||||||
|
hasSubInput: false,
|
||||||
|
scptarg: "",
|
||||||
|
charset: {
|
||||||
|
scriptCode: "",
|
||||||
|
outputCode: "",
|
||||||
|
},
|
||||||
|
tags: [],
|
||||||
|
customOptions: {
|
||||||
|
bin: "",
|
||||||
|
argv: "",
|
||||||
|
ext: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
isResultShow: false,
|
isResultShow: false,
|
||||||
runResult: "",
|
runResult: "",
|
||||||
runResultStatus: true,
|
runResultStatus: true,
|
||||||
resultMaxLength: 10000,
|
resultMaxLength: 10000,
|
||||||
|
routeData: JSON.parse(this.$route.params.data),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.bindKeys();
|
this.init();
|
||||||
this.loadOrSaveHistory();
|
},
|
||||||
|
computed: {
|
||||||
|
currentProgram() {
|
||||||
|
return this.quickcommandInfo.program;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {},
|
|
||||||
created() {},
|
created() {},
|
||||||
watch: {
|
watch: {
|
||||||
program(val) {
|
currentProgram(val) {
|
||||||
this.setLanguage(val);
|
this.setLanguage(val);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 读取历史记录
|
init() {
|
||||||
loadOrSaveHistory() {
|
this.bindKeys();
|
||||||
// 读取
|
let quickCommandInfo =
|
||||||
var history = this.$utools.getDB(this.$utools.DBPRE.CFG + "codeHistory");
|
this.routeData.action === "edit"
|
||||||
if (history.program) {
|
? this.routeData.data
|
||||||
this.$refs.editor.setEditorValue(history.cmd);
|
: this.$utools.getDB(this.$utools.DBPRE.CFG + "codeHistory");
|
||||||
this.program = history.program;
|
quickCommandInfo = this.fillDefaultKeys(quickCommandInfo);
|
||||||
this.scptarg = history.scptarg || "";
|
this.$refs.editor.setEditorValue(quickCommandInfo.cmd);
|
||||||
this.scriptCode = history.scriptCode || "";
|
this.quickcommandInfo = quickCommandInfo;
|
||||||
this.outputCode = history.outputCode || "";
|
// 只有新建或运行时才保存记录
|
||||||
if (history.customOptions) this.customOptions = history.customOptions;
|
if (this.routeData.action === "edit") return;
|
||||||
}
|
|
||||||
utools.onPluginOut(() => {
|
utools.onPluginOut(() => {
|
||||||
var saveData = {
|
this.quickcommandInfo.cmd = this.$refs.editor.getEditorValue();
|
||||||
cmd: this.$refs.editor.getEditorValue(),
|
// 保存本次编辑记录
|
||||||
program: this.program,
|
this.$utools.putDB(
|
||||||
scptarg: this.scptarg,
|
JSON.parse(JSON.stringify(this.quickcommandInfo)),
|
||||||
scriptCode: this.scriptCode,
|
this.$utools.DBPRE.CFG + "codeHistory"
|
||||||
outputCode: this.outputCode,
|
);
|
||||||
customOptions: JSON.parse(JSON.stringify(this.customOptions)),
|
|
||||||
};
|
|
||||||
// 保存
|
|
||||||
this.$utools.putDB(saveData, this.$utools.DBPRE.CFG + "codeHistory");
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// 补充没有的键值
|
||||||
|
fillDefaultKeys(command) {
|
||||||
|
let commandKeys = Object.keys(command);
|
||||||
|
Object.keys(this.quickcommandInfo).forEach((key) => {
|
||||||
|
if (!commandKeys.includes(key))
|
||||||
|
command[key] = this.quickcommandInfo[key];
|
||||||
|
});
|
||||||
|
return command;
|
||||||
|
},
|
||||||
// 绑定快捷键
|
// 绑定快捷键
|
||||||
bindKeys() {
|
bindKeys() {
|
||||||
let that = this;
|
let that = this;
|
||||||
@ -216,7 +243,7 @@ export default {
|
|||||||
// 匹配编程语言
|
// 匹配编程语言
|
||||||
matchLanguage() {
|
matchLanguage() {
|
||||||
let language = Object.values(this.$programmings).filter(
|
let language = Object.values(this.$programmings).filter(
|
||||||
(program) => program.ext === this.customOptions.ext
|
(program) => program.ext === this.quickcommandInfo.customOptions.ext
|
||||||
);
|
);
|
||||||
if (language.length) {
|
if (language.length) {
|
||||||
this.setLanguage(language[0].name);
|
this.setLanguage(language[0].name);
|
||||||
@ -241,12 +268,19 @@ export default {
|
|||||||
{
|
{
|
||||||
labels: ["文件编码", "输出编码"],
|
labels: ["文件编码", "输出编码"],
|
||||||
hints: ["基于iconv-lite进行编码,无乱码请留空", "无乱码请留空"],
|
hints: ["基于iconv-lite进行编码,无乱码请留空", "无乱码请留空"],
|
||||||
values: [this.scriptCode, this.outputCode],
|
values: [
|
||||||
|
this.quickcommandInfo.charset?.scriptCode,
|
||||||
|
this.quickcommandInfo.charset?.outputCode,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
"编码设置"
|
"编码设置"
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) [this.scriptCode, this.outputCode] = res;
|
if (res)
|
||||||
|
[
|
||||||
|
this.quickcommandInfo.charset.scriptCode,
|
||||||
|
this.quickcommandInfo.charset.outputCode,
|
||||||
|
] = res;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 运行命令
|
// 运行命令
|
||||||
@ -267,24 +301,17 @@ export default {
|
|||||||
utools.hideMainWindow();
|
utools.hideMainWindow();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.program === "quickcommand") {
|
if (this.quickcommandInfo.program === "quickcommand") {
|
||||||
window.runCodeInVm(cmd, (stdout, stderr) => {
|
window.runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
if (stderr) return this.showRunResult(stderr, raw, false);
|
if (stderr) return this.showRunResult(stderr, raw, false);
|
||||||
this.showRunResult(stdout, raw, true);
|
this.showRunResult(stdout, raw, true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let option = this.$programmings[this.program];
|
let option = this.$programmings[this.program];
|
||||||
if (this.program === "custom")
|
if (this.quickcommandInfo.program === "custom")
|
||||||
option = {
|
option = this.quickcommandInfo.customOptions;
|
||||||
bin: this.customOptions.bin,
|
option.scptarg = this.quickcommandInfo.scptarg;
|
||||||
argv: this.customOptions.argv,
|
option.charset = this.quickcommandInfo.charset;
|
||||||
ext: this.customOptions.ext,
|
|
||||||
};
|
|
||||||
option.scptarg = this.scptarg;
|
|
||||||
option.charset = {
|
|
||||||
scriptCode: this.scriptCode,
|
|
||||||
outputCode: this.outputCode,
|
|
||||||
};
|
|
||||||
window.runCodeFile(cmd, option, terminal, (stdout, stderr) => {
|
window.runCodeFile(cmd, option, terminal, (stdout, stderr) => {
|
||||||
if (terminal) return;
|
if (terminal) return;
|
||||||
if (stderr) return this.showRunResult(stderr, raw, false);
|
if (stderr) return this.showRunResult(stderr, raw, false);
|
||||||
|
@ -147,7 +147,14 @@
|
|||||||
</q-btn-toggle>
|
</q-btn-toggle>
|
||||||
<q-separator vertical />
|
<q-separator vertical />
|
||||||
<!-- 新建按钮 -->
|
<!-- 新建按钮 -->
|
||||||
<q-btn split flat label="新建" color="teal" icon="add"></q-btn>
|
<q-btn
|
||||||
|
split
|
||||||
|
flat
|
||||||
|
label="新建"
|
||||||
|
@click="addNewCommand"
|
||||||
|
color="teal"
|
||||||
|
icon="add"
|
||||||
|
></q-btn>
|
||||||
<q-separator vertical />
|
<q-separator vertical />
|
||||||
<!-- 下拉菜单 -->
|
<!-- 下拉菜单 -->
|
||||||
<q-btn color="teal" flat icon="menu" size="xs">
|
<q-btn color="teal" flat icon="menu" size="xs">
|
||||||
@ -355,6 +362,8 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
// 初始化
|
// 初始化
|
||||||
initPage() {
|
initPage() {
|
||||||
|
console.log(this.$route);
|
||||||
|
window.configuration = this;
|
||||||
// 已启用的 features
|
// 已启用的 features
|
||||||
let activatedFeatures = this.getActivatedFeatures();
|
let activatedFeatures = this.getActivatedFeatures();
|
||||||
// 已启用的命令的 featureCode
|
// 已启用的命令的 featureCode
|
||||||
@ -368,7 +377,6 @@ export default {
|
|||||||
this.$utools.DBPRE.CFG + "preferences"
|
this.$utools.DBPRE.CFG + "preferences"
|
||||||
);
|
);
|
||||||
this.commandCardStyle = userPreferences.commandCardStyle || "normal";
|
this.commandCardStyle = userPreferences.commandCardStyle || "normal";
|
||||||
console.log("ConfigurationPage", this);
|
|
||||||
utools.onPluginOut(() => {
|
utools.onPluginOut(() => {
|
||||||
userPreferences.commandCardStyle = this.commandCardStyle;
|
userPreferences.commandCardStyle = this.commandCardStyle;
|
||||||
this.$utools.putDB(
|
this.$utools.putDB(
|
||||||
@ -587,6 +595,22 @@ export default {
|
|||||||
.querySelectorAll(".q-toggle[aria-checked='true']")
|
.querySelectorAll(".q-toggle[aria-checked='true']")
|
||||||
.forEach((x) => x.click());
|
.forEach((x) => x.click());
|
||||||
},
|
},
|
||||||
|
// 新建命令
|
||||||
|
addNewCommand() {
|
||||||
|
let routeData = {
|
||||||
|
from: "configuration",
|
||||||
|
action: "new",
|
||||||
|
data: {
|
||||||
|
currentTag: this.currentTag,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.$router.push({
|
||||||
|
name: "code",
|
||||||
|
params: {
|
||||||
|
data: JSON.stringify(routeData),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user