feat: 模板详情弹框优化和单个删除功能修复

- 修改模板详情弹框默认选中标签从'概览'改为'轨道'
- 修复单个模板匹配记录删除时片段使用状态未正确更新的bug
- 新增soft_delete_matching_result_with_usage_reset命令支持单个删除时重置使用状态
- 前端界面优化,提供更好的用户反馈

Changes:
- apps/desktop/src/components/template/TemplateDetailModal.tsx: 默认标签页改为tracks
- apps/desktop/src-tauri/src/business/services/template_matching_result_service.rs: 新增单个删除重置方法
- apps/desktop/src-tauri/src/presentation/commands/template_matching_result_commands.rs: 新增Tauri命令
- apps/desktop/src-tauri/src/lib.rs: 注册新命令
- apps/desktop/src/components/TemplateMatchingResultManager.tsx: 更新前端删除逻辑
This commit is contained in:
imeepos 2025-07-25 18:13:40 +08:00
parent d259961ade
commit 05903e22fc
5 changed files with 36 additions and 2 deletions

View File

@ -201,6 +201,21 @@ impl TemplateMatchingResultService {
Ok(self.repository.soft_delete(result_id)?) Ok(self.repository.soft_delete(result_id)?)
} }
/// 软删除匹配结果并重置资源使用状态
pub async fn soft_delete_matching_result_with_usage_reset(
&self,
result_id: &str,
material_usage_repo: Arc<crate::data::repositories::material_usage_repository::MaterialUsageRepository>
) -> Result<(bool, u32)> {
// 先删除使用记录并重置资源状态
let deleted_usage_records = material_usage_repo.delete_usage_records_by_matching_results(&[result_id.to_string()])?;
// 再软删除匹配结果
let deleted_result = self.soft_delete_matching_result(result_id).await?;
Ok((deleted_result, deleted_usage_records))
}
/// 批量删除匹配结果 /// 批量删除匹配结果
pub async fn batch_delete_matching_results(&self, result_ids: &[String]) -> Result<u32> { pub async fn batch_delete_matching_results(&self, result_ids: &[String]) -> Result<u32> {
let mut deleted_count = 0; let mut deleted_count = 0;

View File

@ -233,6 +233,7 @@ pub fn run() {
commands::template_matching_result_commands::list_matching_results, commands::template_matching_result_commands::list_matching_results,
commands::template_matching_result_commands::delete_matching_result, commands::template_matching_result_commands::delete_matching_result,
commands::template_matching_result_commands::soft_delete_matching_result, commands::template_matching_result_commands::soft_delete_matching_result,
commands::template_matching_result_commands::soft_delete_matching_result_with_usage_reset,
commands::template_matching_result_commands::batch_delete_matching_results, commands::template_matching_result_commands::batch_delete_matching_results,
commands::template_matching_result_commands::batch_soft_delete_matching_results, commands::template_matching_result_commands::batch_soft_delete_matching_results,
commands::template_matching_result_commands::batch_delete_matching_results_with_usage_reset, commands::template_matching_result_commands::batch_delete_matching_results_with_usage_reset,

View File

@ -153,6 +153,21 @@ pub async fn soft_delete_matching_result(
.map_err(|e| e.to_string()) .map_err(|e| e.to_string())
} }
/// 软删除匹配结果并重置资源使用状态
#[command]
pub async fn soft_delete_matching_result_with_usage_reset(
result_id: String,
database: State<'_, Arc<Database>>,
) -> Result<(bool, u32), String> {
let repository = Arc::new(TemplateMatchingResultRepository::new(database.inner().clone()));
let material_usage_repo = Arc::new(crate::data::repositories::material_usage_repository::MaterialUsageRepository::new(database.inner().clone()));
let service = TemplateMatchingResultService::new(repository);
service.soft_delete_matching_result_with_usage_reset(&result_id, material_usage_repo)
.await
.map_err(|e| e.to_string())
}
/// 批量删除匹配结果 /// 批量删除匹配结果
#[command] #[command]
pub async fn batch_delete_matching_results( pub async fn batch_delete_matching_results(

View File

@ -116,10 +116,13 @@ export const TemplateMatchingResultManager: React.FC<TemplateMatchingResultManag
// 删除匹配结果 // 删除匹配结果
const handleDelete = async (result: TemplateMatchingResult) => { const handleDelete = async (result: TemplateMatchingResult) => {
try { try {
await invoke<boolean>('soft_delete_matching_result', { const [deletedResult, deletedUsageRecords] = await invoke<[boolean, number]>('soft_delete_matching_result_with_usage_reset', {
resultId: result.id, resultId: result.id,
}); });
console.log(`删除结果: ${deletedResult ? '成功' : '失败'},重置 ${deletedUsageRecords} 条使用记录`);
success(`成功删除匹配结果,重置 ${deletedUsageRecords} 条使用记录`);
// 重新加载列表 // 重新加载列表
await loadResults(); await loadResults();
await loadStatistics(); await loadStatistics();

View File

@ -15,7 +15,7 @@ export const TemplateDetailModal: React.FC<TemplateDetailModalProps> = ({
onClose, onClose,
onTemplateUpdated, onTemplateUpdated,
}) => { }) => {
const [activeTab, setActiveTab] = useState<'overview' | 'materials' | 'tracks'>('overview'); const [activeTab, setActiveTab] = useState<'overview' | 'materials' | 'tracks'>('tracks');
const [expandedSections, setExpandedSections] = useState<Record<string, boolean>>({}); const [expandedSections, setExpandedSections] = useState<Record<string, boolean>>({});
const [expandedMaterials, setExpandedMaterials] = useState<Record<string, boolean>>({}); const [expandedMaterials, setExpandedMaterials] = useState<Record<string, boolean>>({});
const [expandedSegments, setExpandedSegments] = useState<Record<string, boolean>>({}); const [expandedSegments, setExpandedSegments] = useState<Record<string, boolean>>({});