编辑情况优化-需要继续完善-暂存
This commit is contained in:
@@ -73,59 +73,60 @@ export function ReviewSettings({ onChange, initialData }: ReviewSettingsProps) {
|
||||
|
||||
// 使用useRef跟踪是否已经初始化过
|
||||
const initializedRef = useRef(false);
|
||||
// 保存初始数据的引用,用于检测是否有实际变更
|
||||
const initialDataRef = useRef<any>(null);
|
||||
|
||||
// 加载初始数据
|
||||
useEffect(() => {
|
||||
// 如果已经初始化过,则跳过此次处理
|
||||
if (initialData && !initializedRef.current) {
|
||||
initializedRef.current = true;
|
||||
console.log('加载初始数据(首次):', initialData);
|
||||
|
||||
// 设置规则
|
||||
if (initialData.rules && initialData.rules.length > 0) {
|
||||
// 确保每个规则都有完整的配置
|
||||
const enhancedRules = initialData.rules.map(rule => {
|
||||
// 根据规则类型,确保config包含必要的字段
|
||||
let config = { ...rule.config };
|
||||
|
||||
// 确保有用于展示的字段
|
||||
if (rule.type === 'format' && config.field && !config.checkField) {
|
||||
config.checkField = config.field;
|
||||
if (initializedRef.current) {
|
||||
console.log("ReviewSettings已初始化,跳过后续初始化处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 记录初始化处理
|
||||
console.log("ReviewSettings开始初始化,数据:", initialData);
|
||||
|
||||
// 保存初始数据引用,用于后续比较
|
||||
initialDataRef.current = JSON.parse(JSON.stringify(initialData));
|
||||
|
||||
// 设置已初始化标记
|
||||
initializedRef.current = true;
|
||||
|
||||
// 只有在有initialData时才进行初始化设置
|
||||
if (initialData) {
|
||||
// 处理初始规则数据
|
||||
if (initialData.rules && Array.isArray(initialData.rules) && initialData.rules.length > 0) {
|
||||
console.log("设置初始规则数据:", initialData.rules);
|
||||
|
||||
const validRules = initialData.rules.map(rule => {
|
||||
// 确保每个规则都有id
|
||||
if (!rule.id) {
|
||||
rule.id = `rule_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||||
}
|
||||
|
||||
if (rule.type === 'regex') {
|
||||
if (config.field && !config.checkField) {
|
||||
config.checkField = config.field;
|
||||
}
|
||||
if (config.pattern && !config.regexPattern) {
|
||||
config.regexPattern = config.pattern;
|
||||
}
|
||||
// 确保配置对象存在
|
||||
if (!rule.config) {
|
||||
rule.config = {};
|
||||
}
|
||||
|
||||
// 确保存在字段有正确的内部表示
|
||||
if (rule.type === 'exists' && config.fields && !config.selectedFields) {
|
||||
config.selectedFields = config.fields;
|
||||
config.existsLogic = config.logic || 'all';
|
||||
// 添加可用字段
|
||||
if (availableFields.length > 0) {
|
||||
rule.config.availableFields = availableFields;
|
||||
}
|
||||
|
||||
// 对于条件逻辑规则
|
||||
if ((rule.type === 'consistency' || rule.type === 'logic') && config.logic && !config.logicRelation) {
|
||||
config.logicRelation = config.logic;
|
||||
}
|
||||
|
||||
// 确保所有规则都有可用字段列表
|
||||
if (!config.availableFields) {
|
||||
config.availableFields = availableFields;
|
||||
}
|
||||
|
||||
return {
|
||||
...rule,
|
||||
config
|
||||
};
|
||||
return rule;
|
||||
});
|
||||
|
||||
console.log('增强后的规则(首次):', enhancedRules);
|
||||
setRules(enhancedRules);
|
||||
// 如果没有规则或规则为空,添加一个默认规则
|
||||
if (validRules.length === 0) {
|
||||
validRules.push({ id: '1', type: '', config: { availableFields } });
|
||||
}
|
||||
|
||||
setRules(validRules);
|
||||
} else {
|
||||
// 如果rules为空或不是数组,添加一个默认规则
|
||||
setRules([{ id: '1', type: '', config: { availableFields } }]);
|
||||
}
|
||||
|
||||
// 设置组合逻辑
|
||||
@@ -1520,7 +1521,7 @@ export function ReviewSettings({ onChange, initialData }: ReviewSettingsProps) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 移除只在UI使用的字段
|
||||
// 移除辅助用的UI字段
|
||||
delete processedConfig.availableFields;
|
||||
|
||||
return {
|
||||
@@ -1528,30 +1529,40 @@ export function ReviewSettings({ onChange, initialData }: ReviewSettingsProps) {
|
||||
type: rule.type,
|
||||
config: processedConfig
|
||||
};
|
||||
})
|
||||
}).filter(rule => rule.type && rule.type.trim() !== '')
|
||||
};
|
||||
|
||||
if (onChange) {
|
||||
const updateData = {
|
||||
rules: config.rules,
|
||||
combinationLogic: config.logicType,
|
||||
customLogic: config.customLogic,
|
||||
pass_message: pass_message,
|
||||
fail_message: fail_message,
|
||||
suggestion_message: suggestion_message,
|
||||
suggestion_message_type: suggestion_message_type,
|
||||
post_action: post_action,
|
||||
action_config: action_config,
|
||||
score: score,
|
||||
scoreDisplay: scoreDisplay
|
||||
};
|
||||
|
||||
onChange(updateData);
|
||||
}
|
||||
// 使用setTimeout避免连锁更新
|
||||
setTimeout(() => {
|
||||
if (onChange) {
|
||||
onChange({
|
||||
rules: config.rules,
|
||||
combinationLogic: config.logicType,
|
||||
customLogic: config.customLogic,
|
||||
pass_message: pass_message,
|
||||
fail_message: fail_message,
|
||||
suggestion_message: suggestion_message,
|
||||
suggestion_message_type: suggestion_message_type,
|
||||
post_action: post_action,
|
||||
action_config: action_config,
|
||||
score: score,
|
||||
scoreDisplay: scoreDisplay
|
||||
});
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return config;
|
||||
}, [rules, combinationLogic, customLogic, pass_message, fail_message, suggestion_message, suggestion_message_type, post_action, action_config, score, scoreDisplay, onChange]);
|
||||
|
||||
// 组件初次渲染后,主动发送一次完整配置数据
|
||||
useEffect(() => {
|
||||
// 如果有初始数据,在组件挂载后主动发送一次完整规则配置
|
||||
if (initialDataRef.current && onChange) {
|
||||
console.log("组件挂载后发送初始完整配置");
|
||||
setTimeout(() => generateEvaluationConfig(), 100);
|
||||
}
|
||||
}, [generateEvaluationConfig, onChange]);
|
||||
|
||||
// 处理评查结果消息变更
|
||||
const handleMessageChange = (type: string, value: string) => {
|
||||
switch(type) {
|
||||
|
||||
Reference in New Issue
Block a user