| | |
| | | import * as React from 'react' |
| | | import * as PIXI from 'pixi.js'; |
| | | import * as TWEEDLE from 'tweedle.js'; |
| | | import { FormattedMessage, useIntl, useModel } from '@umijs/max'; |
| | | import { Layout, Button, Flex, Row, Col, FloatButton, Select, notification, Segmented } from 'antd'; |
| | | const { Header, Content } = Layout; |
| | |
| | | FileAddOutlined, |
| | | CompressOutlined, |
| | | SettingOutlined, |
| | | CloseOutlined |
| | | } from '@ant-design/icons'; |
| | | import './index.css' |
| | | import { createStyles } from 'antd-style'; |
| | | import Edit from './components/device'; |
| | | import Settings from './components/settings' |
| | | import * as Utils from './utils' |
| | | import WebSocketClient from './websocket' |
| | | import Player from './player'; |
| | | import MapSearch from './header/search'; |
| | | import MapFloor from './header/floor'; |
| | |
| | | SETTINGS_MODEL: "3", |
| | | }) |
| | | |
| | | let player; |
| | | let player, websocket; |
| | | |
| | | const Map = () => { |
| | | const intl = useIntl(); |
| | |
| | | const [dataFetched, setDataFetched] = React.useState(false); |
| | | const [curSprite, setCurSPrite] = React.useState(null); |
| | | const prevCurSpriteRef = React.useRef(); |
| | | const hasFloor = true; |
| | | // const [hasFloor, setHasFloor] = React.useState(true); |
| | | const [floorList, setFloorList] = React.useState([]); |
| | | const [curFloor, setCurFloor] = React.useState(() => { |
| | | const storedValue = localStorage.getItem('curFloor'); |
| | | return storedValue !== null ? JSON.parse(storedValue) : 1; |
| | | return storedValue !== null ? JSON.parse(storedValue) : null; |
| | | }); |
| | | const curFloorRef = React.useRef(curFloor); |
| | | const [batchSprites, setBatchSprites] = React.useState([]); |
| | | const [batchDrawerVisible, setBatchDrawerVisible] = React.useState(false); |
| | | |
| | |
| | | Utils.syncMapContainer(player.mapContainer); |
| | | Utils.syncNotify(notify); |
| | | |
| | | websocket = new WebSocketClient('/ws/map/websocket'); |
| | | websocket.connect(); |
| | | websocket.onMessage = (data) => { |
| | | Utils.updateMapStatusInRealTime(data, () => curFloorRef.current, setCurSPrite); |
| | | } |
| | | |
| | | const handleResize = () => { |
| | | setWindowSize({ |
| | | width: window.innerWidth, |
| | |
| | | }; |
| | | window.addEventListener('resize', handleResize); |
| | | |
| | | await Utils.fetchMapData(curFloor); |
| | | const mapFloorData = await Utils.fetchMapFloor(); |
| | | setFloorList(mapFloorData); |
| | | let defaultFloor = curFloor || mapFloorData?.[0]?.value; |
| | | setCurFloor(defaultFloor); |
| | | await Utils.fetchMapData(defaultFloor); |
| | | setDataFetched(true); |
| | | setModel(MapModel.OBSERVER_MODEL) |
| | | setTimeout(() => { |
| | |
| | | }, 200) |
| | | } |
| | | initialize(); |
| | | |
| | | return () => { |
| | | websocket.onMessage = (data) => {} |
| | | if (websocket) { |
| | | websocket.close(); |
| | | } |
| | | } |
| | | }, []); |
| | | |
| | | // resize |
| | |
| | | |
| | | // watch curFloor |
| | | React.useEffect(() => { |
| | | curFloorRef.current = curFloor; |
| | | if (!mapContainer && !dataFetched) { |
| | | return; |
| | | } |
| | |
| | | <Content ref={contentRef} className={styles.content}> |
| | | <div ref={mapRef} /> |
| | | |
| | | {hasFloor && ( |
| | | {floorList.length > 0 && ( |
| | | <MapFloor |
| | | floorList={floorList} |
| | | curFloor={curFloor} |
| | | setCurFloor={setCurFloor} |
| | | /> |
| | |
| | | <MapDrawer |
| | | open={drawerVisible} |
| | | curSprite={curSprite} |
| | | curFloor={curFloor} |
| | | refCurr={mapRef.current} |
| | | onCancel={() => { |
| | | setCurSPrite(null); |