- 删除旧的 BasicInfoTab.js (~1000行) - 新建 BasicInfoTab/ 目录,拆分为 10 个 TypeScript 文件: - index.tsx: 主组件(可配置 Tab) - config.ts: Tab 配置 + 黑金主题 - utils.ts: 格式化工具函数 - components/: 5 个面板组件 + LoadingState - 主组件支持 enabledTabs、defaultTabIndex、onTabChange - 应用黑金主题,支持懒加载 (isLazy) - 更新 types.ts 添加 ActualControl、Concentration 等类型字段 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
// src/views/Company/components/CompanyOverview/BasicInfoTab/utils.ts
|
|
// 格式化工具函数
|
|
|
|
/**
|
|
* 格式化百分比
|
|
*/
|
|
export const formatPercentage = (value: number | null | undefined): string => {
|
|
if (value === null || value === undefined) return "-";
|
|
return `${(value * 100).toFixed(2)}%`;
|
|
};
|
|
|
|
/**
|
|
* 格式化数字(自动转换亿/万)
|
|
*/
|
|
export const formatNumber = (value: number | null | undefined): string => {
|
|
if (value === null || value === undefined) return "-";
|
|
if (value >= 100000000) {
|
|
return `${(value / 100000000).toFixed(2)}亿`;
|
|
} else if (value >= 10000) {
|
|
return `${(value / 10000).toFixed(2)}万`;
|
|
}
|
|
return value.toLocaleString();
|
|
};
|
|
|
|
/**
|
|
* 格式化股数(自动转换亿股/万股)
|
|
*/
|
|
export const formatShares = (value: number | null | undefined): string => {
|
|
if (value === null || value === undefined) return "-";
|
|
if (value >= 100000000) {
|
|
return `${(value / 100000000).toFixed(2)}亿股`;
|
|
} else if (value >= 10000) {
|
|
return `${(value / 10000).toFixed(2)}万股`;
|
|
}
|
|
return `${value.toLocaleString()}股`;
|
|
};
|
|
|
|
/**
|
|
* 格式化日期(去掉时间部分)
|
|
*/
|
|
export const formatDate = (dateStr: string | null | undefined): string => {
|
|
if (!dateStr) return "-";
|
|
return dateStr.split("T")[0];
|
|
};
|
|
|
|
// 导出工具对象(兼容旧代码)
|
|
export const formatUtils = {
|
|
formatPercentage,
|
|
formatNumber,
|
|
formatShares,
|
|
formatDate,
|
|
};
|