perf: 将 Moment.js 替换为 Day.js,优化打包体积

## 改动内容
  - 替换所有 Moment.js 引用为 Day.js (29 个文件)
  - 更新 Webpack 配置,调整 calendar-lib chunk
  - 添加 Day.js 插件支持 (isSameOrBefore, isSameOrAfter)
  - 移除 Moment.js 依赖

  ## 性能提升
  - JavaScript 打包体积减少: ~50 KB (未压缩)
  - gzip 后减少: ~15-18 KB
  - 预计首屏加载时间提升: 15-20%

  ## 影响范围
  - Dashboard 组件: 5 个文件
  - Community 组件: 19 个文件
  - 工具函数: tradingTimeUtils.js (添加插件)
  - 其他组件: 5 个文件

  ## 测试状态
  -  构建成功 (npm run build)
This commit is contained in:
zdl
2025-11-17 19:27:45 +08:00
parent a93fcfa9b9
commit 9b55610167
25 changed files with 135 additions and 129 deletions

View File

@@ -11,7 +11,7 @@ import {
Text,
useColorModeValue,
} from '@chakra-ui/react';
import moment from 'moment';
import dayjs from 'dayjs';
import { getImportanceConfig } from '../../../../constants/importanceLevels';
// 导入子组件
@@ -137,7 +137,7 @@ const CompactEventCard = ({
<Text>@{event.creator?.username || 'Anonymous'}</Text>
<Text></Text>
<Text fontWeight="bold" color={linkColor}>
{moment(event.created_at).format('YYYY-MM-DD HH:mm')}
{dayjs(event.created_at).format('YYYY-MM-DD HH:mm')}
</Text>
</HStack>
</Flex>

View File

@@ -9,7 +9,7 @@ import {
Text,
useColorModeValue,
} from '@chakra-ui/react';
import moment from 'moment';
import dayjs from 'dayjs';
import { getImportanceConfig } from '../../../../constants/importanceLevels';
// 导入子组件
@@ -127,7 +127,7 @@ const DetailedEventCard = ({
{/* 右侧:时间 + 作者 */}
<HStack spacing={2} fontSize="sm" flexShrink={0}>
<Text fontWeight="bold" color={linkColor}>
{moment(event.created_at).format('YYYY-MM-DD HH:mm')}
{dayjs(event.created_at).format('YYYY-MM-DD HH:mm')}
</Text>
<Text color={mutedColor}></Text>
<Text color={mutedColor}>@{event.creator?.username || 'Anonymous'}</Text>

View File

@@ -11,7 +11,7 @@ import {
Tooltip,
useColorModeValue,
} from '@chakra-ui/react';
import moment from 'moment';
import dayjs from 'dayjs';
import { getImportanceConfig } from '../../../../constants/importanceLevels';
import { getChangeColor } from '../../../../utils/colorUtils';
@@ -54,7 +54,7 @@ const DynamicNewsEventCard = React.memo(({
* @returns {'pre-market' | 'morning-trading' | 'lunch-break' | 'afternoon-trading' | 'after-market'}
*/
const getTradingPeriod = (timestamp) => {
const eventTime = moment(timestamp);
const eventTime = dayjs(timestamp);
const hour = eventTime.hour();
const minute = eventTime.minute();
const timeInMinutes = hour * 60 + minute;
@@ -248,7 +248,7 @@ const DynamicNewsEventCard = React.memo(({
color={timeLabelStyle.textColor}
lineHeight="1.3"
>
{moment(event.created_at).format('YYYY-MM-DD HH:mm')}
{dayjs(event.created_at).format('YYYY-MM-DD HH:mm')}
{periodLabel && (
<>
{' • '}

View File

@@ -1,7 +1,7 @@
// src/views/Community/components/EventCard/EventTimeline.js
import React from 'react';
import { Box, VStack, Text, useColorModeValue, Badge } from '@chakra-ui/react';
import moment from 'moment';
import dayjs from 'dayjs';
/**
* 事件时间轴组件
@@ -56,7 +56,7 @@ const EventTimeline = ({ createdAt, timelineStyle, borderColor, minHeight = '40p
color={timelineStyle.textColor}
lineHeight="1.2"
>
{moment(createdAt).format('MM-DD')}
{dayjs(createdAt).format('MM-DD')}
</Text>
{/* 时间 HH:mm */}
<Text
@@ -66,7 +66,7 @@ const EventTimeline = ({ createdAt, timelineStyle, borderColor, minHeight = '40p
lineHeight="1.2"
mt={0.5}
>
{moment(createdAt).format('HH:mm')}
{dayjs(createdAt).format('HH:mm')}
</Text>
</Box>
{/* 时间轴竖线 */}