diff --git a/TODO.md b/TODO.md index daa79fe..a527228 100644 --- a/TODO.md +++ b/TODO.md @@ -9,7 +9,7 @@ --- - [x] 实现子网路由功能 -- [ ] 实现配置保存和加载功能(支持加密私钥) +- [x] 实现配置保存和加载功能(支持加密私钥) --- diff --git a/src/App.tsx b/src/App.tsx index 5c09b17..91d793c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -151,12 +151,14 @@ function FlowContent(): ReactNode { const handleSaveConfig = async (pass?: string): Promise => { try { const saveConfig: SaveConfig = {settings: settings, nodes: [], edges: [], encrypted: false} - if(pass) saveConfig.encrypted = true; nodes.forEach(node => { const nodeData = node.data; - let privateKey = nodeData.privateKey; - if(pass && typeof privateKey === 'string') privateKey = CryptoJS.AES.encrypt(privateKey, pass).toString(); + let privateKey: string = nodeData.privateKey; + if(pass) { + privateKey = CryptoJS.AES.encrypt(privateKey, pass).toString(); + saveConfig.encrypted = true; + } saveConfig.nodes.push({...node, data: {...nodeData, privateKey: privateKey}}); }); @@ -184,13 +186,13 @@ function FlowContent(): ReactNode { if (saveConfig.encrypted) { if (!pass) { toast.error('需要密码以解密私钥'); return; } - try { - for(let node of saveConfig.nodes) { - node.data.privateKey = CryptoJS.AES.decrypt(node.data.privateKey, pass).toString(CryptoJS.enc.Utf8); + for(let node of saveConfig.nodes) { + const privateKey = CryptoJS.AES.decrypt(node.data.privateKey, pass).toString(CryptoJS.enc.Utf8); + if(!privateKey) { + toast.error('密码错误'); + return; } - } catch (err) { - toast.error('解密失败: ' + err); - return; + node.data.privateKey = privateKey; } } setSettings(saveConfig.settings); @@ -233,11 +235,6 @@ function FlowContent(): ReactNode {
-
-
文件操作
- -
-
图表操作
+ +
+
文件操作
+ +
diff --git a/src/components/SaveLoadPanel.css b/src/components/SaveLoadPanel.css index a2279c9..2fb80bc 100644 --- a/src/components/SaveLoadPanel.css +++ b/src/components/SaveLoadPanel.css @@ -26,7 +26,7 @@ border-radius:4px; } /* Use .toolbar-btn for button styles so Save/Load matches other toolbar actions */ -.save-load-panel .toolbar-btn{width:100%;text-align:left;padding:8px 16px;border-radius:4px} +.save-load-panel .toolbar-btn{width:100%;text-align:center;padding:8px 16px;border-radius:4px} /* divider removed to match toolbar style */ /* Modal styles */ diff --git a/src/components/SaveLoadPanel.tsx b/src/components/SaveLoadPanel.tsx index 74752ec..ca3d999 100644 --- a/src/components/SaveLoadPanel.tsx +++ b/src/components/SaveLoadPanel.tsx @@ -73,7 +73,7 @@ export default function SaveLoadPanel({ onSave, onLoad }: Props) {
- + setPassword(e.target.value)} /> {modalType === 'load' ? (