| | |
| | | const { curSprite: curSensor, setCurSPrite: setCurSensor } = 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); |
| | | |
| | | useEffect(() => { |
| | | // setSensorList([]); |
| | | // setCurSensorUuid(null); |
| | | // setCurSensorLabel(null); |
| | | // setCurSensor(null); |
| | | }, [props]); |
| | | |
| | | // first select |
| | | React.useEffect(() => { |
| | | if (!Utils.getMapContainer()) { |
| | | return |
| | | } |
| | | setSensorList([]); |
| | | setCurSensorLabel(null); |
| | | let sensorListAll = []; |
| | | Utils.getMapContainer().children.forEach(child => { |
| | | if (child?.data?.type === curSensorType && child?.data?.no) { |
| | | setSensorList(prevArr => [...prevArr, { |
| | | sensorListAll.push({ |
| | | value: child.data.no, |
| | | label: renderTitle(child.data.no, child.data.uuid) |
| | | }]); |
| | | }) |
| | | } |
| | | }); |
| | | setSensorList(sensorListAll); |
| | | setFilterSensorList(sensorListAll); |
| | | setCurSensorLabel(null); |
| | | }, [curSensorType]) |
| | | |
| | | // second select |
| | | React.useEffect(() => { |
| | | if (!Utils.getMapContainer()) { |
| | | return |
| | | } |
| | | if (sensorList && sensorList.length > 0) { |
| | | setFilterSensorList(sensorList.filter(item => item.value.includes(curSensorLabel))); |
| | | } |
| | | }, [curSensorLabel]) |
| | | |
| | | return ( |
| | | <> |
| | |
| | | clearIcon: <CloseOutlined /> |
| | | }} |
| | | popupMatchSelectWidth={500} |
| | | options={sensorList} |
| | | options={filterSensorList} |
| | | value={curSensorLabel} |
| | | onSelect={(value, option) => { |
| | | const uuid = option.label?.props?.children?.[1].props.children |
| | | setCurSensor(Utils.findSpriteByUuid(uuid)); |
| | | }} |
| | | onChange={(value) => { |
| | | setCurSensorLabel(value) |
| | | }} |
| | | onChange={setCurSensorLabel} |
| | | /> |
| | | </> |
| | | ) |