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 * as Utils from '../utils'
|
|
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 { curSprite: curSensor, setCurSPrite: setCurSensor } = props;
|
|
const sensorTypeSelectOptions = Utils.sensorTypeSelectOptions(intl);
|
|
const [curSensorType, setCurSensorType] = React.useState(sensorTypeSelectOptions?.[0]?.value);
|
const [sensorList, setSensorList] = React.useState([]);
|
const [curSensorLabel, setCurSensorLabel] = React.useState(null);
|
|
useEffect(() => {
|
// setSensorList([]);
|
// setCurSensorUuid(null);
|
// setCurSensorLabel(null);
|
// setCurSensor(null);
|
}, [props]);
|
|
React.useEffect(() => {
|
if (!Utils.getMapContainer()) {
|
return
|
}
|
setSensorList([]);
|
setCurSensorLabel(null);
|
Utils.getMapContainer().children.forEach(child => {
|
if (child?.data?.type === curSensorType && child?.data?.no) {
|
setSensorList(prevArr => [...prevArr, {
|
value: child.data.no,
|
label: renderTitle(child.data.no, child.data.uuid)
|
}]);
|
}
|
});
|
}, [curSensorType])
|
|
return (
|
<>
|
<Select
|
className='map-header-select'
|
variant='filled'
|
style={{
|
width: 160,
|
}}
|
size={'large'}
|
options={sensorTypeSelectOptions}
|
value={curSensorType}
|
onChange={setCurSensorType}
|
/>
|
<AutoComplete
|
className='map-header-select'
|
variant='filled'
|
style={{
|
width: 360,
|
}}
|
size={'large'}
|
placeholder={intl.formatMessage({ id: 'common.search.placeholder', defaultMessage: '请输入搜索内容' })}
|
allowClear={{
|
clearIcon: <CloseOutlined />
|
}}
|
popupMatchSelectWidth={500}
|
options={sensorList}
|
value={curSensorLabel}
|
onSelect={(value, option) => {
|
const uuid = option.label?.props?.children?.[1].props.children
|
setCurSensor(Utils.findSpriteByUuid(uuid));
|
}}
|
onChange={setCurSensorLabel}
|
/>
|
</>
|
)
|
}
|
|
export default MapSearch;
|