暂存2
This commit is contained in:
@@ -1532,76 +1532,165 @@ export function ReviewSettings({
|
|||||||
const generateEvaluationConfig = useCallback(() => {
|
const generateEvaluationConfig = useCallback(() => {
|
||||||
// 创建符合数据库模式的evaluation_config对象
|
// 创建符合数据库模式的evaluation_config对象
|
||||||
const evaluationConfig = {
|
const evaluationConfig = {
|
||||||
logicType: combinationLogic,
|
logicType: combinationLogic || 'and',
|
||||||
customLogic: combinationLogic === 'custom' ? customLogic : '',
|
customLogic: combinationLogic === 'custom' ? (customLogic || '') : '',
|
||||||
rules: rules.map(rule => {
|
rules: rules
|
||||||
// 创建一个深拷贝以避免修改原始对象
|
.filter(rule => rule.type && rule.type.trim() !== '')
|
||||||
const processedConfig = JSON.parse(JSON.stringify(rule.config || {}));
|
.map(rule => {
|
||||||
|
// 创建一个深拷贝以避免修改原始对象
|
||||||
|
const processedConfig = JSON.parse(JSON.stringify(rule.config || {}));
|
||||||
|
|
||||||
// 根据规则类型处理特定的字段映射
|
// 根据规则类型处理特定的字段映射
|
||||||
switch(rule.type) {
|
switch(rule.type) {
|
||||||
case 'exists':
|
case 'exists':
|
||||||
// 将UI字段名映射为API字段名
|
// 将UI字段名映射为API字段名
|
||||||
if (processedConfig.selectedFields) {
|
if (Array.isArray(processedConfig.selectedFields)) {
|
||||||
processedConfig.fields = processedConfig.selectedFields;
|
processedConfig.fields = processedConfig.selectedFields;
|
||||||
delete processedConfig.selectedFields;
|
delete processedConfig.selectedFields;
|
||||||
}
|
}
|
||||||
if (processedConfig.existsLogic) {
|
|
||||||
processedConfig.logic = processedConfig.existsLogic;
|
|
||||||
delete processedConfig.existsLogic;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'consistency':
|
// 确保fields字段存在且是数组
|
||||||
case 'logic':
|
if (!Array.isArray(processedConfig.fields)) {
|
||||||
// 将UI字段名映射为API字段名
|
processedConfig.fields = [];
|
||||||
if (processedConfig.logicRelation) {
|
}
|
||||||
processedConfig.logic = processedConfig.logicRelation;
|
|
||||||
delete processedConfig.logicRelation;
|
|
||||||
}
|
|
||||||
// 删除用于UI的临时字段
|
|
||||||
delete processedConfig.initialSourceField;
|
|
||||||
delete processedConfig.initialTargetField;
|
|
||||||
delete processedConfig.initialCompareMethod;
|
|
||||||
delete processedConfig.initialField;
|
|
||||||
delete processedConfig.initialOperator;
|
|
||||||
delete processedConfig.initialValue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'format':
|
if (processedConfig.existsLogic) {
|
||||||
// 确保field字段正确设置
|
processedConfig.logic = processedConfig.existsLogic;
|
||||||
if (processedConfig.checkField) {
|
delete processedConfig.existsLogic;
|
||||||
processedConfig.field = processedConfig.checkField;
|
}
|
||||||
delete processedConfig.checkField;
|
|
||||||
}
|
|
||||||
if (processedConfig.formatParams) {
|
|
||||||
processedConfig.parameters = processedConfig.formatParams;
|
|
||||||
delete processedConfig.formatParams;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'regex':
|
// 确保logic字段有默认值
|
||||||
// 确保field和pattern字段正确设置
|
if (!processedConfig.logic) {
|
||||||
if (processedConfig.checkField) {
|
processedConfig.logic = 'and';
|
||||||
processedConfig.field = processedConfig.checkField;
|
}
|
||||||
delete processedConfig.checkField;
|
break;
|
||||||
}
|
|
||||||
if (processedConfig.regexPattern) {
|
|
||||||
processedConfig.pattern = processedConfig.regexPattern;
|
|
||||||
delete processedConfig.regexPattern;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除辅助用的UI字段
|
case 'consistency':
|
||||||
delete processedConfig.availableFields;
|
case 'logic':
|
||||||
|
// 将UI字段名映射为API字段名
|
||||||
|
if (processedConfig.logicRelation) {
|
||||||
|
processedConfig.logic = processedConfig.logicRelation;
|
||||||
|
delete processedConfig.logicRelation;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
// 确保logic字段有默认值
|
||||||
id: rule.id,
|
if (!processedConfig.logic) {
|
||||||
type: rule.type,
|
processedConfig.logic = 'and';
|
||||||
config: processedConfig
|
}
|
||||||
};
|
|
||||||
}).filter(rule => rule.type && rule.type.trim() !== '')
|
// 确保pairs/conditions字段是数组
|
||||||
|
if (rule.type === 'consistency' && !Array.isArray(processedConfig.pairs)) {
|
||||||
|
processedConfig.pairs = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'logic' && !Array.isArray(processedConfig.conditions)) {
|
||||||
|
processedConfig.conditions = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除用于UI的临时字段
|
||||||
|
delete processedConfig.initialSourceField;
|
||||||
|
delete processedConfig.initialTargetField;
|
||||||
|
delete processedConfig.initialCompareMethod;
|
||||||
|
delete processedConfig.initialField;
|
||||||
|
delete processedConfig.initialOperator;
|
||||||
|
delete processedConfig.initialValue;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'format':
|
||||||
|
// 确保field字段正确设置
|
||||||
|
if (processedConfig.checkField) {
|
||||||
|
processedConfig.field = processedConfig.checkField;
|
||||||
|
delete processedConfig.checkField;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保field字段有值
|
||||||
|
if (!processedConfig.field) {
|
||||||
|
processedConfig.field = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (processedConfig.formatParams) {
|
||||||
|
processedConfig.parameters = processedConfig.formatParams;
|
||||||
|
delete processedConfig.formatParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保formatType字段有值
|
||||||
|
if (!processedConfig.formatType) {
|
||||||
|
processedConfig.formatType = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保parameters字段有值
|
||||||
|
if (!processedConfig.parameters) {
|
||||||
|
processedConfig.parameters = '';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'regex':
|
||||||
|
// 确保field和pattern字段正确设置
|
||||||
|
if (processedConfig.checkField) {
|
||||||
|
processedConfig.field = processedConfig.checkField;
|
||||||
|
delete processedConfig.checkField;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保field字段有值
|
||||||
|
if (!processedConfig.field) {
|
||||||
|
processedConfig.field = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (processedConfig.regexPattern) {
|
||||||
|
processedConfig.pattern = processedConfig.regexPattern;
|
||||||
|
delete processedConfig.regexPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保pattern字段有值
|
||||||
|
if (!processedConfig.pattern) {
|
||||||
|
processedConfig.pattern = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保matchType字段有值
|
||||||
|
if (!processedConfig.matchType) {
|
||||||
|
processedConfig.matchType = 'match';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ai':
|
||||||
|
// 确保model字段有值
|
||||||
|
if (!processedConfig.model) {
|
||||||
|
processedConfig.model = 'qwen14b';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保temperature字段是数字
|
||||||
|
if (typeof processedConfig.temperature !== 'number') {
|
||||||
|
processedConfig.temperature = 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保prompt字段有值
|
||||||
|
if (!processedConfig.prompt) {
|
||||||
|
processedConfig.prompt = '';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'code':
|
||||||
|
// 确保language字段有值
|
||||||
|
if (!processedConfig.language) {
|
||||||
|
processedConfig.language = 'javascript';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保code字段有值
|
||||||
|
if (!processedConfig.code) {
|
||||||
|
processedConfig.code = '';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除辅助用的UI字段
|
||||||
|
delete processedConfig.availableFields;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: rule.id,
|
||||||
|
type: rule.type,
|
||||||
|
config: processedConfig
|
||||||
|
};
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// 使用setTimeout避免连锁更新
|
// 使用setTimeout避免连锁更新
|
||||||
|
|||||||
+292
-54
@@ -36,7 +36,13 @@ import rulesStyles from "~/styles/rules.css?url";
|
|||||||
import { useNavigate, useLocation } from "@remix-run/react";
|
import { useNavigate, useLocation } from "@remix-run/react";
|
||||||
// 导入评查点模型定义和常量
|
// 导入评查点模型定义和常量
|
||||||
import type {
|
import type {
|
||||||
EvaluationPoint
|
EvaluationPoint,
|
||||||
|
LogicOperator,
|
||||||
|
CompareMethod,
|
||||||
|
FormatType,
|
||||||
|
ComparisonOperator,
|
||||||
|
MatchType,
|
||||||
|
ProgrammingLanguage
|
||||||
} from "~/models/evaluation_points";
|
} from "~/models/evaluation_points";
|
||||||
import { EVALUATION_OPTIONS } from "~/models/evaluation_points";
|
import { EVALUATION_OPTIONS } from "~/models/evaluation_points";
|
||||||
import type { EvaluationPointGroup } from "~/models/evaluation_point_groups";
|
import type { EvaluationPointGroup } from "~/models/evaluation_point_groups";
|
||||||
@@ -61,6 +67,68 @@ export const handle = {
|
|||||||
breadcrumb: "评查点管理"
|
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() {
|
export default function RuleNew() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -192,63 +260,208 @@ export default function RuleNew() {
|
|||||||
? `http://127.0.0.1:9000/admin/evaluation_points?id=eq.${formData.id}`
|
? `http://127.0.0.1:9000/admin/evaluation_points?id=eq.${formData.id}`
|
||||||
: 'http://127.0.0.1:9000/admin/evaluation_points';
|
: 'http://127.0.0.1:9000/admin/evaluation_points';
|
||||||
|
|
||||||
// 创建一个符合数据库模式的数据副本
|
try {
|
||||||
const cleanedData = {
|
// 创建一个符合数据库模式的数据副本
|
||||||
id: formData.id,
|
const cleanedData = {
|
||||||
name: formData.name,
|
id: formData.id,
|
||||||
code: formData.code,
|
name: formData.name?.trim(),
|
||||||
risk: formData.risk,
|
code: formData.code?.trim(),
|
||||||
is_enabled: formData.is_enabled !== undefined ? formData.is_enabled : true,
|
risk: formData.risk || 'low',
|
||||||
description: formData.description || '',
|
is_enabled: formData.is_enabled !== undefined ? formData.is_enabled : true,
|
||||||
references_laws: formData.references_laws,
|
description: formData.description || '',
|
||||||
evaluation_point_groups_pid: formData.evaluation_point_groups_pid,
|
references_laws: formData.references_laws || null,
|
||||||
evaluation_point_groups_id: formData.evaluation_point_groups_id,
|
evaluation_point_groups_pid: formData.evaluation_point_groups_pid || null,
|
||||||
extraction_config: formData.extraction_config,
|
evaluation_point_groups_id: formData.evaluation_point_groups_id || null,
|
||||||
evaluation_config: formData.evaluation_config,
|
extraction_config: {
|
||||||
pass_message: formData.pass_message || '文档检查通过,符合规范要求。',
|
llm: {
|
||||||
fail_message: formData.fail_message || '文档存在以下问题,请修改后重新提交。',
|
fields: Array.isArray(formData.extraction_config?.llm?.fields) ?
|
||||||
suggestion_message: formData.suggestion_message || '',
|
[...formData.extraction_config.llm.fields] : [],
|
||||||
suggestion_message_type: formData.suggestion_message_type || 'warning',
|
prompt_setting: {
|
||||||
post_action: formData.post_action || 'none',
|
type: formData.extraction_config?.llm?.prompt_setting?.type || 'system',
|
||||||
action_config: formData.action_config || '',
|
template: formData.extraction_config?.llm?.prompt_setting?.template || ''
|
||||||
score: formData.score !== undefined ? formData.score : 0
|
}
|
||||||
};
|
},
|
||||||
|
vlm: {
|
||||||
|
fields: Array.isArray(formData.extraction_config?.vlm?.fields) ?
|
||||||
|
[...formData.extraction_config.vlm.fields] : [],
|
||||||
|
prompt_setting: {
|
||||||
|
type: formData.extraction_config?.vlm?.prompt_setting?.type || 'system',
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
// 如果是新建模式,则删除id字段
|
// 确保rules中的每个配置对象都被正确处理
|
||||||
if (!isEditMode) {
|
if (cleanedData.evaluation_config && Array.isArray(cleanedData.evaluation_config.rules)) {
|
||||||
delete cleanedData.id;
|
cleanedData.evaluation_config.rules = cleanedData.evaluation_config.rules
|
||||||
}
|
.filter(rule => rule && rule.type) // 确保规则有类型
|
||||||
|
.map(rule => {
|
||||||
|
// 根据规则类型确保config中有必要的字段
|
||||||
|
const config = { ...rule.config } as RuleConfig;
|
||||||
|
|
||||||
console.log("准备提交到API的数据:", cleanedData);
|
switch (rule.type) {
|
||||||
|
case 'exists':
|
||||||
|
if (!Array.isArray((config as ExistsRuleConfig).fields)) (config as ExistsRuleConfig).fields = [];
|
||||||
|
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;
|
||||||
|
|
||||||
// 发送数据到API
|
case 'consistency':
|
||||||
fetch(apiUrl, {
|
if (!Array.isArray((config as ConsistencyRuleConfig).pairs)) (config as ConsistencyRuleConfig).pairs = [];
|
||||||
method: apiMethod,
|
if (!(config as ConsistencyRuleConfig).logic) (config as ConsistencyRuleConfig).logic = 'and';
|
||||||
headers: {
|
delete (config as ConsistencyRuleConfig & {availableFields?: string}).availableFields;
|
||||||
'Accept': 'application/json',
|
delete (config as ConsistencyRuleConfig).logicRelation;
|
||||||
'Content-Type': 'application/json'
|
delete (config as ConsistencyRuleConfig).initialSourceField;
|
||||||
},
|
delete (config as ConsistencyRuleConfig).initialTargetField;
|
||||||
body: JSON.stringify(cleanedData)
|
delete (config as ConsistencyRuleConfig).initialCompareMethod;
|
||||||
})
|
break;
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
case 'format':
|
||||||
throw new Error(`API错误: ${response.status}`);
|
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 (!(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) (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
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return response.json();
|
|
||||||
})
|
// 如果是新建模式,则删除id字段
|
||||||
.then(data => {
|
if (!isEditMode) {
|
||||||
console.log("保存成功:", data);
|
delete cleanedData.id;
|
||||||
alert(`评查点${isEditMode ? '更新' : '创建'}成功!`);
|
}
|
||||||
// 保存成功后返回列表页
|
|
||||||
navigate('/rules');
|
// 确保extraction_config和evaluation_config是有效的JSON对象
|
||||||
})
|
// 通过先序列化再解析来验证
|
||||||
.catch(error => {
|
try {
|
||||||
console.error("保存失败:", error);
|
JSON.parse(JSON.stringify(cleanedData.extraction_config));
|
||||||
alert(`保存失败: ${error.message}`);
|
} catch (e) {
|
||||||
})
|
throw new Error("extraction_config 格式无效");
|
||||||
.finally(() => {
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSON.parse(JSON.stringify(cleanedData.evaluation_config));
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error("evaluation_config 格式无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查JSON字符串长度,如果太长可能会被截断
|
||||||
|
const jsonData = JSON.stringify(cleanedData);
|
||||||
|
const maxLength = 65536; // 通常PostgreSQL的jsonb列可以存储的最大长度
|
||||||
|
|
||||||
|
if (jsonData.length > maxLength) {
|
||||||
|
throw new Error(`数据大小超过限制 (${jsonData.length} > ${maxLength})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("准备提交到API的数据:", cleanedData);
|
||||||
|
console.log("JSON数据长度:", jsonData.length);
|
||||||
|
|
||||||
|
// 发送数据到API
|
||||||
|
fetch(apiUrl, {
|
||||||
|
method: apiMethod,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(cleanedData)
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
// 尝试获取详细错误信息
|
||||||
|
let errorText = '';
|
||||||
|
try {
|
||||||
|
const errorData = await response.json();
|
||||||
|
errorText = JSON.stringify(errorData);
|
||||||
|
} catch (e) {
|
||||||
|
errorText = await response.text();
|
||||||
|
}
|
||||||
|
throw new Error(`API错误 (${response.status}): ${errorText}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log("保存成功:", data);
|
||||||
|
alert(`评查点${isEditMode ? '更新' : '创建'}成功!`);
|
||||||
|
// 保存成功后返回列表页
|
||||||
|
navigate('/rules');
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("保存失败:", error);
|
||||||
|
alert(`保存失败: ${error.message}`);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setIsLoading(false);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理错误:", error);
|
||||||
|
alert(`数据处理错误: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSaveDraft = () => {
|
const handleSaveDraft = () => {
|
||||||
@@ -293,7 +506,32 @@ export default function RuleNew() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleReviewSettingsChange = (data: Record<string, unknown>) => {
|
const handleReviewSettingsChange = (data: Record<string, unknown>) => {
|
||||||
setFormData(prev => ({ ...prev, ...data }));
|
console.log("评查设置变更:", data);
|
||||||
|
|
||||||
|
// 检查数据中是否包含evaluation_config对象
|
||||||
|
if (data.evaluation_config) {
|
||||||
|
// 确保formData.evaluation_config存在并具有必要的默认属性
|
||||||
|
const currentConfig = formData.evaluation_config || {
|
||||||
|
logicType: 'and',
|
||||||
|
customLogic: '',
|
||||||
|
rules: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// 合并评查配置数据
|
||||||
|
const mergedConfig = {
|
||||||
|
...currentConfig,
|
||||||
|
...(data.evaluation_config as object)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新表单数据
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
evaluation_config: mergedConfig
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
// 处理其他普通字段
|
||||||
|
setFormData(prev => ({ ...prev, ...data }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user