From 82cb0b40349274d93af841e129c38928ee0e642e Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Mon, 3 Nov 2025 18:26:59 +0800 Subject: [PATCH] feat: bugfix --- .../RelatedConceptsSection/index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js index 33c6ebb6..f0f80c5e 100644 --- a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js +++ b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js @@ -71,15 +71,19 @@ const RelatedConceptsSection = ({ eventTitle, effectiveTradingDate, eventTime }) setLoading(true); setError(null); - // 格式化交易日期 + // 格式化交易日期 - 统一使用 moment 处理 let formattedTradeDate; - if (typeof effectiveTradingDate === 'string') { - formattedTradeDate = effectiveTradingDate; - } else if (effectiveTradingDate instanceof Date) { + try { + // 不管传入的是什么格式,都用 moment 解析并格式化为 YYYY-MM-DD formattedTradeDate = moment(effectiveTradingDate).format('YYYY-MM-DD'); - } else if (moment.isMoment(effectiveTradingDate)) { - formattedTradeDate = effectiveTradingDate.format('YYYY-MM-DD'); - } else { + + // 验证日期是否有效 + if (!moment(formattedTradeDate, 'YYYY-MM-DD', true).isValid()) { + console.warn('[RelatedConceptsSection] 无效日期,使用当前日期'); + formattedTradeDate = moment().format('YYYY-MM-DD'); + } + } catch (error) { + console.warn('[RelatedConceptsSection] 日期格式化失败,使用当前日期', error); formattedTradeDate = moment().format('YYYY-MM-DD'); }