From f547e6200ad888ed47dd32ed566c5e2b319507ac Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 21 三月 2024 13:09:59 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/map/index.jsx | 278 +++++++++++++++++++++++++++++++++++++------------------
1 files changed, 187 insertions(+), 91 deletions(-)
diff --git a/zy-asrs-flow/src/pages/map/index.jsx b/zy-asrs-flow/src/pages/map/index.jsx
index e7ed9e0..0f603ee 100644
--- a/zy-asrs-flow/src/pages/map/index.jsx
+++ b/zy-asrs-flow/src/pages/map/index.jsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import * as PIXI from 'pixi.js';
import { FormattedMessage, useIntl, useModel } from '@umijs/max';
-import { Layout, Button, Flex, Row, Col, FloatButton, Select, Spin, AutoComplete } from 'antd';
+import { Layout, Button, Flex, Row, Col, FloatButton, Select, notification, Segmented } from 'antd';
const { Header, Content } = Layout;
import {
AppstoreAddOutlined,
@@ -17,6 +17,7 @@
import * as Utils from './utils'
import Player from './player';
import MapSearch from './header/search';
+import MapFloor from './header/floor';
import MapDrawer from './drawer';
const useStyles = createStyles(({ token }) => {
@@ -39,7 +40,8 @@
},
content: {
backgroundColor: '#F8FAFB',
- height: 'calc(100vh - 120px)'
+ height: 'calc(100vh - 120px)',
+ position: 'relative'
},
select: {
color: 'red',
@@ -62,11 +64,12 @@
const Map = () => {
const intl = useIntl();
const { initialState, setInitialState } = useModel('@@initialState');
+ const [notify, contextHolder] = notification.useNotification();
const { styles } = useStyles();
const mapRef = React.useRef();
const contentRef = React.useRef();
- const [model, setModel] = React.useState(() => MapModel.OBSERVER_MODEL);
+ const [model, setModel] = React.useState(null);
const [deviceVisible, setDeviceVisible] = React.useState(false);
const [settingsVisible, setSettingsVisible] = React.useState(false);
const [windowSize, setWindowSize] = React.useState({
@@ -78,24 +81,40 @@
const [didClickSprite, setDidClickSprite] = React.useState(false);
const [spriteBySettings, setSpriteBySettings] = React.useState(null);
const prevSpriteBySettingsRef = React.useRef();
- const [curSprite, setCurSPrite] = React.useState(null);
const [drawerVisible, setDrawerVisible] = React.useState(false);
+ 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 [curFloor, setCurFloor] = React.useState(1);
// init func
React.useEffect(() => {
- player = new Player(mapRef.current, styles.dark, didClickSprite);
- setApp(player.app);
- setMapContainer(player.mapContainer);
- Utils.syncApp(player.app);
- Utils.syncMapContainer(player.mapContainer);
+ const initialize = async () => {
+ player = new Player(mapRef.current, styles.dark, didClickSprite);
+ setApp(player.app);
+ setMapContainer(player.mapContainer);
+ Utils.syncApp(player.app);
+ Utils.syncMapContainer(player.mapContainer);
+ Utils.syncNotify(notify);
- const handleResize = () => {
- setWindowSize({
- width: window.innerWidth,
- height: window.innerHeight,
- });
- };
- window.addEventListener('resize', handleResize);
+ const handleResize = () => {
+ setWindowSize({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+ };
+ window.addEventListener('resize', handleResize);
+ await Utils.fetchMapData(intl);
+ setDataFetched(true);
+ setModel(MapModel.OBSERVER_MODEL)
+ setTimeout(() => {
+ player.adaptScreen();
+ Utils.mapNotify(intl.formatMessage({ id: 'map.load.success', defaultMessage: '娆㈣繋浣跨敤WCS绯荤粺' }));
+ }, 200)
+ }
+ initialize();
}, []);
// resize
@@ -107,14 +126,13 @@
const height = contentRef.current.offsetHeight;
app.renderer.resize(width, height);
if (model !== MapModel.OBSERVER_MODEL) {
- player.hideGridlines();
player.showGridlines();
}
}, [app, mapContainer, windowSize])
// model
React.useEffect(() => {
- if (!mapContainer) {
+ if (!mapContainer && !dataFetched) {
return;
}
switch (model) {
@@ -126,15 +144,9 @@
player.activateMapEvent(null);
Utils.removeSelectedEffect();
+ setCurSPrite(null);
setDeviceVisible(false);
setSettingsVisible(false);
-
- mapContainer.children.forEach(child => {
- child.off('pointerup');
- child.off('pointermove');
- child.off('pointerdown');
- child.off('click');
- })
mapContainer.children.forEach(child => {
Utils.viewFeature(child, setCurSPrite);
@@ -145,11 +157,12 @@
player.showGridlines();
player.hideStarryBackground();
- player.activateMapEvent(Utils.MapEvent.SELECTION_BOX);
+ player.activateMapEvent(Utils.MapEvent.SELECTION_BOX, model);
Utils.removeSelectedEffect();
setSpriteBySettings(null);
setSettingsVisible(false);
+ setDrawerVisible(false);
mapContainer.children.forEach(child => {
Utils.beMovable(child, setDidClickSprite);
@@ -160,9 +173,10 @@
player.showGridlines();
player.showStarryBackground();
- player.activateMapEvent(null);
+ player.activateMapEvent(Utils.MapEvent.SELECTION_BOX, model);
setDeviceVisible(false);
+ setDrawerVisible(false);
mapContainer.children.forEach(child => {
Utils.beSettings(child, setSpriteBySettings, setDidClickSprite);
@@ -183,6 +197,30 @@
mapContainer.addChild(sprite);
Utils.beMovable(sprite, setDidClickSprite);
};
+
+ // watch curSprite
+ React.useEffect(() => {
+ if (!mapContainer) {
+ return;
+ }
+ prevCurSpriteRef.current = curSprite;
+ if (curSprite && prevCurSprite !== curSprite) {
+ Utils.removeSelectedEffect();
+ }
+ if (curSprite) {
+ if (model === MapModel.OBSERVER_MODEL) {
+ Utils.showSelectedEffect(curSprite)
+ setDrawerVisible(true)
+ }
+ } else {
+ Utils.removeSelectedEffect();
+ }
+ }, [curSprite]);
+ const prevCurSprite = prevCurSpriteRef.current;
+
+ // watch curFloor
+ React.useEffect(() => {
+ }, [curFloor]);
// didClickSprite, stop triggers both sprite click and play's selection boxs
React.useEffect(() => {
@@ -213,31 +251,80 @@
// setSpriteBySettings(null);
}
- React.useEffect(() => {
- if (curSprite) {
- if (model === MapModel.OBSERVER_MODEL) {
- setDrawerVisible(true)
- }
- }
- }, [curSprite]);
-
return (
<>
+ {contextHolder}
<Layout className={styles.layout}>
<Header className={styles.header}>
<Row style={{ height: '100%' }}>
<Col className={styles.headerCol} span={12} style={{}}>
- <MapSearch
- curSprite={curSprite}
- setCurSPrite={setCurSPrite}
- />
+ {dataFetched && (
+ <MapSearch
+ model={model}
+ setModel={setModel}
+ ModelEnum={MapModel}
+ curSprite={curSprite}
+ setCurSPrite={setCurSPrite}
+ setSpriteBySettings={setSpriteBySettings}
+ />
+ )}
</Col>
- {/* 3C40C6 */}
- <Col span={12} style={{ backgroundColor: '#4a69bd' }}>
+ <Col span={12} style={{ backgroundColor: styles.dark ? '#2f3542' : '#4a69bd' }}>
<Flex className={styles.flex} gap={'large'} justify={'flex-end'} align={'center'}>
- <span>
- {curSprite?.data?.uuid}
- </span>
+
+ {model === MapModel.OBSERVER_MODEL && (
+ <>
+ <Button
+ className='map-header-button'
+ size={'large'}
+ onClick={async () => {
+ await Utils.fetchMapData(intl);
+
+ player.hideGridlines();
+ player.hideStarryBackground();
+
+ player.activateMapEvent(null);
+
+ Utils.removeSelectedEffect();
+ setCurSPrite(null);
+ setDeviceVisible(false);
+ setSettingsVisible(false);
+ setDrawerVisible(false);
+
+ mapContainer.children.forEach(child => {
+ Utils.viewFeature(child, setCurSPrite);
+ })
+
+ }}
+ >
+ <FormattedMessage id='map.load' defaultMessage='鍔犺浇鍦板浘' />
+ </Button>
+ </>
+ )}
+
+ {model !== MapModel.OBSERVER_MODEL && (
+ <>
+ <Button
+ className='map-header-button'
+ size={'large'}
+ onClick={() => {
+ Utils.clearMapData(intl);
+ }}
+ >
+ <FormattedMessage id='map.clear' defaultMessage='娓呴櫎鍦板浘' />
+ </Button>
+ <Button
+ className='map-header-button'
+ size={'large'}
+ onClick={() => {
+ Utils.saveMapData(intl);
+ }}
+ >
+ <FormattedMessage id='map.save' defaultMessage='淇濆瓨鍦板浘' />
+ </Button>
+ </>
+ )}
+
<Select
className='map-header-select'
size={'large'}
@@ -262,62 +349,71 @@
</Row>
</Header>
<Content ref={contentRef} className={styles.content}>
- <div ref={mapRef} style={{ position: "relative" }} >
- <FloatButton.Group
- shape="square"
- style={{
- left: 35,
- bottom: 35
- }}
- >
- <FloatButton
- icon={<CompressOutlined />}
- onClick={() => {
- player.adaptScreen();
- }}
- />
- </FloatButton.Group>
+ <div ref={mapRef} />
- <FloatButton.Group
- hidden={model === MapModel.OBSERVER_MODEL}
- style={{
- left: 35,
- bottom: window.innerHeight / 2
+ {hasFloor && (
+ <MapFloor
+ curFloor={curFloor}
+ setCurFloor={setCurFloor}
+ />
+ )}
+
+ <FloatButton.Group
+ shape="square"
+ style={{
+ left: 35,
+ bottom: 35
+ }}
+ >
+ <FloatButton
+ icon={<CompressOutlined />}
+ onClick={() => {
+ player.adaptScreen();
}}
- icon={<AppstoreAddOutlined />}
- >
- <FloatButton
- hidden={model === MapModel.OBSERVER_MODEL}
- type={deviceVisible ? 'primary' : 'default'}
- tooltip={<div><FormattedMessage id='map.device.add' defaultMessage='娣诲姞璁惧' /></div>}
- icon={<FileAddOutlined />}
- onClick={() => {
- if (deviceVisible) {
- setDeviceVisible(false);
- } else {
- setDeviceVisible(true);
- setModel(MapModel.MOVABLE_MODEL);
- }
- }}
- />
- <FloatButton
- hidden={model === MapModel.OBSERVER_MODEL}
- type={model === MapModel.SETTINGS_MODEL ? 'primary' : 'default'}
- tooltip={<div><FormattedMessage id='map.device.oper' defaultMessage='鍙傛暟璁剧疆' /></div>}
- icon={<SettingOutlined />}
- onClick={() => {
- setModel(model === MapModel.SETTINGS_MODEL ? MapModel.MOVABLE_MODEL : MapModel.SETTINGS_MODEL)
- }}
- />
- </FloatButton.Group>
- </div>
+ />
+ </FloatButton.Group>
+
+ <FloatButton.Group
+ hidden={model === MapModel.OBSERVER_MODEL}
+ style={{
+ left: 35,
+ bottom: window.innerHeight / 2
+ }}
+ icon={<AppstoreAddOutlined />}
+ >
+ <FloatButton
+ hidden={model === MapModel.OBSERVER_MODEL}
+ type={deviceVisible ? 'primary' : 'default'}
+ tooltip={<div><FormattedMessage id='map.device.add' defaultMessage='娣诲姞璁惧' /></div>}
+ icon={<FileAddOutlined />}
+ onClick={() => {
+ if (deviceVisible) {
+ setDeviceVisible(false);
+ } else {
+ setDeviceVisible(true);
+ setModel(MapModel.MOVABLE_MODEL);
+ }
+ }}
+ />
+ <FloatButton
+ hidden={model === MapModel.OBSERVER_MODEL}
+ type={model === MapModel.SETTINGS_MODEL ? 'primary' : 'default'}
+ tooltip={<div><FormattedMessage id='map.device.oper' defaultMessage='鍙傛暟璁剧疆' /></div>}
+ icon={<SettingOutlined />}
+ onClick={() => {
+ setModel(model === MapModel.SETTINGS_MODEL ? MapModel.MOVABLE_MODEL : MapModel.SETTINGS_MODEL)
+ }}
+ />
+ </FloatButton.Group>
</Content>
</Layout >
<MapDrawer
open={drawerVisible}
+ curSprite={curSprite}
refCurr={mapRef.current}
onCancel={() => {
+ setCurSPrite(null);
setDrawerVisible(false);
}}
/>
--
Gitblit v1.9.1