diff --git a/frontend/src/app/pages/SharePage.tsx b/frontend/src/app/pages/SharePage.tsx index 6b2fb7d..7a74443 100644 --- a/frontend/src/app/pages/SharePage.tsx +++ b/frontend/src/app/pages/SharePage.tsx @@ -42,7 +42,8 @@ export function SharePage() { const [imageUrl, setImageUrl] = useState(null); const [linkCopied, setLinkCopied] = useState(false); const [canShareToWechat, setCanShareToWechat] = useState(false); - const [wxacodeUrl, setWxacodeUrl] = useState(null); + const wxacodeUrl = useRef(null); + const [, forceUpdate] = useState(0); const cardRef = useRef(null); useEffect(() => { @@ -92,7 +93,7 @@ export function SharePage() { let cancelled = false; generateWxacode({ width: 430 }) .then((url) => { - if (!cancelled) setWxacodeUrl(url); + if (!cancelled) { wxacodeUrl.current = url; forceUpdate(n => n + 1); } }) .catch((err) => { console.warn("[SharePage] 太阳码生成失败:", err); @@ -105,20 +106,20 @@ export function SharePage() { // 卸载时清理 blob URL useEffect(() => { return () => { - if (wxacodeUrl?.startsWith("blob:")) URL.revokeObjectURL(wxacodeUrl); + if (wxacodeUrl.current?.startsWith("blob:")) URL.revokeObjectURL(wxacodeUrl.current); }; - }, [wxacodeUrl]); + }, []); // 生成长图 const generateImage = useCallback(async (): Promise => { if (!cardRef.current) return null; // 等待太阳码渲染完成(blob URL 需浏览器解码) - if (shareData && !wxacodeUrl) { + if (shareData && !wxacodeUrl.current) { await new Promise((resolve) => { const start = Date.now(); const tick = () => { - if (wxacodeUrl || Date.now() - start > 1500) { + if (wxacodeUrl.current || Date.now() - start > 1500) { resolve(); return; } @@ -126,7 +127,7 @@ export function SharePage() { }; tick(); }); - if (!wxacodeUrl) { + if (!wxacodeUrl.current) { console.warn("[SharePage] 太阳码未就绪,截图中可能缺失二维码"); } } @@ -147,7 +148,7 @@ export function SharePage() { console.error("生成图片失败:", err); return null; } - }, [shareData, wxacodeUrl]); + }, [shareData]); // 一键保存到相册 / 下载 const handleSaveImage = useCallback(async () => { @@ -665,7 +666,7 @@ function ShareCardContent({ )} {/* 太阳码区(截图包含) */} - {wxacodeUrl && ( + {wxacodeUrl.current && (
扫码下载孕育无忧 { // File types to support raw imports. Never add .css, .tsx, or .ts files to this. assetsInclude: ['**/*.svg', '**/*.csv'], + build: { + // 使用 esbuild 代替 terser 避免变量名 mangling 导致 ReferenceError + minify: 'esbuild', + }, + server: { host: '0.0.0.0', allowedHosts: ['.trycloudflare.com', '.loca.lt'],