| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /**
- * 发送消息给 iframe
- */
- const sendToIframe = (type, data, requestId) {
- if (!this.iframeWindow) {
- console.warn('[Parent] Cannot send message: iframe not initialized');
- return;
- }
- const message = { type, data, requestId };
- console.log('[Parent] Sending message to iframe:', message);
- this.iframeWindow.postMessage(JSON.stringify(message), this.origin);
- }
- var INDEX = {
- init: 0, // 初始化
- login: 1, // 登录
- logout: 2, // 登出
- pay: 3, // 支付
- report: 4, // 角色上报
- onLogout: 5, // 浮标个人/账号中心切换账号
- }
- window.jsBridge({callback:1, param:参数, token:'我给你的原样给我'})
- window.jsBridge = function (data){
- const {callback, param, token} = data
- switch(callback){
- case INDEX.init:
- sendToIframe('INIT_REQUEST', param, token)
- break;
- case INDEX.login:
- sendToIframe('LOGIN_REQUEST', param, token)
- break;
- case INDEX.logout:
- sendToIframe('LOGOUT_REQUEST', param, token)
- break;
- case INDEX.pay:
- sendToIframe('PAY_REQUEST', param, token)
- break;
- case INDEX.report:
- sendToIframe('REPORT_REQUEST', param, token)
- break;
- case INDEX.onLogout:
- sendToIframe('ONLOGOUT_REQUEST', param, token)
- break;
- }
- }
|