#
luxiaotao1123
2024-03-15 3c190ac12e00e0f3435984c5d57351d136530c09
zy-asrs-flow/src/pages/map/header/search.jsx
@@ -45,38 +45,59 @@
    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 } = 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]);
    // useEffect(() => {
    //     const intervalID = setInterval(() => {
    //         if (!curSensorLabel) {
    //             let sensorListAll = getAllSensorList(curSensorType);
    //             setSensorList(sensorListAll);
    //             setFilterSensorList(sensorListAll);
    //         }
    //     }, 1000)
    //     return () => clearInterval(intervalID);
    // }, [props]);
    // first select
    React.useEffect(() => {
        if (!Utils.getMapContainer()) {
            return
        }
        setSensorList([]);
        if (!Utils.getMapContainer()) { return; }
        let sensorListAll = getAllSensorList(curSensorType);
        setSensorList(sensorListAll);
        setFilterSensorList(sensorListAll);
        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])
    // second select
    React.useEffect(() => {
        if (!Utils.getMapContainer()) { return; }
        if ((curSensorLabel !== null || curSensorLabel != undefined)
            && sensorList && sensorList.length > 0) {
            setFilterSensorList(sensorList.filter(item => item.value.includes(curSensorLabel)));
        }
    }, [curSensorLabel])
    return (
        <>
@@ -103,15 +124,13 @@
                    clearIcon: <CloseOutlined />
                }}
                popupMatchSelectWidth={500}
                options={sensorList}
                options={filterSensorList}
                value={curSensorLabel}
                onSelect={(value, option) => {
                    const uuid = option.label?.props?.children?.[1].props.children
                    const uuid = option.label?.props?.children?.[1].props.children;
                    setCurSensor(Utils.findSpriteByUuid(uuid));
                }}
                onChange={(value) => {
                    setCurSensorLabel(value)
                }}
                onChange={setCurSensorLabel}
            />
        </>
    )