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:
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -560,8 +560,11 @@ export const tauriAPI = {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
}> => {
|
}> => {
|
||||||
try {
|
try {
|
||||||
// 后端参数为 snake_case:file_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_case:file_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_case:default_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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user