From 83c548d3dba59aaed9b52b5d413c6912a87d2efc Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 16 六月 2024 15:50:14 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/map/header/search.jsx | 177 ++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 114 insertions(+), 63 deletions(-)
diff --git a/zy-asrs-flow/src/pages/map/header/search.jsx b/zy-asrs-flow/src/pages/map/header/search.jsx
index 587f3da..5c70fe6 100644
--- a/zy-asrs-flow/src/pages/map/header/search.jsx
+++ b/zy-asrs-flow/src/pages/map/header/search.jsx
@@ -1,73 +1,131 @@
import React, { useState, useRef, useEffect } from 'react';
-import { Layout, Button, Flex, Row, Col, FloatButton, Select, Spin, AutoComplete } from 'antd';
-import { FormattedMessage, useIntl, useModel } from '@umijs/max';
-import {
- CloseOutlined
-} from '@ant-design/icons';
+import { Select, AutoComplete } from 'antd';
+import { FormattedMessage, useIntl } from '@umijs/max';
+import { CloseOutlined } from '@ant-design/icons';
import * as Utils from '../utils'
-import { values } from 'lodash';
-const renderTitle = (title) => (
- <span
- style={{
- fontWeight: 'bold'
- }}
- >
- {title}
- </span>
+const renderTitle = (title, uuid) => (
+ <>
+ <span style={{ fontWeight: 'bold' }} >{title}</span>
+ <span style={{ float: 'right', opacity: .3 }} >{uuid}</span>
+ </>
);
-const MapSearch = (props) => {
- const intl = useIntl();
-
- const sensorTypeSelectOptions = Utils.sensorTypeSelectOptions(intl);
-
- const [curSensorType, setCurSensorType] = React.useState(sensorTypeSelectOptions?.[0]?.value);
- const [sensorList, setSensorList] = React.useState([]);
- const [curSensorUuid, setCurSensorUuid] = React.useState(null);
- const [curSensorLabel, setCurSensorLabel] = React.useState(null);
- const [curSensor, setCurSensor] = React.useState(null);
-
- useEffect(() => {
- setSensorList([]);
- setCurSensorUuid(null);
- setCurSensorLabel(null);
- setCurSensor(null);
- }, [props]);
-
- React.useEffect(() => {
- if (!Utils.getMapContainer()) {
- return
- }
- setSensorList([]);
- setCurSensorUuid(null);
- setCurSensorLabel(null);
- setCurSensor(null);
- switch (curSensorType) {
+const sensorTypeSelectOptionsFn = (intl) => {
+ let options = [];
+ Object.entries(Utils.SENSOR_TYPE).forEach(([key, value]) => {
+ switch (key) {
case Utils.SENSOR_TYPE.SHELF:
- Utils.getMapContainer().children.forEach(child => {
- if (child?.data?.type === Utils.SENSOR_TYPE.SHELF) {
- setSensorList(prevArr => [...prevArr, {
- value: child.data.uuid,
- label: renderTitle(child.data.shelfNo)
- }]);
- }
+ options.push({
+ value: value,
+ label:
+ (
+ <>
+ <span style={{ fontWeight: 'bold' }} >{intl.formatMessage({ id: 'map.sensor.type.shelf', defaultMessage: '璐ф灦' })}</span>
+ </>
+ )
})
break;
case Utils.SENSOR_TYPE.AGV:
+ options.push({
+ value: value,
+ label:
+ (
+ <>
+ <span style={{ fontWeight: 'bold' }} >{intl.formatMessage({ id: 'map.sensor.type.agv', defaultMessage: '鏃犱汉灏忚溅' })}</span>
+ </>
+ )
+ })
+ break;
+ case Utils.SENSOR_TYPE.POINT:
+ options.push({
+ value: value,
+ label:
+ (
+ <>
+ <span style={{ fontWeight: 'bold' }} >{intl.formatMessage({ id: 'map.sensor.type.point', defaultMessage: '瀹氫綅鐐�' })}</span>
+ </>
+ )
+ })
break;
default:
break;
}
+
+ })
+ return options;
+}
+
+function getAllSensorList(curSensorType) {
+ let sensorListAll = [];
+ Utils.getMapContainer().children.forEach(child => {
+ if (child?.data?.type === curSensorType && child?.data?.no) {
+ sensorListAll.push({
+ value: child.data.no,
+ label: renderTitle(child.data.no, child.data.uuid)
+ })
+ }
+ });
+ return sensorListAll;
+}
+
+const MapSearch = (props) => {
+ const intl = useIntl();
+ const {
+ curSprite: curSensor,
+ setCurSPrite: setCurSensor,
+ setSpriteBySettings,
+ model,
+ setModel,
+ ModelEnum,
+ } = props;
+
+ const sensorTypeSelectOptions = sensorTypeSelectOptionsFn(intl);
+ const [curSensorType, setCurSensorType] = React.useState(sensorTypeSelectOptions?.[0]?.value);
+
+ const [sensorList, setSensorList] = React.useState([]);
+ const [filterSensorList, setFilterSensorList] = React.useState([]);
+ const [curSensorLabel, setCurSensorLabel] = React.useState(null);
+
+ // first select
+ React.useEffect(() => {
+ if (!Utils.getMapContainer()) { return; }
+ let sensorListAll = getAllSensorList(curSensorType);
+ setSensorList(sensorListAll);
+ setFilterSensorList(sensorListAll);
+ setCurSensorLabel(null);
}, [curSensorType])
+ // second select
React.useEffect(() => {
- setCurSensor(Utils.findSpriteByUuid(curSensorUuid));
- }, [curSensorUuid])
+ if (!Utils.getMapContainer()) { return; }
+ if ((curSensorLabel !== null || curSensorLabel != undefined)
+ && sensorList && sensorList.length > 0) {
+ setFilterSensorList(sensorList.filter(item => item.value.includes(curSensorLabel)));
+ }
+ }, [curSensorLabel])
- React.useEffect(() => {
- console.log(curSensor);
- }, [curSensor])
+ const onSecondSelect = (value, option) => {
+ const uuid = option.label?.props?.children?.[1].props.children;
+ const selectSensor = Utils.findSpriteByUuid(uuid);
+ if (selectSensor) {
+ Utils.beCenter(selectSensor);
+ }
+ switch (model) {
+ case ModelEnum.OBSERVER_MODEL:
+ setCurSensor(selectSensor);
+ break;
+ case ModelEnum.MOVABLE_MODEL:
+ setModel(ModelEnum.SETTINGS_MODEL);
+ setSpriteBySettings(selectSensor);
+ break;
+ case ModelEnum.SETTINGS_MODEL:
+ setSpriteBySettings(selectSensor);
+ break;
+ default:
+ break;
+ }
+ }
return (
<>
@@ -94,17 +152,10 @@
clearIcon: <CloseOutlined />
}}
popupMatchSelectWidth={500}
- onSearch={() => { }}
- options={sensorList}
+ options={filterSensorList}
value={curSensorLabel}
- onSelect={(value, option) => {
- setCurSensorUuid(value);
- if (option.label?.props?.children) {
- setCurSensorLabel(option.label?.props?.children)
- } else {
- return setCurSensorLabel(value);
- }
- }}
+ onSelect={onSecondSelect}
+ onChange={setCurSensorLabel}
/>
</>
)
--
Gitblit v1.9.1