diff --git a/src/views/Community/components/SearchFilters/CompactSearchBox.js b/src/views/Community/components/SearchFilters/CompactSearchBox.js index d6b6016b..a7f20ea0 100644 --- a/src/views/Community/components/SearchFilters/CompactSearchBox.js +++ b/src/views/Community/components/SearchFilters/CompactSearchBox.js @@ -163,13 +163,20 @@ const CompactSearchBox = ({ stockDisplayValueRef.current = null; } - const hasTimeInFilters = filters.start_date || filters.end_date || filters.recent_days; + const hasTimeInFilters = filters.start_date || filters.end_date || filters.recent_days || filters.time_filter_key; if (hasTimeInFilters && (!tradingTimeRange || !tradingTimeRange.key)) { - let inferredKey = 'custom'; + // 优先使用 time_filter_key(来自 useEventFilters 的默认值) + let inferredKey = filters.time_filter_key || 'custom'; let inferredLabel = ''; - if (filters.recent_days) { + if (filters.time_filter_key === 'current-trading-day') { + inferredKey = 'current-trading-day'; + inferredLabel = '当前交易日'; + } else if (filters.time_filter_key === 'all') { + inferredKey = 'all'; + inferredLabel = '全部'; + } else if (filters.recent_days) { if (filters.recent_days === '7') { inferredKey = 'week'; inferredLabel = '近一周'; @@ -377,7 +384,12 @@ const CompactSearchBox = ({ const { range, type, label, key } = timeConfig; let params = {}; - if (type === 'recent_days') { + if (type === 'all') { + // "全部"按钮:清除所有时间限制 + params.start_date = ''; + params.end_date = ''; + params.recent_days = ''; + } else if (type === 'recent_days') { params.recent_days = range; params.start_date = ''; params.end_date = ''; diff --git a/src/views/Community/components/SearchFilters/TradingTimeFilter.js b/src/views/Community/components/SearchFilters/TradingTimeFilter.js index c4b6e4fc..81728152 100644 --- a/src/views/Community/components/SearchFilters/TradingTimeFilter.js +++ b/src/views/Community/components/SearchFilters/TradingTimeFilter.js @@ -7,6 +7,7 @@ import dayjs from 'dayjs'; import locale from 'antd/es/date-picker/locale/zh_CN'; import { logger } from '@utils/logger'; import { PROFESSIONAL_COLORS } from '@constants/professionalTheme'; +import tradingDayUtils from '@utils/tradingDayUtils'; const { RangePicker } = DatePicker; @@ -83,28 +84,10 @@ const TradingTimeFilter = ({ value, onChange, compact = false, mobile = false }) const yesterdayEnd = now.subtract(1, 'day').endOf('day'); // 动态按钮配置(根据时段返回不同按钮数组) + // 注意:"当前交易日"已在固定按钮中,这里只放特定时段的快捷按钮 const dynamicButtonsMap = { - 'pre-market': [ - { - key: 'latest', - label: '最新', - range: [yesterday1500, today0930], - tooltip: '盘前资讯', - timeHint: `昨日 15:00 - 今日 09:30`, - color: 'purple', - type: 'precise' - } - ], + 'pre-market': [], // 盘前:使用"当前交易日"即可 'morning': [ - { - key: 'latest', - label: '最新', - range: [today0930, now], - tooltip: '早盘最新', - timeHint: `今日 09:30 - ${now.format('HH:mm')}`, - color: 'green', - type: 'precise' - }, { key: 'intraday', label: '盘中', @@ -115,27 +98,8 @@ const TradingTimeFilter = ({ value, onChange, compact = false, mobile = false }) type: 'precise' } ], - 'lunch': [ - { - key: 'latest', - label: '最新', - range: [today1130, now], - tooltip: '午休时段', - timeHint: `今日 11:30 - ${now.format('HH:mm')}`, - color: 'orange', - type: 'precise' - } - ], + 'lunch': [], // 午休:使用"当前交易日"即可 'afternoon': [ - { - key: 'latest', - label: '最新', - range: [today1300, now], - tooltip: '午盘最新', - timeHint: `今日 13:00 - ${now.format('HH:mm')}`, - color: 'green', - type: 'precise' - }, { key: 'intraday', label: '盘中', @@ -155,21 +119,35 @@ const TradingTimeFilter = ({ value, onChange, compact = false, mobile = false }) type: 'precise' } ], - 'after-hours': [ - { - key: 'latest', - label: '最新', - range: [today1500, now], - tooltip: '盘后最新', - timeHint: `今日 15:00 - ${now.format('HH:mm')}`, - color: 'red', - type: 'precise' - } - ] + 'after-hours': [] // 盘后:使用"当前交易日"即可 }; + // 获取上一个交易日(使用 tdays.csv 数据) + const getPrevTradingDay = () => { + try { + const prevTradingDay = tradingDayUtils.getPreviousTradingDay(now.toDate()); + return dayjs(prevTradingDay); + } catch (e) { + // 降级:简单地减一天(不考虑周末节假日) + logger.warn('TradingTimeFilter', '获取上一交易日失败,降级处理', e); + return now.subtract(1, 'day'); + } + }; + + const prevTradingDay = getPrevTradingDay(); + const prevTradingDay1500 = prevTradingDay.hour(15).minute(0).second(0); + // 固定按钮配置(始终显示) const fixedButtons = [ + { + key: 'current-trading-day', + label: '当前交易日', + range: [prevTradingDay1500, now], + tooltip: '当前交易日事件', + timeHint: `${prevTradingDay.format('MM-DD')} 15:00 - 现在`, + color: 'green', + type: 'precise' + }, { key: 'morning-fixed', label: '早盘', @@ -214,6 +192,15 @@ const TradingTimeFilter = ({ value, onChange, compact = false, mobile = false }) timeHint: '过去30天', color: 'volcano', type: 'recent_days' + }, + { + key: 'all', + label: '全部', + range: null, // 无时间限制 + tooltip: '显示全部事件', + timeHint: '不限时间', + color: 'default', + type: 'all' } ]; diff --git a/src/views/Community/hooks/useEventFilters.js b/src/views/Community/hooks/useEventFilters.js index 9113d755..5654eaf5 100644 --- a/src/views/Community/hooks/useEventFilters.js +++ b/src/views/Community/hooks/useEventFilters.js @@ -7,6 +7,8 @@ import { logger } from '../../../utils/logger'; import { usePostHogTrack } from '../../../hooks/usePostHogRedux'; import { RETENTION_EVENTS } from '../../../lib/constants'; import { getEventDetailUrl } from '@/utils/idEncoder'; +import tradingDayUtils from '@utils/tradingDayUtils'; +import dayjs from 'dayjs'; /** * 事件筛选逻辑 Hook @@ -22,16 +24,43 @@ export const useEventFilters = ({ navigate, onEventClick, eventTimelineRef } = { // 筛选参数状态 - 初始化时从URL读取,之后只用本地状态 const [filters, setFilters] = useState(() => { + // 计算当前交易日的默认时间范围 + const getDefaultTimeRange = () => { + try { + const now = dayjs(); + const prevTradingDay = tradingDayUtils.getPreviousTradingDay(now.toDate()); + const prevTradingDay1500 = dayjs(prevTradingDay).hour(15).minute(0).second(0); + return { + start_date: prevTradingDay1500.format('YYYY-MM-DD HH:mm:ss'), + end_date: now.format('YYYY-MM-DD HH:mm:ss'), + recent_days: '', // 使用精确时间范围,不使用 recent_days + time_filter_key: 'current-trading-day' // 标记当前选中的时间按钮 + }; + } catch (e) { + // 降级:使用近一周 + logger.warn('useEventFilters', '获取上一交易日失败,降级为近一周', e); + return { + start_date: '', + end_date: '', + recent_days: '7', + time_filter_key: 'week' + }; + } + }; + + const defaultTimeRange = getDefaultTimeRange(); + return { sort: searchParams.get('sort') || 'new', importance: searchParams.get('importance') || 'all', q: searchParams.get('q') || '', industry_code: searchParams.get('industry_code') || '', // 时间筛选参数(从 TradingTimeFilter 传递) - // 默认显示近一周数据(recent_days=7) - start_date: searchParams.get('start_date') || '', - end_date: searchParams.get('end_date') || '', - recent_days: searchParams.get('recent_days') || '7', // 默认近一周 + // 默认显示当前交易日数据(上一交易日15:00 - 现在) + start_date: searchParams.get('start_date') || defaultTimeRange.start_date, + end_date: searchParams.get('end_date') || defaultTimeRange.end_date, + recent_days: searchParams.get('recent_days') || defaultTimeRange.recent_days, + time_filter_key: searchParams.get('time_filter_key') || defaultTimeRange.time_filter_key, page: parseInt(searchParams.get('page') || '1', 10) }; });