From 734f7b457411a2d83adfe195b0a9401f8ed2a780 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Fri, 16 Jan 2026 15:58:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20LimitAnalyse=20=E5=92=8C=20Community?= =?UTF-8?q?=20=E9=A1=B5=E9=9D=A2=E5=85=B1=E4=BA=AB=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/LimitAnalyse/index.tsx | 57 ++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/views/LimitAnalyse/index.tsx b/src/views/LimitAnalyse/index.tsx index 802efd7c..543caa9d 100644 --- a/src/views/LimitAnalyse/index.tsx +++ b/src/views/LimitAnalyse/index.tsx @@ -15,6 +15,7 @@ import { SearchResultsModal } from './components/SearchComponents'; import MarketPanorama from './components/MarketPanorama'; import type { SortedSector, SectorInfo } from './components/MarketPanorama/types'; import { logger } from '../../utils/logger'; +import { getApiBase } from '@utils/apiConfig'; import { useLimitAnalyseEvents } from './hooks/useLimitAnalyseEvents'; // ============ 事件追踪 Hook 类型 ============ @@ -73,20 +74,54 @@ const LimitAnalyse: React.FC = () => { return `${year}${month}${day}`; }, []); - // 使用静态数据服务获取数据 + // YYYYMMDD → YYYY-MM-DD(用于 FullCalendar) + const formatDateToISO = (dateStr: string): string => { + return `${dateStr.slice(0, 4)}-${dateStr.slice(4, 6)}-${dateStr.slice(6, 8)}`; + }; + + // 从 combined-data API 获取日历数据(与 Community 共享数据源) const fetchAvailableDates = useCallback(async () => { try { - const data = await ztStaticService.fetchAvailableDates(); - if (data.success) { - setAvailableDates(data.events || []); - logger.debug('LimitAnalyse', '可用日期加载成功(静态文件)', { - count: data.events?.length || 0, - }); - } else { - // 请求成功但返回失败,设置空数组 - setAvailableDates([]); - logger.warn('LimitAnalyse', '日期列表返回失败', { error: data.error }); + const now = new Date(); + const allDates: DateEvent[] = []; + + // 获取最近 3 个月的数据 + for (let i = 0; i < 3; i++) { + const targetDate = new Date(now.getFullYear(), now.getMonth() - i, 1); + const year = targetDate.getFullYear(); + const month = targetDate.getMonth() + 1; + + const response = await fetch( + `${getApiBase()}/api/v1/calendar/combined-data?year=${year}&month=${month}` + ); + + if (response.ok) { + const result = await response.json(); + if (result.success && result.data) { + // 转换数据格式:zt_count → count + const events: DateEvent[] = result.data + .filter((item: { zt_count?: number }) => item.zt_count && item.zt_count > 0) + .map((item: { date: string; zt_count: number; top_sector?: string }) => ({ + date: item.date, + count: item.zt_count, + top_sector: item.top_sector || '', + fail_rate: null as number | null, + // FullCalendar 需要的字段 + title: `${item.zt_count}只`, + start: formatDateToISO(item.date), + end: formatDateToISO(item.date), + className: 'bg-gradient-primary', + allDay: true, + })); + allDates.push(...events); + } + } } + + setAvailableDates(allDates); + logger.debug('LimitAnalyse', '可用日期加载成功(combined-data API)', { + count: allDates.length, + }); } catch (error) { // 请求失败,设置空数组避免一直 loading setAvailableDates([]);