添加OptionEditor组件,优化参数传递方式

This commit is contained in:
fofolee
2025-01-10 12:15:04 +08:00
parent ada0d2b968
commit 41b3501945
26 changed files with 764 additions and 478 deletions

View File

@@ -52,7 +52,7 @@ export default defineComponent({
localConfig() {
return [...this.commonConfig, ...this.subCommandConfig].map((item) => {
const value =
item.type === "varInput"
item.component === "VariableInput"
? item.defaultValue || newVarInputVal("str")
: // 其他类型情况复杂不做判断没有默认值返回undefined
item.defaultValue;
@@ -147,15 +147,27 @@ export default defineComponent({
if (!code) return argvs;
const variableFormatPaths = [];
const addVariableFormatPath = (prefix, config) => {
if (config.component === "VariableInput") {
variableFormatPaths.push(prefix);
} else if (config.component === "ArrayEditor") {
variableFormatPaths.push(`${prefix}[*]`);
} else if (config.component === "DictEditor") {
variableFormatPaths.push(`${prefix}.**`);
}
};
this.localConfig.forEach((item, index) => {
if (item.type === "varInput") {
variableFormatPaths.push(`arg${index}`);
} else if (item.type === "arrayEditor") {
variableFormatPaths.push(`arg${index}[*]`);
} else if (item.type === "dictEditor") {
variableFormatPaths.push(`arg${index}.**`);
if (item.component === "OptionEditor") {
Object.entries(item.options).forEach(([key, config]) => {
addVariableFormatPath(`arg${index}.${key}`, config);
});
} else {
addVariableFormatPath(`arg${index}`, item);
}
});
try {
argvs = parseFunction(code, { variableFormatPaths }).argvs;
} catch (e) {