Junjie
2024-03-11 17150b54d35c3ab02b2082ac4e9fc34858d43d77
zy-asrs-flow/src/pages/map/components/device.jsx
@@ -33,30 +33,32 @@
});
import agv from '/public/img/map/agv.svg'
import { set } from 'lodash';
const Device = (props) => {
    const { styles } = useStyles();
    const [dragging, setDragging] = useState(false);
    const [dragSprite, setDragSprite] = useState(null);
    const [dragSpriteType, setDragSpriteType] = useState(null);
    const onDragStart = (e, type) => {
        setDragging(true);
        setDragSpriteType(type);
        const sprite = PIXI.Sprite.from(agv);
        setDragSprite(sprite);
    };
    useEffect(() => {
        const handleMouseMove = (e) => {
            if (dragging) {
                props.onDrop(dragSprite, e.clientX, e.clientY);
                props.onDrop(dragSprite, dragSpriteType, e.clientX, e.clientY);
                setDragging(false);
                setDragSpriteType(null);
            }
        };
        window.addEventListener('mousemove', handleMouseMove);
        return () => window.removeEventListener('mousemove', handleMouseMove);
    }, [dragging, props.onDrop, props.onCancel]);
    const onDragStart = (e) => {
        setDragging(true)
        props.onCancel();
        const sprite = PIXI.Sprite.from(agv);
        sprite.anchor.set(0.5);
        setDragSprite(sprite);
    };
    return (
        <>
@@ -83,7 +85,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -93,7 +95,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -103,7 +105,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -115,7 +117,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -125,7 +127,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -135,7 +137,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -147,7 +149,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -157,7 +159,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>
@@ -167,7 +169,7 @@
                                width='50px'
                                preview={false}
                                draggable="true"
                                onDragStart={onDragStart}
                                onDragStart={(e) => onDragStart(e, 'AGV')}
                            />
                            <div>AGV</div>
                        </Col>