Commit 2f452290 authored by 周宏民's avatar 周宏民

fix: BI添加跳转

parent 579f0834
/*
* @Title:
* @Author: hongmye
* @Date: 2023-01-10 11:18:55
*/
import React, { memo, useEffect, useRef } from 'react'; import React, { memo, useEffect, useRef } from 'react';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons'; import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import Iframe from 'react-iframe'; import Iframe from 'react-iframe';
...@@ -13,6 +18,59 @@ const TabWidget = props => { ...@@ -13,6 +18,59 @@ const TabWidget = props => {
const { linkUrl, fullscreen } = params; const { linkUrl, fullscreen } = params;
const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(fullscreen); 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 ( return (
<div className={styles['tab-iframe']} ref={ref}> <div className={styles['tab-iframe']} ref={ref}>
<div className={styles['oper-wrap']}> <div className={styles['oper-wrap']}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment