From 17cec93767caed8f73afea62c8d66ff134d4635b Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 27 Jan 2025 13:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E4=BB=A4=E6=A6=82?= =?UTF-8?q?=E8=A7=88=E7=9A=84=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=98=BE=E7=A4=BA=E8=BE=93=E5=85=A5=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/composer/MultiParams.vue | 81 +++++++++++++++---------- src/js/composer/varInputValManager.js | 2 +- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/components/composer/MultiParams.vue b/src/components/composer/MultiParams.vue index 3e6d6c2..0d13dcc 100644 --- a/src/components/composer/MultiParams.vue +++ b/src/components/composer/MultiParams.vue @@ -3,7 +3,7 @@ @@ -15,7 +15,11 @@ import { defineComponent } from "vue"; import OperationCard from "components/composer/common/OperationCard.vue"; import ParamInput from "components/composer/param/ParamInput.vue"; import { stringifyArgv, parseFunction } from "js/composer/formatString"; -import { newVarInputVal } from "js/composer/varInputValManager"; +import { + newVarInputVal, + isVarInputVal, + stringifyVarInputVal, +} from "js/composer/varInputValManager"; export default defineComponent({ name: "MultiParams", @@ -59,26 +63,8 @@ export default defineComponent({ defaultArgvs() { return this.localConfig.map((item) => item.value); }, - funcName: { - get() { - return this.modelValue.value; - }, - set(value) { - // 构建新的参数数组 - const newArgvs = []; - - // 保留通用配置的参数值 - this.commonConfig.forEach((_, index) => { - newArgvs[index] = this.argvs[index]; - }); - - // 使用新选择的函数独有配置的默认值 - this.getSelectSubCommand(value)?.config?.forEach((config, index) => { - newArgvs[this.commonConfig.length + index] = config.defaultValue; - }); - - this.updateModelValue(value, newArgvs, true); - }, + funcName() { + return this.modelValue.value; }, argvs() { return ( @@ -101,6 +87,22 @@ export default defineComponent({ this.updateModelValue(this.funcName, newArgvs); }, + updateFuncName(value) { + // 构建新的参数数组 + const newArgvs = []; + + // 保留通用配置的参数值 + this.commonConfig.forEach((_, index) => { + newArgvs[index] = this.argvs[index]; + }); + + // 使用新选择的函数独有配置的默认值 + this.getSelectSubCommand(value)?.config?.forEach((config, index) => { + newArgvs[this.commonConfig.length + index] = config.defaultValue; + }); + + this.updateModelValue(value, newArgvs, true); + }, generateCode(funcName, argvs) { if (this.localCommand.isExpression) { return argvs.join(""); @@ -175,18 +177,31 @@ export default defineComponent({ } return argvs; }, - getSummary(argvs) { + getAllInputValues(argvs) { + const flatArgvs = []; + argvs.forEach((item) => { + if (isVarInputVal(item) && item.value) { + flatArgvs.push(stringifyVarInputVal(item)); + } else if (typeof item === "number") { + flatArgvs.push(item.toString()); + } else if (Array.isArray(item)) { + flatArgvs.push(...this.getAllInputValues(item)); + } else if (typeof item === "object") { + flatArgvs.push(...this.getAllInputValues(Object.values(item))); + } + }); + return flatArgvs; + }, + getSummary(funcName, argvs) { // 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间 - const funcNameLabel = this.getSelectSubCommand()?.label; + const funcNameLabel = this.getSelectSubCommand(funcName)?.label; const subFeature = funcNameLabel ? `${funcNameLabel} ` : ""; - const allArgvs = argvs - .filter((item) => item != null && item != "") - .map((item) => - window.lodashM.truncate(stringifyArgv(item).toString(), { - length: 30, - omission: "...", - }) - ); + const allArgvs = this.getAllInputValues(argvs).map((item) => + window.lodashM.truncate(item, { + length: 30, + omission: "...", + }) + ); return `${subFeature}${allArgvs.join(",")}`; }, updateModelValue(funcName, argvs, resetOutputVariable = false) { @@ -194,7 +209,7 @@ export default defineComponent({ ...this.modelValue, value: funcName, argvs, - summary: this.getSummary(argvs), + summary: this.getSummary(funcName, argvs), code: this.generateCode(funcName, argvs), }; if (resetOutputVariable) { diff --git a/src/js/composer/varInputValManager.js b/src/js/composer/varInputValManager.js index 698589a..9085cbf 100644 --- a/src/js/composer/varInputValManager.js +++ b/src/js/composer/varInputValManager.js @@ -37,7 +37,7 @@ export const newEmptyVarInputVal = (type = "str") => { * @returns {string} 处理后的字符串 */ export const stringifyVarInputVal = (argv) => { - if (!argv.isString) return argv.value; + if (!argv.isString) return argv.value.toString(); try { return JSON.stringify(argv.value); } catch (e) {