From 94ba695fa9a4ef02a1ec0bc7b6232afe23cb71d1 Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 6 Jan 2025 00:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E6=8E=92=E6=96=B0=E5=A2=9E=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=BB=84=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/composer/MultiParams.vue | 23 +++++++++++++++++-- src/js/composer/commands/index.js | 2 ++ src/js/composer/commands/uiCommand.js | 30 +++++++++++++++++++++++++ src/js/composer/formatString.js | 3 +++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/js/composer/commands/uiCommand.js diff --git a/src/components/composer/MultiParams.vue b/src/components/composer/MultiParams.vue index ed65fdf..93a1a9a 100644 --- a/src/components/composer/MultiParams.vue +++ b/src/components/composer/MultiParams.vue @@ -53,6 +53,9 @@ :icon="item.icon" /> +
+ +
@@ -62,13 +65,20 @@ import { defineComponent } from "vue"; import VariableInput from "components/composer/ui/VariableInput.vue"; import NumberInput from "components/composer/ui/NumberInput.vue"; -import { stringifyWithType, parseToHasType } from "js/composer/formatString"; +import ArrayEditor from "components/composer/ui/ArrayEditor.vue"; +import { + stringifyWithType, + stringifyObject, + parseToHasType, + parseFunction, +} from "js/composer/formatString"; export default defineComponent({ name: "MultiParams", components: { VariableInput, NumberInput, + ArrayEditor, }, props: { modelValue: { @@ -119,7 +129,11 @@ export default defineComponent({ }, generateCode(funcName, argvs) { const newArgvs = argvs - .map((argv) => stringifyWithType(argv)) + .map((argv) => { + return typeof argv === "string" + ? stringifyWithType(argv) + : stringifyObject(argv); + }) .filter((item) => item != null && item !== ""); console.log(newArgvs); return `${funcName}(${newArgvs.join(",")})`; @@ -167,6 +181,11 @@ export default defineComponent({ } else if (config.type === "numInput") { // 对于 NumberInput 类型,转换为数字 argvs[index] = Number(param) || 0; + } else if (config.type === "arrayEditor") { + let result = parseFunction(`${this.funcName}(${param})`, [ + "arg0[*]", + ]); + argvs[index] = result.argv; } else { // 其他类型直接使用值 argvs[index] = param; diff --git a/src/js/composer/commands/index.js b/src/js/composer/commands/index.js index 36ce5fb..2c52b58 100644 --- a/src/js/composer/commands/index.js +++ b/src/js/composer/commands/index.js @@ -6,6 +6,7 @@ import { dataCommands } from "./dataCommands"; import { otherCommands } from "./otherCommands"; import { simulateCommands } from "./simulateCommands"; import { controlCommands } from "./controlCommands"; +import { uiCommands } from "./uiCommand"; export const commandCategories = [ fileCommands, @@ -16,4 +17,5 @@ export const commandCategories = [ controlCommands, otherCommands, simulateCommands, + uiCommands, ]; diff --git a/src/js/composer/commands/uiCommand.js b/src/js/composer/commands/uiCommand.js new file mode 100644 index 0000000..b60b8fe --- /dev/null +++ b/src/js/composer/commands/uiCommand.js @@ -0,0 +1,30 @@ +export const uiCommands = { + label: "UI操作", + icon: "auto_graph", + defaultOpened: false, + commands: [ + { + value: "quickcommand.showButtonBox", + label: "按钮组弹窗", + isAsync: true, + config: [ + { + label: "按钮组", + type: "arrayEditor", + defaultValue: [ + { + value: "按钮1", + isString: true, + __varInputVal__: true, + }, + { + value: "按钮2", + isString: true, + __varInputVal__: true, + }, + ], + }, + ], + }, + ], +}; diff --git a/src/js/composer/formatString.js b/src/js/composer/formatString.js index 3b2f2f3..96c4915 100644 --- a/src/js/composer/formatString.js +++ b/src/js/composer/formatString.js @@ -95,6 +95,9 @@ const processObject = (obj, parentPath = "") => { * @returns {string} 格式化后的JSON字符串 */ export const stringifyObject = (jsonObj) => { + if (jsonObj instanceof Array) { + return `[${jsonObj.map((item) => stringifyObject(item)).join(",")}]`; + } if (jsonObj?.hasOwnProperty("__varInputVal__")) { return stringifyWithType(jsonObj); }