feat: 在分享功能中添加调试日志,便于排查问题
This commit is contained in:
@@ -370,6 +370,7 @@ export function SharePage() {
|
||||
</Button>
|
||||
<p className="text-center text-xs text-gray-400 mt-2">
|
||||
分享到微信或保存图片到相册
|
||||
<span className="ml-2 opacity-40">v26070201</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -47,6 +47,8 @@ const bridge = {
|
||||
imageUrl?: string
|
||||
scene?: 'WXSceneSession' | 'WXSceneTimeline'
|
||||
}) {
|
||||
console.log('[bridge.share] 触发', JSON.stringify({ title: opts.title, scene: opts.scene }));
|
||||
|
||||
this.postMessage({
|
||||
action: 'share',
|
||||
title: opts.title || '',
|
||||
@@ -55,11 +57,18 @@ const bridge = {
|
||||
imageUrl: opts.imageUrl || '',
|
||||
scene: opts.scene || 'WXSceneSession',
|
||||
})
|
||||
// 微信 web-view 中 postMessage 不会即时投递,只在页面离开时批量发送。
|
||||
// 调用 navigateBack 回到小程序页面触发投递,小程序 onMessage 收到后执行分享。
|
||||
|
||||
const mp = getMiniProgram()
|
||||
console.log('[bridge.share] wx.miniProgram 可用:', !!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 中测试。');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user