diff --git a/frontend/src/app/pages/SharePage.tsx b/frontend/src/app/pages/SharePage.tsx index 07d2ec1..02e398b 100644 --- a/frontend/src/app/pages/SharePage.tsx +++ b/frontend/src/app/pages/SharePage.tsx @@ -31,8 +31,36 @@ export function SharePage() { const [shareData, setShareData] = useState(null); const [saveStatus, setSaveStatus] = useState("idle"); const [imageUrl, setImageUrl] = useState(null); + const [linkCopied, setLinkCopied] = useState(false); const cardRef = useRef(null); + // 复制链接(客户端优先,bridge 降级) + const handleCopyLink = useCallback(async () => { + const shareUrl = `${window.location.origin}/app_03/share/${reportId}`; + let copied = false; + // 尝试 navigator.clipboard + try { + await navigator.clipboard.writeText(shareUrl); + copied = true; + } catch {} + // 降级:execCommand + if (!copied) { + const ta = document.createElement('textarea'); + ta.value = shareUrl; + ta.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0'; + document.body.appendChild(ta); + ta.select(); + try { copied = document.execCommand('copy'); } catch {} + document.body.removeChild(ta); + } + // 再降级:bridge.copyLink(依赖 postMessage,web-view 中可能不即时) + if (!copied) { + bridge.copyLink(shareUrl); + } + setLinkCopied(true); + setTimeout(() => setLinkCopied(false), 2000); + }, [reportId]); + useEffect(() => { if (!reportId) return; generateShareData(reportId) @@ -321,10 +349,11 @@ export function SharePage() { 分享给微信好友