"use client"; import { useEffect, useState } from "react"; import { Copyable } from "../Copyable"; import styles from "../vip.module.css"; const COMMUNITY_URL = "https://qun.hackrobot.cn"; const DEFAULT_PASSWORD = "12345678"; function getStorage(key: string): string | null { if (typeof window === "undefined") return null; return localStorage.getItem(key); } function isAnonymousUserId(value: string | null): value is string { return !!value && /^user\d+$/.test(value); } type CommunityAccessModalProps = { open: boolean; onClose: () => void; }; /** 与 WelcomeBlock 同步的社群登录账号解析,用于弹窗展示 */ export function CommunityAccessModal({ open, onClose }: CommunityAccessModalProps) { const userId = typeof window !== "undefined" ? getStorage("userId") : null; const [backendMemosAccount, setBackendMemosAccount] = useState(null); const memosAccount = getStorage("memosAccount") || backendMemosAccount || (isAnonymousUserId(userId) ? userId : null); useEffect(() => { if (!open || !userId) return; fetch(`/api/vip/linked-email?user_id=${encodeURIComponent(userId)}`, { cache: "no-store", }) .then((res) => res.json()) .then((data) => { const linkedAnonymousUserId = typeof data?.anonymousUserId === "string" && /^user\d+$/.test(data.anonymousUserId) ? data.anonymousUserId : null; if (linkedAnonymousUserId && typeof window !== "undefined") { setBackendMemosAccount(linkedAnonymousUserId); localStorage.setItem("memosAccount", linkedAnonymousUserId); } }) .catch(() => {}); }, [open, userId]); useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [open, onClose]); if (!open) return null; return (
e.stopPropagation()} >
👥

私密社群 · 登录信息

使用以下信息访问社群站点,可随时点击复制

网址
qun.hackrobot.cn 打开
账号 {memosAccount || "—"}
密码 {DEFAULT_PASSWORD}
); }