#
luxiaotao1123
2024-10-09 5333624bc0a4162b26cf1915c007ab92abbe7dd3
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
import React, { useState, useRef, useEffect, useMemo, useCallback } from "react";
import { Drawer, Box, Typography, Grid, IconButton, Stack } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import * as Common from '@/utils/common';
import { PAGE_DRAWER_WIDTH } from '@/config/setting';
 
import shelf from '/map/shelf.svg';
import charge from '/map/charge.svg';
import direction from '/map/direction.svg';
 
const items = [
    { src: shelf, label: 'map.device.type.shelf', type: 'SHELF' },
    { src: charge, label: 'map.device.type.charge', type: 'CHARGE' },
    { src: direction, label: 'map.device.type.direction', type: 'DIRECTION' },
    // { src: point, label: 'map.device.type.point', type: 'POINT' },
    // { src: agv, label: 'map.device.type.agv', type: 'AGV' },
    // { src: conveyor, label: 'map.device.type.conveyor', type: 'CONVEYOR' },
];
 
const Device = (props) => {
    const {
        title = 'Drawer',
        open,
        onCancel,
        closeCallback,
        width = PAGE_DRAWER_WIDTH,
        children
    } = props;
 
    const handleClose = () => {
        onCancel();
        if (closeCallback) {
            closeCallback();
        }
    }
 
    return (
        <Drawer
            variant="persistent"
            open={open}
            anchor="right"
            onClose={handleClose}
            sx={{ zIndex: 100, opacity: .8 }}
        >
            {open && (
                <Box pt={12} width={{ xs: '100vW', sm: width }} height={'calc(100vh - 200px);'} mt={{ xs: 2, sm: 1 }} sx={{
                }}>
                    <Stack direction="row" p={2}>
                        <Typography variant="h6" flex="1">
                            {title}
                        </Typography>
                        <IconButton onClick={handleClose} size="small">
                            <CloseIcon />
                        </IconButton>
                    </Stack>
                    <DeviceContent />
                </Box>
            )}
        </Drawer>
    )
}
 
const DeviceContent = (props) => {
 
    const onDragStart = (e, type) => {
        // setDragging(true);
        // setDragSpriteType(type);
        // 根据需要处理拖拽逻辑
    };
 
    return (
        <Grid container spacing={2}>
            {items.map((item, index) => {
                return (
                    <Grid
                        key={index}
                        item
                        xs={4}
                        onDragStart={(e) => onDragStart(e, item.type)}
                        draggable="true"
                    >
                        <Box
                            sx={{
                                display: 'flex',
                                flexDirection: 'column',
                                justifyContent: 'center',
                                alignItems: 'center',
                                p: 2,
                                cursor: 'pointer',
                                border: '1px solid',
                                borderColor: 'divider',
                                '&:hover': {
                                    boxShadow: 3,
                                },
                            }}
                        >
                            <img src={item.src} alt={item.label} width="50px" />
                            {/* <Typography variant="body2" sx={{ mt: 1 }}>
                                    <FormattedMessage id={item.label} defaultMessage={item.type} />
                                </Typography> */}
                        </Box>
                    </Grid>
                )
            })}
        </Grid>
    )
}
 
export default Device;