XieYongHong 3 лет назад
Родитель
Сommit
26c3e1a83a
2 измененных файлов с 19 добавлено и 21 удалено
  1. 6 9
      src/components/DashBoard/echarts.tsx
  2. 13 12
      src/pages/home/comprehensive/index.tsx

+ 6 - 9
src/components/DashBoard/echarts.tsx

@@ -59,15 +59,12 @@ export default (props: EchartsProps) => {
   const chartsRef = useRef<any>(null);
 
   const initEcharts = (dom: HTMLDivElement) => {
-    console.log(chartsRef.current);
-    if (!chartsRef.current) {
-      console.log(dom);
-      chartsRef.current = echarts.init(dom);
-      if (props.options) {
-        chartsRef.current.setOption(props.options);
-      } else {
-        chartsRef.current.setOption(DefaultOptions);
-      }
+    chartsRef.current = chartsRef.current || echarts.init(dom);
+
+    if (props.options) {
+      chartsRef.current.setOption(props.options);
+    } else {
+      chartsRef.current.setOption(DefaultOptions);
     }
   };
 

+ 13 - 12
src/pages/home/comprehensive/index.tsx

@@ -31,6 +31,18 @@ const Comprehensive = () => {
   const [jvmValue, setJvmValue] = useState<number>(0);
   const [productVisible, setProductVisible] = useState<boolean>(false);
   const [deviceVisible, setDeviceVisible] = useState<boolean>(false);
+  const [StatisticsList] = useState([
+    {
+      name: 'CPU使用率',
+      value: String(cpuValue) + '%',
+      children: <Pie value={cpuValue} />,
+    },
+    {
+      name: 'JVM内存',
+      value: String(jvmValue) + '%',
+      children: <Pie value={jvmValue} />,
+    },
+  ]);
 
   const getProductCount = async () => {
     const resp = await service.productCount({});
@@ -200,18 +212,7 @@ const Comprehensive = () => {
           </Col>
           <Col span={12}>
             <Statistics
-              data={[
-                {
-                  name: 'CPU使用率',
-                  value: String(cpuValue) + '%',
-                  children: <Pie value={cpuValue} />,
-                },
-                {
-                  name: 'JVM内存',
-                  value: String(jvmValue) + '%',
-                  children: <Pie value={jvmValue} />,
-                },
-              ]}
+              data={StatisticsList}
               title="基础统计"
               extra={
                 <div style={{ fontSize: 14, fontWeight: 400 }}>