From 0254b3caa25819d038754baa58b03824303b5fa7 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期日, 07 四月 2024 08:35:55 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/map/index.jsx |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/index.jsx b/zy-asrs-flow/src/pages/map/index.jsx
index 8ed7dd8..a1c3cb2 100644
--- a/zy-asrs-flow/src/pages/map/index.jsx
+++ b/zy-asrs-flow/src/pages/map/index.jsx
@@ -8,13 +8,13 @@
     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';
@@ -60,7 +60,7 @@
     SETTINGS_MODEL: "3",
 })
 
-let player;
+let player, websocket;
 
 const Map = () => {
     const intl = useIntl();
@@ -85,11 +85,10 @@
     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 [batchSprites, setBatchSprites] = React.useState([]);
     const [batchDrawerVisible, setBatchDrawerVisible] = React.useState(false);
@@ -104,6 +103,10 @@
             Utils.syncMapContainer(player.mapContainer);
             Utils.syncNotify(notify);
 
+            websocket = new WebSocketClient('/ws/map/websocket');
+            websocket.connect();
+            websocket.onMessage = Utils.updateMapStatusInRealTime;
+
             const handleResize = () => {
                 setWindowSize({
                     width: window.innerWidth,
@@ -112,7 +115,11 @@
             };
             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(() => {
@@ -295,6 +302,7 @@
                                     model={model}
                                     setModel={setModel}
                                     ModelEnum={MapModel}
+                                    curFloor={curFloor}
                                     curSprite={curSprite}
                                     setCurSPrite={setCurSPrite}
                                     setSpriteBySettings={setSpriteBySettings}
@@ -367,8 +375,9 @@
                 <Content ref={contentRef} className={styles.content}>
                     <div ref={mapRef} />
 
-                    {hasFloor && (
+                    {floorList.length > 0 && (
                         <MapFloor
+                            floorList={floorList}
                             curFloor={curFloor}
                             setCurFloor={setCurFloor}
                         />
@@ -427,6 +436,7 @@
             <MapDrawer
                 open={drawerVisible}
                 curSprite={curSprite}
+                curFloor={curFloor}
                 refCurr={mapRef.current}
                 onCancel={() => {
                     setCurSPrite(null);

--
Gitblit v1.9.1