#
luxiaotao1123
2024-11-21 ef04d6657d2190cb02c821140a2036e7c6760b45
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
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
    DateField,
    EditButton,
    DeleteButton,
    ReferenceField,
    SelectField,
    ShowButton,
    TextField,
    UrlField,
    useRecordContext,
    useTranslate,
    Button as RaButton,
    useNotify,
} from 'react-admin';
import { Link as RouterLink, useLocation } from 'react-router-dom';
import {
    Box,
    Button,
    Card,
    CardContent,
    Skeleton,
    Stack,
    Typography,
    Divider,
    Grid,
} from '@mui/material';
import { formatDistance } from 'date-fns';
import StatusField from "../../components/StatusField";
import AccessTimeIcon from '@mui/icons-material/AccessTime';
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
import request from '@/utils/request';
 
export const AgvShowAside = (props) => {
    const translate = useTranslate();
    const notify = useNotify();
    const record = useRecordContext();
    if (!record) return null;
 
    const removeFromMap = () => {
        if (confirm(translate('common.msg.confirm.desc'))) {
            request.post('/agv/remove/from/map', { ...record }).then(res => {
                const { code, msg, data } = res.data;
                if (code === 200) {
                    notify(msg, { type: 'success', messageArgs: { _: msg } });
                } else {
                    notify(msg, { type: 'error', messageArgs: { _: msg } });
                }
            }).catch(error => {
                notify(error, { type: 'error', messageArgs: { _: error } });
            })
        }
    }
 
    return (
        <Box width={400} display={{ xs: 'none', lg: 'block' }}>
            {record && (
                <Box ml={2}>
                    <Card>
                        <CardContent>
                            <Stack direction="row" spacing={1}>
                                <EditButton />
                            </Stack>
                            <Stack direction="row" mt={.5}>
                                <RaButton label="page.agv.show.remove" onClick={removeFromMap}>
                                    <RemoveCircleIcon />
                                </RaButton>
                            </Stack>
                            <Stack direction="row" mt={.5}>
                                <DeleteButton mutationMode="optimistic" />
                            </Stack>
                            <Box mt={1} />
                            <Typography variant="subtitle2" gutterBottom>
                                {translate('common.edit.side.title')}
                            </Typography>
                            <Divider sx={{ mb: 2 }} />
                            <Grid container rowSpacing={2} columnSpacing={1}>
                                <Grid item xs={12} display="flex" gap={1}>
                                    <StatusField label="Status" />
                                </Grid>
                                <Grid item xs={12} display="flex" gap={1}>
                                    <Stack
                                        direction="row"
                                        alignItems="center"
                                        gap={1}
                                        minHeight={24}
                                    >
                                        <AccessTimeIcon fontSize="small" color="disabled" />
                                        <Typography variant="body2">
                                            {translate('common.field.createTime')}
                                        </Typography>
                                        <DateField
                                            record={record}
                                            source="createTime"
                                            showTime
                                        />
                                    </Stack>
                                </Grid>
                                <Grid item xs={12} display="flex" gap={1}>
                                    <Stack
                                        direction="row"
                                        alignItems="center"
                                        gap={1}
                                        minHeight={24}
                                    >
                                        <AccessTimeIcon fontSize="small" color="disabled" />
                                        <Typography variant="body2">
                                            {translate('common.field.updateTime')}
                                        </Typography>
                                        <DateField
                                            record={record}
                                            source="updateTime"
                                            showTime
                                        />
                                    </Stack>
                                </Grid>
                            </Grid>
                        </CardContent>
                    </Card>
                </Box>
            )}
        </Box>
    );
}