feat: 实现模板片段匹配规则功能并修复数据库迁移问题

新功能:
- 为TrackSegment添加匹配规则字段,支持固定素材和AI分类两种规则
- 实现SegmentMatchingRuleEditor组件,支持在模板详情页面编辑片段匹配规则
- 添加update_segment_matching_rule和get_segment_matching_rule API接口
- 扩展前端类型定义和服务函数以支持匹配规则操作

 修复:
- 修复数据库迁移逻辑导致每次重启清空素材和轨道数据的问题
- 为模板表和轨道片段表迁移添加条件检查,只在必要时执行
- 修正matching_rule字段的默认值格式,匹配Rust枚举序列化格式
- 完善轨道片段表重建时的字段迁移逻辑

 技术改进:
- 数据库schema更新,添加matching_rule列到track_segments表
- 优化数据库迁移性能,避免不必要的表重建操作
- 增强错误处理和日志输出,便于问题排查

 文件变更:
- 后端: template_service.rs, template.rs, database.rs, template_commands.rs, lib.rs
- 前端: SegmentMatchingRuleEditor.tsx, TemplateDetailModal.tsx, templateStore.ts, template.ts
This commit is contained in:
imeepos
2025-07-15 09:43:04 +08:00
parent be8c032158
commit 05d29832b0
9 changed files with 581 additions and 71 deletions

View File

@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { X, Calendar, Clock, Monitor, Layers, FileText, Image, Video, Music, Type, Sparkles, CheckCircle, XCircle, AlertCircle, Upload, Cloud } from 'lucide-react';
import { Template, TemplateMaterial, TemplateMaterialType, TrackType } from '../../types/template';
import { SegmentMatchingRuleEditor } from './SegmentMatchingRuleEditor';
interface TemplateDetailModalProps {
template: Template;
@@ -539,6 +540,18 @@ export const TemplateDetailModal: React.FC<TemplateDetailModalProps> = ({
</div>
)}
{/* 匹配规则编辑器 */}
<div className="bg-yellow-50 p-2 rounded mt-1">
<SegmentMatchingRuleEditor
segmentId={segment.id}
currentRule={segment.matching_rule}
onRuleUpdated={(newRule) => {
// 可以在这里添加更新后的回调逻辑
console.log('片段匹配规则已更新:', segment.id, newRule);
}}
/>
</div>
{segment.template_material_id && (
<div>
使ID: <span className="font-mono text-blue-600">{segment.template_material_id}</span>