#
luxiaotao1123
2024-10-09 66ab394f977a2fcf4b4fc9334829fc5bb171296f
zy-acs-flow/src/map/MapPage.jsx
@@ -1,4 +1,5 @@
import React, { useState, useRef, useEffect, useMemo } from "react";
import { useTranslate } from "react-admin";
import {
    TextField,
    Select,
@@ -22,6 +23,7 @@
import * as Tool from './tool';
import { NotificationProvider, useNotification } from './Notification';
import Device from "./Device";
import * as Http from './http';
let player;
@@ -29,6 +31,7 @@
    const theme = useTheme();
    const themeMode = theme.palette.mode;
    const notify = useNotification();
    const translate = useTranslate();
    const mapRef = useRef();
    const contentRef = useRef();
@@ -47,6 +50,9 @@
            setMapContainer(player.mapContainer);
            Tool.setApp(player.app);
            Tool.setMapContainer(player.mapContainer);
            Http.setNotify(notify);
            await Http.fetchMapData(0);
        }
        initialize();
@@ -57,6 +63,10 @@
            const height = contentRef.current.offsetHeight;
            player.resize(width, height);
            if (mode === MapMode.MOVABLE_MODE) {
                console.log('aa');
                player.showGridLines();
            }
        };
        handleResize();
        window.addEventListener('resize', handleResize);
@@ -73,13 +83,30 @@
    const switchMode = (mode) => {
        switch (mode) {
            case MapMode.OBSERVER_MODE:
                console.log('a');
                setDeviceVisible(false);
                player.hideGridLines();
                player.activateMapMultiSelect((selectedSprites, restartFn) => {
                    console.log(selectedSprites);
                });
                break
            case MapMode.MOVABLE_MODE:
                console.log('b');
                player.showGridLines();
                player.activateMapMultiSelect((selectedSprites, restartFn) => {
                    Tool.spriteListBeMovable(selectedSprites, () => {
                        restartFn();
                    });
                });
                break
            case MapMode.SETTINGS_MODE:
                console.log('c');
                player.hideGridLines();
                setDeviceVisible(false);
                player.activateMapMultiSelect((selectedSprites, restartFn) => {
                    console.log(selectedSprites);
                });
                break
            default:
                break
@@ -94,13 +121,15 @@
    }, [mode]);
    const onDrop = (sprite, type, x, y) => {
        console.log(sprite, type, x, y);
        const { mapX, mapY } = Tool.getRealPosition(x, y);
        sprite.x = mapX;
        sprite.y = mapY;
        // Utils.initSprite(sprite, type);
        // mapContainer.addChild(sprite);
        // Utils.beMovable(sprite);
        Tool.initSprite(sprite, type);
        mapContainer.addChild(sprite);
        Tool.beMovable(sprite);
    };
    const actions = [
@@ -119,6 +148,7 @@
                flexDirection: 'column',
            }}
        >
            {/* header */}
            <Box
                sx={{
                    display: 'flex',
@@ -128,6 +158,7 @@
                    padding: '0 16px',
                    height: '64px',
                    flexShrink: 0, // keep height
                    zIndex: 200
                }}
            >
                <TextField
@@ -163,8 +194,9 @@
                            variant="contained"
                            color="primary"
                            sx={{ mr: 1 }}
                            onClick={() => setDeviceVisible(!deviceVisible)}
                        >
                            添加模型
                            {translate('page.map.devices.title')}
                        </Button>
                    </>
                )}
@@ -192,6 +224,7 @@
                    <MenuItem value={MapMode.SETTINGS_MODE}>配置模式</MenuItem>
                </Select>
            </Box>
            {/* content */}
            <Box
                sx={{
                    flexGrow: 1,    // fill remaining of map space 
@@ -232,13 +265,16 @@
                    ))}
                </SpeedDial>
            </Box>
            <Device
                open={deviceVisible}
                onCancel={() => {
                    setDeviceVisible(false);
                }}
                onDrop={onDrop}
                width={378}
            />
        </Box>
    );
}