feat: 全面完善功能和修复 CSS/API 问题

- 修复暗色主题缺少 --accent 变量导致按钮颜色异常
- 消除所有 CSS 硬编码颜色(btn-primary, btn-danger:hover, sidebar-logo)
- 添加 toast.warning 样式支持
- Modal 支持 Enter 确认和 Escape 关闭
- Dashboard 快速操作按钮添加 loading 状态
- Services 操作后延迟刷新确保状态同步
- Memory 页面添加预览/新建/删除文件功能
- Deploy 页面 .env 路径添加默认值
- Rust 后端补充 delete_memory_file/check_installation/write_env_file 命令
- Mock 数据补全所有 API 端点
This commit is contained in:
晴天
2026-02-26 23:19:00 +08:00
parent 8bf2caf788
commit ed353cb3b5
12 changed files with 187 additions and 10 deletions

View File

@@ -70,3 +70,29 @@ pub fn get_version_info() -> Result<VersionInfo, String> {
update_available: false,
})
}
#[tauri::command]
pub fn check_installation() -> Result<Value, String> {
let openclaw_dir = openclaw_dir();
let installed = openclaw_dir.join("openclaw.json").exists();
let mut result = serde_json::Map::new();
result.insert("installed".into(), Value::Bool(installed));
result.insert("path".into(), Value::String(openclaw_dir.to_string_lossy().to_string()));
Ok(Value::Object(result))
}
#[tauri::command]
pub fn write_env_file(path: String, config: String) -> Result<(), String> {
let expanded = if path.starts_with("~/") {
dirs::home_dir()
.unwrap_or_default()
.join(&path[2..])
} else {
PathBuf::from(&path)
};
if let Some(parent) = expanded.parent() {
let _ = fs::create_dir_all(parent);
}
fs::write(&expanded, &config)
.map_err(|e| format!("写入 .env 失败: {e}"))
}

View File

@@ -110,3 +110,25 @@ pub fn write_memory_file(path: String, content: String) -> Result<(), String> {
fs::write(&target, &content)
.map_err(|e| format!("写入失败: {e}"))
}
#[tauri::command]
pub fn delete_memory_file(path: String) -> Result<(), String> {
if path.contains("..") {
return Err("非法路径".to_string());
}
let candidates = [
memory_dir("memory").join(&path),
memory_dir("archive").join(&path),
memory_dir("core").join(&path),
];
for candidate in &candidates {
if candidate.exists() {
return fs::remove_file(candidate)
.map_err(|e| format!("删除失败: {e}"));
}
}
Err(format!("文件不存在: {path}"))
}

View File

@@ -13,6 +13,8 @@ pub fn run() {
config::read_mcp_config,
config::write_mcp_config,
config::get_version_info,
config::check_installation,
config::write_env_file,
// 服务
service::get_services_status,
service::start_service,
@@ -25,6 +27,7 @@ pub fn run() {
memory::list_memory_files,
memory::read_memory_file,
memory::write_memory_file,
memory::delete_memory_file,
])
.run(tauri::generate_context!())
.expect("启动 ClawPanel 失败");