From 4370189e81cd3bc53a78b12a9fa28d5496955558 Mon Sep 17 00:00:00 2001 From: limil Date: Wed, 18 Feb 2026 15:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E7=A1=80=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 2 +- src/App.tsx | 30 ++++++++++++++++-------------- src/components/SaveLoadPanel.css | 2 +- src/components/SaveLoadPanel.tsx | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) 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' ? (