feat: LimitAnalyse 和 Community 页面共享同一数据源
This commit is contained in:
@@ -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([]);
|
||||
|
||||
Reference in New Issue
Block a user