66d2f7cef4
2.评查点列表添加文档属性类型字段。 3.优化dify的对话侧边栏的显示效果。 4.评查点规则添加使用文档属性类型的输入框。添加多实体开关的操作开关。
1197 lines
46 KiB
TypeScript
1197 lines
46 KiB
TypeScript
/**
|
||
* 评查点管理页面 - 创建或编辑评查点规则
|
||
*
|
||
* 功能概述:
|
||
* - 支持创建新的评查点规则或编辑现有规则
|
||
* - 评查点包含基本信息、抽取设置和评查设置三大部分
|
||
* - 支持使用三种抽取方式: 大模型(LLM)抽取、多模态(VLM)抽取和正则表达式抽取
|
||
* - 支持配置各种类型的评查规则,如存在性检查、内容一致性检查等
|
||
* - 支持保存评查规则和保存草稿功能
|
||
*
|
||
* 组件结构:
|
||
* - PageHeader: 页面标题和保存按钮
|
||
* - BasicInfo: 评查点的基本信息设置,如名称、编码、风险级别等
|
||
* - ExtractionSettings: 抽取设置,配置从文档中抽取哪些字段及抽取方式
|
||
* - ReviewSettings: 评查设置,基于抽取字段配置评查规则、评查结果消息等
|
||
* - ActionButtons: 页面底部的操作按钮,包括保存、保存草稿和返回
|
||
*
|
||
* 数据流转:
|
||
* 1. 页面加载时检查URL参数,确定是新建还是编辑模式
|
||
* 2. 编辑模式下从API获取评查点数据并填充表单
|
||
* 3. ExtractionSettings通过RuleContext将抽取的字段传递给ReviewSettings
|
||
* 4. 各组件的onChange回调收集表单变更并更新formData状态
|
||
* 5. 保存时将formData转换为API需要的格式并提交
|
||
*
|
||
* @author 中国烟草AI合同及卷宗审核系统开发团队
|
||
*/
|
||
|
||
import { type MetaFunction } from "@remix-run/node";
|
||
import { useState, useEffect, useCallback, useRef } from "react";
|
||
import { BasicInfo } from "~/components/rules/new/BasicInfo";
|
||
import { ExtractionSettings } from "~/components/rules/new/ExtractionSettings";
|
||
import { ReviewSettings } from "~/components/rules/new/ReviewSettings";
|
||
import { ActionButtons } from "~/components/rules/new/ActionButtons";
|
||
import { PageHeader } from "~/components/rules/new/PageHeader";
|
||
import rulesStyles from "~/styles/rules.css?url";
|
||
import { useNavigate, useLocation, useRouteLoaderData } from "@remix-run/react";
|
||
// 导入评查点模型定义和常量
|
||
import type {
|
||
EvaluationPoint,
|
||
LogicOperator,
|
||
CompareMethod,
|
||
FormatType,
|
||
ComparisonOperator,
|
||
MatchType,
|
||
ProgrammingLanguage
|
||
} from "~/models/evaluation_points";
|
||
import { EVALUATION_OPTIONS } from "~/models/evaluation_points";
|
||
import type { EvaluationPointGroup } from "~/models/evaluation_point_groups";
|
||
// 导入RuleContext上下文
|
||
import { RuleContext } from "~/contexts/RuleContext";
|
||
import { toastService } from '~/components/ui/Toast';
|
||
import { usePermission } from '~/hooks/usePermission';
|
||
import { getPromptTemplateOptions } from '~/api/prompts/prompts';
|
||
import {
|
||
createEvaluationPoint,
|
||
updateEvaluationPoint,
|
||
getEvaluationPoint,
|
||
type EvaluationPointData
|
||
} from '~/api/evaluation_points/rules';
|
||
import { getRulesList } from '~/api/evaluation_points/rules';
|
||
import { postgrestGet } from '~/api/postgrest-client';
|
||
|
||
export const meta: MetaFunction = () => {
|
||
return [
|
||
{ title: "评查点管理 - 中国烟草AI合同及卷宗审核系统" },
|
||
{
|
||
name: "description",
|
||
content: "创建或修改评查点,设置规则参数"
|
||
}
|
||
];
|
||
};
|
||
|
||
export function links() {
|
||
return [{ rel: "stylesheet", href: rulesStyles }];
|
||
}
|
||
|
||
export const handle = {
|
||
breadcrumb: "评查点管理"
|
||
};
|
||
|
||
// 添加规则配置接口
|
||
interface BaseRuleConfig {
|
||
availableFields?: string[];
|
||
}
|
||
|
||
interface ExistsRuleConfig extends BaseRuleConfig {
|
||
fields: string[];
|
||
logic: LogicOperator;
|
||
selectedFields?: string[];
|
||
existsLogic?: string;
|
||
}
|
||
|
||
interface ConsistencyRuleConfig extends BaseRuleConfig {
|
||
pairs: Array<{sourceField: string; targetField: string; compareMethod: CompareMethod}>;
|
||
logic: LogicOperator;
|
||
logicRelation?: string;
|
||
initialSourceField?: string;
|
||
initialTargetField?: string;
|
||
initialCompareMethod?: string;
|
||
}
|
||
|
||
interface FormatRuleConfig extends BaseRuleConfig {
|
||
field: string;
|
||
formatType: FormatType;
|
||
parameters: string;
|
||
checkField?: string;
|
||
formatParams?: string;
|
||
}
|
||
|
||
interface LogicRuleConfig extends BaseRuleConfig {
|
||
conditions: {
|
||
field: string;
|
||
operator: ComparisonOperator;
|
||
value: string;
|
||
}[];
|
||
logic: LogicOperator;
|
||
logicRelation?: string;
|
||
initialField?: string;
|
||
initialOperator?: string;
|
||
initialValue?: string;
|
||
}
|
||
|
||
interface RegexRuleConfig extends BaseRuleConfig {
|
||
field: string;
|
||
pattern: string;
|
||
matchType: MatchType;
|
||
checkField?: string;
|
||
regexPattern?: string;
|
||
}
|
||
|
||
interface AIRuleConfig extends BaseRuleConfig {
|
||
model: string;
|
||
temperature: number;
|
||
prompt: string;
|
||
}
|
||
|
||
interface CodeRuleConfig extends BaseRuleConfig {
|
||
language: ProgrammingLanguage;
|
||
code: string;
|
||
}
|
||
|
||
type RuleConfig = ExistsRuleConfig | ConsistencyRuleConfig | FormatRuleConfig | LogicRuleConfig | RegexRuleConfig | AIRuleConfig | CodeRuleConfig;
|
||
|
||
export default function RuleNew() {
|
||
const navigate = useNavigate();
|
||
const location = useLocation();
|
||
const [isEditMode, setIsEditMode] = useState(false);
|
||
const [isCopyMode, setIsCopyMode] = useState(false); // 添加复制模式状态
|
||
const [isLoading, setIsLoading] = useState(false);
|
||
const [instanceKey, setInstanceKey] = useState<string>('new');
|
||
// 从root路由获取JWT token
|
||
const rootData = useRouteLoaderData("root") as { frontendJWT?: string };
|
||
const frontendJWT = rootData?.frontendJWT;
|
||
|
||
// ✅ 使用权限 Hook
|
||
const { canCreate, canUpdate } = usePermission();
|
||
const canCreateRule = canCreate('evaluation_point');
|
||
const canUpdateRule = canUpdate('evaluation_point');
|
||
|
||
// ✅ 判断表单是否为只读模式
|
||
// 从 URL 检查是否为查看模式
|
||
const searchParams = new URLSearchParams(location.search);
|
||
const urlMode = searchParams.get('mode');
|
||
const isViewMode = urlMode === 'view';
|
||
|
||
// 根据模式和权限决定是否只读
|
||
const hasEditPermission = isEditMode ? canUpdateRule : canCreateRule;
|
||
const isReadOnly = isViewMode || !hasEditPermission;
|
||
|
||
// 使用 ref 跟踪当前加载的 URL,避免重复加载
|
||
const loadedUrlRef = useRef<string>('');
|
||
|
||
const [formData, setFormData] = useState<EvaluationPoint>({});
|
||
const [evaluationPointGroups, setEvaluationPointGroups] = useState<EvaluationPointGroup[]>([]);
|
||
|
||
// 添加用于共享的字段数据状态
|
||
const [extractionFields, setExtractionFields] = useState<string[]>([]);
|
||
|
||
// VLM字段类型选项
|
||
const [vlmFieldTypeOptions, setVlmFieldTypeOptions] = useState<Array<{ value: string; label: string }>>([]);
|
||
|
||
// ✅ 页面加载时检查权限并提示(仅在只读模式下提示)
|
||
useEffect(() => {
|
||
if (isReadOnly && !isLoading) {
|
||
if (isViewMode) {
|
||
// toastService.info('当前为查看模式');
|
||
} else if (isEditMode && !canUpdateRule) {
|
||
toastService.info('当前为查看模式,您没有编辑权限');
|
||
} else if (!isEditMode && !canCreateRule) {
|
||
toastService.warning('您没有创建评查点的权限');
|
||
}
|
||
}
|
||
}, [isReadOnly, isViewMode, isEditMode, canUpdateRule, canCreateRule, isLoading]);
|
||
|
||
/**
|
||
* 从表单数据中提取所有字段
|
||
* 用于编辑模式下初始化字段数据
|
||
*/
|
||
const extractFieldsFromFormData = useCallback((data: EvaluationPoint) => {
|
||
if (!data || !data.extraction_config) return [];
|
||
|
||
const fields: string[] = [];
|
||
const config = data.extraction_config;
|
||
|
||
// 提取LLM字段
|
||
if (config.llm && Array.isArray(config.llm.fields)) {
|
||
fields.push(...config.llm.fields);
|
||
}
|
||
|
||
// 提取VLM字段
|
||
if (config.vlm && Array.isArray(config.vlm.fields)) {
|
||
const vlmFields = config.vlm.fields.map((f: string | { name: string, type: string }) =>
|
||
typeof f === 'string' ? f : f.name
|
||
);
|
||
fields.push(...vlmFields);
|
||
}
|
||
|
||
// 提取正则字段
|
||
if (config.regex && Array.isArray(config.regex.fields)) {
|
||
const regexFields = config.regex.fields.map((f: { field: string, pattern: string }) => f.field).filter(Boolean);
|
||
fields.push(...regexFields);
|
||
}
|
||
|
||
return fields;
|
||
}, []);
|
||
|
||
/**
|
||
* 重置表单数据到默认状态
|
||
*/
|
||
const resetFormData = useCallback(() => {
|
||
// console.log("重置表单数据到默认状态");
|
||
setFormData({
|
||
name: '',
|
||
code: '',
|
||
risk: 'low',
|
||
is_enabled: true,
|
||
description: '',
|
||
references_laws: { name: '', articles: [], content: '' },
|
||
evaluation_point_groups_pid: null,
|
||
evaluation_point_groups_id: null,
|
||
document_attribute_type: '通用',
|
||
extraction_config: {
|
||
multi_entity: {
|
||
enabled: false,
|
||
expand_mode: 'awareness'
|
||
},
|
||
llm: {
|
||
fields: [],
|
||
prompt_setting: {
|
||
type: 'llm_default_prompt',
|
||
template: ''
|
||
}
|
||
},
|
||
vlm: {
|
||
fields: [],
|
||
prompt_setting: {
|
||
type: 'vlm_default_prompt',
|
||
template: ''
|
||
}
|
||
},
|
||
regex: {
|
||
fields: []
|
||
}
|
||
},
|
||
evaluation_config: {
|
||
logicType: 'and',
|
||
customLogic: '',
|
||
rules: []
|
||
},
|
||
pass_message: '文档检查通过,符合规范要求。',
|
||
fail_message: '文档存在以下问题,请修改后重新提交。',
|
||
suggestion_message: '',
|
||
suggestion_message_type: 'warning',
|
||
post_action: 'none',
|
||
action_config: '',
|
||
score: 0
|
||
});
|
||
setExtractionFields([]);
|
||
// 生成新的实例键,强制所有子组件重新渲染
|
||
setInstanceKey(`new_${Date.now()}`);
|
||
}, []);
|
||
|
||
|
||
/**
|
||
* 从API响应中提取数据
|
||
* @param responseData - API响应数据
|
||
* @returns 提取的数据或null
|
||
*/
|
||
function extractApiData<T>(responseData: unknown): T | null {
|
||
if (!responseData) return null;
|
||
|
||
// 格式1: { code: number, msg: string, data: T }
|
||
if (typeof responseData === 'object' && responseData !== null &&
|
||
'code' in responseData &&
|
||
'data' in responseData &&
|
||
(responseData as { data: unknown }).data) {
|
||
return (responseData as { data: T }).data;
|
||
}
|
||
|
||
// 格式2: 直接是数据对象
|
||
return responseData as T;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取评查点数据
|
||
* 编辑模式下从API获取指定ID的评查点数据
|
||
* @param id 评查点ID
|
||
* @param isCopy 是否为复制模式
|
||
*/
|
||
const fetchEvaluationPoint = useCallback(async (id: number, isCopy = false) => {
|
||
try {
|
||
setIsLoading(true);
|
||
// console.log(`获取评查点数据,ID: ${id}, 复制模式: ${isCopy}`);
|
||
// 使用新的 getEvaluationPoint API 获取数据
|
||
const response = await getEvaluationPoint(String(id), frontendJWT);
|
||
|
||
if (response.error) {
|
||
// API返回错误
|
||
toastService.error(`获取评查点数据失败: ${response.error}`);
|
||
resetFormData();
|
||
navigate('/rules');
|
||
return;
|
||
}
|
||
|
||
if (response.data) {
|
||
try {
|
||
// 使用JSON序列化和反序列化来进行深拷贝,避免浏览器差异
|
||
const originalData = response.data;
|
||
const jsonString = JSON.stringify(originalData);
|
||
const data = JSON.parse(jsonString) as EvaluationPointData;
|
||
|
||
// 🔄 复制模式:删除不应该复制的字段
|
||
if (isCopy) {
|
||
delete data.id;
|
||
delete data.created_at;
|
||
delete data.updated_at;
|
||
// usage_count 不在 EvaluationPointData 接口中,但可能存在于响应数据中
|
||
if ('usage_count' in data) {
|
||
delete (data as Record<string, unknown>).usage_count;
|
||
}
|
||
|
||
// console.log('📋 复制模式:已清除不应复制的字段(id, created_at, updated_at, usage_count)');
|
||
}
|
||
|
||
// 🔑 清洗评查点编码:移除最后一个 '--' 及其后面的字符
|
||
// 例如:'code-mis--mz' --> 'code-mis', 'code-mbs--alsi--gz' --> 'code-mbs--alsi'
|
||
if (data.code) {
|
||
const lastDoubleHyphenIndex = data.code.lastIndexOf('--');
|
||
if (lastDoubleHyphenIndex !== -1) {
|
||
data.code = data.code.substring(0, lastDoubleHyphenIndex);
|
||
// console.log('🔑 已清洗评查点编码:', data.code);
|
||
}
|
||
}
|
||
|
||
// 设置表单数据(EvaluationPointData 兼容 EvaluationPoint)
|
||
setFormData(data as EvaluationPoint);
|
||
|
||
// 初始化extractionFields
|
||
const extractedFields = extractFieldsFromFormData(data as EvaluationPoint);
|
||
setExtractionFields(extractedFields);
|
||
|
||
// 设置实例键
|
||
setInstanceKey(isCopy ? `copy_${id}_${Date.now()}` : `edit_${id}_${Date.now()}`);
|
||
} catch (jsonError) {
|
||
console.error('JSON处理错误:', jsonError);
|
||
toastService.error(`数据处理错误: ${jsonError instanceof Error ? jsonError.message : '未知错误'}`);
|
||
resetFormData();
|
||
navigate('/rules');
|
||
}
|
||
}
|
||
} catch (error) {
|
||
console.error('获取评查点数据失败:', error);
|
||
toastService.error(`获取评查点数据失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||
// 获取数据失败时返回上一页
|
||
resetFormData();
|
||
navigate('/rules');
|
||
} finally {
|
||
setIsLoading(false);
|
||
}
|
||
}, [navigate, extractFieldsFromFormData, resetFormData, frontendJWT]);
|
||
|
||
/**
|
||
* 获取评查点组数据
|
||
* 从API获取所有评查点组,用于基本信息表单中选择
|
||
*/
|
||
const fetchEvaluationPointGroups = useCallback(async () => {
|
||
try {
|
||
// console.log("🔍 [fetchEvaluationPointGroups] 开始获取评查点组数据");
|
||
const response = await postgrestGet('/api/postgrest/proxy/evaluation_point_groups', { token: frontendJWT });
|
||
|
||
// console.log("🔍 [fetchEvaluationPointGroups] API响应:", response);
|
||
|
||
if (response.data) {
|
||
// 使用 extractApiData 提取数据(处理可能的包装格式)
|
||
const extractedData = extractApiData<EvaluationPointGroup[]>(response.data);
|
||
// console.log("🔍 [fetchEvaluationPointGroups] 提取后的数据:", extractedData);
|
||
|
||
if (extractedData && Array.isArray(extractedData) && extractedData.length > 0) {
|
||
setEvaluationPointGroups(extractedData);
|
||
// console.log(`✅ [fetchEvaluationPointGroups] 成功加载 ${extractedData.length} 个评查点组`);
|
||
} else {
|
||
console.warn("⚠️ [fetchEvaluationPointGroups] 提取的数据为空或格式不正确");
|
||
setEvaluationPointGroups([]);
|
||
}
|
||
} else if (response.error) {
|
||
console.error('❌ [fetchEvaluationPointGroups] API返回错误:', response.error);
|
||
setEvaluationPointGroups([]);
|
||
}
|
||
} catch (error) {
|
||
console.error('❌ [fetchEvaluationPointGroups] 获取评查点组数据失败:', error);
|
||
setEvaluationPointGroups([]);
|
||
// 显示错误提示但不影响应用继续使用
|
||
toastService.error(`获取评查点组数据失败: ${error instanceof Error ? error.message : '未知错误'}\n将使用默认数据`);
|
||
}
|
||
}, [frontendJWT]);
|
||
|
||
/**
|
||
* 获取VLM字段类型选项
|
||
* 从API获取多模态抽取的字段类型选项
|
||
*/
|
||
const fetchVlmFieldTypeOptions = useCallback(async () => {
|
||
try {
|
||
// console.log("获取VLM字段类型选项");
|
||
const response = await getPromptTemplateOptions('VLM_Extraction', frontendJWT);
|
||
|
||
if (response.data && Array.isArray(response.data)) {
|
||
// 添加自定义选项
|
||
const optionsWithCustom = [
|
||
...response.data,
|
||
// { value: 'custom', label: '自定义' }
|
||
];
|
||
setVlmFieldTypeOptions(optionsWithCustom);
|
||
} else if (response.error) {
|
||
console.error('获取VLM字段类型选项失败:', response.error);
|
||
// 使用默认选项作为备选
|
||
setVlmFieldTypeOptions(EVALUATION_OPTIONS.vlmFieldTypeOptions);
|
||
}
|
||
} catch (error) {
|
||
console.error('获取VLM字段类型选项失败:', error);
|
||
// 使用默认选项作为备选
|
||
setVlmFieldTypeOptions(EVALUATION_OPTIONS.vlmFieldTypeOptions);
|
||
}
|
||
}, [frontendJWT]);
|
||
|
||
const handleSave = async () => {
|
||
// console.log("保存评查点", formData);
|
||
|
||
// ✅ Runtime permission check
|
||
if (isEditMode && !canUpdateRule) {
|
||
toastService.warning('您没有修改权限,无法保存更改');
|
||
return;
|
||
}
|
||
|
||
if (!isEditMode && !canCreateRule) {
|
||
toastService.warning('您没有创建权限,无法新增评查点');
|
||
return;
|
||
}
|
||
|
||
// ========== 验证必填字段 ==========
|
||
|
||
// 1. 验证评查点名称
|
||
if (!formData.name?.trim()) {
|
||
toastService.warning("评查点名称不能为空");
|
||
return;
|
||
}
|
||
|
||
if (formData.name.trim().length > 30) {
|
||
toastService.warning("评查点名称不能超过30个字符");
|
||
return;
|
||
}
|
||
|
||
// 2. 验证评查点编码
|
||
if (!formData.code?.trim()) {
|
||
toastService.warning("评查点编码不能为空");
|
||
return;
|
||
}
|
||
|
||
// 3. 验证风险等级
|
||
if (!formData.risk) {
|
||
toastService.warning("请选择风险等级");
|
||
return;
|
||
}
|
||
|
||
// 4. 验证评查点类型(父级类型组)
|
||
if (!formData.evaluation_point_groups_pid) {
|
||
toastService.warning("请选择评查点类型");
|
||
return;
|
||
}
|
||
|
||
// 5. 验证所属规则组
|
||
if (!formData.evaluation_point_groups_id) {
|
||
toastService.warning("请选择所属规则组");
|
||
return;
|
||
}
|
||
|
||
|
||
// 6. 验证评查设置中的规则
|
||
if (formData.evaluation_config?.rules && Array.isArray(formData.evaluation_config.rules)) {
|
||
const rules = formData.evaluation_config.rules;
|
||
|
||
if (rules.length <=0){
|
||
toastService.warning('评查设置中尚未添加或完善规则')
|
||
return;
|
||
}
|
||
|
||
// 检查每个规则是否选择了评查类型
|
||
for (let i = 0; i < rules.length; i++) {
|
||
const rule = rules[i];
|
||
|
||
console.log("log",rule)
|
||
|
||
if (!rule.type) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1} 未选择评查类型`);
|
||
return;
|
||
}
|
||
|
||
// 根据不同规则类型验证配置
|
||
if (!rule.config) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1} 配置不完整`);
|
||
return;
|
||
}
|
||
|
||
// 验证各类型规则的必填字段
|
||
switch (rule.type) {
|
||
case 'exists':
|
||
if (!rule.config.fields || rule.config.fields.length === 0) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(有无判断):请至少选择一个字段`);
|
||
return;
|
||
}
|
||
if (!rule.config.logic) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(有无判断):请选择逻辑关系`);
|
||
return;
|
||
}
|
||
break;
|
||
|
||
case 'consistency':
|
||
if (!rule.config.pairs || rule.config.pairs.length === 0) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(一致性判断):请至少添加一对比较字段`);
|
||
return;
|
||
}
|
||
// 检查每对字段是否完整
|
||
for (let j = 0; j < rule.config.pairs.length; j++) {
|
||
const pair = rule.config.pairs[j];
|
||
if (!pair.sourceField || !pair.targetField || !pair.compareMethod) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(一致性判断):第 ${j + 1} 对比较字段配置不完整`);
|
||
return;
|
||
}
|
||
}
|
||
break;
|
||
|
||
case 'format':
|
||
if (!rule.config.field) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(格式判断):请选择检查字段`);
|
||
return;
|
||
}
|
||
if (!rule.config.formatType) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(格式判断):请选择格式类型`);
|
||
return;
|
||
}
|
||
break;
|
||
|
||
case 'logic':
|
||
if (!rule.config.conditions || rule.config.conditions.length === 0) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(逻辑判断):请至少添加一个条件`);
|
||
return;
|
||
}
|
||
// 检查每个条件是否完整
|
||
for (let j = 0; j < rule.config.conditions.length; j++) {
|
||
const condition = rule.config.conditions[j];
|
||
if (!condition.field || !condition.operator || condition.value === undefined || condition.value === '') {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(逻辑判断):第 ${j + 1} 个条件配置不完整`);
|
||
return;
|
||
}
|
||
}
|
||
break;
|
||
|
||
case 'regex':
|
||
if (!rule.config.field) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(正则表达式):请选择检查字段`);
|
||
return;
|
||
}
|
||
if (!rule.config.pattern) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(正则表达式):请输入正则表达式`);
|
||
return;
|
||
}
|
||
if (!rule.config.matchType) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(正则表达式):请选择匹配类型`);
|
||
return;
|
||
}
|
||
break;
|
||
|
||
case 'ai':
|
||
if (!rule.config.model) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(大模型判断):请选择模型`);
|
||
return;
|
||
}
|
||
if (!rule.config.prompt) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(大模型判断):请输入提示词`);
|
||
return;
|
||
}
|
||
break;
|
||
|
||
case 'code':
|
||
if (!rule.config.language) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(自定义代码):请选择编程语言`);
|
||
return;
|
||
}
|
||
if (!rule.config.code) {
|
||
toastService.warning(`评查设置中的规则 ${i + 1}(自定义代码):请输入代码`);
|
||
return;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 7. 验证组合逻辑
|
||
if (formData.evaluation_config?.logicType === 'custom') {
|
||
if (!formData.evaluation_config.customLogic?.trim()) {
|
||
toastService.warning("请输入自定义组合逻辑");
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 显示保存中状态
|
||
setIsLoading(true);
|
||
|
||
try {
|
||
// 创建一个符合数据库模式的数据副本
|
||
const cleanedData = {
|
||
id: formData.id,
|
||
name: formData.name?.trim(),
|
||
code: formData.code?.trim(),
|
||
risk: formData.risk || 'low',
|
||
is_enabled: formData.is_enabled !== undefined ? formData.is_enabled : true,
|
||
description: formData.description || '',
|
||
references_laws: formData.references_laws || null,
|
||
evaluation_point_groups_pid: formData.evaluation_point_groups_pid || null,
|
||
evaluation_point_groups_id: formData.evaluation_point_groups_id || null,
|
||
document_attribute_type: formData.document_attribute_type || '',
|
||
extraction_config: {
|
||
multi_entity: {
|
||
enabled: formData.extraction_config?.multi_entity?.enabled ?? false,
|
||
expand_mode: formData.extraction_config?.multi_entity?.expand_mode || 'awareness'
|
||
},
|
||
llm: {
|
||
fields: Array.isArray(formData.extraction_config?.llm?.fields) ?
|
||
[...formData.extraction_config.llm.fields] : [],
|
||
prompt_setting: {
|
||
type: formData.extraction_config?.llm?.prompt_setting?.type || 'llm_default_prompt',
|
||
template: formData.extraction_config?.llm?.prompt_setting?.template || ''
|
||
}
|
||
},
|
||
vlm: {
|
||
fields: Array.isArray(formData.extraction_config?.vlm?.fields) ?
|
||
[...formData.extraction_config.vlm.fields] : [],
|
||
prompt_setting: {
|
||
type: formData.extraction_config?.vlm?.prompt_setting?.type || 'vlm_default_prompt',
|
||
template: formData.extraction_config?.vlm?.prompt_setting?.template || ''
|
||
}
|
||
},
|
||
regex: {
|
||
fields: Array.isArray(formData.extraction_config?.regex?.fields) ?
|
||
[...formData.extraction_config.regex.fields] : []
|
||
}
|
||
},
|
||
evaluation_config: {
|
||
logicType: formData.evaluation_config?.logicType || 'and',
|
||
customLogic: formData.evaluation_config?.customLogic || '',
|
||
rules: Array.isArray(formData.evaluation_config?.rules) ?
|
||
formData.evaluation_config.rules.map(rule => ({
|
||
id: rule.id || '1',
|
||
type: rule.type || '',
|
||
config: rule.config || {}
|
||
})) : []
|
||
},
|
||
pass_message: formData.pass_message || '文档检查通过,符合规范要求。',
|
||
fail_message: formData.fail_message || '文档存在以下问题,请修改后重新提交。',
|
||
suggestion_message: formData.suggestion_message || '',
|
||
suggestion_message_type: formData.suggestion_message_type || 'warning',
|
||
post_action: formData.post_action || 'none',
|
||
action_config: formData.action_config || '',
|
||
score: formData.score !== undefined ? Number(formData.score) : 0
|
||
};
|
||
|
||
// 获取当前所有有效的抽取字段
|
||
const currentExtractionFields = extractionFields.map(field => {
|
||
// 处理字段名,去掉类型后缀(如果有)
|
||
if (field.includes('_')) {
|
||
return field.split('_')[0];
|
||
}
|
||
return field;
|
||
});
|
||
|
||
// 去重,确保不会有重复字段
|
||
const validFields = [...new Set(currentExtractionFields)];
|
||
// console.log("当前有效的抽取字段:", validFields);
|
||
|
||
// 重要:这段代码解决了字段删除后,评查配置中仍保留已删除字段的问题
|
||
// 在保存前,我们会确保所有规则中引用的字段都是当前有效的抽取字段
|
||
// 这样即使用户在界面操作中删除了某个抽取字段,相关的评查规则也会被自动清理
|
||
|
||
// 确保rules中的每个配置对象都被正确处理
|
||
if (cleanedData.evaluation_config && Array.isArray(cleanedData.evaluation_config.rules)) {
|
||
cleanedData.evaluation_config.rules = cleanedData.evaluation_config.rules
|
||
.filter(rule => rule && rule.type) // 确保规则有类型
|
||
.map(rule => {
|
||
// 根据规则类型确保config中有必要的字段
|
||
const config = { ...rule.config } as RuleConfig;
|
||
|
||
switch (rule.type) {
|
||
case 'exists':
|
||
if (!Array.isArray((config as ExistsRuleConfig).fields)) (config as ExistsRuleConfig).fields = [];
|
||
// 过滤掉不存在于当前抽取字段中的字段
|
||
if (Array.isArray((config as ExistsRuleConfig).fields)) {
|
||
(config as ExistsRuleConfig).fields = (config as ExistsRuleConfig).fields.filter(
|
||
field => validFields.includes(field)
|
||
);
|
||
}
|
||
if (!(config as ExistsRuleConfig).logic) (config as ExistsRuleConfig).logic = 'and';
|
||
// 删除不必要的字段
|
||
delete (config as ExistsRuleConfig & {availableFields?: string}).availableFields;
|
||
delete (config as ExistsRuleConfig).selectedFields;
|
||
delete (config as ExistsRuleConfig).existsLogic;
|
||
break;
|
||
|
||
case 'consistency':
|
||
if (!Array.isArray((config as ConsistencyRuleConfig).pairs)) (config as ConsistencyRuleConfig).pairs = [];
|
||
// 过滤掉包含不存在于当前抽取字段中的字段的配对
|
||
if (Array.isArray((config as ConsistencyRuleConfig).pairs)) {
|
||
(config as ConsistencyRuleConfig).pairs = (config as ConsistencyRuleConfig).pairs.filter(
|
||
pair => validFields.includes(pair.sourceField) && validFields.includes(pair.targetField)
|
||
);
|
||
}
|
||
if (!(config as ConsistencyRuleConfig).logic) (config as ConsistencyRuleConfig).logic = 'and';
|
||
delete (config as ConsistencyRuleConfig & {availableFields?: string}).availableFields;
|
||
delete (config as ConsistencyRuleConfig).logicRelation;
|
||
delete (config as ConsistencyRuleConfig).initialSourceField;
|
||
delete (config as ConsistencyRuleConfig).initialTargetField;
|
||
delete (config as ConsistencyRuleConfig).initialCompareMethod;
|
||
break;
|
||
|
||
case 'format':
|
||
// 检查字段是否存在于当前抽取字段中
|
||
if ((config as FormatRuleConfig).field && !validFields.includes((config as FormatRuleConfig).field)) {
|
||
(config as FormatRuleConfig).field = '';
|
||
}
|
||
if (!(config as FormatRuleConfig).field) (config as FormatRuleConfig).field = '';
|
||
if (!(config as FormatRuleConfig).formatType) (config as FormatRuleConfig).formatType = 'date';
|
||
if (!(config as FormatRuleConfig).parameters) (config as FormatRuleConfig).parameters = '';
|
||
delete (config as FormatRuleConfig & {availableFields?: string}).availableFields;
|
||
delete (config as FormatRuleConfig).checkField;
|
||
delete (config as FormatRuleConfig).formatParams;
|
||
break;
|
||
|
||
case 'logic':
|
||
if (!Array.isArray((config as LogicRuleConfig).conditions)) (config as LogicRuleConfig).conditions = [];
|
||
// 过滤掉包含不存在于当前抽取字段中的字段的条件
|
||
if (Array.isArray((config as LogicRuleConfig).conditions)) {
|
||
(config as LogicRuleConfig).conditions = (config as LogicRuleConfig).conditions.filter(
|
||
condition => validFields.includes(condition.field)
|
||
);
|
||
}
|
||
if (!(config as LogicRuleConfig).logic) (config as LogicRuleConfig).logic = 'and';
|
||
delete (config as LogicRuleConfig & {availableFields?: string}).availableFields;
|
||
delete (config as LogicRuleConfig).logicRelation;
|
||
delete (config as LogicRuleConfig).initialField;
|
||
delete (config as LogicRuleConfig).initialOperator;
|
||
delete (config as LogicRuleConfig).initialValue;
|
||
break;
|
||
|
||
case 'regex':
|
||
// 检查字段是否存在于当前抽取字段中
|
||
if ((config as RegexRuleConfig).field && !validFields.includes((config as RegexRuleConfig).field)) {
|
||
(config as RegexRuleConfig).field = '';
|
||
}
|
||
if (!(config as RegexRuleConfig).field) (config as RegexRuleConfig).field = '';
|
||
if (!(config as RegexRuleConfig).pattern) (config as RegexRuleConfig).pattern = '';
|
||
if (!(config as RegexRuleConfig).matchType) (config as RegexRuleConfig).matchType = 'match';
|
||
delete (config as RegexRuleConfig & {availableFields?: string}).availableFields;
|
||
delete (config as RegexRuleConfig).checkField;
|
||
delete (config as RegexRuleConfig).regexPattern;
|
||
break;
|
||
|
||
case 'ai':
|
||
if (!(config as AIRuleConfig).model) (config as AIRuleConfig).model = 'qwen14b';
|
||
if (typeof (config as AIRuleConfig).temperature !== 'number') (config as AIRuleConfig).temperature = 0.1;
|
||
if (!(config as AIRuleConfig).prompt) (config as AIRuleConfig).prompt = '';
|
||
delete (config as AIRuleConfig & {availableFields?: string}).availableFields;
|
||
break;
|
||
|
||
case 'code':
|
||
if (!(config as CodeRuleConfig).language) (config as CodeRuleConfig).language = 'javascript';
|
||
if (!(config as CodeRuleConfig).code) (config as CodeRuleConfig).code = '';
|
||
delete (config as CodeRuleConfig & {availableFields?: string}).availableFields;
|
||
break;
|
||
}
|
||
|
||
return {
|
||
id: rule.id,
|
||
type: rule.type,
|
||
config
|
||
};
|
||
});
|
||
}
|
||
|
||
|
||
// console.log("当前表单数据-----------------:", formData);
|
||
// console.log("当前评查配置-----------------:", formData.evaluation_config);
|
||
// return;
|
||
|
||
// 如果是新建模式,则删除id字段
|
||
if (!isEditMode) {
|
||
delete cleanedData.id;
|
||
}
|
||
|
||
try {
|
||
// 使用JSON序列化和反序列化来进行深拷贝,避免浏览器差异
|
||
const jsonString = JSON.stringify(cleanedData);
|
||
const finalData = JSON.parse(jsonString);
|
||
|
||
// 确保extraction_config和evaluation_config是有效的JSON对象
|
||
try {
|
||
JSON.parse(JSON.stringify(finalData.extraction_config));
|
||
} catch (e) {
|
||
throw new Error("extraction_config 格式无效");
|
||
}
|
||
|
||
try {
|
||
JSON.parse(JSON.stringify(finalData.evaluation_config));
|
||
} catch (e) {
|
||
throw new Error("evaluation_config 格式无效");
|
||
}
|
||
|
||
// 检查JSON字符串长度,如果太长可能会被截断
|
||
const dataLength = jsonString.length;
|
||
const maxLength = 65536; // 通常PostgreSQL的jsonb列可以存储的最大长度
|
||
|
||
if (dataLength > maxLength) {
|
||
throw new Error(`数据大小超过限制 (${dataLength} > ${maxLength})`);
|
||
}
|
||
|
||
// console.log("准备提交到API的数据(已经过深拷贝处理):", finalData);
|
||
// console.log("JSON数据长度:", dataLength);
|
||
|
||
let response;
|
||
if (isEditMode) {
|
||
// 使用新的 updateEvaluationPoint API
|
||
response = await updateEvaluationPoint(String(formData.id!), finalData, frontendJWT);
|
||
console.log("最终提交的数据", finalData)
|
||
} else {
|
||
// 使用新的 createEvaluationPoint API
|
||
response = await createEvaluationPoint(finalData as Omit<EvaluationPointData, 'id' | 'created_at' | 'updated_at'>, frontendJWT);
|
||
}
|
||
|
||
if (response.error) {
|
||
if (response.error.includes('evaluation_points_code_key')) {
|
||
toastService.error('在基本信息中:评查点编码已存在,请修改后保存。');
|
||
} else {
|
||
toastService.error(`系统繁忙: ${response.error}`);
|
||
}
|
||
setIsLoading(false);
|
||
} else if (response.data) {
|
||
// 获取新创建或更新的评查点ID
|
||
let savedPointId: number | undefined;
|
||
let successMessage = '';
|
||
|
||
if (isEditMode) {
|
||
// 编辑模式:直接从 response.data.id 获取
|
||
savedPointId = response.data.id;
|
||
successMessage = '评查点更新成功!';
|
||
} else {
|
||
// 创建模式:从 items 数组中找到 code 不包含 '--' 后缀的基础评查点
|
||
const responseData = response.data as {
|
||
success?: boolean;
|
||
total_created?: number;
|
||
message?: string;
|
||
items?: Array<{ id: number; code: string; [key: string]: unknown }>;
|
||
};
|
||
|
||
if (responseData.items && Array.isArray(responseData.items) && responseData.items.length > 0) {
|
||
// 查找 code 不包含 '--' 的评查点(基础评查点)
|
||
const baseItem = responseData.items.find(item => !item.code.includes('--'));
|
||
if (baseItem) {
|
||
savedPointId = baseItem.id;
|
||
} else {
|
||
// 如果所有 code 都包含 '--',取第一个
|
||
savedPointId = responseData.items[0].id;
|
||
}
|
||
// 使用后端返回的消息,或生成默认消息
|
||
successMessage = responseData.message || `评查点创建成功! 共创建 ${responseData.total_created || responseData.items.length} 个地区的评查点`;
|
||
} else if (response.data.id) {
|
||
// 兼容旧格式:直接返回单个评查点
|
||
savedPointId = response.data.id;
|
||
successMessage = '评查点创建成功!';
|
||
}
|
||
}
|
||
|
||
if (savedPointId) {
|
||
// 显示成功消息
|
||
toastService.success(successMessage);
|
||
|
||
// 保存成功后跳转到编辑页面并重新加载数据
|
||
navigate(`/rules/new?id=${savedPointId}`, { replace: true });
|
||
// 重新获取评查点数据
|
||
await fetchEvaluationPoint(savedPointId);
|
||
} else {
|
||
// 无法获取ID的情况
|
||
toastService.warning(`评查点${isEditMode ? '更新' : '创建'}成功,但无法获取ID。正在返回列表页面。`);
|
||
navigate('/rules');
|
||
}
|
||
} else {
|
||
toastService.error('系统繁忙');
|
||
}
|
||
} catch (jsonError) {
|
||
console.error("JSON处理错误:", jsonError);
|
||
toastService.error(`数据处理错误: ${jsonError instanceof Error ? jsonError.message : '未知错误'}`);
|
||
setIsLoading(false);
|
||
return;
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error("数据处理错误:", error);
|
||
toastService.error(`数据处理错误: ${error instanceof Error ? error.message : '未知错误'}`);
|
||
setIsLoading(false);
|
||
}
|
||
}
|
||
|
||
const handleSaveDraft = () => {
|
||
console.log("保存草稿");
|
||
}
|
||
|
||
const handleBasicInfoChange = (data: Record<string, unknown>) => {
|
||
setFormData(prev => ({ ...prev, ...data }));
|
||
}
|
||
|
||
const handleExtractionSettingsChange = (data: Record<string, unknown>) => {
|
||
setFormData(prev => ({ ...prev, ...data }));
|
||
|
||
// 提取并处理字段数据
|
||
const processFields = () => {
|
||
// 使用类型断言处理字段访问
|
||
const extractionConfig = data.extraction_config as {
|
||
llm?: { fields?: string[] };
|
||
vlm?: { fields?: Array<string | { name: string, type: string }> };
|
||
regex?: { fields?: Array<{ field: string, pattern: string }> };
|
||
} | undefined;
|
||
if (!extractionConfig) return;
|
||
|
||
const llmFields = extractionConfig.llm?.fields || [];
|
||
const vlmFields = extractionConfig.vlm?.fields || [];
|
||
const regexFields = (extractionConfig.regex?.fields || []).map((f: { field: string }) => f.field);
|
||
|
||
// 合并所有字段
|
||
const allFields = [
|
||
...llmFields,
|
||
...vlmFields.map((f: string | { name: string }) => typeof f === 'string' ? f : f.name),
|
||
...regexFields
|
||
].filter(Boolean);
|
||
|
||
setExtractionFields(allFields);
|
||
};
|
||
|
||
// 处理字段数据
|
||
if (data.extraction_config) {
|
||
processFields();
|
||
}
|
||
};
|
||
|
||
const handleReviewSettingsChange = (data: Record<string, unknown>) => {
|
||
// console.log("评查设置变更:", data);
|
||
|
||
// 检查数据中是否包含evaluation_config对象
|
||
if (data.evaluation_config) {
|
||
// 确保formData.evaluation_config存在并具有必要的默认属性
|
||
const currentConfig = formData.evaluation_config || {
|
||
logicType: 'and',
|
||
customLogic: '',
|
||
rules: []
|
||
};
|
||
|
||
// console.log("当前评查配置:", currentConfig);
|
||
// console.log("变更评查配置:", data.evaluation_config);
|
||
|
||
// 合并评查配置数据
|
||
const mergedConfig = {
|
||
...currentConfig,
|
||
...(data.evaluation_config as object)
|
||
};
|
||
// console.log("合并评查配置:", data.evaluation_config);
|
||
// 更新表单数据
|
||
setFormData(prev => ({
|
||
...prev,
|
||
evaluation_config: mergedConfig
|
||
// evaluation_config: data.evaluation_config as typeof prev.evaluation_config
|
||
}));
|
||
} else {
|
||
// 处理其他普通字段
|
||
setFormData(prev => ({ ...prev, ...data }));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加事件监听,处理抽取字段更新
|
||
*/
|
||
useEffect(() => {
|
||
// 定义事件处理函数
|
||
const handleExtractionFieldsUpdated = (event: CustomEvent<{fields: string[]}>) => {
|
||
const { fields } = event.detail;
|
||
if (Array.isArray(fields) && fields.length > 0) {
|
||
// 更新字段数据
|
||
setExtractionFields(fields);
|
||
}
|
||
};
|
||
|
||
// 添加事件监听
|
||
window.addEventListener('extraction-fields-updated', handleExtractionFieldsUpdated as EventListener);
|
||
|
||
// 清理函数
|
||
return () => {
|
||
window.removeEventListener('extraction-fields-updated', handleExtractionFieldsUpdated as EventListener);
|
||
};
|
||
}, []);
|
||
|
||
/**
|
||
* 页面加载时初始化处理
|
||
* 1. 检查URL参数,判断是新建还是编辑模式
|
||
* 2. 编辑模式下获取评查点数据
|
||
* 3. 获取评查点组数据(用于表单选择项)
|
||
*/
|
||
useEffect(() => {
|
||
const currentUrl = location.search;
|
||
const currentPathname = location.pathname;
|
||
const fullUrl = `${currentPathname}${currentUrl}`;
|
||
|
||
// 🔑 如果 URL 没有变化,不重复加载(避免无限循环)
|
||
// 使用完整路径(pathname + search)进行比较,避免新增页面被拦截
|
||
if (loadedUrlRef.current === fullUrl) {
|
||
console.log('🔄 [useEffect] URL未变化,跳过重复加载:', fullUrl);
|
||
return;
|
||
}
|
||
|
||
// console.log('🔄 [useEffect] URL变化,开始加载数据:', { previous: loadedUrlRef.current, current: fullUrl });
|
||
|
||
const searchParams = new URLSearchParams(currentUrl);
|
||
const id = searchParams.get('id');
|
||
const mode = searchParams.get('mode');
|
||
|
||
// 判断是否为复制模式
|
||
const isCopy = mode === 'copy';
|
||
|
||
// 编辑或复制模式下设置加载状态
|
||
if (id || isCopy) {
|
||
setIsLoading(true);
|
||
}
|
||
|
||
// 设置复制模式状态
|
||
setIsCopyMode(isCopy);
|
||
|
||
// 设置编辑模式(复制模式不是编辑模式)
|
||
if (isCopy) {
|
||
setIsEditMode(false);
|
||
} else {
|
||
setIsEditMode(!!id);
|
||
}
|
||
|
||
if (id) {
|
||
// 编辑或复制模式:获取数据(传入复制模式标志)
|
||
console.log('📝 [useEffect] 编辑/复制模式,加载评查点数据,ID:', id);
|
||
fetchEvaluationPoint(parseInt(id), isCopy);
|
||
} else {
|
||
// 新建模式:重置表单数据
|
||
console.log('📝 [useEffect] 新建模式,重置表单数据');
|
||
resetFormData();
|
||
}
|
||
|
||
// 获取评查点组数据
|
||
// console.log('📝 [useEffect] 获取评查点组数据');
|
||
fetchEvaluationPointGroups();
|
||
// 获取VLM字段类型选项
|
||
// console.log('📝 [useEffect] 获取VLM字段类型选项');
|
||
fetchVlmFieldTypeOptions();
|
||
|
||
// 记录已加载的 URL(使用完整路径)
|
||
loadedUrlRef.current = fullUrl;
|
||
}, [location.search, location.pathname, fetchEvaluationPoint, fetchEvaluationPointGroups, fetchVlmFieldTypeOptions, resetFormData]);
|
||
|
||
// 处理返回按钮点击
|
||
const handleBack = () => {
|
||
navigate(-1);
|
||
};
|
||
|
||
// 渲染页面内容
|
||
return (
|
||
<div className="container">
|
||
{/* 页面标题和右上角保存按钮 */}
|
||
<PageHeader
|
||
title={isCopyMode ? "复制评查点" : (isEditMode ? (isReadOnly ? "查看评查点" : "编辑评查点") : "新增评查点")}
|
||
onSave={handleSave}
|
||
onBack={handleBack}
|
||
showSaveButton={!isReadOnly}
|
||
/>
|
||
|
||
{/* 复制模式提示 */}
|
||
{isCopyMode && !isLoading && (
|
||
<div className="mb-4 p-1 bg-blue-50 border border-blue-200 rounded-md">
|
||
<div className="flex items-center">
|
||
<i className="ri-information-line text-blue-500 text-xl mr-2"></i>
|
||
<div className="text-sm text-blue-800">
|
||
<span className="font-medium">复制模式:</span>
|
||
请检查并修改评查点信息后保存。
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* 加载状态显示 */}
|
||
{isLoading ? (
|
||
<div className="flex justify-center items-center p-12">
|
||
<div className="loading-spinner"></div>
|
||
<span className="ml-3">加载中...</span>
|
||
</div>
|
||
) : (
|
||
<RuleContext.Provider value={{
|
||
extractionFields,
|
||
updateFields: setExtractionFields
|
||
}}>
|
||
{/* 使用key属性强制在模式切换时重新渲染所有组件 */}
|
||
<div key={instanceKey}>
|
||
{/* 评查点基本信息设置 */}
|
||
<div className="mb-8">
|
||
<BasicInfo
|
||
key={instanceKey}
|
||
onChange={handleBasicInfoChange}
|
||
initialData={formData}
|
||
evaluationPointGroups={evaluationPointGroups}
|
||
riskOptions={EVALUATION_OPTIONS.riskLevelOptions}
|
||
frontendJWT={frontendJWT}
|
||
evaluationPointId={formData.id}
|
||
/>
|
||
</div>
|
||
|
||
{/* 抽取设置 - 配置从文档中提取的字段 */}
|
||
<div className="mb-8">
|
||
<ExtractionSettings
|
||
key={instanceKey}
|
||
onChange={handleExtractionSettingsChange}
|
||
initialData={formData}
|
||
promptTypeOptions={EVALUATION_OPTIONS.llmPromptTypeOptions}
|
||
vlmFieldTypeOptions={vlmFieldTypeOptions.length > 0 ? vlmFieldTypeOptions : EVALUATION_OPTIONS.vlmFieldTypeOptions}
|
||
/>
|
||
</div>
|
||
|
||
{/* 评查设置 - 配置评查规则、消息等 */}
|
||
<div className="mb-8">
|
||
<ReviewSettings
|
||
key={instanceKey}
|
||
onChange={handleReviewSettingsChange}
|
||
initialData={{
|
||
rules: formData.evaluation_config?.rules || [],
|
||
combinationLogic: formData.evaluation_config?.logicType || 'and',
|
||
customLogic: formData.evaluation_config?.customLogic || '',
|
||
pass_message: formData.pass_message || '文档检查通过,符合规范要求。',
|
||
fail_message: formData.fail_message || '文档存在以下问题,请修改后重新提交。',
|
||
suggestion_message: formData.suggestion_message || '',
|
||
suggestion_message_type: formData.suggestion_message_type || 'warning',
|
||
post_action: formData.post_action || 'none',
|
||
action_config: formData.action_config || '',
|
||
score: formData.score !== undefined ? formData.score : 0
|
||
}}
|
||
ruleTypeOptions={EVALUATION_OPTIONS.ruleTypeOptions}
|
||
logicTypeOptions={EVALUATION_OPTIONS.logicTypeOptions}
|
||
logicOperatorOptions={EVALUATION_OPTIONS.logicOperatorOptions}
|
||
compareMethodOptions={EVALUATION_OPTIONS.compareMethodOptions}
|
||
formatTypeOptions={EVALUATION_OPTIONS.formatTypeOptions}
|
||
comparisonOperatorOptions={EVALUATION_OPTIONS.comparisonOperatorOptions}
|
||
matchTypeOptions={EVALUATION_OPTIONS.matchTypeOptions}
|
||
suggestionMessageTypeOptions={EVALUATION_OPTIONS.suggestionMessageTypeOptions}
|
||
postActionOptions={EVALUATION_OPTIONS.postActionOptions}
|
||
/>
|
||
</div>
|
||
|
||
{/* 底部操作按钮区域 */}
|
||
<ActionButtons
|
||
onSave={handleSave}
|
||
onSaveDraft={handleSaveDraft}
|
||
isEditMode={isEditMode}
|
||
showButtons={!isReadOnly}
|
||
/>
|
||
</div>
|
||
</RuleContext.Provider>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|