diff --git a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseHandlingQuantity/index.tsx b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseHandlingQuantity/index.tsx index d48d857d373a8d435ee30697cd2e0dc81d042a2b..2c9b07569d1f5402a6fa1aa50bb0982a490b763d 100644 --- a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseHandlingQuantity/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseHandlingQuantity/index.tsx @@ -92,6 +92,49 @@ const CaseHandlingQuantity: React.FC = ({ setCurrentTab(tab as AreaType); }; + // 使用usePageAwareApi管理办案数量API调用 + const highFrequencyApi = usePageAwareApi({ + apiFunction: async (params) => { + console.log('发起办案数量请求,参数:', params); + const response = await getDistrictHighFrequencyArea(params); + + if (response.code === 200 && response.data) { + return response.data; + } + + throw new Error('获取办案数量数据失败'); + }, + onSuccess: (data) => { + if (!data || !Array.isArray(data) || data.length === 0) { + setData([]); + return; + } + + let isUsingMock = true; + const defaultPercentage = isUsingMock ? 99 : 0; + const defaultValue = isUsingMock ? 200 : 0; + + // 转换接口返回的数据格式为图表需要的格式 + const formattedData = data.map((item: any) => ({ + name: item.name, + percentage: parseFloat(item.percent) || defaultPercentage, + count: parseInt(item.value) || defaultValue + })); + + console.log('办案数量数据成功:'); + setData(formattedData); + }, + onError: (error) => { + console.error('获取办案数量数据出错:', error); + setData([]); + }, + apiName: '办案数量', + debounceTime: 300, + cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 + pageId: pageId, // 传入页面ID用于页面感知 + panelType: 'right', // 指定为右侧面板 + }); + // 构建API请求参数 const buildApiParams = useCallback(() => { const currentMapState = mapStateRef.current; @@ -128,72 +171,30 @@ const CaseHandlingQuantity: React.FC = ({ } // 获取区域编码列表 - const districtCodeList = getRegionCodes(currentTabRef.current, currentMapState.regionCode); + const districtCodeList = getRegionCodes(currentTabRef.current, highFrequencyApi.regionCode); if (districtCodeList) { params.districtCodeList = districtCodeList; } // 处理区域参数 - if (currentMapState.regionCode === '5101') { + if (highFrequencyApi.regionCode === '5101') { // 成都,这两个参数就不传 params.districtCode = undefined; params.streetCode = undefined; - } else if (currentMapState.regionCode.length === 6) { + } else if (highFrequencyApi.regionCode.length === 6) { // 区县级别 - params.districtCode = currentMapState.regionCode; - } else if (currentMapState.regionCode.length === 9) { + params.districtCode = highFrequencyApi.regionCode; + } else if (highFrequencyApi.regionCode.length === 9) { // 街道级别 - params.districtCode = currentMapState.regionCode.substring(0, 6); - params.streetCode = currentMapState.regionCode; + params.districtCode = highFrequencyApi.regionCode.substring(0, 6); + params.streetCode = highFrequencyApi.regionCode; } // 使用传入的dataTypeKey获取对应的subTypeCode params.subTypeCode = useDataType(dataTypeKey); return params; - }, [mapStateRef, currentTabRef, dateType, translateDateType, dataTypeKey, pageId]); - - // 使用usePageAwareApi管理办案数量API调用 - const highFrequencyApi = usePageAwareApi({ - apiFunction: async (params) => { - console.log('发起办案数量请求,参数:', params); - const response = await getDistrictHighFrequencyArea(params); - - if (response.code === 200 && response.data) { - return response.data; - } - - throw new Error('获取办案数量数据失败'); - }, - onSuccess: (data) => { - if (!data || !Array.isArray(data) || data.length === 0) { - setData([]); - return; - } - - let isUsingMock = true; - const defaultPercentage = isUsingMock ? 99 : 0; - const defaultValue = isUsingMock ? 200 : 0; - - // 转换接口返回的数据格式为图表需要的格式 - const formattedData = data.map((item: any) => ({ - name: item.name, - percentage: parseFloat(item.percent) || defaultPercentage, - count: parseInt(item.value) || defaultValue - })); - - console.log('办案数量数据成功:'); - setData(formattedData); - }, - onError: (error) => { - console.error('获取办案数量数据出错:', error); - setData([]); - }, - apiName: '办案数量', - debounceTime: 300, - cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 - pageId: pageId, // 传入页面ID用于页面感知 - }); + }, [mapStateRef, currentTabRef, dateType, translateDateType, dataTypeKey, pageId, highFrequencyApi.regionCode]); // 在地图状态变化和Tab变化时加载数据 useEffect(() => { @@ -208,7 +209,7 @@ const CaseHandlingQuantity: React.FC = ({ // 调用API - 现在usePageAwareApi内部会处理参数比较和页面状态 highFrequencyApi.callApi(params); - }, [mapState.regionCode, mapState.rightPanelTime, mapState.pageTimeSettings, currentTab, buildApiParams, highFrequencyApi]); + }, [currentTab, buildApiParams, highFrequencyApi]); return (
diff --git a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseSource/index.tsx b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseSource/index.tsx index 3fdf726b504861f167591440d95a7712802e3c0b..b94d712e86c9fe0a0b613d214b58a627036c58c7 100644 --- a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseSource/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/CaseSource/index.tsx @@ -46,61 +46,6 @@ const ProgramType: React.FC = ({ } }, []); - // 构建API请求参数 - const buildApiParams = useCallback(() => { - const currentMapState = mapStateRef.current; - - // 如果没有必要的时间参数,返回null表示不应该发起请求 - if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { - return null; - } - - // 获取当前页面的时间设置 - const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; - if (!pageTimeSettings) { - console.log(`缺少${pageId}页面的时间设置,使用全局设置`); - } - - // 使用页面级别的时间设置,如果存在的话 - const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; - - // 使用当前时间类型,如果不存在则使用props或默认值 - const effectiveType = rightPanelTime.type || dateType || 'month'; - - // 基础参数对象 - const params: any = { - type: translateDateType(effectiveType) - }; - - // 处理日期参数 - if (effectiveType === 'range') { - params.customizeStart = formatDateTime(rightPanelTime.startTime); - params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); - } else { - // 年、月、日视图使用time参数 - params.time = formatDateTime(rightPanelTime.startTime); - } - - // 处理区域参数 - if (currentMapState.regionCode === '5101') { - // 成都,这两个参数就不传 - params.districtCode = undefined; - params.streetCode = undefined; - } else if (currentMapState.regionCode.length === 6) { - // 区县级别 - params.districtCode = currentMapState.regionCode; - } else if (currentMapState.regionCode.length === 9) { - // 街道级别 - params.districtCode = currentMapState.regionCode.substring(0, 6); - params.streetCode = currentMapState.regionCode; - } - - // 使用传入的dataTypeKey获取对应的subTypeCode - params.subTypeCode = useDataType(dataTypeKey); - - return params; - }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId]); - // 使用usePageAwareApi管理问题来源API调用 const sourceSystemRankApi = usePageAwareApi({ apiFunction: async (params: any) => { @@ -150,7 +95,63 @@ const ProgramType: React.FC = ({ cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 enableDebug: false, pageId: pageId, // 添加页面ID以启用页面感知 + panelType: 'right', // 指定为右侧面板 }); + + // 构建API请求参数 + const buildApiParams = useCallback(() => { + const currentMapState = mapStateRef.current; + + // 如果没有必要的时间参数,返回null表示不应该发起请求 + if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { + return null; + } + + // 获取当前页面的时间设置 + const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; + if (!pageTimeSettings) { + console.log(`缺少${pageId}页面的时间设置,使用全局设置`); + } + + // 使用页面级别的时间设置,如果存在的话 + const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; + + // 使用当前时间类型,如果不存在则使用props或默认值 + const effectiveType = rightPanelTime.type || dateType || 'month'; + + // 基础参数对象 + const params: any = { + type: translateDateType(effectiveType) + }; + + // 处理日期参数 + if (effectiveType === 'range') { + params.customizeStart = formatDateTime(rightPanelTime.startTime); + params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); + } else { + // 年、月、日视图使用time参数 + params.time = formatDateTime(rightPanelTime.startTime); + } + + // 处理区域参数 + if (sourceSystemRankApi.regionCode === '5101') { + // 成都,这两个参数就不传 + params.districtCode = undefined; + params.streetCode = undefined; + } else if (sourceSystemRankApi.regionCode.length === 6) { + // 区县级别 + params.districtCode = sourceSystemRankApi.regionCode; + } else if (sourceSystemRankApi.regionCode.length === 9) { + // 街道级别 + params.districtCode = sourceSystemRankApi.regionCode.substring(0, 6); + params.streetCode = sourceSystemRankApi.regionCode; + } + + // 使用传入的dataTypeKey获取对应的subTypeCode + params.subTypeCode = useDataType(dataTypeKey); + + return params; + }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId, sourceSystemRankApi.regionCode]); // 在地图状态变化时加载数据 useEffect(() => { @@ -165,7 +166,7 @@ const ProgramType: React.FC = ({ console.log(`加载${pageId}页面-案件来源 数据,参数:`, params); sourceSystemRankApi.callApi(params); - }, [mapState.regionCode, mapState.rightPanelTime, mapState.pageTimeSettings, buildApiParams, sourceSystemRankApi, pageId]); + }, [buildApiParams, sourceSystemRankApi, pageId]); return (
diff --git a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/HighFrequencyType/index.tsx b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/HighFrequencyType/index.tsx index 31b8a67eee4212804b07ec6277c545ebcc53bfad..11bcc413db6204bf6f87ae124a3c4cc558727929 100644 --- a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/HighFrequencyType/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/HighFrequencyType/index.tsx @@ -90,6 +90,49 @@ const HighFrequencyType: React.FC = ({ setCurrentTab(tab as AreaType); }; + // 使用usePageAwareApi管理高发区域API调用 + const highFrequencyApi = usePageAwareApi({ + apiFunction: async (params) => { + console.log('发起高发区域请求,参数:', params); + const response = await getDistrictHighFrequencyArea(params); + + if (response.code === 200 && response.data) { + return response.data; + } + + throw new Error('获取高发区域数据失败'); + }, + onSuccess: (data) => { + if (!data || !Array.isArray(data) || data.length === 0) { + setData([]); + return; + } + + let isUsingMock = true; + const defaultPercentage = isUsingMock ? 99 : 0; + const defaultValue = isUsingMock ? 200 : 0; + + // 转换接口返回的数据格式为图表需要的格式 + const formattedData = data.map((item: any) => ({ + name: item.name, + percentage: parseFloat(item.percent) || defaultPercentage, + count: parseInt(item.value) || defaultValue + })); + + console.log('高发区域数据成功:'); + setData(formattedData); + }, + onError: (error) => { + console.error('获取高发区域数据出错:', error); + setData([]); + }, + apiName: '高发类型', + debounceTime: 300, + cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 + pageId: pageId, // 传入页面ID用于页面感知 + panelType: 'right', // 指定为右侧面板 + }); + // 构建API请求参数 const buildApiParams = useCallback(() => { const currentMapState = mapStateRef.current; @@ -126,72 +169,30 @@ const HighFrequencyType: React.FC = ({ } // 获取区域编码列表 - const districtCodeList = getRegionCodes(currentTabRef.current, currentMapState.regionCode); + const districtCodeList = getRegionCodes(currentTabRef.current, highFrequencyApi.regionCode); if (districtCodeList) { params.districtCodeList = districtCodeList; } // 处理区域参数 - if (currentMapState.regionCode === '5101') { + if (highFrequencyApi.regionCode === '5101') { // 成都,这两个参数就不传 params.districtCode = undefined; params.streetCode = undefined; - } else if (currentMapState.regionCode.length === 6) { + } else if (highFrequencyApi.regionCode.length === 6) { // 区县级别 - params.districtCode = currentMapState.regionCode; - } else if (currentMapState.regionCode.length === 9) { + params.districtCode = highFrequencyApi.regionCode; + } else if (highFrequencyApi.regionCode.length === 9) { // 街道级别 - params.districtCode = currentMapState.regionCode.substring(0, 6); - params.streetCode = currentMapState.regionCode; + params.districtCode = highFrequencyApi.regionCode.substring(0, 6); + params.streetCode = highFrequencyApi.regionCode; } // 使用传入的dataTypeKey获取对应的subTypeCode params.subTypeCode = useDataType(dataTypeKey); return params; - }, [mapStateRef, currentTabRef, dateType, translateDateType, dataTypeKey, pageId]); - - // 使用usePageAwareApi管理高发区域API调用 - const highFrequencyApi = usePageAwareApi({ - apiFunction: async (params) => { - console.log('发起高发区域请求,参数:', params); - const response = await getDistrictHighFrequencyArea(params); - - if (response.code === 200 && response.data) { - return response.data; - } - - throw new Error('获取高发区域数据失败'); - }, - onSuccess: (data) => { - if (!data || !Array.isArray(data) || data.length === 0) { - setData([]); - return; - } - - let isUsingMock = true; - const defaultPercentage = isUsingMock ? 99 : 0; - const defaultValue = isUsingMock ? 200 : 0; - - // 转换接口返回的数据格式为图表需要的格式 - const formattedData = data.map((item: any) => ({ - name: item.name, - percentage: parseFloat(item.percent) || defaultPercentage, - count: parseInt(item.value) || defaultValue - })); - - console.log('高发区域数据成功:'); - setData(formattedData); - }, - onError: (error) => { - console.error('获取高发区域数据出错:', error); - setData([]); - }, - apiName: '高发类型', - debounceTime: 300, - cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 - pageId: pageId, // 传入页面ID用于页面感知 - }); + }, [mapStateRef, currentTabRef, dateType, translateDateType, dataTypeKey, pageId, highFrequencyApi.regionCode]); // 在地图状态变化和Tab变化时加载数据 useEffect(() => { @@ -206,7 +207,7 @@ const HighFrequencyType: React.FC = ({ // 调用API - 现在usePageAwareApi内部会处理参数比较和页面状态 highFrequencyApi.callApi(params); - }, [mapState.regionCode, mapState.rightPanelTime, mapState.pageTimeSettings, currentTab, buildApiParams, highFrequencyApi]); + }, [currentTab, buildApiParams, highFrequencyApi]); return (
diff --git a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/ProgramType/index.tsx b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/ProgramType/index.tsx index bd22115793bb84453273525139d28b1b5a40ff93..604833e3687dd953ee7b7a4575fc8dac0711eb62 100644 --- a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/ProgramType/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/ProgramType/index.tsx @@ -46,61 +46,6 @@ const ProgramType: React.FC = ({ } }, []); - // 构建API请求参数 - const buildApiParams = useCallback(() => { - const currentMapState = mapStateRef.current; - - // 如果没有必要的时间参数,返回null表示不应该发起请求 - if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { - return null; - } - - // 获取当前页面的时间设置 - const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; - if (!pageTimeSettings) { - console.log(`缺少${pageId}页面的时间设置,使用全局设置`); - } - - // 使用页面级别的时间设置,如果存在的话 - const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; - - // 使用当前时间类型,如果不存在则使用props或默认值 - const effectiveType = rightPanelTime.type || dateType || 'month'; - - // 基础参数对象 - const params: any = { - type: translateDateType(effectiveType) - }; - - // 处理日期参数 - if (effectiveType === 'range') { - params.customizeStart = formatDateTime(rightPanelTime.startTime); - params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); - } else { - // 年、月、日视图使用time参数 - params.time = formatDateTime(rightPanelTime.startTime); - } - - // 处理区域参数 - if (currentMapState.regionCode === '5101') { - // 成都,这两个参数就不传 - params.districtCode = undefined; - params.streetCode = undefined; - } else if (currentMapState.regionCode.length === 6) { - // 区县级别 - params.districtCode = currentMapState.regionCode; - } else if (currentMapState.regionCode.length === 9) { - // 街道级别 - params.districtCode = currentMapState.regionCode.substring(0, 6); - params.streetCode = currentMapState.regionCode; - } - - // 使用传入的dataTypeKey获取对应的subTypeCode - params.subTypeCode = useDataType(dataTypeKey); - - return params; - }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId]); - // 使用usePageAwareApi管理问题来源API调用 const sourceSystemRankApi = usePageAwareApi({ apiFunction: async (params: any) => { @@ -159,7 +104,63 @@ const ProgramType: React.FC = ({ cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 enableDebug: false, pageId: pageId, // 添加页面ID以启用页面感知 + panelType: 'right', // 指定为右侧面板 }); + + // 构建API请求参数 + const buildApiParams = useCallback(() => { + const currentMapState = mapStateRef.current; + + // 如果没有必要的时间参数,返回null表示不应该发起请求 + if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { + return null; + } + + // 获取当前页面的时间设置 + const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; + if (!pageTimeSettings) { + console.log(`缺少${pageId}页面的时间设置,使用全局设置`); + } + + // 使用页面级别的时间设置,如果存在的话 + const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; + + // 使用当前时间类型,如果不存在则使用props或默认值 + const effectiveType = rightPanelTime.type || dateType || 'month'; + + // 基础参数对象 + const params: any = { + type: translateDateType(effectiveType) + }; + + // 处理日期参数 + if (effectiveType === 'range') { + params.customizeStart = formatDateTime(rightPanelTime.startTime); + params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); + } else { + // 年、月、日视图使用time参数 + params.time = formatDateTime(rightPanelTime.startTime); + } + + // 处理区域参数 + if (sourceSystemRankApi.regionCode === '5101') { + // 成都,这两个参数就不传 + params.districtCode = undefined; + params.streetCode = undefined; + } else if (sourceSystemRankApi.regionCode.length === 6) { + // 区县级别 + params.districtCode = sourceSystemRankApi.regionCode; + } else if (sourceSystemRankApi.regionCode.length === 9) { + // 街道级别 + params.districtCode = sourceSystemRankApi.regionCode.substring(0, 6); + params.streetCode = sourceSystemRankApi.regionCode; + } + + // 使用传入的dataTypeKey获取对应的subTypeCode + params.subTypeCode = useDataType(dataTypeKey); + + return params; + }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId, sourceSystemRankApi.regionCode]); // 在地图状态变化时加载数据 useEffect(() => { @@ -174,7 +175,7 @@ const ProgramType: React.FC = ({ console.log(`加载${pageId}页面-程序类型数据,参数:`, params); sourceSystemRankApi.callApi(params); - }, [mapState.regionCode, mapState.rightPanelTime, mapState.pageTimeSettings, buildApiParams, sourceSystemRankApi, pageId]); + }, [buildApiParams, sourceSystemRankApi, pageId]); return (
diff --git a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/PunishmentTrend/index.tsx b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/PunishmentTrend/index.tsx index dc60d0aaf4c1647b4d894c20a4e1ff8fc97150f9..a6cedb5bed25fa4578549e3090ee8582b4d4cff4 100644 --- a/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/PunishmentTrend/index.tsx +++ b/src/pages/Home_v_2504/components/SubPages/LawEnforcementPunishment/components/RightContent/PunishmentTrend/index.tsx @@ -86,61 +86,6 @@ const PunishmentTrend: React.FC = ({ return inputDate; }, []); - // 构建API请求参数 - const buildApiParams = useCallback(() => { - const currentMapState = mapStateRef.current; - - // 如果没有必要的时间参数,返回null表示不应该发起请求 - if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { - return null; - } - - // 获取当前页面的时间设置 - const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; - if (!pageTimeSettings) { - console.log(`缺少${pageId}页面的时间设置,使用全局设置`); - } - - // 使用页面级别的时间设置,如果存在的话 - const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; - - // 使用当前时间类型,如果不存在则使用props或默认值 - const effectiveType = rightPanelTime.type || dateType || 'month'; - - // 基础参数对象 - const params: any = { - type: translateDateType(effectiveType) - }; - - // 处理日期参数 - if (effectiveType === 'range') { - params.customizeStart = formatDateTime(rightPanelTime.startTime); - params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); - } else { - // 年、月、日视图使用time参数 - params.time = formatDateTime(rightPanelTime.startTime); - } - - // 处理区域参数 - if (currentMapState.regionCode === '5101') { - // 成都,这两个参数就不传 - params.districtCode = undefined; - params.streetCode = undefined; - } else if (currentMapState.regionCode.length === 6) { - // 区县级别 - params.districtCode = currentMapState.regionCode; - } else if (currentMapState.regionCode.length === 9) { - // 街道级别 - params.districtCode = currentMapState.regionCode.substring(0, 6); - params.streetCode = currentMapState.regionCode; - } - - // 使用传入的dataTypeKey获取对应的subTypeCode - params.subTypeCode = useDataType(dataTypeKey); - - return params; - }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId]); - // 使用usePageAwareApi管理问题趋势API调用 const eventTrendsApi = usePageAwareApi({ apiFunction: async (params: any) => { @@ -221,7 +166,6 @@ const PunishmentTrend: React.FC = ({ }, onError: (error: any) => { console.error('获取问题趋势数据出错:', error); - // 出错时使用空数据 setData([]); }, apiName: '问题趋势', @@ -229,7 +173,63 @@ const PunishmentTrend: React.FC = ({ cacheTime: 5000, // 缓存5秒,避免频繁刷新时重复请求 enableDebug: false, pageId: pageId, // 添加页面ID以启用页面感知 + panelType: 'right', // 指定为右侧面板 }); + + // 构建API请求参数 + const buildApiParams = useCallback(() => { + const currentMapState = mapStateRef.current; + + // 如果没有必要的时间参数,返回null表示不应该发起请求 + if (!currentMapState.rightPanelTime?.startTime || !currentMapState.rightPanelTime?.endTime) { + return null; + } + + // 获取当前页面的时间设置 + const pageTimeSettings = currentMapState.pageTimeSettings?.[pageId]; + if (!pageTimeSettings) { + console.log(`缺少${pageId}页面的时间设置,使用全局设置`); + } + + // 使用页面级别的时间设置,如果存在的话 + const rightPanelTime = pageTimeSettings?.rightPanelTime || currentMapState.rightPanelTime; + + // 使用当前时间类型,如果不存在则使用props或默认值 + const effectiveType = rightPanelTime.type || dateType || 'month'; + + // 基础参数对象 + const params: any = { + type: translateDateType(effectiveType) + }; + + // 处理日期参数 + if (effectiveType === 'range') { + params.customizeStart = formatDateTime(rightPanelTime.startTime); + params.customizeEnd = formatDateTime(rightPanelTime.endTime, true); + } else { + // 年、月、日视图使用time参数 + params.time = formatDateTime(rightPanelTime.startTime); + } + + // 处理区域参数 + if (eventTrendsApi.regionCode === '5101') { + // 成都,这两个参数就不传 + params.districtCode = undefined; + params.streetCode = undefined; + } else if (eventTrendsApi.regionCode.length === 6) { + // 区县级别 + params.districtCode = eventTrendsApi.regionCode; + } else if (eventTrendsApi.regionCode.length === 9) { + // 街道级别 + params.districtCode = eventTrendsApi.regionCode.substring(0, 6); + params.streetCode = eventTrendsApi.regionCode; + } + + // 使用传入的dataTypeKey获取对应的subTypeCode + params.subTypeCode = useDataType(dataTypeKey); + + return params; + }, [mapStateRef, dateType, translateDateType, dataTypeKey, pageId, eventTrendsApi.regionCode]); // 在地图状态变化时加载数据 useEffect(() => { @@ -244,7 +244,7 @@ const PunishmentTrend: React.FC = ({ console.log(`加载${pageId}页面问题趋势数据,参数:`, params); eventTrendsApi.callApi(params); - }, [mapState.regionCode, mapState.rightPanelTime, mapState.pageTimeSettings, buildApiParams, eventTrendsApi, pageId]); + }, [buildApiParams, eventTrendsApi, pageId]); const chartStyle = useMemo(() => ({ height: isThinLayout ? '278px' : '178px',