zhang
2025-05-20 1313906bb1eb983d3beece810035e7fc28d6a92f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { useState, useRef, useEffect } from 'react';
import { useTranslate } from "react-admin";
import { Box, Typography, Tabs, Tab, Stack, useTheme, Divider } from '@mui/material';
import JsonShow from '../../JsonShow';
import { getPointInfo } from '../../http';
 
const PointInsight = (props) => {
    const { sprite, setTitle } = props;
    const translate = useTranslate();
    const theme = useTheme();
 
    const [activeTab, setActiveTab] = useState(0);
    const [curPoint, setCurPoint] = useState(null);
    const [curPointInfo, setCurPointInfo] = useState(null);
 
    const fetchInfo = (param) => {
        setTitle(translate('page.map.devices.point') + ' - ' + param);
        setCurPoint(param);
        getPointInfo(param, (response) => {
            setCurPointInfo(response);
        });
    }
 
    useEffect(() => {
        if (sprite) {
            const param = sprite.data.no;
            if (param) {
                fetchInfo(param);
            }
        }
 
        return () => {
            setTitle(null);
            setCurPoint(null);
            setCurPointInfo(null);
        }
    }, [sprite])
 
    const handleTabChange = (event, newValue) => {
        setActiveTab(newValue);
    };
 
    return (
        <Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
            <Tabs
                value={activeTab}
                onChange={handleTabChange}
                centered
                sx={{ mb: 0 }}
            >
                <Tab label={translate('page.map.insight.title')} />
                <Tab label={'JSON'} />
            </Tabs>
 
            <Divider />
 
            <Box flex={1} pt={2}>
                {activeTab === 0 && (
                    <JsonShow
                        data={curPointInfo || sprite?.data}
                        height={550}
                    />
                )}
                {activeTab === 1 && (
                    <JsonShow
                        data={curPointInfo || sprite?.data}
                        height={550}
                    />
                )}
            </Box>
        </Box>
    )
}
 
export default PointInsight;