- GlobalSidebar: JS 转换为 TypeScript,添加完整类型定义 - HotConceptsPanel 拆分为模块化目录结构: - types.ts: 类型定义 (Concept, ConceptStock, Props) - styles.ts: 样式常量 + 配置 (COLORS, CONFIG) - utils.ts: 工具函数 (formatChangePercent, getChangeColor) - hooks/useHotConcepts.ts: 数据获取 Hook - components/ConceptCard.tsx: 概念卡片原子组件 (memo 优化) - 性能优化:useMemo 缓存计算,useCallback 缓存事件处理 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
26 lines
683 B
TypeScript
26 lines
683 B
TypeScript
/**
|
|
* HotConceptsPanel 工具函数
|
|
*/
|
|
import { COLORS } from './styles';
|
|
|
|
/**
|
|
* 格式化涨跌幅显示
|
|
* 复用自 src/views/Company/components/StockQuoteCard/components/formatters.ts
|
|
*/
|
|
export const formatChangePercent = (value: number | null | undefined): string => {
|
|
if (value == null) return '--';
|
|
const sign = value >= 0 ? '+' : '';
|
|
return `${sign}${value.toFixed(2)}%`;
|
|
};
|
|
|
|
/**
|
|
* 获取涨跌颜色
|
|
* 简化版本,深色主题专用
|
|
*/
|
|
export const getChangeColor = (value: number | null | undefined): string => {
|
|
if (value == null) return COLORS.neutral;
|
|
if (value > 0) return COLORS.up;
|
|
if (value < 0) return COLORS.down;
|
|
return COLORS.neutral;
|
|
};
|