diff --git a/app/admin-app.tsx b/app/admin-app.tsx index 3deabb6..bf75f26 100644 --- a/app/admin-app.tsx +++ b/app/admin-app.tsx @@ -3196,6 +3196,10 @@ function ResourcesPage({ }); const [singleWorking, setSingleWorking] = useState(false); const [singleError, setSingleError] = useState(""); + const [editAccount, setEditAccount] = useState(null); + const [editAccountId, setEditAccountId] = useState(""); + const [editWorking, setEditWorking] = useState(false); + const [editError, setEditError] = useState(""); const resourceAccounts = useMemo(() => { const deliveriesByAccount = new Map(); distributions.forEach((distribution) => { @@ -3403,6 +3407,46 @@ function ResourcesPage({ setImportWorking(false); } }; + const closeAccountEdit = () => { + if (editWorking) return; + setEditAccount(null); + setEditAccountId(""); + setEditError(""); + }; + const submitAccountEdit = async () => { + if (!editAccount) return; + const value = editAccountId.trim(); + if (!value) { + setEditError("请填写新的账号ID"); + return; + } + if (!/^[\p{L}\p{N}._-]{2,80}$/u.test(value)) { + setEditError("账号ID需为 2-80 位字母、数字或 . _ - 组合"); + return; + } + try { + setEditWorking(true); + setEditError(""); + const response = await fetch("/api/action", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + action: "set_public_account_ids", + items: [{ accountId: editAccount.id, publicAccountId: value }], + }), + }); + const result = await readApiResponse<{ error?: string }>(response, "保存失败"); + if (!response.ok) throw new Error(result.error || "保存失败"); + const label = editAccount.nickname || editAccount.public_account_id || "该账号"; + setEditAccount(null); + setEditAccountId(""); + await onImported(`已更新 ${label} 的账号ID`); + } catch (reason) { + setEditError(reason instanceof Error ? reason.message : "保存失败"); + } finally { + setEditWorking(false); + } + }; return (
@@ -3548,6 +3592,18 @@ function ResourcesPage({
{accountIdLabel} {account.public_account_id || "待识别"} +
@@ -3601,6 +3657,59 @@ function ResourcesPage({
)}
+ {editAccount && ( +
+
event.stopPropagation()} + > +
+
+

{editAccount.nickname || "账号"}

+

修改账号ID

+
+ +
+
+ + {editError &&
{editError}
} +
+
+ + +
+
+
+ )} {importOpen && (