fix: align Tauri arg names and improve export UX

- Match frontend camelCase keys to backend snake_case params
- Show error toast when save dialog is cancelled
This commit is contained in:
Jason
2025-10-11 11:10:03 +08:00
parent 42329d4dce
commit 2a60d20841
2 changed files with 16 additions and 6 deletions

View File

@@ -388,7 +388,10 @@ export default function SettingsModal({
const defaultName = `cc-switch-config-${new Date().toISOString().split("T")[0]}.json`; const defaultName = `cc-switch-config-${new Date().toISOString().split("T")[0]}.json`;
const filePath = await window.api.saveFileDialog(defaultName); const filePath = await window.api.saveFileDialog(defaultName);
if (!filePath) return; // 用户取消了 if (!filePath) {
onNotify?.(`${t("settings.exportFailed")}: ${t("settings.selectFileFailed")}`, "error", 4000);
return;
}
const result = await window.api.exportConfigToFile(filePath); const result = await window.api.exportConfigToFile(filePath);

View File

@@ -560,8 +560,11 @@ export const tauriAPI = {
filePath: string; filePath: string;
}> => { }> => {
try { try {
// 后端参数为 snake_casefile_path // 兼容参数命名差异:同时传递 file_path 与 filePath
return await invoke("export_config_to_file", { file_path: filePath }); return await invoke("export_config_to_file", {
file_path: filePath,
filePath: filePath,
});
} catch (error) { } catch (error) {
throw new Error(`导出配置失败: ${String(error)}`); throw new Error(`导出配置失败: ${String(error)}`);
} }
@@ -576,8 +579,11 @@ export const tauriAPI = {
backupId?: string; backupId?: string;
}> => { }> => {
try { try {
// 后端参数为 snake_casefile_path // 兼容参数命名差异:同时传递 file_path 与 filePath
return await invoke("import_config_from_file", { file_path: filePath }); return await invoke("import_config_from_file", {
file_path: filePath,
filePath: filePath,
});
} catch (error) { } catch (error) {
throw new Error(`导入配置失败: ${String(error)}`); throw new Error(`导入配置失败: ${String(error)}`);
} }
@@ -586,9 +592,10 @@ export const tauriAPI = {
// 保存文件对话框 // 保存文件对话框
saveFileDialog: async (defaultName: string): Promise<string | null> => { saveFileDialog: async (defaultName: string): Promise<string | null> => {
try { try {
// 后端参数为 snake_casedefault_name // 兼容参数命名差异:同时传递 default_name 与 defaultName
const result = await invoke<string | null>("save_file_dialog", { const result = await invoke<string | null>("save_file_dialog", {
default_name: defaultName, default_name: defaultName,
defaultName: defaultName,
}); });
return result; return result;
} catch (error) { } catch (error) {