完善执行命令功能 90%

This commit is contained in:
fofolee
2022-04-10 00:38:56 +08:00
parent e86fb1b02a
commit 73c5dbacee
9 changed files with 200 additions and 140 deletions

View File

@@ -108,10 +108,9 @@
<span v-for="cmd in commandInfo.features.cmds" :key="cmd">
<span v-if="typeof cmd === 'string'">
<q-badge rounded :color="cmdBadgeColor()"
><q-icon
class="q-mr-xs"
:name="commandTypes.key.icon"
/>{{ getShortStrByByte(cmd) }}</q-badge
><q-icon class="q-mr-xs" :name="commandTypes.key.icon" />{{
getShortStrByByte(cmd)
}}</q-badge
>
<q-tooltip>
<div class="text-subtitle2">
@@ -302,9 +301,11 @@ export default {
},
// 运行命令
runCommand() {
utools.redirect(
this.commandInfo.features.cmds.filter((x) => x.length)[0]
);
let event = {
type: "run",
data: this.commandInfo.features.code,
};
this.$emit("commandChanged", event);
},
// 启用/禁用命令
toggleCommandActivated() {

View File

@@ -361,7 +361,7 @@ export default {
// 如果 action 是 run 则输出一律为 text
this.quickcommandInfo.output =
this.$refs.menu?.currentCommand.output || "text";
this.$refs.result.runCurrentCommand(this.quickcommandInfo);
this.$refs.result.runCurrentCommand(_.cloneDeep(this.quickcommandInfo));
},
},
};

View File

@@ -165,13 +165,8 @@
<q-item v-bind="scope.itemProps">
<q-item-section>
<q-item-label v-html="scope.opt.label" />
<q-tooltip v-if="!scope.opt.type">
注意需要自行在变量两边加上引号,如"{{ scope.opt.label }}"
</q-tooltip>
<q-tooltip v-else>
需要自行对json进行处理如json.loads(r"""{{
scope.opt.label
}}""")
<q-tooltip v-if="scope.opt.tooltip">
{{ scope.opt.tooltip }}
</q-tooltip>
<q-item-label caption>{{ scope.opt.desc }}</q-item-label>
</q-item-section>
@@ -337,7 +332,7 @@ export default {
this.cmdMatch = `/${this.cmdMatch}/`;
},
insertSpecialVar(text) {
this.$parent.$refs.editor.repacleEditorSelection(text);
this.$parent.$refs.editor.repacleEditorSelection(`'${text}'`);
},
// 保存各类数据
SaveMenuData() {

View File

@@ -44,6 +44,7 @@
<script>
import outputTypes from "../js/options/outputTypes.js";
import specialVars from "../js/options/specialVars.js";
export default {
data() {
@@ -67,8 +68,8 @@ export default {
methods: {
// 运行命令
async runCurrentCommand(currentCommand) {
currentCommand.cmd = window.special(currentCommand.cmd);
currentCommand.cmd = await this.replaceTempInputVals(currentCommand.cmd);
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
// currentCommand.cmd = await this.replaceTempInputVars(currentCommand.cmd);
let { hideWindow, outPlugin, action } =
outputTypes[currentCommand.output];
// 需要隐藏的提前隐藏窗口
@@ -102,14 +103,24 @@ export default {
);
}
},
// 特殊变量赋值
assignSpecialVars(cmd) {
let spVars = _.filter(specialVars, (sp) => sp.repl);
_.forIn(spVars, (val, key) => {
if (cmd.includes(val.label.slice(0, 12))) {
cmd = cmd.replace(val.match, (x) => val.repl(x));
}
});
return cmd;
},
// 替换特殊变量
async replaceTempInputVals(cmd) {
async replaceTempInputVars(cmd) {
let tempInputVals = [];
let needInputVal = [
"input",
"subinput",
"pwd",
"SelectFile",
// "SelectFile",
"WindowInfo",
"MatchedFiles",
];