fix: 修复分享长图页面微信分享和复制链接在 web-view 中失效
- bridge.share(): postMessage 后调用 navigateBack() 触发消息投递 - SharePage: 复制链接增加客户端三层降级 (clipboard → execCommand → bridge) - .env: 更新已下架的 AI 模型 (VL→Qwen3-VL-32B, Text→Qwen2.5-72B)
This commit is contained in:
@@ -31,8 +31,36 @@ export function SharePage() {
|
|||||||
const [shareData, setShareData] = useState<any>(null);
|
const [shareData, setShareData] = useState<any>(null);
|
||||||
const [saveStatus, setSaveStatus] = useState<SaveStatus>("idle");
|
const [saveStatus, setSaveStatus] = useState<SaveStatus>("idle");
|
||||||
const [imageUrl, setImageUrl] = useState<string | null>(null);
|
const [imageUrl, setImageUrl] = useState<string | null>(null);
|
||||||
|
const [linkCopied, setLinkCopied] = useState(false);
|
||||||
const cardRef = useRef<HTMLDivElement>(null);
|
const cardRef = useRef<HTMLDivElement>(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(() => {
|
useEffect(() => {
|
||||||
if (!reportId) return;
|
if (!reportId) return;
|
||||||
generateShareData(reportId)
|
generateShareData(reportId)
|
||||||
@@ -321,10 +349,11 @@ export function SharePage() {
|
|||||||
<span>分享给微信好友</span>
|
<span>分享给微信好友</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => bridge.copyLink(window.location.href)}
|
onClick={handleCopyLink}
|
||||||
className="w-full h-12 rounded-2xl text-sm font-medium flex items-center justify-center gap-2 border-2 border-gray-200 bg-white hover:bg-gray-50 text-gray-600"
|
className="w-full h-12 rounded-2xl text-sm font-medium flex items-center justify-center gap-2 border-2 border-gray-200 bg-white hover:bg-gray-50 text-gray-600"
|
||||||
>
|
>
|
||||||
<span>复制链接分享</span>
|
{linkCopied ? <Check className="w-4 h-4 text-green-500" /> : null}
|
||||||
|
<span>{linkCopied ? "已复制链接" : "复制链接分享"}</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSaveImage}
|
onClick={handleSaveImage}
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ const bridge = {
|
|||||||
imageUrl: opts.imageUrl || '',
|
imageUrl: opts.imageUrl || '',
|
||||||
scene: opts.scene || 'WXSceneSession',
|
scene: opts.scene || 'WXSceneSession',
|
||||||
})
|
})
|
||||||
|
// 微信 web-view 中 postMessage 不会即时投递,只在页面离开时批量发送。
|
||||||
|
// 调用 navigateBack 回到小程序页面触发投递,小程序 onMessage 收到后执行分享。
|
||||||
|
const mp = getMiniProgram()
|
||||||
|
if (mp) {
|
||||||
|
mp.navigateBack({ delta: 1 })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user