- 从 CompanyOverview/ 移动到 DynamicTracking/(修复跨目录引用) - 拆分为目录结构:constants.ts, types.ts, utils.ts - 提取 5 个子组件:NewsSearchBar, NewsEventCard, NewsPagination, NewsEmptyState, NewsLoadingState - 转换为 TypeScript,添加完整类型定义(ThemeConfig, NewsEvent 等) - 所有子组件使用 React.memo 优化渲染 - 更新 NewsPanel.js 引用路径 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
102 lines
2.4 KiB
TypeScript
102 lines
2.4 KiB
TypeScript
// src/views/Company/components/DynamicTracking/NewsEventsTab/utils.ts
|
|
// 新闻动态 - 工具函数
|
|
|
|
import type { IconType } from 'react-icons';
|
|
import {
|
|
FaNewspaper,
|
|
FaBullhorn,
|
|
FaGavel,
|
|
FaFlask,
|
|
FaDollarSign,
|
|
FaShieldAlt,
|
|
FaFileAlt,
|
|
FaIndustry,
|
|
} from 'react-icons/fa';
|
|
import type { ThemeConfig, BadgeStyle } from './types';
|
|
|
|
/**
|
|
* 事件类型图标映射
|
|
*/
|
|
const EVENT_TYPE_ICONS: Record<string, IconType> = {
|
|
企业公告: FaBullhorn,
|
|
政策: FaGavel,
|
|
技术突破: FaFlask,
|
|
企业融资: FaDollarSign,
|
|
政策监管: FaShieldAlt,
|
|
政策动态: FaFileAlt,
|
|
行业事件: FaIndustry,
|
|
};
|
|
|
|
/**
|
|
* 获取事件类型对应的图标
|
|
*/
|
|
export const getEventTypeIcon = (eventType?: string): IconType => {
|
|
if (!eventType) return FaNewspaper;
|
|
return EVENT_TYPE_ICONS[eventType] || FaNewspaper;
|
|
};
|
|
|
|
/**
|
|
* 获取重要性徽章样式
|
|
*/
|
|
export const getImportanceBadgeStyle = (
|
|
importance: string | undefined,
|
|
theme: ThemeConfig,
|
|
isBlackGold: boolean
|
|
): BadgeStyle => {
|
|
if (isBlackGold) {
|
|
const styles: Record<string, BadgeStyle> = {
|
|
S: theme.badgeS,
|
|
A: theme.badgeA,
|
|
B: theme.badgeB,
|
|
C: theme.badgeC,
|
|
};
|
|
return styles[importance || ''] || { bg: 'rgba(107, 114, 128, 0.2)', color: '#9CA3AF' };
|
|
}
|
|
|
|
// 默认主题使用 colorScheme
|
|
const colorMap: Record<string, string> = {
|
|
S: 'red',
|
|
A: 'orange',
|
|
B: 'yellow',
|
|
C: 'green',
|
|
};
|
|
return { colorScheme: colorMap[importance || ''] || 'gray', bg: '', color: '' };
|
|
};
|
|
|
|
/**
|
|
* 格式化日期
|
|
*/
|
|
export const formatDate = (dateStr?: string): string => {
|
|
if (!dateStr) return '';
|
|
return new Date(dateStr).toLocaleDateString('zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 格式化涨跌幅
|
|
*/
|
|
export const formatChange = (value: number | null | undefined): string => {
|
|
if (value === null || value === undefined) return '-';
|
|
const prefix = value > 0 ? '+' : '';
|
|
return `${prefix}${value.toFixed(2)}%`;
|
|
};
|
|
|
|
/**
|
|
* 获取涨跌幅颜色
|
|
*/
|
|
export const getChangeColor = (value: number | null | undefined): string => {
|
|
if (value === null || value === undefined) return '#9CA3AF';
|
|
return value > 0 ? '#EF4444' : '#10B981';
|
|
};
|
|
|
|
/**
|
|
* 提取关键词显示文本
|
|
*/
|
|
export const getKeywordText = (keyword: string | { concept?: string; name?: string }): string => {
|
|
if (typeof keyword === 'string') return keyword;
|
|
return keyword?.concept || keyword?.name || '未知';
|
|
};
|