diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 46af740..81e818b 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -4,9 +4,9 @@ ref="sidebar" :canCommandSave="canCommandSave" :quickcommandInfo="quickcommandInfo" + :allQuickCommandTags="allQuickCommandTags" class="absolute-left shadow-1" :style="{ - width: sideBarWidth + 'px', zIndex: 1, transform: isFullscreen ? 'translateX(-100%)' : 'translateX(0)', transition: 'transform 0.3s cubic-bezier(0.4, 0, 0.2, 1)', @@ -64,7 +64,11 @@ - + @@ -78,6 +82,7 @@ import CommandLanguageBar from "components/editor/CommandLanguageBar"; import EditorTools from "components/editor/EditorTools"; import CommandRunResult from "components/CommandRunResult"; import CommandComposer from "components/composer/CommandComposer.vue"; +import programs from "js/options/programs.js"; // 预加载 MonacoEditor const MonacoEditorPromise = import("components/editor/MonacoEditor"); @@ -109,13 +114,22 @@ export default { }, data() { return { - programLanguages: Object.keys(this.$root.programs), + programLanguages: Object.keys(programs), sideBarWidth: 200, languageBarHeight: 40, showComposer: false, isRunCodePage: this.action.type === "run", canCommandSave: this.action.type !== "run", showSidebar: this.action.type !== "run", + flows: [ + { + id: "main", + name: "main", + label: "主流程", + commands: [], + customVariables: [], + }, + ], quickcommandInfo: { program: "quickcommand", cmd: "", @@ -141,15 +155,9 @@ export default { required: true, }, allQuickCommandTags: Array, - isLeaving: { - type: Boolean, - default: false, - }, - }, - created() { - this.commandInit(); }, mounted() { + this.commandInit(); this.sidebarInit(); }, computed: { @@ -196,7 +204,7 @@ export default { // 匹配编程语言 matchLanguage() { if (!this.quickcommandInfo.customOptions.ext) return; - let language = Object.values(this.$root.programs).filter( + let language = Object.values(programs).filter( (program) => program.ext === this.quickcommandInfo.customOptions.ext ); if (language.length) { @@ -205,7 +213,7 @@ export default { }, // 设置编程语言 setLanguage(language) { - let highlight = this.$root.programs[language].highlight; + let highlight = programs[language].highlight; this.$refs.editor.setEditorLanguage(highlight ? highlight : language); }, insertText(text) { @@ -216,14 +224,16 @@ export default { this.$refs.editor.setEditorValue(text); this.$refs.editor.formatDocument(); }, - handleComposer({ type, code }) { - switch (type) { + handleComposerAction(actionType, actionData) { + switch (actionType) { case "run": - return this.runCurrentCommand(code); + return this.runCurrentCommand(actionData); case "insert": - return this.insertText(code); + return this.insertText(actionData); case "apply": - return this.replaceText(code); + return this.replaceText(actionData); + case "close": + return this.showComposer = false; } }, // 保存 diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index de82142..19f8428 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -75,6 +75,8 @@ import specialVars from "js/options/specialVars.js"; import commandTypes from "js/options/commandTypes.js"; import ResultArea from "components/ResultArea.vue"; import ResultMenu from "components/popup/ResultMenu.vue"; +import { generateFlowsCode } from "js/composer/generateCode"; +import { getValidCommand } from "js/commandManager"; export default { components: { ResultArea, ResultMenu }, @@ -127,11 +129,20 @@ export default { methods: { // 运行命令 async runCurrentCommand(currentCommand) { + let command = window.lodashM.cloneDeep(currentCommand); + // 如果是composer命令,则动态生成cmd + if (command.program === "quickcomposer") { + command.cmd = generateFlowsCode(command.flows); + } this.$root.isRunningCommand = true; - await this.getTempPayload(currentCommand); - if (currentCommand.cmd.includes("{{subinput")) - return this.setSubInput(currentCommand); - this.fire(currentCommand); + try { + await this.getTempPayload(command); + } catch (error) { + return quickcommand.showMessageBox(error.toString(), "error"); + } + // 如果命令包含子输入框,则设置子输入框 + if (command.cmd.includes("{{subinput")) return this.setSubInput(command); + this.fire(command); }, async fire(currentCommand) { currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd); @@ -147,6 +158,7 @@ export default { let resultOpts = { outPlugin, action, earlyExit }; switch (currentCommand.program) { case "quickcommand": + case "quickcomposer": window.runCodeInSandbox( currentCommand.cmd, (stdout, stderr) => this.handleResult(stdout, stderr, resultOpts), @@ -278,11 +290,15 @@ export default { // payload 临时赋值 async getTempPayload(currentCommand) { if (!this.needTempPayload) return; - let type = - currentCommand.cmdType || currentCommand.features?.cmds[0].type; + currentCommand = getValidCommand(currentCommand); + const firstCmd = currentCommand.features.cmds[0]; + const type = firstCmd.type || "text"; this.$root.enterData = { - type: type || "text", - payload: await commandTypes[type]?.tempPayload?.(), + type, + payload: + type === "text" + ? firstCmd + : (await commandTypes[type]?.tempPayload?.()) || {}, }; }, handleResult(stdout, stderr, options) { diff --git a/src/components/ComposerEditor.vue b/src/components/ComposerEditor.vue index 19b7cdb..6cdfc8a 100644 --- a/src/components/ComposerEditor.vue +++ b/src/components/ComposerEditor.vue @@ -1,8 +1,9 @@