From 653b20ed6131c2a9fa3defd015b8c8ae32012144 Mon Sep 17 00:00:00 2001 From: limil Date: Wed, 11 Feb 2026 00:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8A=82=E7=82=B9=E5=A4=96?= =?UTF-8?q?=E8=A7=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 58 +++++++++++++++---------------- src/components/CustomNode.css | 57 +++++++++++++++--------------- src/components/CustomNode.tsx | 33 ++++++++++++++++-- src/components/FormEditor.css | 4 --- src/components/NodeEditor.tsx | 8 ++--- src/components/SettingsEditor.tsx | 4 +-- src/types/graph.ts | 9 ++++- 7 files changed, 99 insertions(+), 74 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e1b8774..1fe706f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,7 +18,7 @@ import { EdgeMouseHandler } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; -import { AppNode, AppEdge, NodeData, EdgeData, NodeDataUpdate, EdgeDataUpdate, Settings } from './types/graph'; +import { AppNode, AppEdge, NodeData, EdgeData, NodeDataUpdate, EdgeDataUpdate, Settings, initialSettings, SettingsContext } from './types/graph'; import CustomNode from './components/CustomNode'; import NodeEditor from './components/NodeEditor'; import EdgeEditor from './components/EdgeEditor' @@ -29,10 +29,6 @@ import './App.css'; const initialNodes: AppNode[] = []; const initialEdges: AppEdge[] = []; -const initialSettings : Settings = { - listenPort: 38894, - mtu: 1420, -}; const nodeTypes : NodeTypes = { custom: CustomNode, @@ -147,31 +143,33 @@ function FlowContent(): ReactNode { return (
- - - - { - if (n.type === 'input') return 'blue'; - return '#eee'; - }} - maskColor="rgba(0, 0, 0, 0.1)" - position="bottom-right" // 也可以是 top-right 等 - /> - - + + + + + { + if (n.type === 'input') return 'blue'; + return '#eee'; + }} + maskColor="rgba(0, 0, 0, 0.1)" + position="bottom-right" // 也可以是 top-right 等 + /> + + +
{ e.stopPropagation(); }; + + const settings = useContext(SettingsContext); return (
- {data.label} + +
+ +
+ {settings.ipv4Subnet && ( +
+ IPv4地址: + {data.ipv4Address || "未设置"} +
+ )} + + {settings.ipv6Subnet && ( +
+ IPv6地址: + {data.ipv6Address || "未设置"} +
+ )} + + {(!settings.ipv4Subnet && !settings.ipv6Subnet) && ( +
+ 未设置任何子网,请在设置中设置 +
+ )} +
+ +
diff --git a/src/components/FormEditor.css b/src/components/FormEditor.css index 1cf26c3..ee2486d 100644 --- a/src/components/FormEditor.css +++ b/src/components/FormEditor.css @@ -160,10 +160,6 @@ font-weight: 500; cursor: pointer; transition: all 0.2s ease; /* 稍微拉长过渡,显得更平滑 */ - display: flex; - align-items: center; - justify-content: center; - /* 基础阴影 */ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); } diff --git a/src/components/NodeEditor.tsx b/src/components/NodeEditor.tsx index 5dacb42..eb1317a 100644 --- a/src/components/NodeEditor.tsx +++ b/src/components/NodeEditor.tsx @@ -27,18 +27,14 @@ function Validate(updateData : NodeDataUpdate, settings : Settings) : string[] { if(ipv4Subnet) { const cidr = IPNetwork.parse(ipv4Subnet); - if(!ipv4Address) { - errors.push("需要设置IPv4地址"); - } else if(!cidr.contains(IPNetwork.parse(`${ipv4Address}/32`))) { + if(ipv4Address && !cidr.contains(IPNetwork.parse(`${ipv4Address}/32`))) { errors.push("IPv4不在子网范围中"); } } if(ipv6Subnet) { const cidr = IPNetwork.parse(ipv6Subnet); - if(!ipv6Address) { - errors.push("需要设置IPv6地址"); - } else if(!cidr.contains(IPNetwork.parse(`${ipv6Address}/128`))) { + if(ipv6Address && !cidr.contains(IPNetwork.parse(`${ipv6Address}/128`))) { errors.push("IPv6不在子网范围中"); } } diff --git a/src/components/SettingsEditor.tsx b/src/components/SettingsEditor.tsx index 20c1fba..15fdced 100644 --- a/src/components/SettingsEditor.tsx +++ b/src/components/SettingsEditor.tsx @@ -17,7 +17,7 @@ function Validate(updateData: Settings) : string[] { if(ipv4Subnet) { const result = IPNetwork.parse(ipv4Subnet) if(!result.isValid) { - errors.push("IPv4子网:" + (result.error ?? "ipv4子网不合法")) + errors.push("IPv4子网:" + (result.error || "ipv4子网不合法")) } else if(result.version != 'IPv4') { errors.push("IPv4子网:" + "非IPv4 CIDR"); } @@ -26,7 +26,7 @@ function Validate(updateData: Settings) : string[] { if(ipv6Subnet) { const result = IPNetwork.parse(ipv6Subnet) if(!result.isValid) { - errors.push("IPv6子网:" + (result.error ?? "子网不合法")); + errors.push("IPv6子网:" + (result.error || "子网不合法")); } else if(result.version != 'IPv6') { errors.push("IPv6子网:" + "非IPv6 CIDR"); } diff --git a/src/types/graph.ts b/src/types/graph.ts index 172fed6..97fe114 100644 --- a/src/types/graph.ts +++ b/src/types/graph.ts @@ -38,4 +38,11 @@ export interface Settings { ipv4Subnet?: string; ipv6Subnet?: string; -} \ No newline at end of file +} + +export const initialSettings : Settings = { + listenPort: 38894, + mtu: 1420, +}; + +export const SettingsContext = createContext(initialSettings); \ No newline at end of file