feat: 在分享功能中添加调试日志,便于排查问题

This commit is contained in:
2026-07-02 20:07:46 +08:00
parent 85d238fb35
commit 6b04e10552
2 changed files with 13 additions and 3 deletions

View File

@@ -370,6 +370,7 @@ export function SharePage() {
</Button> </Button>
<p className="text-center text-xs text-gray-400 mt-2"> <p className="text-center text-xs text-gray-400 mt-2">
分享到微信或保存图片到相册 分享到微信或保存图片到相册
<span className="ml-2 opacity-40">v26070201</span>
</p> </p>
</div> </div>
</div> </div>

View File

@@ -47,6 +47,8 @@ const bridge = {
imageUrl?: string imageUrl?: string
scene?: 'WXSceneSession' | 'WXSceneTimeline' scene?: 'WXSceneSession' | 'WXSceneTimeline'
}) { }) {
console.log('[bridge.share] 触发', JSON.stringify({ title: opts.title, scene: opts.scene }));
this.postMessage({ this.postMessage({
action: 'share', action: 'share',
title: opts.title || '', title: opts.title || '',
@@ -55,11 +57,18 @@ const bridge = {
imageUrl: opts.imageUrl || '', imageUrl: opts.imageUrl || '',
scene: opts.scene || 'WXSceneSession', scene: opts.scene || 'WXSceneSession',
}) })
// 微信 web-view 中 postMessage 不会即时投递,只在页面离开时批量发送。
// 调用 navigateBack 回到小程序页面触发投递,小程序 onMessage 收到后执行分享。
const mp = getMiniProgram() const mp = getMiniProgram()
console.log('[bridge.share] wx.miniProgram 可用:', !!mp);
if (mp) { if (mp) {
mp.navigateBack({ delta: 1 }) console.log('[bridge.share] 调用 navigateBack({delta:1})');
mp.navigateBack({
delta: 1,
success: () => console.log('[bridge.share] navigateBack 成功'),
fail: (err: any) => console.warn('[bridge.share] navigateBack 失败:', err),
})
} else {
console.warn('[bridge.share] 不在小程序环境中,share 不会生效。当前只在浏览器预览,需在微信小程序 web-view 中测试。');
} }
}, },