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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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 { locateAllAgv, startPatrolBatch, cancelPatrolBatch } from "../http";
import GpsFixedIcon from '@mui/icons-material/GpsFixed';
import { VERIFY_PASSWORD } from '@/config/setting';
import TimelineIcon from '@mui/icons-material/Timeline';
import CloseIcon from '@mui/icons-material/Close';
 
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 debounced = async (fn) => {
        setLoading(true);
        try {
            await fn();
        } finally {
            setLoading(false);
        }
    }
 
    const handleLocateAll = () => {
        debounced(locateAllAgv);
    }
 
    const handleStartPatrolBatch = () => {
        debounced(startPatrolBatch);
    }
 
    const handleCancelPatrolBatch = () => {
        debounced(cancelPatrolBatch);
    }
 
    return (
        <>
            <Select
                value={translate('page.map.action.moreOperation')}
                onChange={(event) => {
                }}
                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>
                <MenuItem
                    onClick={() => {
                        verifyPassword(handleStartPatrolBatch);
                    }}
                    disabled={loading}
                >
                    <ListItemIcon>
                        {loading
                            ? <CircularProgress size={20} />
                            : <TimelineIcon fontSize="small" />
                        }
                    </ListItemIcon>
                    <ListItemText>{translate('page.map.action.oneClickPatrol')}</ListItemText>
                </MenuItem>
                <MenuItem
                    onClick={() => {
                        verifyPassword(handleCancelPatrolBatch);
                    }}
                    disabled={loading}
                >
                    <ListItemIcon>
                        {loading
                            ? <CircularProgress size={20} />
                            : <CloseIcon fontSize="small" />
                        }
                    </ListItemIcon>
                    <ListItemText>{translate('page.map.action.cancelPatrol')}</ListItemText>
                </MenuItem>
            </Select>
        </>
    );
}
 
export default MoreOperate;