fix: 修复匹配记录批量删除功能

- 修复 DeleteConfirmDialog 组件中确认按钮缺少 onClick 事件处理
- 修复 props 解构中缺少 onConfirm 参数的问题
- 修复文件名序号001匹配限制逻辑,确保单个模板匹配过程中只能使用一个序号001的视频

问题原因:
1. DeleteConfirmDialog 确认按钮没有绑定 onConfirm 回调函数
2. 组件 props 解构时遗漏了 onConfirm 参数
3. 序号001限制逻辑在模板匹配过程中的检查时机不正确
This commit is contained in:
imeepos 2025-07-21 19:18:18 +08:00
parent 5091493a8c
commit 856d0b1055
3 changed files with 17 additions and 7 deletions

View File

@ -736,13 +736,16 @@ impl MaterialMatchingService {
let target_duration = track_segment.duration as f64 / 1_000_000.0; // 转换为秒
println!(" 目标时长(秒): {:.3}", target_duration);
// 特殊处理如果目标序号是001检查是否已经使用了序号001的视频
// 特殊处理如果目标序号是001检查当前模板匹配过程中是否已经使用了序号001的视频
let mut template_already_used_sequence_001 = false;
if target_sequence == "001" {
// 检查已使用的片段中是否有序号001的视频
// 检查当前模板匹配过程中已使用的片段中是否有序号001的视频
for used_id in used_segment_ids.iter() {
if let Some((used_segment, _)) = available_segments.iter().find(|(seg, _)| seg.id == *used_id) {
if FilenameUtils::has_sequence_001(&used_segment.file_path) && FilenameUtils::is_video_file(&used_segment.file_path) {
return Err("该模板已经使用了一个序号为001的视频不能再使用其他序号001的视频".to_string());
template_already_used_sequence_001 = true;
println!("⚠️ 当前模板已使用序号001视频: {}", FilenameUtils::extract_filename(&used_segment.file_path));
break;
}
}
}
@ -759,6 +762,13 @@ impl MaterialMatchingService {
// 检查文件名是否包含目标序号
if FilenameUtils::has_sequence_number(&segment.file_path, target_sequence) {
// 特殊处理如果目标序号是001且当前模板已经使用了序号001的视频则跳过这个片段
if target_sequence == "001" && template_already_used_sequence_001 {
println!(" ⏭️ 跳过序号001片段模板已使用序号001: {}",
FilenameUtils::extract_filename(&segment.file_path));
continue;
}
// 确保是视频文件
if FilenameUtils::is_video_file(&segment.file_path) {
// 查找对应的素材信息
@ -778,7 +788,7 @@ impl MaterialMatchingService {
println!(" 找到 {} 个包含目标序号的视频片段", matching_segments.len());
// 在匹配的片段中找到最佳时长匹配
if let Some((best_segment, best_category, best_material)) = self.find_best_duration_match(
if let Some((best_segment, _best_category, best_material)) = self.find_best_duration_match(
&matching_segments,
target_duration,
) {
@ -857,8 +867,7 @@ impl MaterialMatchingService {
let mut template_counters: HashMap<String, u32> = HashMap::new();
// 跟踪哪些模板已经使用了序号001的视频确保每个模板只能使用一个序号001的视频
// TODO: 实现模板级别的序号001使用限制
// let mut _templates_used_sequence_001: HashSet<String> = HashSet::new();
// 注意:这个跟踪在单个模板匹配过程中进行,不需要全局恢复
// 获取项目中已使用的素材片段ID列表从数据库
let existing_used_segments = match self.material_usage_repo.get_usage_records_by_project(&request.project_id) {

View File

@ -106,7 +106,6 @@ impl MaterialRepository {
let mut materials = Vec::new();
for material in material_iter {
let material = material?;
println!("📄 找到素材: {} ({})", material.name, material.id);
materials.push(material);
}

View File

@ -30,6 +30,7 @@ export const DeleteConfirmDialog: React.FC<DeleteConfirmDialogProps> = ({
message,
itemName,
deleting,
onConfirm,
onCancel,
}) => {
return (
@ -81,6 +82,7 @@ export const DeleteConfirmDialog: React.FC<DeleteConfirmDialogProps> = ({
</button>
<button
type="button"
onClick={onConfirm}
disabled={deleting}
className="px-4 py-2.5 bg-gradient-to-r from-red-600 to-red-700 hover:from-red-700 hover:to-red-800 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 transition-all duration-200 font-medium text-sm disabled:opacity-50 disabled:cursor-not-allowed shadow-sm hover:shadow-md min-w-[100px]"
>