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 | 188 ++++++++++++++++++++++++++++------------------
1 files changed, 113 insertions(+), 75 deletions(-)
diff --git a/zy-asrs-flow/src/pages/map/index.jsx b/zy-asrs-flow/src/pages/map/index.jsx
index 2c78b79..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,6 +64,7 @@
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();
@@ -82,28 +85,36 @@
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(async () => {
- player = new Player(mapRef.current, styles.dark, didClickSprite);
- setApp(player.app);
- setMapContainer(player.mapContainer);
- Utils.syncApp(player.app);
- Utils.syncMapContainer(player.mapContainer);
+ React.useEffect(() => {
+ 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);
- await Utils.fetchMapData(intl);
- setDataFetched(true);
- setModel(MapModel.OBSERVER_MODEL)
- setTimeout(() => {
- player.adaptScreen();
- }, 200)
+ 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
@@ -115,7 +126,6 @@
const height = contentRef.current.offsetHeight;
app.renderer.resize(width, height);
if (model !== MapModel.OBSERVER_MODEL) {
- player.hideGridlines();
player.showGridlines();
}
}, [app, mapContainer, windowSize])
@@ -125,7 +135,6 @@
if (!mapContainer && !dataFetched) {
return;
}
-
switch (model) {
case MapModel.OBSERVER_MODEL:
@@ -135,6 +144,7 @@
player.activateMapEvent(null);
Utils.removeSelectedEffect();
+ setCurSPrite(null);
setDeviceVisible(false);
setSettingsVisible(false);
@@ -147,7 +157,7 @@
player.showGridlines();
player.hideStarryBackground();
- player.activateMapEvent(Utils.MapEvent.SELECTION_BOX);
+ player.activateMapEvent(Utils.MapEvent.SELECTION_BOX, model);
Utils.removeSelectedEffect();
setSpriteBySettings(null);
@@ -163,7 +173,7 @@
player.showGridlines();
player.showStarryBackground();
- player.activateMapEvent(null);
+ player.activateMapEvent(Utils.MapEvent.SELECTION_BOX, model);
setDeviceVisible(false);
setDrawerVisible(false);
@@ -208,6 +218,10 @@
}, [curSprite]);
const prevCurSprite = prevCurSpriteRef.current;
+ // watch curFloor
+ React.useEffect(() => {
+ }, [curFloor]);
+
// didClickSprite, stop triggers both sprite click and play's selection boxs
React.useEffect(() => {
player.updateDidClickSprite(didClickSprite);
@@ -239,6 +253,7 @@
return (
<>
+ {contextHolder}
<Layout className={styles.layout}>
<Header className={styles.header}>
<Row style={{ height: '100%' }}>
@@ -254,7 +269,7 @@
/>
)}
</Col>
- <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'}>
{model === MapModel.OBSERVER_MODEL && (
@@ -262,8 +277,24 @@
<Button
className='map-header-button'
size={'large'}
- onClick={() => {
- Utils.fetchMapData(intl);
+ 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='鍔犺浇鍦板浘' />
@@ -318,55 +349,62 @@
</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 >
--
Gitblit v1.9.1