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 |   52 +++++++++++++---------------------------------------
 1 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/src/utils/iframeCall.ts b/src/utils/iframeCall.ts
index 311890c..70254c8 100644
--- a/src/utils/iframeCall.ts
+++ b/src/utils/iframeCall.ts
@@ -1,43 +1,17 @@
-/**
- * 璁剧疆鍏ㄥ眬鍑芥暟锛岀敤浜� Child 娉ㄥ唽
- */
-export const registerChildFunction = () => {
-	/** @description 鎶� Child 鐨勫嚱鏁版敞鍐岃繃鏉�, 鏂逛究鑷繁璋冪敤 */
-	(window as any).register = (cb: (...args: any[]) => void) => {
-		console.log('register children function');
-		(window as any).childCall = (...args: any[]) => {
-			cb?.(...args);
-		};
-	};
+
+const notifyFunc = (jsonObj: any) => {
+	console.log('message from parent馃殌 ~ jsonObj:', jsonObj);
+	// 鎵цAI閫氱煡娑堟伅
 };
-const fun = (msg: string) => {
-	console.log('鍑芥暟鏉ヨ嚜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?.(fun);
-};
-
-/**
- * 瀛� iframe 璋冪敤
- */
-export const childCall = (...args: any[]) => {
-	(window as any)?.childCall?.(...args);
-};
-
-for (let index = 0; index < window.frames.length; index++) {
-	const element = window.frames[index];
-	console.log('馃殌 ~ element:', element);
 }

--
Gitblit v1.9.3