From 2f452290c93bc651ad327740417bc193dfeb2e5e Mon Sep 17 00:00:00 2001
From: hongmye <1014185119@qq.com>
Date: Fri, 22 Sep 2023 19:39:35 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20BI=E6=B7=BB=E5=8A=A0=E8=B7=B3=E8=BD=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/pages/system/iframe/TabWidget.js | 58 ++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/src/pages/system/iframe/TabWidget.js b/src/pages/system/iframe/TabWidget.js
index 09f88456..9b5388e1 100644
--- a/src/pages/system/iframe/TabWidget.js
+++ b/src/pages/system/iframe/TabWidget.js
@@ -1,3 +1,8 @@
+/*
+ * @Title:
+ * @Author: hongmye
+ * @Date: 2023-01-10 11:18:55
+ */
 import React, { memo, useEffect, useRef } from 'react';
 import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
 import Iframe from 'react-iframe';
@@ -13,6 +18,59 @@ const TabWidget = props => {
   const { linkUrl, fullscreen } = params;
   const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(fullscreen);
 
+  const goToPath = (name, data, widgetId) => {
+    try {
+      const routes = window.globalConfig?.allWidgets || [];
+      let info = null;
+      // eslint-disable-next-line no-inner-declarations
+      function urlSearch(arr) {
+        arr.forEach(a => {
+          if (a.label) {
+            if (a.label === name) {
+              info = JSON.parse(JSON.stringify(a));
+            }
+          }
+          if (a.widgets) {
+            urlSearch(a.widgets);
+          }
+        });
+      }
+      urlSearch(routes);
+      if (!info) return info;
+      info.url = info.url.substr(0, 1) === '/' ? info.url : `/${info.url}`;
+      let url = `/civbase/${info.product}${info.url}`;
+      const arr = url.split('|');
+      let paramsData = {};
+      // eslint-disable-next-line prefer-destructuring
+      url = arr[0];
+      if (arr[1]) {
+        url += encodeURI(`|${arr[1]}`);
+        const arrObj = arr[1].split('&');
+        arrObj.forEach(item => {
+          const temp = item.split('=');
+          // eslint-disable-next-line prefer-destructuring
+          paramsData[temp[0]] = temp[1];
+        });
+      }
+      paramsData = { ...paramsData, ...data, refresh: true };
+      paramsData.widget = widgetId || paramsData.widget;
+      console.log(paramsData, url);
+      window.history.pushState(paramsData, '', url);
+    } catch (error) {
+      console.log('馃殌 ~ error:', error);
+    }
+  };
+  const onMessage = e => {
+    if (e?.data?.name) {
+      goToPath(e?.data?.name);
+    }
+  };
+  useEffect(() => {
+    window.addEventListener('message', onMessage);
+    return () => {
+      window.removeEventListener('message', onMessage);
+    };
+  }, [onMessage]);
   return (
     <div className={styles['tab-iframe']} ref={ref}>
       <div className={styles['oper-wrap']}>
-- 
2.17.1