fix(config-page): 支持 json 配置类型的序列化/反序列化(同 dict_str_int)
llm_token_price 新 type=json(嵌套 JSON 含浮点数,非 str→int 映射)在配置页 需 JSON.stringify/JSON.parse,与 dict_str_int 共用编辑框。
This commit is contained in:
@@ -11,7 +11,7 @@ interface ConfigItem {
|
|||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
group: string;
|
group: string;
|
||||||
type: string; // int / int_list / dict_str_int / bool
|
type: string; // int / int_list / dict_str_int / bool / json
|
||||||
help: string | null;
|
help: string | null;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
default: any;
|
default: any;
|
||||||
@@ -24,7 +24,7 @@ interface ConfigItem {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function toEdit(item: ConfigItem): any {
|
function toEdit(item: ConfigItem): any {
|
||||||
if (item.type === 'int_list') return (item.value as number[]).join(', ');
|
if (item.type === 'int_list') return (item.value as number[]).join(', ');
|
||||||
if (item.type === 'dict_str_int') return JSON.stringify(item.value);
|
if (item.type === 'dict_str_int' || item.type === 'json') return JSON.stringify(item.value);
|
||||||
return item.value;
|
return item.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ function fromEdit(type: string, raw: any): any {
|
|||||||
.split(',')
|
.split(',')
|
||||||
.map((s) => parseInt(s.trim(), 10));
|
.map((s) => parseInt(s.trim(), 10));
|
||||||
}
|
}
|
||||||
if (type === 'dict_str_int') return JSON.parse(raw);
|
if (type === 'dict_str_int' || type === 'json') return JSON.parse(raw);
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user