feat(json-schema-editor): JSON编辑器新增 isContainer 容器字段联动隐藏配置
将旧的分级 upLevel/remove 联动规则改为基于完整路径的平铺结构。
新增特性:
- 标量字段(string/number/boolean)配置面板中增加"容器字段"开关
- 开关打开后展示"联动隐藏"下拉菜单,列出当前字段同级及以上所有可选字段
- 下拉展示格式:"字段key — 完整路径"(如 type — messages.attrs[0].content.attrs[0].type)
- 选中后以 { key: path } 格式输出,渲染器按路径直接定位隐藏字段
核心改动:
- index.vue: 新增 getAvailableFields / getNodeJsonPath 替代旧的分级遍历逻辑
- getAvailableFields: 从当前字段向上遍历,跳过数组层级,根级只含容器自身
- getNodeJsonPath: inAttrs 状态机生成完整路径(messages.attrs[0].content.attrs[0].type)
- linkRules 类型从 Array<{ upLevel, remove[] }> 改为 Array<Record<string, string>>
- formToConfig / hasAnyConfig 同步更新
- FieldConfigDialog.vue: 重构联动隐藏UI,单 el-select multiple 替代分级 checkbox
- JsonNode.vue: 类型同步 + 摘要显示容器触发器及规则数
数据格式示例:
"isContainer": true,
"linkRules": [
{ "type": "messages.attrs[0].content.attrs[0].type" }
]
This commit is contained in:
@@ -92,6 +92,8 @@ interface JsonNodeData {
|
||||
role?: string;
|
||||
isForm?: boolean;
|
||||
required?: boolean;
|
||||
isContainer?: boolean;
|
||||
linkRules?: Array<Record<string, string>>;
|
||||
defaultValue?: string | number;
|
||||
options?: Array<{ label: string; value: string }>;
|
||||
constraint?: Record<string, any>;
|
||||
@@ -105,6 +107,8 @@ function hasConfig(node: JsonNodeData): boolean {
|
||||
if (c.options?.length) return true;
|
||||
if (c.required) return true;
|
||||
if (c.isForm === false) return true;
|
||||
if (c.isContainer) return true;
|
||||
if (c.linkRules?.length) return true;
|
||||
if (c.constraint && Object.keys(c.constraint).length > 0) return true;
|
||||
const defaultTypes: Record<string, string> = { string: 'string', number: 'number', boolean: 'switch' };
|
||||
if (c.fieldType && c.fieldType !== defaultTypes[node.type]) return true;
|
||||
@@ -128,6 +132,10 @@ function configSummary(node: JsonNodeData): string {
|
||||
if (c.defaultValue !== undefined && c.defaultValue !== '' && c.defaultValue !== null) {
|
||||
parts.push(`默认=${c.defaultValue}`);
|
||||
}
|
||||
if (c.isContainer) {
|
||||
parts.push("容器触发器");
|
||||
if (c.linkRules?.length) parts.push(`联动 ${c.linkRules.length} 条规则`);
|
||||
}
|
||||
const con = c.constraint;
|
||||
if (con) {
|
||||
if (con.minLength || con.maxLength) {
|
||||
|
||||
Reference in New Issue
Block a user