From 2cb0c6bb325ce9f2d5a9904cc5745e4364363781 Mon Sep 17 00:00:00 2001 From: fofolee Date: Wed, 12 Feb 2025 23:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E7=BC=96=E6=8E=92?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4=E9=85=8D=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandEditor.vue | 44 +- src/components/CommandRunResult.vue | 32 +- src/components/ComposerEditor.vue | 127 ++++- src/components/card/layouts/DenseLayout.vue | 8 +- src/components/card/layouts/ListLayout.vue | 6 + src/components/composer/CommandComposer.vue | 14 +- src/components/composer/ComposerCard.vue | 9 +- src/components/composer/ComposerFlow.vue | 4 - src/components/composer/FlowTabs.vue | 164 +++---- .../composer/flow/ComposerButtons.vue | 26 +- src/components/editor/CommandConfig.vue | 336 +++++++++++++ src/components/editor/MatchRuleEditor.vue | 449 ++++++++++++++++++ src/css/composer.css | 4 + src/js/autoDetach.js | 66 --- src/js/commandManager.js | 53 ++- src/js/common/uuid.js | 6 +- src/js/composer/generateCode.js | 7 + src/js/options/commandTypes.js | 17 +- src/pages/CommandPage.vue | 2 +- src/pages/ConfigurationPage.vue | 16 +- 20 files changed, 1147 insertions(+), 243 deletions(-) create mode 100644 src/components/editor/CommandConfig.vue create mode 100644 src/components/editor/MatchRuleEditor.vue delete mode 100644 src/js/autoDetach.js 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 @@