|
@@ -2,9 +2,10 @@ import React, { useState, useEffect, useRef } from 'react';
|
|
|
import echarts from 'echarts';
|
|
|
import { connect } from 'dva';
|
|
|
import moment from 'moment';
|
|
|
+import style from './Chart.less';
|
|
|
import { getPlcOptions, getFormOptions } from '@/components/ChartUtils/utils';
|
|
|
const dataCache = {};
|
|
|
-
|
|
|
+console.log(style);
|
|
|
function DataCenter(props) {
|
|
|
const [chart, setChart] = useState();
|
|
|
const [timer, setTimer] = useState();
|
|
@@ -15,7 +16,7 @@ function DataCenter(props) {
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const { chartConfigList, dispatch } = props;
|
|
|
// const { projectId } = props.location; //?
|
|
|
- const projectId = 46;
|
|
|
+ const projectId = 92;
|
|
|
|
|
|
const handleClickTabs = id => {
|
|
|
let item = chartConfigList.find(c => c.id == id);
|
|
@@ -30,26 +31,15 @@ function DataCenter(props) {
|
|
|
payload: {
|
|
|
projectId,
|
|
|
},
|
|
|
- // callback: list => console.log(list),
|
|
|
});
|
|
|
}
|
|
|
}, [projectId]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- let chart = echarts.init(chartEle.current);
|
|
|
- setChart(chart);
|
|
|
- const controller = new AbortController();
|
|
|
- signalRef.current = controller;
|
|
|
- return () => {
|
|
|
- clearTimeout(timer);
|
|
|
- signalRef.current.abort();
|
|
|
- };
|
|
|
- }, []);
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
const chartWindow = iframeRef.current?.contentWindow;
|
|
|
if (!chartWindow) return;
|
|
|
if (chartWindow.render) {
|
|
|
+ console.log(chartWindow.render)
|
|
|
renderChart();
|
|
|
} else {
|
|
|
chartWindow.onload = () => {
|
|
@@ -58,9 +48,14 @@ function DataCenter(props) {
|
|
|
}
|
|
|
}, [chartOptions]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ chartConfigList && handleClickTabs(chartConfigList[0].id);
|
|
|
+ }, [chartConfigList]);
|
|
|
+
|
|
|
const getOptionsForConfig = item => {
|
|
|
console.log(item);
|
|
|
setChartOptions(item);
|
|
|
+ clearTimeout(timer);
|
|
|
let t = setTimeout(() => {
|
|
|
getOptionsForConfig({ ...item });
|
|
|
}, 1000 * 60);
|
|
@@ -89,34 +84,30 @@ function DataCenter(props) {
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
- <>
|
|
|
- <ul>
|
|
|
- {/* <ul className={style.tabsList}> */}
|
|
|
- {(chartConfigList || [])
|
|
|
- // .filter(item => item.show)
|
|
|
- .map(item => (
|
|
|
- <li
|
|
|
- // key={item.key}
|
|
|
- key = {item.id}
|
|
|
- // className={`${active == item.key ? style.active : ''}`}
|
|
|
- onClick={() => handleClickTabs(item.id)}
|
|
|
- >
|
|
|
- {/* {item.title} */}
|
|
|
+ <div className={style.body}>
|
|
|
+ <div className={style.title}>数据项</div>
|
|
|
+ <div className={style.listWrapper}>
|
|
|
+ <div className={style.list}>
|
|
|
+ {(chartConfigList || []).map(item => (
|
|
|
+ <div key={item.id} onClick={() => handleClickTabs(item.id)} className={style.listItem}>
|
|
|
{item.name}
|
|
|
- </li>
|
|
|
+ </div>
|
|
|
))}
|
|
|
- </ul>
|
|
|
- <div style={{ paddingTop: '0.1rem', overflow: 'hidden' }}>
|
|
|
- {chartOptions && chartOptions.template && (
|
|
|
- <iframe
|
|
|
- ref={iframeRef}
|
|
|
- style={{ width: '100%', height: '98%', border: 'none' }}
|
|
|
- srcDoc={chartOptions.template.Content}
|
|
|
- ></iframe>
|
|
|
- )}
|
|
|
- <div style={{ display: chartOptions, height: '100%' }} ref={chartEle}></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div className={style.title}>图表</div>
|
|
|
+ <div className={style.chartWrapper}>
|
|
|
+ <div style={{ paddingTop: '0.1rem', overflow: 'hidden' }}>
|
|
|
+ {chartOptions && chartOptions.template && (
|
|
|
+ <iframe
|
|
|
+ ref={iframeRef}
|
|
|
+ style={{ width: '100%', height: '30vh', border: 'none' }}
|
|
|
+ srcDoc={chartOptions.template.Content}
|
|
|
+ ></iframe>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </>
|
|
|
+ </div>
|
|
|
);
|
|
|
}
|
|
|
export default connect(({ dataMeterNew, user }) => ({
|