实现编排的插入、应用、运行功能

This commit is contained in:
fofolee 2024-12-23 13:31:13 +08:00
parent a22e1e23e9
commit c8a9a63dcb
3 changed files with 40 additions and 43 deletions

View File

@ -38,7 +38,7 @@
@program-changed="programChanged" @program-changed="programChanged"
@run="runCurrentCommand" @run="runCurrentCommand"
@save="saveCurrentCommand" @save="saveCurrentCommand"
@add-action="insertText" @use-composer="handleComposer"
/> />
<!-- 编辑器 --> <!-- 编辑器 -->
@ -196,6 +196,16 @@ export default {
insertText(text) { insertText(text) {
this.$refs.editor.repacleEditorSelection(text); this.$refs.editor.repacleEditorSelection(text);
}, },
handleComposer({ type, code }) {
switch (type) {
case "run":
return this.runCurrentCommand(code);
case "insert":
return this.insertText(code);
case "apply":
return this.$refs.editor.setEditorValue(code);
}
},
// //
saveCurrentCommand(message = "保存成功") { saveCurrentCommand(message = "保存成功") {
let updatedData = this.$refs.sidebar?.SaveMenuData(); let updatedData = this.$refs.sidebar?.SaveMenuData();

View File

@ -39,8 +39,8 @@
<template v-if="modelValue.program === 'quickcommand'"> <template v-if="modelValue.program === 'quickcommand'">
<q-btn <q-btn
v-for="(item, index) in [ v-for="(item, index) in [
'keyboard', // 'keyboard',
'rocket_launch', // 'rocket_launch',
'help_center', 'help_center',
'view_timeline', 'view_timeline',
]" ]"
@ -53,7 +53,8 @@
@click="handleQuickCommandAction(index)" @click="handleQuickCommandAction(index)"
> >
<q-tooltip> <q-tooltip>
{{ ["录制按键", "快捷动作", "查看文档", "可视化编排"][index] }} <!-- {{ ["录制按键", "快捷动作", "查看文档", "可视化编排"][index] }} -->
{{ ["查看文档", "可视化编排"][index] }}
</q-tooltip> </q-tooltip>
</q-btn> </q-btn>
</template> </template>
@ -162,17 +163,16 @@
</div> </div>
<!-- 移动对话框到这里 --> <!-- 移动对话框到这里 -->
<q-dialog v-model="showActions"> <!-- <q-dialog v-model="showActions">
<QuickAction @addAction="addAction" /> <QuickAction @addAction="addAction" />
</q-dialog> </q-dialog> -->
<q-dialog v-model="showRecorder" position="bottom"> <!-- <q-dialog v-model="showRecorder" position="bottom">
<KeyRecorder @sendKeys="addAction" /> <KeyRecorder @sendKeys="addAction" />
</q-dialog> </q-dialog> -->
<q-dialog v-model="showComposer" maximized> <q-dialog v-model="showComposer" maximized>
<CommandComposer <CommandComposer
ref="composer" ref="composer"
@run="handleComposerRun" @use-composer="handleComposer"
@apply="handleComposerApply"
@update:model-value="showComposer = false" @update:model-value="showComposer = false"
/> />
</q-dialog> </q-dialog>
@ -180,15 +180,15 @@
</template> </template>
<script> <script>
import QuickAction from "components/popup/QuickAction"; // import QuickAction from "components/popup/QuickAction";
import KeyRecorder from "components/popup/KeyRecorder"; // import KeyRecorder from "components/popup/KeyRecorder";
import CommandComposer from "components/editor/composer/CommandComposer.vue"; import CommandComposer from "components/editor/composer/CommandComposer.vue";
export default { export default {
name: "CommandLanguageBar", name: "CommandLanguageBar",
components: { components: {
QuickAction, // QuickAction,
KeyRecorder, // KeyRecorder,
CommandComposer, CommandComposer,
}, },
props: { props: {
@ -211,8 +211,8 @@ export default {
}, },
data() { data() {
return { return {
showActions: false, // showActions: false,
showRecorder: false, // showRecorder: false,
showComposer: false, showComposer: false,
}; };
}, },
@ -280,32 +280,22 @@ export default {
}, },
handleQuickCommandAction(index) { handleQuickCommandAction(index) {
const actions = [ const actions = [
() => (this.showRecorder = true), // () => (this.showRecorder = true),
() => (this.showActions = true), // () => (this.showActions = true),
() => this.showHelp(), () => this.showHelp(),
() => (this.showComposer = true), () => (this.showComposer = true),
]; ];
actions[index](); actions[index]();
}, },
addAction(text) { // addAction(text) {
this.$emit("add-action", text); // this.$emit("add-action", text);
}, // },
showHelp() { showHelp() {
window.showUb.docs(); window.showUb.docs();
}, },
handleComposerRun(code) { handleComposer({ type, code }) {
this.$emit("add-action", code); this.$emit("use-composer", { type, code });
}, if (type !== "run") this.showComposer = false;
handleComposerApply(code) {
this.$emit("add-action", code);
this.showComposer = false;
},
applyComposerCommands() {
if (this.$refs.composer) {
const code = this.$refs.composer.generateCode();
this.$emit("add-action", code);
}
this.showComposer = false;
}, },
}, },
}; };

View File

@ -25,8 +25,9 @@
<!-- 固定底部 --> <!-- 固定底部 -->
<div class="composer-footer q-pa-sm q-gutter-sm row justify-end"> <div class="composer-footer q-pa-sm q-gutter-sm row justify-end">
<q-btn label="取消" v-close-popup /> <q-btn label="取消" v-close-popup />
<q-btn color="primary" label="确认" @click="applyCommands" /> <q-btn color="primary" label="插入" @click="handleComposer('insert')" />
<q-btn color="positive" label="运行" @click="runCommands" /> <q-btn color="primary" label="应用" @click="handleComposer('apply')" />
<q-btn color="positive" label="运行" @click="handleComposer('run')" />
</div> </div>
</div> </div>
</template> </template>
@ -98,14 +99,10 @@ export default defineComponent({
return code.join("\n"); return code.join("\n");
}, },
runCommands() { handleComposer(type) {
const code = this.generateCode(); const code = this.generateCode();
this.$emit("run", code); this.$emit("use-composer", { type, code });
}, if (type !== "run") this.$emit("update:modelValue", false);
applyCommands() {
const code = this.generateCode();
this.$emit("apply", code);
this.$emit("update:modelValue", false);
}, },
}, },
}); });