diff --git a/frontend/src/app/pages/SharePage.tsx b/frontend/src/app/pages/SharePage.tsx index 7a74443..621a05c 100644 --- a/frontend/src/app/pages/SharePage.tsx +++ b/frontend/src/app/pages/SharePage.tsx @@ -33,6 +33,9 @@ function supportsWxMiniProgramShare(): boolean { } catch { return false; } } + +/** 模块级状态:避免构建压缩时变量名不一致导致 ReferenceError */ +const _wp = { url: null as string | null, tick: 0 }; export function SharePage() { const navigate = useNavigate(); const { reportId } = useParams(); @@ -93,7 +96,7 @@ export function SharePage() { let cancelled = false; generateWxacode({ width: 430 }) .then((url) => { - if (!cancelled) { wxacodeUrl.current = url; forceUpdate(n => n + 1); } + if (!cancelled) { _wp.url = url; forceUpdate(n => n + 1); } }) .catch((err) => { console.warn("[SharePage] 太阳码生成失败:", err); @@ -106,7 +109,7 @@ export function SharePage() { // 卸载时清理 blob URL useEffect(() => { return () => { - if (wxacodeUrl.current?.startsWith("blob:")) URL.revokeObjectURL(wxacodeUrl.current); + if (_wp.url?.startsWith("blob:")) URL.revokeObjectURL(_wp.url); }; }, []); @@ -115,11 +118,11 @@ export function SharePage() { if (!cardRef.current) return null; // 等待太阳码渲染完成(blob URL 需浏览器解码) - if (shareData && !wxacodeUrl.current) { + if (shareData && !_wp.url) { await new Promise((resolve) => { const start = Date.now(); const tick = () => { - if (wxacodeUrl.current || Date.now() - start > 1500) { + if (_wp.url || Date.now() - start > 1500) { resolve(); return; } @@ -127,7 +130,7 @@ export function SharePage() { }; tick(); }); - if (!wxacodeUrl.current) { + if (!_wp.url) { console.warn("[SharePage] 太阳码未就绪,截图中可能缺失二维码"); } } @@ -666,7 +669,7 @@ function ShareCardContent({ )} {/* 太阳码区(截图包含) */} - {wxacodeUrl.current && ( + {_wp.url && (