#
vincentlu
2025-04-21 7fba4f90e8f6a489bb8767fb48a8c1028fe1ed9f
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React, { useState, useRef, useEffect, useMemo } from "react";
import { useTranslate } from "react-admin";
import {
    Box,
    Select,
    MenuItem,
    Button,
    useTheme,
    ListItemIcon,
    ListItemText,
    CircularProgress,
} from '@mui/material';
import { handleLocateAllAgv } from "../http";
import GpsFixedIcon from '@mui/icons-material/GpsFixed';
import { VERIFY_PASSWORD } from '@/config/setting';
 
const MoreOperate = ({ }) => {
    const translate = useTranslate();
    const theme = useTheme();
    const [loading, setLoading] = useState(false);
 
    const verifyPassword = (fn) => {
        let pass = true;
        const pwd = prompt("please enter password:");
        if (pwd === VERIFY_PASSWORD) {
            pass = true;
        } else {
            pass = false;
            if (pwd) {
                alert('Incorrect password');
            }
        }
        if (pass) {
            if (fn) {
                fn();
            }
        }
    }
 
    const handleLocateAll = async () => {
        setLoading(true)
        try {
            await handleLocateAllAgv();
        } finally {
            setLoading(false);
        }
    }
 
    return (
        <>
            <Select
                value={translate('page.map.action.moreOperation')}
                onChange={(event) => {
                    console.log(event.target.value);
                }}
                renderValue={() => (
                    <Box sx={{ display: 'flex', alignItems: 'center' }}>
                        {loading && (
                            <CircularProgress size={20} sx={{ mr: 1 }} />
                        )}
                        {translate('page.map.action.moreOperation')}
                    </Box>
                )}
                variant="outlined"
                size="small"
                disabled={loading}
                sx={{
                    ml: 2,
                    backgroundColor: theme.palette.background.paper,
                    color: theme.palette.text.primary,
                    borderRadius: 1,
                }}
            >
                <MenuItem value={translate('page.map.action.moreOperation')} sx={{ display: 'none' }} />
                <MenuItem
                    onClick={() => {
                        verifyPassword(handleLocateAll);
                    }}
                    disabled={loading}
                >
                    <ListItemIcon>
                        {loading
                            ? <CircularProgress size={20} />
                            : <GpsFixedIcon fontSize="small" />
                        }
                    </ListItemIcon>
                    <ListItemText>{translate('page.map.action.oneClickLocate')}</ListItemText>
                </MenuItem>
            </Select>
            {/* <Button
                variant="contained"
                color="primary"
                onClick={handleToggle}
                sx={{ mr: 2 }}
            >
                重新定位
            </Button> */}
        </>
 
    );
}
 
export default MoreOperate;