yjtgq-web/src/views/Home/_.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-11-22 11:00:19 +08:00
import { useEffect, useMemo, useState } from "react";
import { httpGet3 } from "../../utils/request";
const tabRole = [
{ label: '水质', value: 'D00000290', roleCode: 'A06A20', chanCode: '420802001350', extent: [1701, 147, 5120, 666] },
{ label: '流量', value: 'D00000290', roleCode: 'A06A20', chanCode: '420802001350', extent: [1701, 147, 5120, 666] },
]
export function usePageContext() {
const [filterName, setFilterName] = useState();
const [selArea, setSelArea] = useState(tabRole[0]);
const [stData, setStData] = useState([])
// const [specialStationData, setSpecialStationData] = useState([]);
const dataWithSpecialStation = useMemo(() => {
const kw = (filterName || '').trim().toLowerCase();
if (!kw) return stData;
return stData.filter(o => ((o.mn).toLowerCase()).includes(kw));
}, [stData, filterName])
const fetchSpecialStationData = async () => {
try {
// 获取所有水质数据
const allList = await httpGet3(`/yjt/wq/real/online`);
let data = [];
if (Array.isArray(allList)) {
data = allList;
} else if (allList && typeof allList === 'object') {
data = Object.keys(allList).reduce((acc, statusKey) => {
const arr = Array.isArray(allList[statusKey]) ? allList[statusKey] : [];
return acc.concat(arr.map(item => ({ ...item, status: statusKey })));
}, []);
}
setStData(data.map(o => ({ ...o, name: o.name || o.stationName || o.stnm })));
} catch (error) {
console.log(error);
}
}
useEffect(()=>{
fetchSpecialStationData()
},[])
return {
// reqTm,
// fav,
// dataReq,
// officeCode: user.roleCodes,
tabRole,
selArea,
setSelArea,
dataWithFav: dataWithSpecialStation,
// popSt,
// setPopSt,
// popChan,
// setPopChan,
filterName,
setFilterName,
// filterIrrCode,
// setFilterIrrCode,
// waterTm,
// setWaterTm,
// cntStat,
}
}