fix(share): 用模块级对象属性 _wp.url 彻底避免 minifier 变量名不一致
This commit is contained in:
@@ -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<void>((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 && (
|
||||
<div
|
||||
style={{
|
||||
textAlign: "center",
|
||||
@@ -675,7 +678,7 @@ function ShareCardContent({
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={wxacodeUrl.current}
|
||||
src={_wp.url}
|
||||
alt="扫码下载孕育无忧"
|
||||
crossOrigin="anonymous"
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user