feat: sync rule management and review ui fixes

This commit is contained in:
wren
2026-05-07 17:27:42 +08:00
parent 87e82d1caa
commit c00e5feff0
13 changed files with 565 additions and 161 deletions
+40 -3
View File
@@ -179,6 +179,15 @@ export function validateEditableRuleConfig(config: EditableRuleConfig): Validati
message: '字段类型不能为空。'
});
}
if (field.type === 'enum' && (!Array.isArray(field.allowed) || field.allowed.length === 0)) {
issues.push({
id: `field-allowed-${field.id}`,
severity: 'error',
area: '抽取配置',
target: field.name || '未命名字段',
message: '枚举字段必须配置可选值。'
});
}
});
config.subDocuments.forEach(document => {
@@ -219,6 +228,15 @@ export function validateEditableRuleConfig(config: EditableRuleConfig): Validati
message: '文书字段类型不能为空。'
});
}
if (field.type === 'enum' && (!Array.isArray(field.allowed) || field.allowed.length === 0)) {
issues.push({
id: `document-field-allowed-${document.id}-${field.id}`,
severity: 'error',
area: '案卷文书',
target: field.name || '未命名字段',
message: '文书枚举字段必须配置可选值。'
});
}
});
});
@@ -318,6 +336,7 @@ function rewriteExtractNodes(fields: ExtractFieldSummary[]): Array<Record<string
fields: items.map((field) => ({
name: field.name,
type: field.multipleEntities ? 'multi_entity' : field.type || 'verbatim',
...(field.type === 'enum' && Array.isArray(field.allowed) && field.allowed.length > 0 ? { allowed: [...field.allowed] } : {}),
required_from: field.requiredFrom || 'draft',
desc: field.description || '',
})),
@@ -334,6 +353,7 @@ function rewriteSubDocumentNodes(subDocuments: SubDocumentSummary[]): Array<Reco
fields: fields.map((field) => ({
name: field.name,
type: field.multipleEntities ? 'multi_entity' : field.type || 'verbatim',
...(field.type === 'enum' && Array.isArray(field.allowed) && field.allowed.length > 0 ? { allowed: [...field.allowed] } : {}),
desc: field.description || '',
})),
})),
@@ -353,11 +373,21 @@ function rewriteVisualElementNodes(visualElements: VisualElementSummary[]): Reco
name: item.name,
required: normalizeBooleanText(item.required),
};
if (item.signerRoles && item.signerRoles.length > 0) node.signer_roles = [...item.signerRoles];
if (item.signatureTypes && item.signatureTypes.length > 0) node.signature_types = [...item.signatureTypes];
if (item.privateSealRestricted) node.private_seal_restricted = true;
if (item.requiredFrom) node.required_from = item.requiredFrom;
if (item.expectedMatchField) {
node.expected_text_match = {
field: item.expectedMatchField,
...(item.expectedMatchAlternatives && item.expectedMatchAlternatives.length > 0
? { alternatives: [...item.expectedMatchAlternatives] }
: {}),
};
}
if (item.prompt) node.prompt = item.prompt;
if (item.type === '签名') {
if (item.signerRoles && item.signerRoles.length > 0) node.signer_roles = [...item.signerRoles];
if (item.signatureTypes && item.signatureTypes.length > 0) node.signature_types = [...item.signatureTypes];
if (item.privateSealRestricted) node.private_seal_restricted = true;
sections.signatures.push(node);
return;
}
@@ -365,6 +395,7 @@ function rewriteVisualElementNodes(visualElements: VisualElementSummary[]): Reco
sections.cross_page_seals.push(node);
return;
}
if (item.signatureTypes && item.signatureTypes.length > 0) node.allowed_types = [...item.signatureTypes];
sections.seals.push(node);
});
@@ -584,6 +615,9 @@ export function buildYamlPreview(config: EditableRuleConfig): string {
lines.push(
` - name: ${yamlValue(field.name)}`,
` type: ${yamlValue(field.multipleEntities ? 'multi_entity' : field.type)}`,
...(field.type === 'enum' && Array.isArray(field.allowed) && field.allowed.length > 0
? [` allowed: [${field.allowed.map((item) => yamlValue(item)).join(', ')}]`]
: []),
` desc: ${yamlValue(field.description)}`
);
});
@@ -607,6 +641,9 @@ export function buildYamlPreview(config: EditableRuleConfig): string {
lines.push(
` - name: ${yamlValue(field.name)}`,
` type: ${yamlValue(field.multipleEntities ? 'multi_entity' : field.type)}`,
...(field.type === 'enum' && Array.isArray(field.allowed) && field.allowed.length > 0
? [` allowed: [${field.allowed.map((item) => yamlValue(item)).join(', ')}]`]
: []),
` desc: ${yamlValue(field.description)}`
);
});