From ec38164aff3f52f7d9ea9da94393c40c2a80180b Mon Sep 17 00:00:00 2001 From: Bot Date: Mon, 11 May 2026 17:35:06 +0800 Subject: [PATCH] feat: optimize server management and fix visual config sync --- public/nzcfg.html | 21 ++-- src/components/server.tsx | 158 +++++++++++++--------------- src/routes/server.tsx | 215 +++++++++++++++++++------------------- 3 files changed, 200 insertions(+), 194 deletions(-) diff --git a/public/nzcfg.html b/public/nzcfg.html index 0dd188f..b08b2c8 100644 --- a/public/nzcfg.html +++ b/public/nzcfg.html @@ -782,7 +782,7 @@
-
@@ -889,7 +889,7 @@
-
@@ -976,20 +976,29 @@ } } - function copyToClipboard(elementId) { + function copyToClipboard(elementId, btn) { + const urlParams = new URLSearchParams(window.location.search); + const targetParam = urlParams.get('target'); + const oldText = btn ? btn.innerHTML : null; + var text = document.querySelector("#" + elementId + " code").innerText navigator.clipboard.writeText(text).then(function () { if (window.opener) { window.opener.postMessage( { type: "NZCFG_JSON", - target: elementId === "jsonOutput" ? "public_note" : "traffic", + target: targetParam || (elementId === "jsonOutput" ? "public_note" : "traffic"), payload: text, }, "*", ) - alert("已生成并同步至控制面板中!") - window.close() + if (btn) { + btn.innerHTML = ' 已同步至控制面板'; + btn.style.backgroundColor = '#2ecc71'; + } + setTimeout(() => { + window.close(); + }, 600); } else { alert("已复制到剪贴板!") } diff --git a/src/components/server.tsx b/src/components/server.tsx index 018cd68..2b128f9 100644 --- a/src/components/server.tsx +++ b/src/components/server.tsx @@ -95,9 +95,12 @@ export const ServerCard: React.FC = ({ data, mutate }) => { useEffect(() => { const handleMessage = (e: MessageEvent) => { if (e.data?.type === "NZCFG_JSON") { - if (e.data.target === "public_note") { - form.setValue("public_note", e.data.payload) - toast(t("Success"), { description: "配置已通过可视化构建器自动填入" }) + const target = e.data.target === "traffic" ? "public_note" : e.data.target + if (target === "public_note" || target === "note") { + form.setValue(target, e.data.payload) + toast(t("Success"), { + description: `配置已自动填入${target === "public_note" ? t("PublicNote.Label") : t("Private") + t("Note")}`, + }) } } } @@ -127,24 +130,45 @@ export const ServerCard: React.FC = ({ data, mutate }) => { } return ( - - - - - - -
- - {t("EditServer")} - - -
- - ( - + <> + { + setOpen(true) + }} + /> + { + setOpen(val) + }} + > + { + e.preventDefault() + }} + onInteractOutside={(e) => { + e.preventDefault() + }} + onFocusOutside={(e) => { + e.preventDefault() + }} + > + +
+ + {t("EditServer")} + + + + + ( + {t("Name")} @@ -248,7 +272,26 @@ export const ServerCard: React.FC = ({ data, mutate }) => { name="note" render={({ field }) => ( - {t("Private") + t("Note")} + + {t("Private") + t("Note")} + +