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;
|