diff --git a/control/frontend/src/pages/Settings.tsx b/control/frontend/src/pages/Settings.tsx index 2f7a6df..8fed0b9 100644 --- a/control/frontend/src/pages/Settings.tsx +++ b/control/frontend/src/pages/Settings.tsx @@ -150,6 +150,39 @@ export default function SettingsPage() { } } + async function copyToken(text: string) { + setErr(""); + setOk(""); + try { + if (navigator.clipboard?.writeText) { + await navigator.clipboard.writeText(text); + setOk("已复制到剪贴板"); + return; + } + } catch { + /* fall through to legacy copy */ + } + try { + const ta = document.createElement("textarea"); + ta.value = text; + ta.setAttribute("readonly", ""); + ta.style.position = "fixed"; + ta.style.left = "-9999px"; + document.body.appendChild(ta); + ta.select(); + ta.setSelectionRange(0, text.length); + const okCopy = document.execCommand("copy"); + document.body.removeChild(ta); + if (okCopy) { + setOk("已复制到剪贴板"); + return; + } + } catch { + /* ignore */ + } + setErr("复制失败,请手动选中 Token 复制"); + } + return (