From 7c40da1b83db6f5cc5322197482f1c58a63c06cb Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 15 Jul 2025 14:18:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B4=A0=E6=9D=90?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA=E6=9A=82?= =?UTF-8?q?=E6=97=A0=E7=B4=A0=E6=9D=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加get_all_materials后端命令获取所有项目的素材 - 在MaterialRepository中实现get_all方法 - 在MaterialService中添加get_all_materials方法 - 修改MaterialModelBindingService的getMaterialsByFilter方法,在没有指定项目时获取所有素材而不是返回空数组 - 确保素材绑定页面能正确显示所有素材数据,与统计信息保持一致 - 支持在全局素材列表上应用绑定状态和搜索过滤 --- .../src/business/services/material_service.rs | 18 +++++++++++-- .../data/repositories/material_repository.rs | 25 ++++++++++++++++++- apps/desktop/src-tauri/src/lib.rs | 1 + .../commands/material_commands.rs | 17 ++++++++++++- .../services/materialModelBindingService.ts | 18 +++++++++++-- 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src-tauri/src/business/services/material_service.rs b/apps/desktop/src-tauri/src/business/services/material_service.rs index 7b9e391..737e4d8 100644 --- a/apps/desktop/src-tauri/src/business/services/material_service.rs +++ b/apps/desktop/src-tauri/src/business/services/material_service.rs @@ -183,12 +183,26 @@ impl MaterialService { project_id: &str, ) -> Result> { let mut materials = repository.get_by_project_id(project_id)?; - + // 为每个素材加载片段信息 for material in &mut materials { material.segments = repository.get_segments(&material.id)?; } - + + Ok(materials) + } + + /// 获取所有素材 + pub fn get_all_materials( + repository: &MaterialRepository, + ) -> Result> { + let mut materials = repository.get_all()?; + + // 为每个素材加载片段信息 + for material in &mut materials { + material.segments = repository.get_segments(&material.id)?; + } + Ok(materials) } diff --git a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs index adaffe8..f535dcc 100644 --- a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs +++ b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs @@ -88,7 +88,7 @@ impl MaterialRepository { /// 根据项目ID获取所有素材 pub fn get_by_project_id(&self, project_id: &str) -> Result> { let conn = self.connection.lock().unwrap(); - + let mut stmt = conn.prepare( "SELECT id, project_id, model_id, name, original_path, file_size, md5_hash, material_type, processing_status, metadata, scene_detection, @@ -108,6 +108,29 @@ impl MaterialRepository { Ok(materials) } + /// 获取所有素材 + pub fn get_all(&self) -> Result> { + let conn = self.connection.lock().unwrap(); + + let mut stmt = conn.prepare( + "SELECT id, project_id, model_id, name, original_path, file_size, md5_hash, + material_type, processing_status, metadata, scene_detection, + created_at, updated_at, processed_at, error_message + FROM materials ORDER BY created_at DESC" + )?; + + let material_iter = stmt.query_map([], |row| { + self.row_to_material(row) + })?; + + let mut materials = Vec::new(); + for material in material_iter { + materials.push(material?); + } + + Ok(materials) + } + /// 根据MD5哈希检查素材是否存在 pub fn exists_by_md5(&self, project_id: &str, md5_hash: &str) -> Result { let conn = self.connection.lock().unwrap(); diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 044e3be..b38ded7 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -51,6 +51,7 @@ pub fn run() { commands::material_commands::select_material_folders, commands::material_commands::scan_folder_materials, commands::material_commands::get_project_materials, + commands::material_commands::get_all_materials, commands::material_commands::get_material_by_id, commands::material_commands::delete_material, commands::material_commands::get_project_material_stats, diff --git a/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs index be2e2aa..51ba449 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/material_commands.rs @@ -514,7 +514,7 @@ pub async fn get_project_materials( ) -> Result, String> { let repository_guard = state.get_material_repository() .map_err(|e| format!("获取素材仓库失败: {}", e))?; - + let repository = repository_guard.as_ref() .ok_or("素材仓库未初始化")?; @@ -522,6 +522,21 @@ pub async fn get_project_materials( .map_err(|e| e.to_string()) } +/// 获取所有素材列表命令 +#[command] +pub async fn get_all_materials( + state: State<'_, AppState>, +) -> Result, String> { + let repository_guard = state.get_material_repository() + .map_err(|e| format!("获取素材仓库失败: {}", e))?; + + let repository = repository_guard.as_ref() + .ok_or("素材仓库未初始化")?; + + MaterialService::get_all_materials(repository) + .map_err(|e| e.to_string()) +} + /// 获取素材详情命令 #[command] pub async fn get_material_by_id( diff --git a/apps/desktop/src/services/materialModelBindingService.ts b/apps/desktop/src/services/materialModelBindingService.ts index 49f1a9f..8ddae12 100644 --- a/apps/desktop/src/services/materialModelBindingService.ts +++ b/apps/desktop/src/services/materialModelBindingService.ts @@ -154,6 +154,13 @@ export class MaterialModelBindingService { }); } + /** + * 获取所有素材 + */ + static async getAllMaterials(): Promise { + return await invoke('get_all_materials'); + } + /** * 根据过滤条件获取素材 */ @@ -178,8 +185,15 @@ export class MaterialModelBindingService { materials = materials.filter(m => m.model_id); } } else { - // 如果没有指定项目,返回空数组 - return []; + // 如果没有指定项目,获取所有素材 + materials = await this.getAllMaterials(); + + // 如果指定了绑定状态过滤 + if (filter.bound === true) { + materials = materials.filter(m => m.model_id); + } else if (filter.bound === false) { + materials = materials.filter(m => !m.model_id); + } } // 应用搜索过滤