feat(h5): 引入微信JSSDK并实现跨域消息通信

- 在H5环境中动态加载微信JSSDK 实脚本
-现向父窗口发送postMessage消息
- 支持向微信小程序发送postMessage消息
- 添加延迟执行机制确保消息发送时机
- 增强与微信小程序的交互能力
This commit is contained in:
liguigong
2025-10-11 10:32:12 +08:00
parent 2af8b9d635
commit 5c279028c3
2 changed files with 27 additions and 0 deletions
+6
View File
@@ -3,6 +3,12 @@
import { ShoproInit } from './sheep';
onLaunch(() => {
// #ifdef H5
const script = document.createElement('script');
script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
script.type = 'text/javascript';
document.body.appendChild(script);
// #endif
// 隐藏原生导航栏 使用自定义底部导航
uni.hideTabBar({
fail: () => {},
+21
View File
@@ -113,6 +113,27 @@
onLoad((options) => {
console.log('🚀 ~ 🐶106 ~ options: ', options);
setTimeout(() => {
window?.parent?.postMessage(
{
data: {
code: 'success',
test: '我是子页面的test',
},
},
'*',
);
wx?.miniProgram?.postMessage({
data: {
action: 'type',
message: '1234',
timestamp: new Date().getTime(),
},
});
console.log(wx?.miniProgram?.postMessage);
console.log(window?.parent);
}, 2000);
if (options?.fileUrl) {
isEdit.value = true;
}