From f6eb88d75e03466e2775721d23c5ac20a81d7853 Mon Sep 17 00:00:00 2001 From: sagit <36596628+Sagit-chu@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:07:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E6=9C=AF?= =?UTF-8?q?=E8=AF=AD=EF=BC=8C=E5=B0=86'=E8=BD=AC=E5=8F=91'=E6=94=B9?= =?UTF-8?q?=E4=B8=BA'=E8=A7=84=E5=88=99'=20(#273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新所有页面中的'转发'术语为'规则' - 统一UI文案,提升用户体验一致性 - 关联 #269 #271 Entire-Checkpoint: 5646e42aa33b --- vite-frontend/src/pages/config.tsx | 6 +- vite-frontend/src/pages/dashboard.tsx | 16 +- vite-frontend/src/pages/forward.tsx | 171 ++++----- vite-frontend/src/pages/settings.tsx | 6 +- vite-frontend/src/pages/tunnel.tsx | 486 ++++++++++++++------------ vite-frontend/src/pages/user.tsx | 12 +- 6 files changed, 367 insertions(+), 330 deletions(-) diff --git a/vite-frontend/src/pages/config.tsx b/vite-frontend/src/pages/config.tsx index 0726f26..2f5b1e1 100644 --- a/vite-frontend/src/pages/config.tsx +++ b/vite-frontend/src/pages/config.tsx @@ -119,8 +119,8 @@ const CONFIG_ITEMS: ConfigItem[] = [ }, { key: "forward_compact_mode", - label: "转发页面精简模式", - description: "开启后,转发页面列表使用 2.1.6-alpha8 样式(全局配置)", + label: "规则页面精简模式", + description: "开启后,规则页面列表使用 2.1.6-alpha8 样式(全局配置)", type: "switch", }, { @@ -153,7 +153,7 @@ const BACKUP_TYPE_OPTIONS = [ { value: "users", label: "用户" }, { value: "nodes", label: "节点" }, { value: "tunnels", label: "隧道" }, - { value: "forwards", label: "转发" }, + { value: "forwards", label: "规则" }, { value: "userTunnels", label: "用户隧道权限" }, { value: "speedLimits", label: "限速规则" }, { value: "tunnelGroups", label: "隧道分组" }, diff --git a/vite-frontend/src/pages/dashboard.tsx b/vite-frontend/src/pages/dashboard.tsx index 9daa1b5..889a481 100644 --- a/vite-frontend/src/pages/dashboard.tsx +++ b/vite-frontend/src/pages/dashboard.tsx @@ -616,7 +616,7 @@ export default function DashboardPage() { } iconClassName="bg-purple-100 dark:bg-purple-500/20" - title="转发配额" + title="规则配额" value={formatNumber(userInfo.num || 0)} /> @@ -650,7 +650,7 @@ export default function DashboardPage() { } iconClassName="bg-orange-100 dark:bg-orange-500/20" - title="已用转发" + title="已用规则" value={forwardList.length} /> @@ -753,7 +753,7 @@ export default function DashboardPage() {

- 转发配额 + 规则配额

{formatNumber(tunnel.num)} @@ -761,7 +761,7 @@ export default function DashboardPage() {

- 已用转发 + 已用规则

{getTunnelUsedForwards(tunnel.tunnelId)} @@ -784,7 +784,7 @@ export default function DashboardPage() { )} - {/* 转发配置 */} + {/* 规则配置 */}

@@ -801,7 +801,7 @@ export default function DashboardPage() { />

- 转发配置 + 规则配置

{forwardList.length} @@ -825,7 +825,7 @@ export default function DashboardPage() { strokeWidth={1.5} /> -

暂无转发配置

+

暂无规则配置

) : (
@@ -839,7 +839,7 @@ export default function DashboardPage() { {group.tunnelName} - {group.forwards.length} 个转发 + {group.forwards.length} 个规则
diff --git a/vite-frontend/src/pages/forward.tsx b/vite-frontend/src/pages/forward.tsx index f8cc5ac..f1028be 100644 --- a/vite-frontend/src/pages/forward.tsx +++ b/vite-frontend/src/pages/forward.tsx @@ -675,7 +675,9 @@ export default function ForwardPage() { return false; } - const currentTunnel = allTunnels.find((tunnel) => tunnel.id === form.tunnelId); + const currentTunnel = allTunnels.find( + (tunnel) => tunnel.id === form.tunnelId, + ); return (currentTunnel?.inNodeId?.length || 0) > 1; }, [allTunnels, form.tunnelId]); @@ -1174,7 +1176,7 @@ export default function ForwardPage() { saveOrder(FORWARD_ORDER_KEY, order); } } else { - toast.error(forwardsRes.msg || "获取转发列表失败"); + toast.error(forwardsRes.msg || "获取规则列表失败"); } if (tunnelsRes.code === 0) { @@ -1256,9 +1258,9 @@ export default function ForwardPage() { const newErrors: { [key: string]: string } = {}; if (!form.name.trim()) { - newErrors.name = "请输入转发名称"; + newErrors.name = "请输入规则名称"; } else if (form.name.length < 2 || form.name.length > 50) { - newErrors.name = "转发名称长度应在2-50个字符之间"; + newErrors.name = "规则名称长度应在2-50个字符之间"; } if (!form.tunnelId) { @@ -1308,7 +1310,7 @@ export default function ForwardPage() { return Object.keys(newErrors).length === 0; }; - // 新增转发 + // 新增规则 const handleAdd = () => { setIsEdit(false); setInIpTouched(false); @@ -1326,7 +1328,7 @@ export default function ForwardPage() { setModalOpen(true); }; - // 编辑转发 + // 编辑规则 const handleEdit = (forward: Forward) => { setIsEdit(true); setInIpTouched(false); @@ -1352,7 +1354,7 @@ export default function ForwardPage() { setDeleteModalOpen(true); }; - // 确认删除转发 + // 确认删除规则 const confirmDelete = async () => { if (!forwardToDelete) return; @@ -1367,7 +1369,7 @@ export default function ForwardPage() { } else { // 删除失败,询问是否强制删除 const confirmed = window.confirm( - `常规删除失败:${res.msg || "删除失败"}\n\n是否需要强制删除?\n\n⚠️ 注意:强制删除不会去验证节点端是否已经删除对应的转发服务。`, + `常规删除失败:${res.msg || "删除失败"}\n\n是否需要强制删除?\n\n⚠️ 注意:强制删除不会去验证节点端是否已经删除对应的规则服务。`, ); if (confirmed) { @@ -1489,7 +1491,7 @@ export default function ForwardPage() { // 处理服务开关 const handleServiceToggle = async (forward: Forward) => { if (forward.status !== 1 && forward.status !== 0) { - toast.error("转发状态异常,无法操作"); + toast.error("规则状态异常,无法操作"); return; } @@ -1514,7 +1516,7 @@ export default function ForwardPage() { if (res.code === 0) { toast.success(targetState ? "服务已启动" : "服务已暂停"); - // 更新转发状态 + // 更新规则状态 setForwards((prev) => prev.map((f) => f.id === forward.id ? { ...f, status: targetState ? 1 : 0 } : f, @@ -1540,7 +1542,7 @@ export default function ForwardPage() { } }; - // 诊断转发 + // 诊断规则 const handleDiagnose = async (forward: Forward) => { diagnosisAbortRef.current?.abort(); const abortController = new AbortController(); @@ -1795,7 +1797,7 @@ export default function ForwardPage() { await copyToClipboard(allAddresses, "所有地址"); }; - // 导出转发数据 + // 导出规则数据 const handleExport = () => { setSelectedTunnelForExport(null); setExportData(""); @@ -1813,13 +1815,13 @@ export default function ForwardPage() { setExportLoading(true); try { - // 获取要导出的转发列表 + // 获取要导出的规则列表 const forwardsToExport = sortedForwards.filter( (forward) => forward.tunnelId === selectedTunnelForExport, ); if (forwardsToExport.length === 0) { - toast.error("所选隧道没有转发数据"); + toast.error("所选隧道没有规则数据"); setExportLoading(false); return; @@ -1842,10 +1844,10 @@ export default function ForwardPage() { // 复制导出数据 const copyExportData = async () => { - await copyToClipboard(exportData, "转发数据"); + await copyToClipboard(exportData, "规则数据"); }; - // 导入转发数据 + // 导入规则数据 const handleImport = () => { setImportData(""); setImportResults([]); @@ -1967,7 +1969,7 @@ export default function ForwardPage() { { line, success: false, - message: "格式错误:需要至少包含目标地址和转发名称", + message: "格式错误:需要至少包含目标地址和规则名称", }, ...prev, ]); @@ -1981,7 +1983,7 @@ export default function ForwardPage() { { line, success: false, - message: "目标地址和转发名称不能为空", + message: "目标地址和规则名称不能为空", }, ...prev, ]); @@ -2395,7 +2397,7 @@ export default function ForwardPage() { }), ); - // 根据排序顺序获取转发列表 + // 根据排序顺序获取规则列表 const orderedForwards = useMemo((): Forward[] => { // 确保 forwards 数组存在且有效 if (!forwards || forwards.length === 0) { @@ -2430,7 +2432,7 @@ export default function ForwardPage() { ); } - // 确保过滤后的转发列表有效 + // 确保过滤后的规则列表有效 if (!filteredForwards || filteredForwards.length === 0) { return []; } @@ -2464,7 +2466,7 @@ export default function ForwardPage() { } }); - // 添加不在排序列表中的转发(新添加的) + // 添加不在排序列表中的规则(新添加的) filteredForwards.forEach((forward) => { if (!forwardOrder.includes(forward.id)) { localSortedForwards.push(forward); @@ -2768,7 +2770,7 @@ export default function ForwardPage() { {tunnel.tunnelName}
- {tunnel.items.length} 条转发 + {tunnel.items.length} 条规则
{ const { attributes, @@ -3292,7 +3294,7 @@ export default function ForwardPage() { ); }; - // 渲染转发卡片 + // 渲染规则卡片 const renderForwardCard = (forward: Forward, listeners?: any) => { const statusDisplay = getStatusDisplay(forward.status); const strategyDisplay = getStrategyDisplay(forward.strategy); @@ -3585,7 +3587,7 @@ export default function ForwardPage() {
setIsSearchVisible(false)} @@ -3811,7 +3813,7 @@ export default function ForwardPage() { strategy={verticalListSortingStrategy} > 状态操作 - + {(forward) => (

- 暂无转发配置 + 暂无规则配置

- 还没有创建任何转发配置,点击上方按钮开始创建 + 还没有创建任何规则配置,点击上方按钮开始创建

) ) : sortedForwards.length > 0 ? ( - {}} - > - +
+ + 全部规则 + + + {sortedForwards.length} 条规则 + +
+ {}} > -
- {sortedForwards.map((forward) => - forward && forward.id ? ( - - ) : null, - )} -
-
-
+ +
+ {sortedForwards.map((forward) => + forward && forward.id ? ( + + ) : null, + )} +
+
+ + ) : (

- 暂无转发配置 + 暂无规则配置

- 还没有创建任何转发配置,点击上方按钮开始创建 + 还没有创建任何规则配置,点击上方按钮开始创建

@@ -3929,7 +3944,7 @@ export default function ForwardPage() { )} - {groupForwardCount} 条转发 + {groupForwardCount} 条规则 @@ -3984,7 +3999,7 @@ export default function ForwardPage() { onDragEnd={handleDragEnd} >
{(forward) => ( @@ -4110,10 +4125,10 @@ export default function ForwardPage() {

- 暂无转发配置 + 暂无规则配置

- 还没有创建任何转发配置,点击上方按钮开始创建 + 还没有创建任何规则配置,点击上方按钮开始创建

@@ -4145,7 +4160,7 @@ export default function ForwardPage() { )} - {groupForwardCount} 条转发 + {groupForwardCount} 条规则 @@ -4230,10 +4245,10 @@ export default function ForwardPage() {

- 暂无转发配置 + 暂无规则配置

- 还没有创建任何转发配置,点击上方按钮开始创建 + 还没有创建任何规则配置,点击上方按钮开始创建

@@ -4253,10 +4268,10 @@ export default function ForwardPage() { <>

- {isEdit ? "编辑转发" : "新增转发"} + {isEdit ? "编辑规则" : "新增规则"}

- {isEdit ? "修改现有转发配置的信息" : "创建新的转发配置"} + {isEdit ? "修改现有规则配置的信息" : "创建新的规则配置"}

@@ -4264,8 +4279,8 @@ export default function ForwardPage() { @@ -4369,10 +4384,10 @@ export default function ForwardPage() { isCurrentTunnelMultiEntrance ? "多入口隧道使用节点默认IP" : form.tunnelId - ? currentTunnelIpOptions.length > 0 - ? "选择入口监听IP" - : "当前隧道入口节点暂无可选IP" - : "请先选择隧道" + ? currentTunnelIpOptions.length > 0 + ? "选择入口监听IP" + : "当前隧道入口节点暂无可选IP" + : "请先选择隧道" } selectedKeys={[form.inIp || "__default__"]} variant="bordered" @@ -4441,7 +4456,7 @@ export default function ForwardPage() { isLoading={submitLoading} onPress={handleSubmit} > - {isEdit ? "保存修改" : "创建转发"} + {isEdit ? "保存修改" : "创建规则"} @@ -4466,14 +4481,14 @@ export default function ForwardPage() {

- 确定要删除转发{" "} + 确定要删除规则{" "} "{forwardToDelete?.name}" {" "} 吗?

- 此操作无法撤销,删除后该转发将永久消失。 + 此操作无法撤销,删除后该规则将永久消失。

@@ -4548,9 +4563,9 @@ export default function ForwardPage() { > -

导出转发数据

+

导出规则数据

- 格式:目标地址|转发名称|入口端口 + 格式:目标地址|规则名称|入口端口

@@ -4700,11 +4715,11 @@ export default function ForwardPage() { > -

导入转发数据

+

导入规则数据

{importFormat === "flvx" ? ( <>

- 格式:目标地址|转发名称|入口端口,每行一个,入口端口留空将自动分配可用端口 + 格式:目标地址|规则名称|入口端口,每行一个,入口端口留空将自动分配可用端口

目标地址支持单个地址(如:example.com:8080)或多个地址用逗号分隔(如:3.3.3.3:3,4.4.4.4:4) @@ -4788,8 +4803,8 @@ export default function ForwardPage() { minRows={8} placeholder={ importFormat === "flvx" - ? "请输入要导入的转发数据,格式:目标地址|转发名称|入口端口" - : '请输入ny格式数据,每行一个JSON对象,如:{"dest":["1.2.3.4:80"],"listen_port":8080,"name":"转发1"};listen_port可省略自动分配' + ? "请输入要导入的规则数据,格式:目标地址|规则名称|入口端口" + : '请输入ny格式数据,每行一个JSON对象,如:{"dest":["1.2.3.4:80"],"listen_port":8080,"name":"规则1"};listen_port可省略自动分配' } value={importData} variant="flat" @@ -4929,7 +4944,7 @@ export default function ForwardPage() { {(onClose) => ( <> -

转发诊断结果

+

规则诊断结果

{currentDiagnosisForward && (
@@ -4941,7 +4956,7 @@ export default function ForwardPage() { size="sm" variant="flat" > - 转发服务 + 规则服务
)} @@ -5500,7 +5515,7 @@ export default function ForwardPage() { 确认删除

- 确定要删除选中的 {selectedIds.size} 项转发吗?此操作不可撤销。 + 确定要删除选中的 {selectedIds.size} 项规则吗?此操作不可撤销。

@@ -5531,7 +5546,7 @@ export default function ForwardPage() { 隧道

- 将选中的 {selectedIds.size} 项转发迁移到新隧道: + 将选中的 {selectedIds.size} 项规则迁移到新隧道:

node.status !== 1) - .map((node) => node.id.toString()), - ...form.inNodeId.map((ct) => - ct.nodeId.toString(), - ), - ...getSelectedChainNodeIds().map((id) => - id.toString(), - ), - ]} - dropdownPlacement="top" - errorMessage={errors.outNodeId} - isInvalid={!!errors.outNodeId} - label="节点" - placeholder="请选择出口节点(可多选)" - selectedKeys={ - form.outNodeId - ? form.outNodeId - .filter((ct) => ct.nodeId !== -1) - .map((ct) => ct.nodeId.toString()) - : [] - } - selectionMode="multiple" - variant="bordered" - onSelectionChange={(keys) => { - const selectedIds = toSelectedNodeIds(keys); + {/* 节点选择 - 移动端100%,桌面端50% */} +
+ -
+
+ {node.name} +
+ + {node.status === 1 + ? "在线" + : "离线"} + + {form.inNodeId.some( + (ct) => ct.nodeId === node.id, + ) && ( + + 已选为入口 + + )} + {getSelectedChainNodeIds().includes( + node.id, + ) && ( + + 已选为转发链 + + )} +
+
+ + ))} + + - {/* 协议选择 - 25% */} - { + if ( + !form.outNodeId || + form.outNodeId.length === 0 + ) + return "tls"; - return form.outNodeId[0].protocol || "tls"; - })(), - ]} - variant="bordered" - onSelectionChange={(keys) => { - const selectedKey = Array.from(keys)[0] as string; + return form.outNodeId[0].protocol || "tls"; + })(), + ]} + variant="bordered" + onSelectionChange={(keys) => { + const selectedKey = Array.from( + keys, + )[0] as string; - if (selectedKey) { - setForm((prev) => { - const currentOutNodes = prev.outNodeId || []; - const currentStrategy = - currentOutNodes.length > 0 - ? currentOutNodes[0].strategy || "round" - : "round"; + if (selectedKey) { + setForm((prev) => { + const currentOutNodes = + prev.outNodeId || []; + const currentStrategy = + currentOutNodes.length > 0 + ? currentOutNodes[0].strategy || + "round" + : "round"; - if (currentOutNodes.length === 0) { - // 如果还没有出口节点,创建一个占位节点保存设置 - return { - ...prev, - outNodeId: [ - { - nodeId: -1, - chainType: 3, - protocol: selectedKey, - strategy: currentStrategy, - }, - ], - }; - } + if (currentOutNodes.length === 0) { + // 如果还没有出口节点,创建一个占位节点保存设置 + return { + ...prev, + outNodeId: [ + { + nodeId: -1, + chainType: 3, + protocol: selectedKey, + strategy: currentStrategy, + }, + ], + }; + } - // 更新所有出口节点的协议 - return { - ...prev, - outNodeId: currentOutNodes.map((ct) => ({ - ...ct, - protocol: selectedKey, - })), - }; - }); - } - }} - > - TLS - WSS - TCP - MTLS - MWSS - MTCP - + // 更新所有出口节点的协议 + return { + ...prev, + outNodeId: currentOutNodes.map( + (ct) => ({ + ...ct, + protocol: selectedKey, + }), + ), + }; + }); + } + }} + > + TLS + WSS + TCP + MTLS + MWSS + MTCP + - {/* 负载策略 - 25% */} - { + if ( + !form.outNodeId || + form.outNodeId.length === 0 + ) + return "round"; - return form.outNodeId[0].strategy || "round"; - })(), - ]} - variant="bordered" - onSelectionChange={(keys) => { - const selectedKey = Array.from(keys)[0] as string; + return ( + form.outNodeId[0].strategy || "round" + ); + })(), + ]} + variant="bordered" + onSelectionChange={(keys) => { + const selectedKey = Array.from( + keys, + )[0] as string; - if (selectedKey) { - setForm((prev) => { - const currentOutNodes = prev.outNodeId || []; - const currentProtocol = - currentOutNodes.length > 0 - ? currentOutNodes[0].protocol || "tls" - : "tls"; + if (selectedKey) { + setForm((prev) => { + const currentOutNodes = + prev.outNodeId || []; + const currentProtocol = + currentOutNodes.length > 0 + ? currentOutNodes[0].protocol || "tls" + : "tls"; - if (currentOutNodes.length === 0) { - return { - ...prev, - outNodeId: [ - { - nodeId: -1, - chainType: 3, - protocol: currentProtocol, - strategy: selectedKey, - }, - ], - }; - } + if (currentOutNodes.length === 0) { + return { + ...prev, + outNodeId: [ + { + nodeId: -1, + chainType: 3, + protocol: currentProtocol, + strategy: selectedKey, + }, + ], + }; + } - return { - ...prev, - outNodeId: currentOutNodes.map((ct) => ({ - ...ct, - strategy: selectedKey, - })), - }; - }); - } - }} - > - 主备 - 轮询 - 随机 - + return { + ...prev, + outNodeId: currentOutNodes.map( + (ct) => ({ + ...ct, + strategy: selectedKey, + }), + ), + }; + }); + } + }} + > + 主备 + 轮询 + 随机 + {/* 连接IP - 出口节点 */} @@ -2179,9 +2195,13 @@ export default function TunnelPage() { size="sm" variant="bordered" onSelectionChange={(keys) => { - const selectedKey = Array.from(keys)[0] as string; + const selectedKey = Array.from( + keys, + )[0] as string; const value = - selectedKey === "__default__" ? "" : selectedKey; + selectedKey === "__default__" + ? "" + : selectedKey; setForm((prev) => { const currentOutNodes = prev.outNodeId || []; @@ -2211,7 +2231,9 @@ export default function TunnelPage() { }); }} > - 默认连接IP + + 默认连接IP + {commonOutIpOptions.map((ip) => ( {ip} ))} @@ -2887,7 +2909,7 @@ export default function TunnelPage() {

确定要删除选中的 {selectedIds.size}{" "} - 项隧道吗?此操作不可撤销,相关转发也将被删除。 + 项隧道吗?此操作不可撤销,相关规则也将被删除。

diff --git a/vite-frontend/src/pages/user.tsx b/vite-frontend/src/pages/user.tsx index 9b6fc1b..2850177 100644 --- a/vite-frontend/src/pages/user.tsx +++ b/vite-frontend/src/pages/user.tsx @@ -845,7 +845,7 @@ export default function UserPage() { {/* 其他信息 */}
- 转发数量 + 规则数量 {user.num} @@ -1001,7 +1001,7 @@ export default function UserPage() { /> 分配新权限
- 流量限制、转发数量、到期时间、流量重置时间将自动继承用户设置 + 流量限制、规则数量、到期时间、流量重置时间将自动继承用户设置
@@ -1296,7 +1296,7 @@ export default function UserPage() { 隧道名称 流量统计 - 转发数量 + 规则数量 状态 限速规则 重置时间 @@ -1453,7 +1453,7 @@ export default function UserPage() { />

- 删除后该用户将无法使用此隧道创建转发,此操作不可撤销。 + 删除后该用户将无法使用此隧道创建规则,此操作不可撤销。{" "}