Implement code changes to enhance functionality and improve performance
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useNavigate, useParams } from "react-router";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import bridge from "../services/bridge";
|
||||
import {
|
||||
ChevronLeft,
|
||||
Heart,
|
||||
@@ -48,28 +49,33 @@ export function AIAnalysisPage() {
|
||||
}, [reportId]);
|
||||
|
||||
const handleCopyLink = async () => {
|
||||
const shareUrl = `${window.location.origin}/share/${reportId}`;
|
||||
// 微信 web-view 中 navigator.clipboard 不可用,用 execCommand 替代
|
||||
let copied = false;
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = shareUrl;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
textArea.style.top = '-999999px';
|
||||
textArea.style.opacity = '0';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
const shareUrl = `${window.location.origin}/share/${reportId}`;
|
||||
await navigator.clipboard.writeText(shareUrl);
|
||||
copied = document.execCommand('copy');
|
||||
} catch (e) {
|
||||
console.warn('[copy] execCommand failed:', e);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
|
||||
if (copied) {
|
||||
setLinkCopied(true);
|
||||
setTimeout(() => setLinkCopied(false), 2000);
|
||||
} else {
|
||||
// 兜底:通过小程序桥接(postMessage 在页面离开时触发)
|
||||
bridge.copyLink(shareUrl);
|
||||
setLinkCopied(true);
|
||||
setTimeout(() => setLinkCopied(false), 2000);
|
||||
} catch (error) {
|
||||
console.error('复制失败:', error);
|
||||
// 降级方案:使用旧的复制方法
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = `${window.location.origin}/share/${reportId}`;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
setLinkCopied(true);
|
||||
setTimeout(() => setLinkCopied(false), 2000);
|
||||
} catch (err) {
|
||||
alert('复制失败,请手动复制链接');
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user