diff --git a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/components/RealtimeMonitoring/index.tsx b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/components/RealtimeMonitoring/index.tsx index 8f9444f528efa3a8b1a0eda29c40c1ead4f0c094..97a89973045b301c2a9244f3a10645403a9ce895 100644 --- a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/components/RealtimeMonitoring/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/components/RealtimeMonitoring/index.tsx @@ -3,7 +3,8 @@ import ModuleTitleWithTabs from '@/pages/Home_v_2504/components/common/ModuleTit import { ColumnsType } from 'antd/es/table'; import styles from './index.less'; import services from '@/services'; -import useApiControl, { formatDateTime, useDateParamFormatter } from '@/pages/Home_v_2504/hooks/useApiControl'; +import usePageAwareApi from '@/pages/Home_v_2504/hooks/usePageAwareApi'; +import { formatDateTime, useDateParamFormatter } from '@/pages/Home_v_2504/hooks/useApiControl'; import BlueTableWithScroll from '@/components/BlueTableWithScroll'; import { useGlobalModalServices } from '@/pages/GlobalModalServices/provider'; import useLatestValue from '@/pages/Home_v_2504/hooks/useLatestValue'; @@ -25,12 +26,14 @@ interface RealtimeMonitoringProps { districtCode?: string; streetCode?: string; }; + pageId?: string; } const RealtimeMonitoring: React.FC = ({ startTime, endTime, - regionParams + regionParams, + pageId = 'restaurantOil' }) => { // 获取全局弹窗服务 const { dispatch } = useGlobalModalServices(); @@ -58,9 +61,9 @@ const RealtimeMonitoring: React.FC = ({ // 日期格式化工具 const { formatDateParams } = useDateParamFormatter(); - // 使用useApiControl管理实时监测API调用 - const monitoringApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理实时监测API调用 + const monitoringApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime) { throw new Error('缺少必要的日期参数'); } @@ -76,7 +79,7 @@ const RealtimeMonitoring: React.FC = ({ throw new Error('获取实时监测数据失败'); }, - onSuccess: (data, params) => { + onSuccess: (data: any, params: any) => { const { records } = data; if (records?.length > 0) { @@ -116,7 +119,7 @@ const RealtimeMonitoring: React.FC = ({ } } }, - onError: (error, params) => { + onError: (error: any, params: any) => { console.error('获取实时监测数据出错:', error); // 只有在第一页时清空数据源 if (params.pageNo === 0) { @@ -125,9 +128,10 @@ const RealtimeMonitoring: React.FC = ({ } }, formatParams: formatDateParams, - apiName: '实时监测', + apiName: '餐饮油烟实时监测', debounceTime: 300, - cacheTime: 5000 // 缓存5秒 + cacheTime: 5000, // 缓存5秒 + pageId: pageId }); // 处理设备点击,显示设备详情弹窗 diff --git a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/index.tsx b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/index.tsx index 68e99b617948cce37e81765d777785351459d3c9..f812e3d685aacf56590e7f41c0d717236bcf238c 100644 --- a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/components/LeftContent/index.tsx @@ -10,7 +10,8 @@ import RealtimeMonitoring from './components/RealtimeMonitoring'; import styles from './index.less'; import { useMapState } from '@/pages/Home_v_2504/components/MapStateContext'; import services from '@/services'; -import useApiControl, { formatDateTime, useDateParamFormatter } from '@/pages/Home_v_2504/hooks/useApiControl'; +import usePageAwareApi from '@/pages/Home_v_2504/hooks/usePageAwareApi'; +import { formatDateTime, useDateParamFormatter } from '@/pages/Home_v_2504/hooks/useApiControl'; import useLatestValue from '@/pages/Home_v_2504/hooks/useLatestValue'; import dayjs from 'dayjs'; @@ -48,7 +49,11 @@ interface MonitoringListItem { type AreaType = 'all' | 'urban' | 'central' | 'county'; const isUseRealtimeMonitoring = false; -const LeftContent: React.FC = () => { +interface LeftContentProps { + pageId?: string; +} + +const LeftContent: React.FC = ({ pageId = 'restaurantOil' }) => { // 地图状态 const { mapState } = useMapState(); @@ -171,9 +176,9 @@ const LeftContent: React.FC = () => { const { formatDateParams } = useDateParamFormatter(); const regionCodeRef = useRef(''); - // 使用useApiControl管理油烟统计API调用 - const oilStatisticsApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理油烟统计API调用 + const oilStatisticsApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime) { throw new Error('缺少必要的日期参数'); } @@ -189,7 +194,7 @@ const LeftContent: React.FC = () => { throw new Error('获取油烟统计数据失败'); }, - onSuccess: (data) => { + onSuccess: (data: any) => { // 提取正确路径下的数据 const record = data?.records?.[0] || {}; @@ -201,7 +206,7 @@ const LeftContent: React.FC = () => { qy: record.qy ?? 0 }); }, - onError: (error) => { + onError: (error: any) => { console.error('获取油烟统计数据出错:', error); setOilStatistics({ gj: 0, @@ -212,14 +217,15 @@ const LeftContent: React.FC = () => { }); }, formatParams: formatDateParams, - apiName: '油烟统计', + apiName: '餐饮油烟统计', debounceTime: 300, - cacheTime: 5000 // 缓存5秒 + cacheTime: 5000, // 缓存5秒 + pageId: pageId }); - // 使用useApiControl管理告警区域API调用 - const alertAreaApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理告警区域API调用 + const alertAreaApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime || !params.districtCodeList) { throw new Error('缺少必要的参数'); } @@ -235,7 +241,7 @@ const LeftContent: React.FC = () => { throw new Error('获取告警区域数据失败'); }, - onSuccess: (data) => { + onSuccess: (data: any) => { // 提取正确路径下的数据并格式化 const records = data?.records || []; const formattedData = records.map((item: any) => ({ @@ -246,19 +252,20 @@ const LeftContent: React.FC = () => { setAlertAreaData(formattedData); }, - onError: (error) => { + onError: (error: any) => { console.error('获取告警区域数据出错:', error); setAlertAreaData([]); }, formatParams: formatDateParams, - apiName: '告警区域', + apiName: '餐饮油烟告警区域', debounceTime: 300, - cacheTime: 5000 // 缓存5秒 + cacheTime: 5000, // 缓存5秒 + pageId: pageId }); - // 使用useApiControl管理设备告警排行API调用 - const alertRankingApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理设备告警排行API调用 + const alertRankingApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime) { throw new Error('缺少必要的日期参数'); } @@ -274,7 +281,7 @@ const LeftContent: React.FC = () => { throw new Error('获取告警排行数据失败'); }, - onSuccess: (data) => { + onSuccess: (data: any) => { // 提取正确路径下的数据并格式化 const records = data?.records || []; @@ -293,19 +300,20 @@ const LeftContent: React.FC = () => { setAlertRankingData(formattedData); }, - onError: (error) => { + onError: (error: any) => { console.error('获取告警排行数据出错:', error); setAlertRankingData([]); }, formatParams: formatDateParams, - apiName: '告警排行', + apiName: '餐饮油烟告警排行', debounceTime: 300, - cacheTime: 5000 // 缓存5秒 + cacheTime: 5000, // 缓存5秒 + pageId: pageId }); - // 使用useApiControl管理油烟告警趋势API调用 - const alertTrendApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理油烟告警趋势API调用 + const alertTrendApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime) { throw new Error('缺少必要的日期参数'); } @@ -321,7 +329,7 @@ const LeftContent: React.FC = () => { throw new Error('获取油烟告警趋势数据失败'); }, - onSuccess: (data) => { + onSuccess: (data: any) => { // 提取正确路径下的数据并格式化 let records = data?.records || []; @@ -386,14 +394,15 @@ const LeftContent: React.FC = () => { setAlertTrendData([]); } }, - onError: (error) => { + onError: (error: any) => { console.error('获取油烟告警趋势数据出错:', error); setAlertTrendData([]); }, formatParams: formatDateParams, - apiName: '油烟告警趋势', + apiName: '餐饮油烟告警趋势', debounceTime: 300, - cacheTime: 5000 // 缓存5秒 + cacheTime: 5000, // 缓存5秒 + pageId: pageId }); const translateTrendTime = (inputDate: string | number) => { @@ -421,9 +430,9 @@ const LeftContent: React.FC = () => { return inputDate; } - // 使用useApiControl管理街道告警次数API调用 - const streetAlertAreaApi = useApiControl({ - apiFunction: async (params) => { + // 使用usePageAwareApi管理街道告警次数API调用 + const streetAlertAreaApi = usePageAwareApi({ + apiFunction: async (params: any) => { if (!params.startTime || !params.endTime || !params.districtCodeList) { throw new Error('缺少必要的参数'); } @@ -439,7 +448,7 @@ const LeftContent: React.FC = () => { throw new Error('获取街道告警区域数据失败'); }, - onSuccess: (data) => { + onSuccess: (data: any) => { // 提取正确路径下的数据并格式化 const records = data?.records || []; const formattedData = records.map((item: any) => ({ @@ -451,13 +460,14 @@ const LeftContent: React.FC = () => { console.log('街道告警区域数据成功:', formattedData); setAlertAreaData(formattedData); }, - onError: (error) => { + onError: (error: any) => { console.error('获取街道告警区域数据出错:', error); setAlertAreaData([]); }, formatParams: formatDateParams, // enableDebug: true, - apiName: '街道告警区域' + apiName: '餐饮油烟街道告警区域', + pageId: pageId }); // 加载油烟统计数据 - 使用本地状态的日期参数 @@ -961,6 +971,7 @@ const LeftContent: React.FC = () => { startTime={dateRange.startTime} endTime={dateRange.endTime} regionParams={params} + pageId={pageId} key={`monitoring-${dateRange.startTime}-${dateRange.endTime}-${mapState.regionCode}`} /> ); @@ -989,7 +1000,7 @@ const LeftContent: React.FC = () => { onChange={handleDateChange} defaultType="day" panelType="left" - pageId="restaurantOil" + pageId={pageId} /> diff --git a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/index.tsx b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/index.tsx index a653707cfb5fe0cd9da4201bc0ac1c3ea26c128b..44d0e34334cc8fb8f8517bbce26b9d3b48c2e67e 100644 --- a/src/pages/Home_v_2504/components/SubPages/RestaurantOil/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/RestaurantOil/index.tsx @@ -17,9 +17,18 @@ const RestaurantOil: React.FC = ({ visible }) => { ( + + )} + rightComponent={(props) => ( + + )} title="餐饮油烟监管" /> );