dev-manager-tauri/src-tauri/src/commands/canvas.rs
lanrtop 0cdaa3678c feat: add Blueprint feature to ProjectCard and commands
- Introduced BlueprintModal in ProjectCard for project blueprint visualization.
- Added state management for displaying the BlueprintModal.
- Implemented Blueprint-related interfaces and functions in commands.ts for handling blueprint data.
2026-04-02 19:12:53 +09:00

31 lines
1012 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::db::pool;
use rusqlite::params;
/// 读取产品组的画布状态(JSON 字符串),不存在时返回 null
#[tauri::command]
pub fn get_canvas_state(group_id: String) -> Result<Option<String>, String> {
let conn = pool().get().map_err(|e| e.to_string())?;
match conn.query_row(
"SELECT data FROM canvas_states WHERE group_id = ?1",
params![group_id],
|row| row.get::<_, String>(0),
) {
Ok(data) => Ok(Some(data)),
Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None),
Err(e) => Err(e.to_string()),
}
}
/// 保存(覆盖)产品组的画布状态
#[tauri::command]
pub fn save_canvas_state(group_id: String, data: String) -> Result<(), String> {
let conn = pool().get().map_err(|e| e.to_string())?;
conn.execute(
"INSERT OR REPLACE INTO canvas_states (group_id, data, updated_at)
VALUES (?1, ?2, datetime('now'))",
params![group_id, data],
)
.map_err(|e| e.to_string())?;
Ok(())
}