feat: align frontend document and rule management flows
This commit is contained in:
@@ -89,7 +89,7 @@ export type RuleYamlPack = RulePackScope & {
|
||||
}>;
|
||||
};
|
||||
|
||||
const EMPTY_YAML = `metadata:
|
||||
export const EMPTY_RULE_YAML = `metadata:
|
||||
type_id: pending.internal.document
|
||||
name: 内部公文规则配置
|
||||
version: '0.1'
|
||||
@@ -377,6 +377,10 @@ function parseRules(source: string): RuleSummary[] {
|
||||
});
|
||||
}
|
||||
|
||||
export function parseRuleSummariesFromYaml(source: string): RuleSummary[] {
|
||||
return parseRules(source);
|
||||
}
|
||||
|
||||
function parseTopLevelFields(source: string): ExtractFieldSummary[] {
|
||||
const section = getTopLevelSection(source, 'extract');
|
||||
const extractedFields = splitBlocks(section, /^-\s+group:\s*/).flatMap(groupBlock => {
|
||||
@@ -513,7 +517,11 @@ function parseVisualElements(source: string): RuleYamlPack['visualElements'] {
|
||||
}).filter(item => item.id);
|
||||
}
|
||||
|
||||
function buildPack(config: RulePackScope & { id: string; yamlPath: string | null }, yamlSource: string, sourceStatus: RuleYamlPack['sourceStatus']): RuleYamlPack {
|
||||
export function buildRuleYamlPack(
|
||||
config: RulePackScope & { id: string; yamlPath: string | null },
|
||||
yamlSource: string,
|
||||
sourceStatus: RuleYamlPack['sourceStatus']
|
||||
): RuleYamlPack {
|
||||
const metadata = parseMetadata(yamlSource);
|
||||
const fields = parseTopLevelFields(yamlSource);
|
||||
const subDocuments = parseSubDocuments(yamlSource);
|
||||
@@ -547,14 +555,14 @@ export async function loadRuleYamlPacks(): Promise<RuleYamlPack[]> {
|
||||
// 2. 后端读取 OSS YAML 正文并返回元数据和内容;
|
||||
// 3. 前端仍消费 buildPack 之后的结构化数据,页面不直接关心 OSS 实现。
|
||||
if (!config.yamlPath) {
|
||||
return buildPack(config, EMPTY_YAML, 'empty');
|
||||
return buildRuleYamlPack(config, EMPTY_RULE_YAML, 'empty');
|
||||
}
|
||||
|
||||
try {
|
||||
const yamlSource = await readFile(config.yamlPath, 'utf8');
|
||||
return buildPack(config, yamlSource, 'ready');
|
||||
return buildRuleYamlPack(config, yamlSource, 'ready');
|
||||
} catch {
|
||||
return buildPack(config, EMPTY_YAML, 'missing');
|
||||
return buildRuleYamlPack(config, EMPTY_RULE_YAML, 'missing');
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user