From 6980c5ee057cee41c795cda6e0ec23b521ff947d Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Fri, 3 Jul 2026 03:16:55 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20SharePage=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E8=A7=81=E8=B0=83=E8=AF=95=E9=9D=A2=E6=9D=BF=EF=BC=8C?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=E5=88=86=E4=BA=AB=E6=8C=89=E9=92=AE=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/app/pages/SharePage.tsx | 89 ++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/pages/SharePage.tsx b/frontend/src/app/pages/SharePage.tsx index 81a4055..62c6eaf 100644 --- a/frontend/src/app/pages/SharePage.tsx +++ b/frontend/src/app/pages/SharePage.tsx @@ -24,6 +24,27 @@ import bridge from "../services/bridge"; type SaveStatus = "idle" | "generating" | "success" | "error"; +/** 调试:检查小程序环境 */ +function checkEnv(): string[] { + const lines: string[] = []; + lines.push('UA: ' + navigator.userAgent.substring(0, 60)); + try { + const w = (window as any).wx; + lines.push('wx 对象: ' + (typeof w !== 'undefined' ? '存在' : '不存在')); + if (w) { + lines.push('wx.miniProgram: ' + (w.miniProgram ? '存在' : '不存在')); + if (w.miniProgram) { + lines.push('navigateBack: ' + (typeof w.miniProgram.navigateBack)); + lines.push('postMessage: ' + (typeof w.miniProgram.postMessage)); + w.miniProgram.getEnv((res: any) => { + lines.push('getEnv: ' + JSON.stringify(res)); + }); + } + } + } catch (e: any) { lines.push('wx 检测异常: ' + e.message); } + return lines; +} + export function SharePage() { const navigate = useNavigate(); const { reportId } = useParams(); @@ -32,8 +53,48 @@ export function SharePage() { const [saveStatus, setSaveStatus] = useState("idle"); const [imageUrl, setImageUrl] = useState(null); const [linkCopied, setLinkCopied] = useState(false); + const [debugLog, setDebugLog] = useState([]); const cardRef = useRef(null); + const addLog = useCallback((msg: string) => { + console.log('[ShareDebug]', msg); + setDebugLog(prev => [...prev.slice(-15), new Date().toLocaleTimeString() + ' ' + msg]); + }, []); + + // 分享按钮(带调试日志) + const handleShare = useCallback(() => { + setDebugLog([]); + const envInfo = checkEnv(); + envInfo.forEach(m => addLog(m)); + + const w = (window as any).wx; + const mp = w?.miniProgram; + + if (!mp) { + addLog('❌ wx.miniProgram 不存在,分享功能不可用'); + return; + } + + addLog('→ postMessage 发送 share 数据'); + mp.postMessage({ + data: { + action: 'share', + title: '孕育无忧 · 报告解读', + summary: shareData?.overall_summary || shareData?.emotional_summary || '', + href: window.location.href, + scene: 'WXSceneSession', + } + }); + + addLog('→ 调用 navigateBack({delta:1})'); + mp.navigateBack({ + delta: 1, + success: () => addLog('✅ navigateBack 成功'), + fail: (err: any) => addLog('❌ navigateBack 失败: ' + JSON.stringify(err)), + complete: () => addLog('→ navigateBack complete'), + }); + }, [addLog, shareData]); + // 复制链接(客户端优先,bridge 降级) const handleCopyLink = useCallback(async () => { const shareUrl = `${window.location.origin}/app_03/share/${reportId}`; @@ -304,6 +365,27 @@ export function SharePage() { + {/* 调试面板:点击分享后显示执行步骤 */} + + {debugLog.length > 0 && ( + + +
+

🔍 分享调试

+ +
+
+ {debugLog.map((m, i) =>
{m}
)} +
+
+
+ )} +
+ {/* 操作提示 */} {/* 微信分享按钮(仅在 web-view 环境下生效) */}