From fe4b76e24c82abf35afaaa07f3e681ba14ee2d80 Mon Sep 17 00:00:00 2001 From: tanghaolin <1723298894@qq.com> Date: 星期日, 20 四月 2025 22:22:30 +0800 Subject: [PATCH] 修改头部 --- src/utils/iframeCall.ts | 54 +++++++++++++----------------------------------------- 1 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/utils/iframeCall.ts b/src/utils/iframeCall.ts index 2c514b4..70254c8 100644 --- a/src/utils/iframeCall.ts +++ b/src/utils/iframeCall.ts @@ -1,45 +1,17 @@ -/** - * 璁剧疆鍏ㄥ眬鍑芥暟锛岀敤浜� Child 娉ㄥ唽 - */ -export const registerChildFunction = () => { - /** @description 鎶� Child 鐨勫嚱鏁版敞鍐岃繃鏉�, 鏂逛究鑷繁璋冪敤 */ - (window as any).register = (funObj: any) => { - console.log('register children function obj', funObj); - (window as any).childCallObj = funObj; - }; -}; -/** - * 杩斿洖瀛� iframe 璋冪敤鍔熻兘鍒楄〃 - */ -export const getChildCallObj = () => { - return (window as any)?.childCallObj ?? {}; +const notifyFunc = (jsonObj: any) => { + console.log('message from parent馃殌 ~ jsonObj:', jsonObj); + // 鎵цAI閫氱煡娑堟伅 }; - -/** - * 杩斿洖涓�涓璞★紝缁� child 璋冪敤 - * 姝ゅ璞″寘鍚涓嚱鏁� - * @returns - */ -const parentCallObj = { - /** @description 娴嬭瘯鍑芥暟 */ - test: (msg: string) => { - console.log('test 鍑芥暟鏉ヨ嚜 parent', msg); - }, -}; -/** - * 寰� windows 涓婂姞鍑芥暟锛岀粰 child 璋冪敤 - */ -export const setParentFunction = () => { - let child: any; - for (let index = 0; index < window.frames.length; index++) { - const frame = window.frames[index]; - if ((frame as any).register) { - child = frame; - break; +export class ChildRegister { + static childCallObj = null; + static registerNotifyFunction() { + for (let index = 0; index < window.frames.length; index++) { + const frame = window.frames[index]; + if ((frame as any).registerNotifyFunction) { + ChildRegister.childCallObj = (frame as any).registerNotifyFunction(notifyFunc); + break; + } } } - if (!child) return; - - child.register?.(parentCallObj); -}; +} -- Gitblit v1.9.3