Compare commits
39 Commits
bc6d370f55
...
feature_20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a446f71c04 | ||
|
|
e02cbcd9b7 | ||
|
|
9bb9eab922 | ||
|
|
3d7b0045b7 | ||
|
|
ada9f6e778 | ||
|
|
07aebbece5 | ||
|
|
7a11800cba | ||
|
|
3b352be1a8 | ||
|
|
c49dee72eb | ||
|
|
7159e510a6 | ||
|
|
385d452f5a | ||
|
|
bdc823e122 | ||
|
|
c83d239219 | ||
|
|
c4900bd280 | ||
|
|
7736212235 | ||
|
|
348d8a0ec3 | ||
|
|
5a0d6e1569 | ||
|
|
bc2b6ae41c | ||
|
|
ac7e627b2d | ||
|
|
21e83ac1bc | ||
|
|
e2dd9e2648 | ||
|
|
f2463922f3 | ||
|
|
9aaad00f87 | ||
|
|
024126025d | ||
|
|
e2f9f3278f | ||
|
|
2d03c88f43 | ||
|
|
515b538c84 | ||
|
|
b52b54347d | ||
|
|
4954373b5b | ||
|
|
66cd6c3a29 | ||
|
|
ba99f55b16 | ||
|
|
2f69f83d16 | ||
|
|
3bd48e1ddd | ||
|
|
84914b3cca | ||
|
|
da455946a3 | ||
|
|
e734319ec4 | ||
|
|
faf2446203 | ||
|
|
83b24b6d54 | ||
|
|
ab7164681a |
110
.husky/pre-commit
Executable file
110
.husky/pre-commit
Executable file
@@ -0,0 +1,110 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Git Pre-commit Hook
|
||||||
|
# ============================================
|
||||||
|
# 规则:
|
||||||
|
# 1. src 目录下新增的代码文件必须使用 TypeScript (.ts/.tsx)
|
||||||
|
# 2. 修改的代码不能使用 fetch,应使用 axios
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
# 颜色定义
|
||||||
|
RED='\033[0;31m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
has_error=0
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "🔍 正在检查代码规范..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 规则 1: 新文件必须使用 TypeScript
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
# 获取新增的文件(只检查 src 目录下的代码文件)
|
||||||
|
new_js_files=$(git diff --cached --name-only --diff-filter=A | grep -E '^src/.*\.(js|jsx)$' || true)
|
||||||
|
|
||||||
|
if [ -n "$new_js_files" ]; then
|
||||||
|
echo "${RED}❌ 错误: 发现新增的 JavaScript 文件${NC}"
|
||||||
|
echo "${YELLOW} 新文件必须使用 TypeScript (.ts/.tsx)${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " 以下文件需要改为 TypeScript:"
|
||||||
|
echo "$new_js_files" | while read file; do
|
||||||
|
echo " - $file"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo " 💡 提示: 请将文件扩展名改为 .ts 或 .tsx"
|
||||||
|
echo ""
|
||||||
|
has_error=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 规则 2: 禁止使用 fetch,应使用 axios
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
# 获取所有暂存的文件(新增 + 修改)
|
||||||
|
staged_files=$(git diff --cached --name-only --diff-filter=AM | grep -E '^src/.*\.(js|jsx|ts|tsx)$' || true)
|
||||||
|
|
||||||
|
if [ -n "$staged_files" ]; then
|
||||||
|
# 检查暂存内容中是否包含 fetch 调用
|
||||||
|
# 使用 git diff --cached 检查实际修改的内容
|
||||||
|
fetch_found=""
|
||||||
|
|
||||||
|
for file in $staged_files; do
|
||||||
|
# 检查该文件暂存的更改中是否有 fetch 调用
|
||||||
|
# 排除注释和字符串中的 fetch
|
||||||
|
# 匹配: fetch(, await fetch, .fetch(
|
||||||
|
fetch_matches=$(git diff --cached -U0 "$file" 2>/dev/null | grep -E '^\+.*[^a-zA-Z_]fetch\s*\(' | grep -v '^\+\s*//' || true)
|
||||||
|
|
||||||
|
if [ -n "$fetch_matches" ]; then
|
||||||
|
fetch_found="$fetch_found
|
||||||
|
$file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$fetch_found" ]; then
|
||||||
|
echo "${RED}❌ 错误: 检测到使用了 fetch API${NC}"
|
||||||
|
echo "${YELLOW} 请使用 axios 进行 HTTP 请求${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " 以下文件包含 fetch 调用:"
|
||||||
|
echo "$fetch_found" | while read file; do
|
||||||
|
if [ -n "$file" ]; then
|
||||||
|
echo " - $file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo " 💡 修改建议:"
|
||||||
|
echo " ${GREEN}// 替换前${NC}"
|
||||||
|
echo " fetch('/api/data').then(res => res.json())"
|
||||||
|
echo ""
|
||||||
|
echo " ${GREEN}// 替换后${NC}"
|
||||||
|
echo " import axios from 'axios';"
|
||||||
|
echo " axios.get('/api/data').then(res => res.data)"
|
||||||
|
echo ""
|
||||||
|
has_error=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 检查结果
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
if [ $has_error -eq 1 ]; then
|
||||||
|
echo "${RED}========================================${NC}"
|
||||||
|
echo "${RED}提交被阻止,请修复以上问题后重试${NC}"
|
||||||
|
echo "${RED}========================================${NC}"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${GREEN}✅ 代码规范检查通过${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 运行 lint-staged(如果配置了)
|
||||||
|
# 可选:在 package.json 中添加 "lint-staged" 配置来启用代码格式化
|
||||||
|
# if [ -f "package.json" ] && grep -q '"lint-staged"' package.json; then
|
||||||
|
# npx lint-staged
|
||||||
|
# fi
|
||||||
@@ -131,12 +131,14 @@
|
|||||||
"eslint-plugin-prettier": "3.4.0",
|
"eslint-plugin-prettier": "3.4.0",
|
||||||
"gulp": "4.0.2",
|
"gulp": "4.0.2",
|
||||||
"gulp-append-prepend": "1.0.9",
|
"gulp-append-prepend": "1.0.9",
|
||||||
|
"husky": "^9.1.7",
|
||||||
"imagemin": "^9.0.1",
|
"imagemin": "^9.0.1",
|
||||||
"imagemin-mozjpeg": "^10.0.0",
|
"imagemin-mozjpeg": "^10.0.0",
|
||||||
"imagemin-pngquant": "^10.0.0",
|
"imagemin-pngquant": "^10.0.0",
|
||||||
"kill-port": "^2.0.1",
|
"kill-port": "^2.0.1",
|
||||||
"less": "^4.4.2",
|
"less": "^4.4.2",
|
||||||
"less-loader": "^12.3.0",
|
"less-loader": "^12.3.0",
|
||||||
|
"lint-staged": "^16.2.7",
|
||||||
"msw": "^2.11.5",
|
"msw": "^2.11.5",
|
||||||
"prettier": "2.2.1",
|
"prettier": "2.2.1",
|
||||||
"react-error-overlay": "6.0.9",
|
"react-error-overlay": "6.0.9",
|
||||||
|
|||||||
@@ -118,6 +118,11 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
|
|||||||
// 当前索引
|
// 当前索引
|
||||||
const currentIndex = controlledIndex ?? internalIndex;
|
const currentIndex = controlledIndex ?? internalIndex;
|
||||||
|
|
||||||
|
// 记录已访问的 Tab 索引(用于真正的懒加载)
|
||||||
|
const [visitedTabs, setVisitedTabs] = useState<Set<number>>(
|
||||||
|
() => new Set([controlledIndex ?? defaultIndex])
|
||||||
|
);
|
||||||
|
|
||||||
// 合并主题
|
// 合并主题
|
||||||
const theme: SubTabTheme = {
|
const theme: SubTabTheme = {
|
||||||
...THEME_PRESETS[themePreset],
|
...THEME_PRESETS[themePreset],
|
||||||
@@ -132,6 +137,12 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
|
|||||||
const tabKey = tabs[newIndex]?.key || '';
|
const tabKey = tabs[newIndex]?.key || '';
|
||||||
onTabChange?.(newIndex, tabKey);
|
onTabChange?.(newIndex, tabKey);
|
||||||
|
|
||||||
|
// 记录已访问的 Tab(用于懒加载)
|
||||||
|
setVisitedTabs(prev => {
|
||||||
|
if (prev.has(newIndex)) return prev;
|
||||||
|
return new Set(prev).add(newIndex);
|
||||||
|
});
|
||||||
|
|
||||||
if (controlledIndex === undefined) {
|
if (controlledIndex === undefined) {
|
||||||
setInternalIndex(newIndex);
|
setInternalIndex(newIndex);
|
||||||
}
|
}
|
||||||
@@ -197,11 +208,16 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
|
|||||||
</TabList>
|
</TabList>
|
||||||
|
|
||||||
<TabPanels p={contentPadding}>
|
<TabPanels p={contentPadding}>
|
||||||
{tabs.map((tab) => {
|
{tabs.map((tab, idx) => {
|
||||||
const Component = tab.component;
|
const Component = tab.component;
|
||||||
|
// 懒加载:只渲染已访问过的 Tab
|
||||||
|
const shouldRender = !isLazy || visitedTabs.has(idx);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabPanel key={tab.key} p={0}>
|
<TabPanel key={tab.key} p={0}>
|
||||||
{Component ? <Component {...componentProps} /> : null}
|
{shouldRender && Component ? (
|
||||||
|
<Component {...componentProps} />
|
||||||
|
) : null}
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -661,6 +661,12 @@ export const NotificationProvider = ({ children }) => {
|
|||||||
|
|
||||||
// ========== 连接到 Socket 服务(⚡ 异步初始化,不阻塞首屏) ==========
|
// ========== 连接到 Socket 服务(⚡ 异步初始化,不阻塞首屏) ==========
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// ⚡ Mock 模式下跳过 Socket 连接(避免连接生产服务器失败的错误)
|
||||||
|
if (process.env.REACT_APP_ENABLE_MOCK === 'true') {
|
||||||
|
logger.debug('NotificationContext', 'Mock 模式,跳过 Socket 连接');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ⚡ 防止 React Strict Mode 导致的重复初始化
|
// ⚡ 防止 React Strict Mode 导致的重复初始化
|
||||||
if (socketInitialized) {
|
if (socketInitialized) {
|
||||||
logger.debug('NotificationContext', 'Socket 已初始化,跳过重复执行(Strict Mode 保护)');
|
logger.debug('NotificationContext', 'Socket 已初始化,跳过重复执行(Strict Mode 保护)');
|
||||||
|
|||||||
11
src/index.js
11
src/index.js
@@ -5,6 +5,17 @@ import { BrowserRouter as Router } from 'react-router-dom';
|
|||||||
|
|
||||||
// ⚡ 性能监控:在应用启动时尽早标记
|
// ⚡ 性能监控:在应用启动时尽早标记
|
||||||
import { performanceMonitor } from './utils/performanceMonitor';
|
import { performanceMonitor } from './utils/performanceMonitor';
|
||||||
|
|
||||||
|
// T0: HTML 加载完成时间点
|
||||||
|
if (document.readyState === 'complete') {
|
||||||
|
performanceMonitor.mark('html-loaded');
|
||||||
|
} else {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
performanceMonitor.mark('html-loaded');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// T1: React 开始初始化
|
||||||
performanceMonitor.mark('app-start');
|
performanceMonitor.mark('app-start');
|
||||||
|
|
||||||
// ⚡ 已删除 brainwave.css(项目未安装 Tailwind CSS,该文件无效)
|
// ⚡ 已删除 brainwave.css(项目未安装 Tailwind CSS,该文件无效)
|
||||||
|
|||||||
@@ -874,8 +874,20 @@ export function generateMockEvents(params = {}) {
|
|||||||
e.title.toLowerCase().includes(query) ||
|
e.title.toLowerCase().includes(query) ||
|
||||||
e.description.toLowerCase().includes(query) ||
|
e.description.toLowerCase().includes(query) ||
|
||||||
// keywords 是对象数组 { concept, score, ... },需要访问 concept 属性
|
// keywords 是对象数组 { concept, score, ... },需要访问 concept 属性
|
||||||
e.keywords.some(k => k.concept && k.concept.toLowerCase().includes(query))
|
e.keywords.some(k => k.concept && k.concept.toLowerCase().includes(query)) ||
|
||||||
|
// 搜索 related_stocks 中的股票名称和代码
|
||||||
|
(e.related_stocks && e.related_stocks.some(stock =>
|
||||||
|
(stock.stock_name && stock.stock_name.toLowerCase().includes(query)) ||
|
||||||
|
(stock.stock_code && stock.stock_code.toLowerCase().includes(query))
|
||||||
|
)) ||
|
||||||
|
// 搜索行业
|
||||||
|
(e.industry && e.industry.toLowerCase().includes(query))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 如果搜索结果为空,返回所有事件(宽松模式)
|
||||||
|
if (filteredEvents.length === 0) {
|
||||||
|
filteredEvents = allEvents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 行业筛选
|
// 行业筛选
|
||||||
@@ -1042,7 +1054,7 @@ function generateTransmissionChain(industry, index) {
|
|||||||
|
|
||||||
let nodeName;
|
let nodeName;
|
||||||
if (nodeType === 'company' && industryStock) {
|
if (nodeType === 'company' && industryStock) {
|
||||||
nodeName = industryStock.name;
|
nodeName = industryStock.stock_name;
|
||||||
} else if (nodeType === 'industry') {
|
} else if (nodeType === 'industry') {
|
||||||
nodeName = `${industry}产业`;
|
nodeName = `${industry}产业`;
|
||||||
} else if (nodeType === 'policy') {
|
} else if (nodeType === 'policy') {
|
||||||
@@ -1133,7 +1145,7 @@ export function generateDynamicNewsEvents(timeRange = null, count = 30) {
|
|||||||
const stock = industryStocks[j % industryStocks.length];
|
const stock = industryStocks[j % industryStocks.length];
|
||||||
relatedStocks.push({
|
relatedStocks.push({
|
||||||
stock_code: stock.stock_code,
|
stock_code: stock.stock_code,
|
||||||
stock_name: stock.name,
|
stock_name: stock.stock_name,
|
||||||
relation_desc: relationDescriptions[j % relationDescriptions.length]
|
relation_desc: relationDescriptions[j % relationDescriptions.length]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1145,7 +1157,7 @@ export function generateDynamicNewsEvents(timeRange = null, count = 30) {
|
|||||||
if (!relatedStocks.some(s => s.stock_code === randomStock.stock_code)) {
|
if (!relatedStocks.some(s => s.stock_code === randomStock.stock_code)) {
|
||||||
relatedStocks.push({
|
relatedStocks.push({
|
||||||
stock_code: randomStock.stock_code,
|
stock_code: randomStock.stock_code,
|
||||||
stock_name: randomStock.name,
|
stock_name: randomStock.stock_name,
|
||||||
relation_desc: relationDescriptions[relatedStocks.length % relationDescriptions.length]
|
relation_desc: relationDescriptions[relatedStocks.length % relationDescriptions.length]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,35 +366,50 @@ export const generateFinancialData = (stockCode) => {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
// 期间对比
|
// 期间对比 - 营收与利润趋势数据
|
||||||
periodComparison: {
|
periodComparison: [
|
||||||
periods: ['Q3-2024', 'Q2-2024', 'Q1-2024', 'Q4-2023'],
|
{
|
||||||
metrics: [
|
period: '2024-09-30',
|
||||||
{
|
performance: {
|
||||||
name: '营业收入',
|
revenue: 41500000000, // 415亿
|
||||||
unit: '百万元',
|
net_profit: 13420000000 // 134.2亿
|
||||||
values: [41500, 40800, 40200, 40850],
|
|
||||||
yoy: [8.2, 7.8, 8.5, 9.2]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '净利润',
|
|
||||||
unit: '百万元',
|
|
||||||
values: [13420, 13180, 13050, 13210],
|
|
||||||
yoy: [12.5, 11.2, 10.8, 12.3]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ROE',
|
|
||||||
unit: '%',
|
|
||||||
values: [16.23, 15.98, 15.75, 16.02],
|
|
||||||
yoy: [1.2, 0.8, 0.5, 1.0]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'EPS',
|
|
||||||
unit: '元',
|
|
||||||
values: [0.69, 0.68, 0.67, 0.68],
|
|
||||||
yoy: [12.3, 11.5, 10.5, 12.0]
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
|
period: '2024-06-30',
|
||||||
|
performance: {
|
||||||
|
revenue: 40800000000, // 408亿
|
||||||
|
net_profit: 13180000000 // 131.8亿
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
period: '2024-03-31',
|
||||||
|
performance: {
|
||||||
|
revenue: 40200000000, // 402亿
|
||||||
|
net_profit: 13050000000 // 130.5亿
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
period: '2023-12-31',
|
||||||
|
performance: {
|
||||||
|
revenue: 40850000000, // 408.5亿
|
||||||
|
net_profit: 13210000000 // 132.1亿
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
period: '2023-09-30',
|
||||||
|
performance: {
|
||||||
|
revenue: 38500000000, // 385亿
|
||||||
|
net_profit: 11920000000 // 119.2亿
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
period: '2023-06-30',
|
||||||
|
performance: {
|
||||||
|
revenue: 37800000000, // 378亿
|
||||||
|
net_profit: 11850000000 // 118.5亿
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
// src/mocks/handlers/bytedesk.js
|
// src/mocks/handlers/bytedesk.js
|
||||||
/**
|
/**
|
||||||
* Bytedesk 客服 Widget MSW Handler
|
* Bytedesk 客服 Widget MSW Handler
|
||||||
* 使用 passthrough 让请求通过到真实服务器,消除 MSW 警告
|
* Mock 模式下返回模拟数据
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { http, passthrough } from 'msw';
|
import { http, HttpResponse, passthrough } from 'msw';
|
||||||
|
|
||||||
export const bytedeskHandlers = [
|
export const bytedeskHandlers = [
|
||||||
// Bytedesk API 请求 - 直接 passthrough
|
// 未读消息数量
|
||||||
// 匹配 /bytedesk/* 路径(通过代理访问后端)
|
http.get('/bytedesk/visitor/api/v1/message/unread/count', () => {
|
||||||
|
return HttpResponse.json({
|
||||||
|
code: 200,
|
||||||
|
message: 'success',
|
||||||
|
data: { count: 0 },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
// 其他 Bytedesk API - 返回通用成功响应
|
||||||
http.all('/bytedesk/*', () => {
|
http.all('/bytedesk/*', () => {
|
||||||
return passthrough();
|
return HttpResponse.json({
|
||||||
|
code: 200,
|
||||||
|
message: 'success',
|
||||||
|
data: null,
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Bytedesk 外部 CDN/服务请求
|
// Bytedesk 外部 CDN/服务请求
|
||||||
|
|||||||
@@ -119,9 +119,12 @@ export const eventHandlers = [
|
|||||||
try {
|
try {
|
||||||
const result = generateMockEvents(params);
|
const result = generateMockEvents(params);
|
||||||
|
|
||||||
|
// 返回格式兼容 NewsPanel 期望的结构
|
||||||
|
// NewsPanel 期望: { success, data: [], pagination: {} }
|
||||||
return HttpResponse.json({
|
return HttpResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: result,
|
data: result.events, // 事件数组
|
||||||
|
pagination: result.pagination, // 分页信息
|
||||||
message: '获取成功'
|
message: '获取成功'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -135,16 +138,14 @@ export const eventHandlers = [
|
|||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
error: '获取事件列表失败',
|
error: '获取事件列表失败',
|
||||||
data: {
|
data: [],
|
||||||
events: [],
|
pagination: {
|
||||||
pagination: {
|
page: 1,
|
||||||
page: 1,
|
per_page: 10,
|
||||||
per_page: 10,
|
total: 0,
|
||||||
total: 0,
|
pages: 0,
|
||||||
pages: 0, // ← 对齐后端字段名
|
has_prev: false,
|
||||||
has_prev: false, // ← 对齐后端
|
has_next: false
|
||||||
has_next: false // ← 对齐后端
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
|
|||||||
@@ -341,6 +341,68 @@ export const stockHandlers = [
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// 获取股票业绩预告
|
||||||
|
http.get('/api/stock/:stockCode/forecast', async ({ params }) => {
|
||||||
|
await delay(200);
|
||||||
|
|
||||||
|
const { stockCode } = params;
|
||||||
|
console.log('[Mock Stock] 获取业绩预告:', { stockCode });
|
||||||
|
|
||||||
|
// 生成股票列表用于查找名称
|
||||||
|
const stockList = generateStockList();
|
||||||
|
const stockInfo = stockList.find(s => s.code === stockCode.replace(/\.(SH|SZ)$/i, ''));
|
||||||
|
const stockName = stockInfo?.name || `股票${stockCode}`;
|
||||||
|
|
||||||
|
// 业绩预告类型列表
|
||||||
|
const forecastTypes = ['预增', '预减', '略增', '略减', '扭亏', '续亏', '首亏', '续盈'];
|
||||||
|
|
||||||
|
// 生成业绩预告数据
|
||||||
|
const forecasts = [
|
||||||
|
{
|
||||||
|
forecast_type: '预增',
|
||||||
|
report_date: '2024年年报',
|
||||||
|
content: `${stockName}预计2024年度归属于上市公司股东的净利润为58亿元至62亿元,同比增长10%至17%。`,
|
||||||
|
reason: '报告期内,公司主营业务收入稳步增长,产品结构持续优化,毛利率提升;同时公司加大研发投入,新产品市场表现良好。',
|
||||||
|
change_range: {
|
||||||
|
lower: 10,
|
||||||
|
upper: 17
|
||||||
|
},
|
||||||
|
publish_date: '2024-10-15'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
forecast_type: '略增',
|
||||||
|
report_date: '2024年三季报',
|
||||||
|
content: `${stockName}预计2024年1-9月归属于上市公司股东的净利润为42亿元至45亿元,同比增长5%至12%。`,
|
||||||
|
reason: '公司积极拓展市场渠道,销售规模持续扩大,经营效益稳步提升。',
|
||||||
|
change_range: {
|
||||||
|
lower: 5,
|
||||||
|
upper: 12
|
||||||
|
},
|
||||||
|
publish_date: '2024-07-12'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
forecast_type: forecastTypes[Math.floor(Math.random() * forecastTypes.length)],
|
||||||
|
report_date: '2024年中报',
|
||||||
|
content: `${stockName}预计2024年上半年归属于上市公司股东的净利润为28亿元至30亿元。`,
|
||||||
|
reason: '受益于行业景气度回升及公司降本增效措施效果显现,经营业绩同比有所改善。',
|
||||||
|
change_range: {
|
||||||
|
lower: 3,
|
||||||
|
upper: 8
|
||||||
|
},
|
||||||
|
publish_date: '2024-04-20'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return HttpResponse.json({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
stock_code: stockCode,
|
||||||
|
stock_name: stockName,
|
||||||
|
forecasts: forecasts
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// 获取股票报价(批量)
|
// 获取股票报价(批量)
|
||||||
http.post('/api/stock/quotes', async ({ request }) => {
|
http.post('/api/stock/quotes', async ({ request }) => {
|
||||||
await delay(200);
|
await delay(200);
|
||||||
@@ -421,7 +483,19 @@ export const stockHandlers = [
|
|||||||
// 行业和指数标签
|
// 行业和指数标签
|
||||||
industry_l1: industryInfo.industry_l1,
|
industry_l1: industryInfo.industry_l1,
|
||||||
industry: industryInfo.industry,
|
industry: industryInfo.industry,
|
||||||
index_tags: industryInfo.index_tags || []
|
index_tags: industryInfo.index_tags || [],
|
||||||
|
// 关键指标
|
||||||
|
pe: parseFloat((Math.random() * 50 + 5).toFixed(2)),
|
||||||
|
eps: parseFloat((Math.random() * 5 + 0.1).toFixed(3)),
|
||||||
|
pb: parseFloat((Math.random() * 8 + 0.5).toFixed(2)),
|
||||||
|
market_cap: `${(Math.random() * 5000 + 100).toFixed(0)}亿`,
|
||||||
|
week52_low: parseFloat((basePrice * 0.7).toFixed(2)),
|
||||||
|
week52_high: parseFloat((basePrice * 1.3).toFixed(2)),
|
||||||
|
// 主力动态
|
||||||
|
main_net_inflow: parseFloat((Math.random() * 10 - 5).toFixed(2)),
|
||||||
|
institution_holding: parseFloat((Math.random() * 50 + 10).toFixed(2)),
|
||||||
|
buy_ratio: parseFloat((Math.random() * 40 + 30).toFixed(2)),
|
||||||
|
sell_ratio: parseFloat((100 - (Math.random() * 40 + 30)).toFixed(2))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// 性能监控工具 - 统计白屏时间和性能指标
|
// 性能监控工具 - 统计白屏时间和性能指标
|
||||||
|
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
|
import { reportPerformanceMetrics } from '../lib/posthog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 性能指标接口
|
* 性能指标接口
|
||||||
@@ -208,6 +209,9 @@ class PerformanceMonitor {
|
|||||||
// 性能分析建议
|
// 性能分析建议
|
||||||
this.analyzePerformance();
|
this.analyzePerformance();
|
||||||
|
|
||||||
|
// 上报性能指标到 PostHog
|
||||||
|
reportPerformanceMetrics(this.metrics);
|
||||||
|
|
||||||
return this.metrics;
|
return this.metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Company 目录结构说明
|
# Company 目录结构说明
|
||||||
|
|
||||||
> 最后更新:2025-12-16
|
> 最后更新:2025-12-17(API 接口清单梳理)
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
@@ -11,24 +11,40 @@ src/views/Company/
|
|||||||
│
|
│
|
||||||
├── components/ # UI 组件
|
├── components/ # UI 组件
|
||||||
│ │
|
│ │
|
||||||
|
│ ├── LoadingState.tsx # 通用加载状态组件
|
||||||
|
│ │
|
||||||
│ ├── CompanyHeader/ # 页面头部
|
│ ├── CompanyHeader/ # 页面头部
|
||||||
│ │ ├── index.js # 组合导出
|
│ │ ├── index.js # 组合导出
|
||||||
│ │ └── SearchBar.js # 股票搜索栏
|
│ │ └── SearchBar.js # 股票搜索栏
|
||||||
│ │
|
│ │
|
||||||
│ ├── CompanyTabs/ # Tab 切换容器
|
│ ├── CompanyTabs/ # Tab 切换容器
|
||||||
│ │ ├── index.js # Tab 容器(状态管理 + 内容渲染)
|
│ │ └── index.js # Tab 容器(状态管理 + 内容渲染)
|
||||||
│ │ └── TabNavigation.js # Tab 导航栏
|
|
||||||
│ │
|
│ │
|
||||||
│ ├── StockQuoteCard/ # 股票行情卡片(TypeScript)
|
│ ├── StockQuoteCard/ # 股票行情卡片(TypeScript,数据已下沉)
|
||||||
│ │ ├── index.tsx # 主组件
|
│ │ ├── index.tsx # 主组件(Props 从 11 个精简为 4 个)
|
||||||
│ │ ├── types.ts # 类型定义
|
│ │ ├── types.ts # 类型定义
|
||||||
│ │ └── mockData.ts # Mock 数据
|
│ │ ├── mockData.ts # Mock 数据
|
||||||
|
│ │ ├── hooks/ # 内部数据 Hooks(2025-12-17 新增)
|
||||||
|
│ │ │ ├── index.ts # hooks 导出索引
|
||||||
|
│ │ │ ├── useStockQuoteData.ts # 行情数据+基本信息获取
|
||||||
|
│ │ │ └── useStockCompare.ts # 股票对比逻辑
|
||||||
|
│ │ └── components/ # 子组件
|
||||||
|
│ │ ├── index.ts # 组件导出
|
||||||
|
│ │ ├── theme.ts # 主题配置
|
||||||
|
│ │ ├── formatters.ts # 格式化工具
|
||||||
|
│ │ ├── StockHeader.tsx # 股票头部(名称、代码、收藏按钮)
|
||||||
|
│ │ ├── PriceDisplay.tsx # 价格显示组件
|
||||||
|
│ │ ├── CompanyInfo.tsx # 公司信息(行业、市值等)
|
||||||
|
│ │ ├── KeyMetrics.tsx # 关键指标(PE、PB、换手率等)
|
||||||
|
│ │ ├── MainForceInfo.tsx # 主力资金信息
|
||||||
|
│ │ ├── SecondaryQuote.tsx # 副行情(对比股票)
|
||||||
|
│ │ ├── CompareStockInput.tsx # 对比股票输入
|
||||||
|
│ │ └── StockCompareModal.tsx # 股票对比弹窗
|
||||||
│ │
|
│ │
|
||||||
│ ├── CompanyOverview/ # Tab: 公司概览(TypeScript)
|
│ ├── CompanyOverview/ # Tab: 公司概览(TypeScript)
|
||||||
│ │ ├── index.tsx # 主组件(组合层)
|
│ │ ├── index.tsx # 主组件(组合层)
|
||||||
│ │ ├── types.ts # 类型定义
|
│ │ ├── types.ts # 类型定义
|
||||||
│ │ ├── utils.ts # 格式化工具
|
│ │ ├── utils.ts # 格式化工具
|
||||||
│ │ ├── DeepAnalysisTab/ # 深度分析 Tab(21 个 TS 文件)
|
|
||||||
│ │ ├── NewsEventsTab.js # 新闻事件 Tab
|
│ │ ├── NewsEventsTab.js # 新闻事件 Tab
|
||||||
│ │ │
|
│ │ │
|
||||||
│ │ ├── hooks/ # 数据 Hooks
|
│ │ ├── hooks/ # 数据 Hooks
|
||||||
@@ -47,29 +63,69 @@ src/views/Company/
|
|||||||
│ │ │ ├── ConcentrationCard.tsx # 股权集中度卡片
|
│ │ │ ├── ConcentrationCard.tsx # 股权集中度卡片
|
||||||
│ │ │ └── ShareholdersTable.tsx # 股东表格
|
│ │ │ └── ShareholdersTable.tsx # 股东表格
|
||||||
│ │ │
|
│ │ │
|
||||||
│ │ └── BasicInfoTab/ # 基本信息 Tab(可配置化)
|
│ │ ├── BasicInfoTab/ # 基本信息 Tab(可配置化)
|
||||||
│ │ ├── index.tsx # 主组件(可配置)
|
│ │ │ ├── index.tsx # 主组件(可配置)
|
||||||
│ │ ├── config.ts # Tab 配置 + 黑金主题
|
│ │ │ ├── config.ts # Tab 配置 + 黑金主题
|
||||||
│ │ ├── utils.ts # 格式化工具函数
|
│ │ │ ├── utils.ts # 格式化工具函数
|
||||||
│ │ └── components/ # 子组件
|
│ │ │ └── components/ # 子组件
|
||||||
│ │ ├── index.ts # 组件统一导出
|
│ │ │ ├── index.ts # 组件统一导出
|
||||||
│ │ ├── LoadingState.tsx # 加载状态组件
|
│ │ │ ├── LoadingState.tsx # 加载状态组件
|
||||||
│ │ ├── ShareholderPanel.tsx # 股权结构面板
|
│ │ │ ├── ShareholderPanel.tsx # 股权结构面板
|
||||||
│ │ ├── AnnouncementsPanel.tsx # 公告信息面板
|
│ │ │ ├── AnnouncementsPanel.tsx # 公告信息面板
|
||||||
│ │ ├── BranchesPanel.tsx # 分支机构面板
|
│ │ │ ├── BranchesPanel.tsx # 分支机构面板
|
||||||
│ │ ├── BusinessInfoPanel.tsx # 工商信息面板
|
│ │ │ ├── BusinessInfoPanel.tsx # 工商信息面板
|
||||||
│ │ ├── DisclosureSchedulePanel.tsx # 披露日程面板
|
│ │ │ ├── DisclosureSchedulePanel.tsx # 披露日程面板
|
||||||
│ │ └── management/ # 管理团队模块
|
│ │ │ └── management/ # 管理团队模块
|
||||||
│ │ ├── index.ts # 模块导出
|
│ │ │ ├── index.ts # 模块导出
|
||||||
│ │ ├── types.ts # 类型定义
|
│ │ │ ├── types.ts # 类型定义
|
||||||
│ │ ├── ManagementPanel.tsx # 主组件(useMemo)
|
│ │ │ ├── ManagementPanel.tsx # 主组件(useMemo)
|
||||||
│ │ ├── CategorySection.tsx # 分类区块(memo)
|
│ │ │ ├── CategorySection.tsx # 分类区块(memo)
|
||||||
│ │ └── ManagementCard.tsx # 人员卡片(memo)
|
│ │ │ └── ManagementCard.tsx # 人员卡片(memo)
|
||||||
|
│ │ │
|
||||||
|
│ │ └── DeepAnalysisTab/ # 深度分析 Tab(原子设计模式)
|
||||||
|
│ │ ├── index.tsx # 主入口组件
|
||||||
|
│ │ ├── types.ts # 类型定义
|
||||||
|
│ │ ├── atoms/ # 原子组件
|
||||||
|
│ │ │ ├── index.ts
|
||||||
|
│ │ │ ├── DisclaimerBox.tsx # 免责声明
|
||||||
|
│ │ │ ├── ScoreBar.tsx # 评分进度条
|
||||||
|
│ │ │ ├── BusinessTreeItem.tsx # 业务树形项
|
||||||
|
│ │ │ ├── KeyFactorCard.tsx # 关键因素卡片
|
||||||
|
│ │ │ ├── ProcessNavigation.tsx # 流程导航
|
||||||
|
│ │ │ └── ValueChainFilterBar.tsx # 产业链筛选栏
|
||||||
|
│ │ ├── components/ # Card 组件
|
||||||
|
│ │ │ ├── index.ts
|
||||||
|
│ │ │ ├── CorePositioningCard/ # 核心定位卡片(含 atoms)
|
||||||
|
│ │ │ │ ├── index.tsx
|
||||||
|
│ │ │ │ ├── theme.ts
|
||||||
|
│ │ │ │ └── atoms/
|
||||||
|
│ │ │ ├── CompetitiveAnalysisCard.tsx
|
||||||
|
│ │ │ ├── BusinessStructureCard.tsx
|
||||||
|
│ │ │ ├── BusinessSegmentsCard.tsx
|
||||||
|
│ │ │ ├── ValueChainCard.tsx
|
||||||
|
│ │ │ ├── KeyFactorsCard.tsx
|
||||||
|
│ │ │ ├── TimelineCard.tsx
|
||||||
|
│ │ │ └── StrategyAnalysisCard.tsx
|
||||||
|
│ │ ├── organisms/ # 复杂交互组件
|
||||||
|
│ │ │ ├── ValueChainNodeCard/
|
||||||
|
│ │ │ │ ├── index.tsx
|
||||||
|
│ │ │ │ └── RelatedCompaniesModal.tsx
|
||||||
|
│ │ │ └── TimelineComponent/
|
||||||
|
│ │ │ ├── index.tsx
|
||||||
|
│ │ │ └── EventDetailModal.tsx
|
||||||
|
│ │ ├── tabs/ # Tab 面板
|
||||||
|
│ │ │ ├── index.ts
|
||||||
|
│ │ │ ├── BusinessTab.tsx
|
||||||
|
│ │ │ ├── DevelopmentTab.tsx
|
||||||
|
│ │ │ ├── StrategyTab.tsx
|
||||||
|
│ │ │ └── ValueChainTab.tsx
|
||||||
|
│ │ └── utils/
|
||||||
|
│ │ └── chartOptions.ts
|
||||||
│ │
|
│ │
|
||||||
│ ├── MarketDataView/ # Tab: 股票行情(TypeScript)
|
│ ├── MarketDataView/ # Tab: 股票行情(TypeScript)
|
||||||
│ │ ├── index.tsx # 主组件入口(~285 行,Tab 容器)
|
│ │ ├── index.tsx # 主组件入口
|
||||||
│ │ ├── types.ts # 类型定义
|
│ │ ├── types.ts # 类型定义
|
||||||
│ │ ├── constants.ts # 主题配置、常量(含黑金主题 darkGoldTheme)
|
│ │ ├── constants.ts # 主题配置(含黑金主题 darkGoldTheme)
|
||||||
│ │ ├── services/
|
│ │ ├── services/
|
||||||
│ │ │ └── marketService.ts # API 服务层
|
│ │ │ └── marketService.ts # API 服务层
|
||||||
│ │ ├── hooks/
|
│ │ ├── hooks/
|
||||||
@@ -83,71 +139,90 @@ src/views/Company/
|
|||||||
│ │ ├── MarkdownRenderer.tsx # Markdown 渲染
|
│ │ ├── MarkdownRenderer.tsx # Markdown 渲染
|
||||||
│ │ ├── AnalysisModal.tsx # 涨幅分析模态框
|
│ │ ├── AnalysisModal.tsx # 涨幅分析模态框
|
||||||
│ │ ├── StockSummaryCard/ # 股票概览卡片(黑金主题 4 列布局)
|
│ │ ├── StockSummaryCard/ # 股票概览卡片(黑金主题 4 列布局)
|
||||||
│ │ │ ├── index.tsx # 主组件(4 列 SimpleGrid 布局)
|
│ │ │ ├── index.tsx
|
||||||
│ │ │ ├── StockHeaderCard.tsx # 股票信息卡片(名称、价格、涨跌幅)
|
│ │ │ ├── StockHeaderCard.tsx
|
||||||
│ │ │ ├── MetricCard.tsx # 指标卡片模板
|
│ │ │ ├── MetricCard.tsx
|
||||||
│ │ │ ├── utils.ts # 状态计算工具函数
|
│ │ │ ├── utils.ts
|
||||||
│ │ │ └── atoms/ # 原子组件
|
│ │ │ └── atoms/
|
||||||
│ │ │ ├── index.ts # 原子组件导出
|
│ │ │ ├── index.ts
|
||||||
│ │ │ ├── DarkGoldCard.tsx # 黑金主题卡片容器
|
│ │ │ ├── DarkGoldCard.tsx
|
||||||
│ │ │ ├── CardTitle.tsx # 卡片标题(图标+标题+副标题)
|
│ │ │ ├── CardTitle.tsx
|
||||||
│ │ │ ├── MetricValue.tsx # 核心数值展示
|
│ │ │ ├── MetricValue.tsx
|
||||||
│ │ │ ├── PriceDisplay.tsx # 价格显示(价格+涨跌箭头)
|
│ │ │ ├── PriceDisplay.tsx
|
||||||
│ │ │ └── StatusTag.tsx # 状态标签(活跃/健康等)
|
│ │ │ └── StatusTag.tsx
|
||||||
│ │ └── panels/ # Tab 面板组件
|
│ │ └── panels/ # Tab 面板组件
|
||||||
│ │ ├── index.ts # 面板组件统一导出
|
│ │ ├── index.ts
|
||||||
│ │ ├── TradeDataPanel/ # 交易数据面板(原子设计模式)
|
│ │ ├── TradeDataPanel/
|
||||||
│ │ │ ├── index.tsx # 主入口组件(~50 行)
|
│ │ │ ├── index.tsx
|
||||||
│ │ │ ├── KLineChart.tsx # 日K线图组件(~40 行)
|
│ │ │ └── KLineModule.tsx
|
||||||
│ │ │ ├── MinuteKLineSection.tsx # 分钟K线区域(~95 行)
|
│ │ ├── FundingPanel.tsx
|
||||||
│ │ │ ├── TradeTable.tsx # 交易明细表格(~75 行)
|
│ │ ├── BigDealPanel.tsx
|
||||||
│ │ │ └── atoms/ # 原子组件
|
│ │ ├── UnusualPanel.tsx
|
||||||
│ │ │ ├── index.ts # 统一导出
|
│ │ └── PledgePanel.tsx
|
||||||
│ │ │ ├── MinuteStats.tsx # 分钟数据统计(~80 行)
|
|
||||||
│ │ │ ├── TradeAnalysis.tsx # 成交分析(~65 行)
|
|
||||||
│ │ │ └── EmptyState.tsx # 空状态组件(~35 行)
|
|
||||||
│ │ ├── FundingPanel.tsx # 融资融券面板
|
|
||||||
│ │ ├── BigDealPanel.tsx # 大宗交易面板
|
|
||||||
│ │ ├── UnusualPanel.tsx # 龙虎榜面板
|
|
||||||
│ │ └── PledgePanel.tsx # 股权质押面板
|
|
||||||
│ │
|
│ │
|
||||||
│ ├── DeepAnalysis/ # Tab: 深度分析
|
│ ├── DeepAnalysis/ # Tab: 深度分析(入口)
|
||||||
│ │ └── index.js
|
│ │ └── index.js
|
||||||
│ │
|
│ │
|
||||||
│ ├── DynamicTracking/ # Tab: 动态跟踪
|
│ ├── DynamicTracking/ # Tab: 动态跟踪
|
||||||
│ │ └── index.js
|
│ │ ├── index.js # 主组件
|
||||||
|
│ │ └── components/
|
||||||
|
│ │ ├── index.js # 组件导出
|
||||||
|
│ │ ├── NewsPanel.js # 新闻面板
|
||||||
|
│ │ └── ForecastPanel.js # 业绩预告面板
|
||||||
│ │
|
│ │
|
||||||
│ ├── FinancialPanorama/ # Tab: 财务全景(TypeScript 模块化)
|
│ ├── FinancialPanorama/ # Tab: 财务全景(TypeScript 模块化)
|
||||||
│ │ ├── index.tsx # 主组件入口(~400 行)
|
│ │ ├── index.tsx # 主组件入口
|
||||||
│ │ ├── types.ts # TypeScript 类型定义
|
│ │ ├── types.ts # TypeScript 类型定义
|
||||||
│ │ ├── constants.ts # 常量配置(颜色、指标定义)
|
│ │ ├── constants.ts # 常量配置(颜色、指标定义)
|
||||||
│ │ ├── hooks/
|
│ │ ├── hooks/
|
||||||
│ │ │ ├── index.ts # Hook 统一导出
|
│ │ │ ├── index.ts
|
||||||
│ │ │ └── useFinancialData.ts # 财务数据加载 Hook
|
│ │ │ └── useFinancialData.ts
|
||||||
│ │ ├── utils/
|
│ │ ├── utils/
|
||||||
│ │ │ ├── index.ts # 工具函数统一导出
|
│ │ │ ├── index.ts
|
||||||
│ │ │ ├── calculations.ts # 计算工具(同比变化、单元格颜色)
|
│ │ │ ├── calculations.ts
|
||||||
│ │ │ └── chartOptions.ts # ECharts 图表配置生成器
|
│ │ │ └── chartOptions.ts
|
||||||
|
│ │ ├── tabs/ # Tab 面板组件
|
||||||
|
│ │ │ ├── index.ts
|
||||||
|
│ │ │ ├── BalanceSheetTab.tsx
|
||||||
|
│ │ │ ├── CashflowTab.tsx
|
||||||
|
│ │ │ ├── FinancialMetricsTab.tsx
|
||||||
|
│ │ │ ├── IncomeStatementTab.tsx
|
||||||
|
│ │ │ └── MetricsCategoryTab.tsx
|
||||||
│ │ └── components/
|
│ │ └── components/
|
||||||
│ │ ├── index.ts # 组件统一导出
|
│ │ ├── index.ts
|
||||||
│ │ ├── StockInfoHeader.tsx # 股票信息头部
|
│ │ ├── StockInfoHeader.tsx
|
||||||
│ │ ├── BalanceSheetTable.tsx # 资产负债表
|
│ │ ├── FinancialTable.tsx # 通用财务表格
|
||||||
│ │ ├── IncomeStatementTable.tsx # 利润表
|
│ │ ├── FinancialOverviewPanel.tsx # 财务概览面板
|
||||||
│ │ ├── CashflowTable.tsx # 现金流量表
|
│ │ ├── KeyMetricsOverview.tsx # 关键指标概览
|
||||||
│ │ ├── FinancialMetricsTable.tsx # 财务指标表
|
│ │ ├── PeriodSelector.tsx # 期数选择器
|
||||||
│ │ ├── MainBusinessAnalysis.tsx # 主营业务分析
|
│ │ ├── BalanceSheetTable.tsx
|
||||||
│ │ ├── IndustryRankingView.tsx # 行业排名
|
│ │ ├── IncomeStatementTable.tsx
|
||||||
│ │ ├── StockComparison.tsx # 股票对比
|
│ │ ├── CashflowTable.tsx
|
||||||
│ │ └── ComparisonAnalysis.tsx # 综合对比分析
|
│ │ ├── FinancialMetricsTable.tsx
|
||||||
|
│ │ ├── MainBusinessAnalysis.tsx
|
||||||
|
│ │ ├── IndustryRankingView.tsx
|
||||||
|
│ │ ├── StockComparison.tsx
|
||||||
|
│ │ └── ComparisonAnalysis.tsx
|
||||||
│ │
|
│ │
|
||||||
│ └── ForecastReport/ # Tab: 盈利预测(待拆分)
|
│ └── ForecastReport/ # Tab: 盈利预测(TypeScript,已模块化)
|
||||||
│ └── index.js
|
│ ├── index.tsx # 主组件入口
|
||||||
|
│ ├── types.ts # 类型定义
|
||||||
|
│ ├── constants.ts # 配色、图表配置常量
|
||||||
|
│ └── components/
|
||||||
|
│ ├── index.ts
|
||||||
|
│ ├── ChartCard.tsx # 图表卡片容器
|
||||||
|
│ ├── IncomeProfitGrowthChart.tsx # 营收与利润趋势图
|
||||||
|
│ ├── IncomeProfitChart.tsx # 营收利润图(备用)
|
||||||
|
│ ├── GrowthChart.tsx # 增长率图(备用)
|
||||||
|
│ ├── EpsChart.tsx # EPS 趋势图
|
||||||
|
│ ├── PePegChart.tsx # PE/PEG 分析图
|
||||||
|
│ └── DetailTable.tsx # 详细数据表格
|
||||||
│
|
│
|
||||||
├── hooks/ # 页面级 Hooks
|
├── hooks/ # 页面级 Hooks
|
||||||
│ ├── useCompanyStock.js # 股票代码管理(URL 同步)
|
│ ├── useCompanyStock.js # 股票代码管理(URL 同步)
|
||||||
│ ├── useCompanyWatchlist.js # 自选股管理(Redux 集成)
|
│ ├── useCompanyWatchlist.js # 自选股管理(Redux 集成)
|
||||||
│ ├── useCompanyEvents.js # PostHog 事件追踪
|
│ └── useCompanyEvents.js # PostHog 事件追踪
|
||||||
│ └── useStockQuote.js # 股票行情数据 Hook
|
│ # 注:useStockQuote.js 已下沉到 StockQuoteCard/hooks/useStockQuoteData.ts
|
||||||
│
|
│
|
||||||
└── constants/ # 常量定义
|
└── constants/ # 常量定义
|
||||||
└── index.js # Tab 配置、Toast 消息、默认值
|
└── index.js # Tab 配置、Toast 消息、默认值
|
||||||
@@ -155,19 +230,101 @@ src/views/Company/
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## API 接口清单
|
||||||
|
|
||||||
|
Company 模块共使用 **27 个** API 接口(去重后)。
|
||||||
|
|
||||||
|
### 一、股票基础信息 (8 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/stock/${stockCode}/basic-info` | GET | useBasicInfo.ts, useStockQuoteData.ts, NewsPanel.js |
|
||||||
|
| `/api/stock/${stockCode}/branches` | GET | useBranchesData.ts |
|
||||||
|
| `/api/stock/${stockCode}/management?active_only=true` | GET | useManagementData.ts |
|
||||||
|
| `/api/stock/${stockCode}/announcements?limit=20` | GET | useAnnouncementsData.ts |
|
||||||
|
| `/api/stock/${stockCode}/disclosure-schedule` | GET | useDisclosureData.ts |
|
||||||
|
| `/api/stock/${stockCode}/forecast` | GET | ForecastPanel.js |
|
||||||
|
| `/api/stock/${stockCode}/forecast-report` | GET | ForecastReport/index.tsx |
|
||||||
|
| `/api/stock/${stockCode}/latest-minute` | GET | marketService.ts |
|
||||||
|
|
||||||
|
### 二、股东信息 (4 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/stock/${stockCode}/actual-control` | GET | useShareholderData.ts |
|
||||||
|
| `/api/stock/${stockCode}/concentration` | GET | useShareholderData.ts |
|
||||||
|
| `/api/stock/${stockCode}/top-shareholders?limit=10` | GET | useShareholderData.ts |
|
||||||
|
| `/api/stock/${stockCode}/top-circulation-shareholders?limit=10` | GET | useShareholderData.ts |
|
||||||
|
|
||||||
|
### 三、行情数据 (8 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/stock/quotes` | POST | stockService.getQuotes |
|
||||||
|
| `/api/market/summary/${stockCode}` | GET | marketService.ts |
|
||||||
|
| `/api/market/trade/${stockCode}?days=${days}` | GET | marketService.ts |
|
||||||
|
| `/api/market/funding/${stockCode}?days=${days}` | GET | marketService.ts |
|
||||||
|
| `/api/market/bigdeal/${stockCode}?days=${days}` | GET | marketService.ts |
|
||||||
|
| `/api/market/unusual/${stockCode}?days=${days}` | GET | marketService.ts |
|
||||||
|
| `/api/market/pledge/${stockCode}` | GET | marketService.ts |
|
||||||
|
| `/api/market/rise-analysis/${stockCode}` | GET | marketService.ts |
|
||||||
|
|
||||||
|
### 四、深度分析 (5 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/company/comprehensive-analysis/${stockCode}` | GET | DeepAnalysis/index.js |
|
||||||
|
| `/api/company/value-chain-analysis/${stockCode}` | GET | DeepAnalysis/index.js |
|
||||||
|
| `/api/company/key-factors-timeline/${stockCode}` | GET | DeepAnalysis/index.js |
|
||||||
|
| `/api/company/value-chain/related-companies?node_name=...` | GET | ValueChainNodeCard/index.tsx |
|
||||||
|
| `/api/financial/industry-rank/${stockCode}` | GET | DeepAnalysis/index.js |
|
||||||
|
|
||||||
|
### 五、财务数据 (1 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/financial/financial-metrics/${stockCode}?limit=${limit}` | GET | financialService.getFinancialMetrics |
|
||||||
|
|
||||||
|
### 六、事件/新闻 (1 个)
|
||||||
|
|
||||||
|
| 接口 | 方法 | 调用位置 |
|
||||||
|
|------|------|----------|
|
||||||
|
| `/api/events?q=${searchTerm}&page=${page}&per_page=10` | GET | NewsPanel.js |
|
||||||
|
|
||||||
|
### 统计汇总
|
||||||
|
|
||||||
|
| 分类 | 数量 |
|
||||||
|
|------|------|
|
||||||
|
| 股票基础信息 | 8 |
|
||||||
|
| 股东信息 | 4 |
|
||||||
|
| 行情数据 | 8 |
|
||||||
|
| 深度分析 | 5 |
|
||||||
|
| 财务数据 | 1 |
|
||||||
|
| 事件/新闻 | 1 |
|
||||||
|
| **去重后总计** | **27** |
|
||||||
|
|
||||||
|
> 注:`/api/stock/${stockCode}/basic-info` 在 3 处调用,但只算 1 个接口。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 文件职责说明
|
## 文件职责说明
|
||||||
|
|
||||||
### 入口文件
|
### 入口文件
|
||||||
|
|
||||||
#### `index.js` - 页面入口
|
#### `index.js` - 页面入口
|
||||||
- **职责**:纯组合层,协调 Hooks 和 Components
|
- **职责**:纯组合层,协调 Hooks 和 Components
|
||||||
- **代码行数**:95 行
|
- **代码行数**:~105 行(2025-12-17 优化后精简)
|
||||||
- **依赖**:
|
- **依赖**:
|
||||||
- `useCompanyStock` - 股票代码状态
|
- `useCompanyStock` - 股票代码状态
|
||||||
- `useCompanyWatchlist` - 自选股状态
|
- `useCompanyWatchlist` - 自选股状态
|
||||||
- `useCompanyEvents` - 事件追踪
|
- `useCompanyEvents` - 事件追踪
|
||||||
- `CompanyHeader` - 页面头部
|
- `CompanyHeader` - 页面头部
|
||||||
|
- `StockQuoteCard` - 股票行情卡片(内部自行获取数据)
|
||||||
- `CompanyTabs` - Tab 切换区
|
- `CompanyTabs` - Tab 切换区
|
||||||
|
- **已移除**(2025-12-17):
|
||||||
|
- `useStockQuote` - 已下沉到 StockQuoteCard
|
||||||
|
- `useBasicInfo` - 已下沉到 StockQuoteCard
|
||||||
|
- 股票对比逻辑 - 已下沉到 StockQuoteCard
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -999,4 +1156,98 @@ index.tsx
|
|||||||
- **原子设计模式**:atoms(MinuteStats、TradeAnalysis、EmptyState)→ 业务组件(KLineChart、MinuteKLineSection、TradeTable)→ 主组件
|
- **原子设计模式**:atoms(MinuteStats、TradeAnalysis、EmptyState)→ 业务组件(KLineChart、MinuteKLineSection、TradeTable)→ 主组件
|
||||||
- **职责分离**:图表、统计、表格各自独立
|
- **职责分离**:图表、统计、表格各自独立
|
||||||
- **组件复用**:EmptyState 可在其他场景复用
|
- **组件复用**:EmptyState 可在其他场景复用
|
||||||
- **类型安全**:完整的 Props 类型定义和导出
|
- **类型安全**:完整的 Props 类型定义和导出
|
||||||
|
|
||||||
|
### 2025-12-17 StockQuoteCard 数据下沉优化
|
||||||
|
|
||||||
|
**改动概述**:
|
||||||
|
- StockQuoteCard Props 从 **11 个** 精简至 **4 个**(减少 64%)
|
||||||
|
- 行情数据、基本信息、股票对比逻辑全部下沉到组件内部
|
||||||
|
- Company/index.js 移除约 **40 行** 数据获取代码
|
||||||
|
- 删除 `Company/hooks/useStockQuote.js`
|
||||||
|
|
||||||
|
**创建的文件**:
|
||||||
|
```
|
||||||
|
StockQuoteCard/hooks/
|
||||||
|
├── index.ts # hooks 导出索引
|
||||||
|
├── useStockQuoteData.ts # 行情数据 + 基本信息获取(~152 行)
|
||||||
|
└── useStockCompare.ts # 股票对比逻辑(~91 行)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Props 对比**:
|
||||||
|
|
||||||
|
**优化前(11 个 Props)**:
|
||||||
|
```tsx
|
||||||
|
<StockQuoteCard
|
||||||
|
data={quoteData}
|
||||||
|
isLoading={isQuoteLoading}
|
||||||
|
basicInfo={basicInfo}
|
||||||
|
currentStockInfo={currentStockInfo}
|
||||||
|
compareStockInfo={compareStockInfo}
|
||||||
|
isCompareLoading={isCompareLoading}
|
||||||
|
onCompare={handleCompare}
|
||||||
|
onCloseCompare={handleCloseCompare}
|
||||||
|
isInWatchlist={isInWatchlist}
|
||||||
|
isWatchlistLoading={isWatchlistLoading}
|
||||||
|
onWatchlistToggle={handleWatchlistToggle}
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
**优化后(4 个 Props)**:
|
||||||
|
```tsx
|
||||||
|
<StockQuoteCard
|
||||||
|
stockCode={stockCode}
|
||||||
|
isInWatchlist={isInWatchlist}
|
||||||
|
isWatchlistLoading={isWatchlistLoading}
|
||||||
|
onWatchlistToggle={handleWatchlistToggle}
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hook 返回值**:
|
||||||
|
|
||||||
|
`useStockQuoteData(stockCode)`:
|
||||||
|
```typescript
|
||||||
|
{
|
||||||
|
quoteData: StockQuoteCardData | null; // 行情数据
|
||||||
|
basicInfo: BasicInfo | null; // 基本信息
|
||||||
|
isLoading: boolean; // 加载状态
|
||||||
|
error: string | null; // 错误信息
|
||||||
|
refetch: () => void; // 手动刷新
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`useStockCompare(stockCode)`:
|
||||||
|
```typescript
|
||||||
|
{
|
||||||
|
currentStockInfo: StockInfo | null; // 当前股票财务信息
|
||||||
|
compareStockInfo: StockInfo | null; // 对比股票财务信息
|
||||||
|
isCompareLoading: boolean; // 对比数据加载中
|
||||||
|
handleCompare: (code: string) => Promise<void>; // 触发对比
|
||||||
|
clearCompare: () => void; // 清除对比
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改的文件**:
|
||||||
|
| 文件 | 操作 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| `StockQuoteCard/hooks/useStockQuoteData.ts` | 新建 | 合并行情+基本信息获取 |
|
||||||
|
| `StockQuoteCard/hooks/useStockCompare.ts` | 新建 | 股票对比逻辑 |
|
||||||
|
| `StockQuoteCard/hooks/index.ts` | 新建 | hooks 导出索引 |
|
||||||
|
| `StockQuoteCard/index.tsx` | 修改 | 使用内部 hooks,减少 props |
|
||||||
|
| `StockQuoteCard/types.ts` | 修改 | Props 从 11 个精简为 4 个 |
|
||||||
|
| `Company/index.js` | 修改 | 移除下沉的数据获取逻辑 |
|
||||||
|
| `Company/hooks/useStockQuote.js` | 删除 | 已移到 StockQuoteCard |
|
||||||
|
|
||||||
|
**优化收益**:
|
||||||
|
| 指标 | 优化前 | 优化后 | 改善 |
|
||||||
|
|------|--------|--------|------|
|
||||||
|
| Props 数量 | 11 | 4 | -64% |
|
||||||
|
| Company/index.js 行数 | ~172 | ~105 | -39% |
|
||||||
|
| 数据获取位置 | 页面层 | 组件内部 | 就近原则 |
|
||||||
|
| 可复用性 | 依赖父组件 | 独立可用 | 提升 |
|
||||||
|
|
||||||
|
**设计原则**:
|
||||||
|
- **数据就近获取**:组件自己获取自己需要的数据
|
||||||
|
- **Props 最小化**:只传递真正需要外部控制的状态
|
||||||
|
- **职责清晰**:自选股状态保留在页面层(涉及 Redux 和事件追踪)
|
||||||
|
- **可复用性**:StockQuoteCard 可独立在其他页面使用
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
VStack,
|
VStack,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { SearchIcon } from '@chakra-ui/icons';
|
import { SearchIcon } from '@chakra-ui/icons';
|
||||||
|
import { useStockSearch } from '../../hooks/useStockSearch';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 股票搜索栏组件(带模糊搜索下拉)
|
* 股票搜索栏组件(带模糊搜索下拉)
|
||||||
@@ -31,27 +32,18 @@ const SearchBar = ({
|
|||||||
}) => {
|
}) => {
|
||||||
// 下拉状态
|
// 下拉状态
|
||||||
const [showDropdown, setShowDropdown] = useState(false);
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
const [filteredStocks, setFilteredStocks] = useState([]);
|
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
|
|
||||||
// 从 Redux 获取全部股票列表
|
// 从 Redux 获取全部股票列表
|
||||||
const allStocks = useSelector(state => state.stock.allStocks);
|
const allStocks = useSelector(state => state.stock.allStocks);
|
||||||
|
|
||||||
// 模糊搜索过滤
|
// 使用共享的搜索 Hook
|
||||||
|
const filteredStocks = useStockSearch(allStocks, inputCode, { limit: 10 });
|
||||||
|
|
||||||
|
// 根据搜索结果更新下拉显示状态
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputCode && inputCode.trim()) {
|
setShowDropdown(filteredStocks.length > 0 && !!inputCode?.trim());
|
||||||
const searchTerm = inputCode.trim().toLowerCase();
|
}, [filteredStocks, inputCode]);
|
||||||
const filtered = allStocks.filter(stock =>
|
|
||||||
stock.code.toLowerCase().includes(searchTerm) ||
|
|
||||||
stock.name.includes(inputCode.trim())
|
|
||||||
).slice(0, 10); // 限制显示10条
|
|
||||||
setFilteredStocks(filtered);
|
|
||||||
setShowDropdown(filtered.length > 0);
|
|
||||||
} else {
|
|
||||||
setFilteredStocks([]);
|
|
||||||
setShowDropdown(false);
|
|
||||||
}
|
|
||||||
}, [inputCode, allStocks]);
|
|
||||||
|
|
||||||
// 点击外部关闭下拉
|
// 点击外部关闭下拉
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
Text,
|
Text,
|
||||||
Badge,
|
Badge,
|
||||||
Icon,
|
|
||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
IconButton,
|
IconButton,
|
||||||
@@ -23,7 +22,6 @@ import {
|
|||||||
ModalFooter,
|
ModalFooter,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { FaBullhorn } from "react-icons/fa";
|
|
||||||
import { ExternalLinkIcon } from "@chakra-ui/icons";
|
import { ExternalLinkIcon } from "@chakra-ui/icons";
|
||||||
|
|
||||||
import { useAnnouncementsData } from "../../hooks/useAnnouncementsData";
|
import { useAnnouncementsData } from "../../hooks/useAnnouncementsData";
|
||||||
@@ -55,10 +53,6 @@ const AnnouncementsPanel: React.FC<AnnouncementsPanelProps> = ({ stockCode }) =>
|
|||||||
<VStack spacing={4} align="stretch">
|
<VStack spacing={4} align="stretch">
|
||||||
{/* 最新公告 */}
|
{/* 最新公告 */}
|
||||||
<Box>
|
<Box>
|
||||||
<HStack mb={3}>
|
|
||||||
<Icon as={FaBullhorn} color={THEME.gold} />
|
|
||||||
<Text fontWeight="bold" color={THEME.textPrimary}>最新公告</Text>
|
|
||||||
</HStack>
|
|
||||||
<VStack spacing={2} align="stretch">
|
<VStack spacing={2} align="stretch">
|
||||||
{announcements.map((announcement: any, idx: number) => (
|
{announcements.map((announcement: any, idx: number) => (
|
||||||
<Card
|
<Card
|
||||||
|
|||||||
@@ -12,15 +12,27 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
Center,
|
Center,
|
||||||
Code,
|
Code,
|
||||||
|
Spinner,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
|
|
||||||
import { THEME } from "../config";
|
import { THEME } from "../config";
|
||||||
|
import { useBasicInfo } from "../../hooks/useBasicInfo";
|
||||||
|
|
||||||
interface BusinessInfoPanelProps {
|
interface BusinessInfoPanelProps {
|
||||||
basicInfo: any;
|
stockCode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BusinessInfoPanel: React.FC<BusinessInfoPanelProps> = ({ basicInfo }) => {
|
const BusinessInfoPanel: React.FC<BusinessInfoPanelProps> = ({ stockCode }) => {
|
||||||
|
const { basicInfo, loading } = useBasicInfo(stockCode);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<Center h="200px">
|
||||||
|
<Spinner size="lg" color={THEME.gold} />
|
||||||
|
</Center>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!basicInfo) {
|
if (!basicInfo) {
|
||||||
return (
|
return (
|
||||||
<Center h="200px">
|
<Center h="200px">
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ import React from "react";
|
|||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
VStack,
|
VStack,
|
||||||
HStack,
|
|
||||||
Text,
|
Text,
|
||||||
Badge,
|
Badge,
|
||||||
Icon,
|
|
||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
SimpleGrid,
|
SimpleGrid,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { FaCalendarAlt } from "react-icons/fa";
|
|
||||||
|
|
||||||
import { useDisclosureData } from "../../hooks/useDisclosureData";
|
import { useDisclosureData } from "../../hooks/useDisclosureData";
|
||||||
import { THEME } from "../config";
|
import { THEME } from "../config";
|
||||||
@@ -42,10 +39,6 @@ const DisclosureSchedulePanel: React.FC<DisclosureSchedulePanelProps> = ({ stock
|
|||||||
return (
|
return (
|
||||||
<VStack spacing={4} align="stretch">
|
<VStack spacing={4} align="stretch">
|
||||||
<Box>
|
<Box>
|
||||||
<HStack mb={3}>
|
|
||||||
<Icon as={FaCalendarAlt} color={THEME.gold} />
|
|
||||||
<Text fontWeight="bold" color={THEME.textPrimary}>财报披露日程</Text>
|
|
||||||
</HStack>
|
|
||||||
<SimpleGrid columns={{ base: 2, md: 4 }} spacing={3}>
|
<SimpleGrid columns={{ base: 2, md: 4 }} spacing={3}>
|
||||||
{disclosureSchedule.map((schedule: any, idx: number) => (
|
{disclosureSchedule.map((schedule: any, idx: number) => (
|
||||||
<Card
|
<Card
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
// Props 类型定义
|
// Props 类型定义
|
||||||
export interface BasicInfoTabProps {
|
export interface BasicInfoTabProps {
|
||||||
stockCode: string;
|
stockCode: string;
|
||||||
basicInfo?: any;
|
|
||||||
|
|
||||||
// 可配置项
|
// 可配置项
|
||||||
enabledTabs?: string[]; // 指定显示哪些 Tab(通过 key)
|
enabledTabs?: string[]; // 指定显示哪些 Tab(通过 key)
|
||||||
@@ -59,7 +58,6 @@ const buildTabsConfig = (enabledKeys?: string[]): SubTabConfig[] => {
|
|||||||
*/
|
*/
|
||||||
const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
||||||
stockCode,
|
stockCode,
|
||||||
basicInfo,
|
|
||||||
enabledTabs,
|
enabledTabs,
|
||||||
defaultTabIndex = 0,
|
defaultTabIndex = 0,
|
||||||
onTabChange,
|
onTabChange,
|
||||||
@@ -72,7 +70,7 @@ const BasicInfoTab: React.FC<BasicInfoTabProps> = ({
|
|||||||
<CardBody p={0}>
|
<CardBody p={0}>
|
||||||
<SubTabContainer
|
<SubTabContainer
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
componentProps={{ stockCode, basicInfo }}
|
componentProps={{ stockCode }}
|
||||||
defaultIndex={defaultTabIndex}
|
defaultIndex={defaultTabIndex}
|
||||||
onTabChange={onTabChange}
|
onTabChange={onTabChange}
|
||||||
themePreset="blackGold"
|
themePreset="blackGold"
|
||||||
|
|||||||
@@ -234,10 +234,10 @@ const CompetitiveAnalysisCard: React.FC<CompetitiveAnalysisCardProps> = memo(
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
{/* 主要竞争对手 */}
|
{/* 主要竞争对手 */}
|
||||||
{/* {competitors.length > 0 && <CompetitorTags competitors={competitors} />} */}
|
{competitors.length > 0 && <CompetitorTags competitors={competitors} />}
|
||||||
|
|
||||||
{/* 评分和雷达图 */}
|
{/* 评分和雷达图 */}
|
||||||
{/* <Grid templateColumns="repeat(2, 1fr)" gap={6}>
|
<Grid templateColumns="repeat(2, 1fr)" gap={6}>
|
||||||
<GridItem colSpan={GRID_COLSPAN}>
|
<GridItem colSpan={GRID_COLSPAN}>
|
||||||
<ScoreSection scores={competitivePosition.scores} />
|
<ScoreSection scores={competitivePosition.scores} />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
@@ -251,9 +251,9 @@ const CompetitiveAnalysisCard: React.FC<CompetitiveAnalysisCardProps> = memo(
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</GridItem>
|
</GridItem>
|
||||||
</Grid> */}
|
</Grid>
|
||||||
|
|
||||||
{/* <Divider my={4} borderColor="yellow.600" /> */}
|
<Divider my={4} borderColor="yellow.600" />
|
||||||
|
|
||||||
{/* 竞争优势和劣势 */}
|
{/* 竞争优势和劣势 */}
|
||||||
<AdvantagesSection
|
<AdvantagesSection
|
||||||
|
|||||||
@@ -155,24 +155,28 @@ const ValueChainCard: React.FC<ValueChainCardProps> = memo(({
|
|||||||
align="center"
|
align="center"
|
||||||
flexWrap="wrap"
|
flexWrap="wrap"
|
||||||
>
|
>
|
||||||
{/* 左侧:流程式导航 */}
|
{/* 左侧:流程式导航 - 仅在层级视图显示 */}
|
||||||
<ProcessNavigation
|
{viewMode === 'hierarchy' && (
|
||||||
activeTab={activeTab}
|
<ProcessNavigation
|
||||||
onTabChange={setActiveTab}
|
activeTab={activeTab}
|
||||||
upstreamCount={upstreamNodes.length}
|
onTabChange={setActiveTab}
|
||||||
coreCount={coreNodes.length}
|
upstreamCount={upstreamNodes.length}
|
||||||
downstreamCount={downstreamNodes.length}
|
coreCount={coreNodes.length}
|
||||||
/>
|
downstreamCount={downstreamNodes.length}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 右侧:筛选与视图切换 */}
|
{/* 右侧:筛选与视图切换 - 始终靠右 */}
|
||||||
<ValueChainFilterBar
|
<Box ml="auto">
|
||||||
typeFilter={typeFilter}
|
<ValueChainFilterBar
|
||||||
onTypeChange={setTypeFilter}
|
typeFilter={typeFilter}
|
||||||
importanceFilter={importanceFilter}
|
onTypeChange={setTypeFilter}
|
||||||
onImportanceChange={setImportanceFilter}
|
importanceFilter={importanceFilter}
|
||||||
viewMode={viewMode}
|
onImportanceChange={setImportanceFilter}
|
||||||
onViewModeChange={setViewMode}
|
viewMode={viewMode}
|
||||||
/>
|
onViewModeChange={setViewMode}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{/* 内容区域 */}
|
{/* 内容区域 */}
|
||||||
|
|||||||
@@ -11,9 +11,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Card, CardBody, Center, VStack, Spinner, Text } from '@chakra-ui/react';
|
import { Card, CardBody } from '@chakra-ui/react';
|
||||||
import { FaBrain, FaBuilding, FaLink, FaHistory } from 'react-icons/fa';
|
import { FaBrain, FaBuilding, FaLink, FaHistory } from 'react-icons/fa';
|
||||||
import SubTabContainer, { type SubTabConfig } from '@components/SubTabContainer';
|
import SubTabContainer, { type SubTabConfig } from '@components/SubTabContainer';
|
||||||
|
import LoadingState from '../../LoadingState';
|
||||||
import { StrategyTab, BusinessTab, ValueChainTab, DevelopmentTab } from './tabs';
|
import { StrategyTab, BusinessTab, ValueChainTab, DevelopmentTab } from './tabs';
|
||||||
import type { DeepAnalysisTabProps, DeepAnalysisTabKey } from './types';
|
import type { DeepAnalysisTabProps, DeepAnalysisTabKey } from './types';
|
||||||
|
|
||||||
@@ -75,12 +76,7 @@ const DeepAnalysisTab: React.FC<DeepAnalysisTabProps> = ({
|
|||||||
componentProps={{}}
|
componentProps={{}}
|
||||||
themePreset="blackGold"
|
themePreset="blackGold"
|
||||||
/>
|
/>
|
||||||
<Center h="200px">
|
<LoadingState message="加载数据中..." height="200px" />
|
||||||
<VStack spacing={4}>
|
|
||||||
<Spinner size="xl" color="blue.500" />
|
|
||||||
<Text color="gray.400">加载数据中...</Text>
|
|
||||||
</VStack>
|
|
||||||
</Center>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ import {
|
|||||||
FaStar,
|
FaStar,
|
||||||
} from 'react-icons/fa';
|
} from 'react-icons/fa';
|
||||||
import { logger } from '@utils/logger';
|
import { logger } from '@utils/logger';
|
||||||
import { getApiBase } from '@utils/apiConfig';
|
import axios from '@utils/axiosConfig';
|
||||||
import RelatedCompaniesModal from './RelatedCompaniesModal';
|
import RelatedCompaniesModal from './RelatedCompaniesModal';
|
||||||
import type { ValueChainNodeCardProps, RelatedCompany } from '../../types';
|
import type { ValueChainNodeCardProps, RelatedCompany } from '../../types';
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
// 黑金主题配置
|
// 黑金主题配置
|
||||||
const THEME = {
|
const THEME = {
|
||||||
cardBg: 'gray.700',
|
cardBg: 'gray.700',
|
||||||
@@ -120,12 +118,11 @@ const ValueChainNodeCard: React.FC<ValueChainNodeCardProps> = memo(({
|
|||||||
const fetchRelatedCompanies = async () => {
|
const fetchRelatedCompanies = async () => {
|
||||||
setLoadingRelated(true);
|
setLoadingRelated(true);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const { data } = await axios.get(
|
||||||
`${API_BASE_URL}/api/company/value-chain/related-companies?node_name=${encodeURIComponent(
|
`/api/company/value-chain/related-companies?node_name=${encodeURIComponent(
|
||||||
node.node_name
|
node.node_name
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
setRelatedCompanies(data.data || []);
|
setRelatedCompanies(data.data || []);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -36,6 +36,58 @@ import {
|
|||||||
FaChevronRight,
|
FaChevronRight,
|
||||||
} from "react-icons/fa";
|
} from "react-icons/fa";
|
||||||
|
|
||||||
|
// 黑金主题配色
|
||||||
|
const THEME_PRESETS = {
|
||||||
|
blackGold: {
|
||||||
|
bg: "#0A0E17",
|
||||||
|
cardBg: "#1A1F2E",
|
||||||
|
cardHoverBg: "#212633",
|
||||||
|
cardBorder: "rgba(212, 175, 55, 0.2)",
|
||||||
|
cardHoverBorder: "#D4AF37",
|
||||||
|
textPrimary: "#E8E9ED",
|
||||||
|
textSecondary: "#A0A4B8",
|
||||||
|
textMuted: "#6B7280",
|
||||||
|
gold: "#D4AF37",
|
||||||
|
goldLight: "#FFD54F",
|
||||||
|
inputBg: "#151922",
|
||||||
|
inputBorder: "#2D3748",
|
||||||
|
buttonBg: "#D4AF37",
|
||||||
|
buttonText: "#0A0E17",
|
||||||
|
buttonHoverBg: "#FFD54F",
|
||||||
|
badgeS: { bg: "rgba(255, 195, 0, 0.2)", color: "#FFD54F" },
|
||||||
|
badgeA: { bg: "rgba(249, 115, 22, 0.2)", color: "#FB923C" },
|
||||||
|
badgeB: { bg: "rgba(59, 130, 246, 0.2)", color: "#60A5FA" },
|
||||||
|
badgeC: { bg: "rgba(107, 114, 128, 0.2)", color: "#9CA3AF" },
|
||||||
|
tagBg: "rgba(212, 175, 55, 0.15)",
|
||||||
|
tagColor: "#D4AF37",
|
||||||
|
spinnerColor: "#D4AF37",
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
bg: "white",
|
||||||
|
cardBg: "white",
|
||||||
|
cardHoverBg: "gray.50",
|
||||||
|
cardBorder: "gray.200",
|
||||||
|
cardHoverBorder: "blue.300",
|
||||||
|
textPrimary: "gray.800",
|
||||||
|
textSecondary: "gray.600",
|
||||||
|
textMuted: "gray.500",
|
||||||
|
gold: "blue.500",
|
||||||
|
goldLight: "blue.400",
|
||||||
|
inputBg: "white",
|
||||||
|
inputBorder: "gray.200",
|
||||||
|
buttonBg: "blue.500",
|
||||||
|
buttonText: "white",
|
||||||
|
buttonHoverBg: "blue.600",
|
||||||
|
badgeS: { bg: "red.100", color: "red.600" },
|
||||||
|
badgeA: { bg: "orange.100", color: "orange.600" },
|
||||||
|
badgeB: { bg: "yellow.100", color: "yellow.600" },
|
||||||
|
badgeC: { bg: "green.100", color: "green.600" },
|
||||||
|
tagBg: "cyan.50",
|
||||||
|
tagColor: "cyan.600",
|
||||||
|
spinnerColor: "blue.500",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新闻动态 Tab 组件
|
* 新闻动态 Tab 组件
|
||||||
*
|
*
|
||||||
@@ -48,6 +100,7 @@ import {
|
|||||||
* - onSearch: 搜索提交回调 () => void
|
* - onSearch: 搜索提交回调 () => void
|
||||||
* - onPageChange: 分页回调 (page) => void
|
* - onPageChange: 分页回调 (page) => void
|
||||||
* - cardBg: 卡片背景色
|
* - cardBg: 卡片背景色
|
||||||
|
* - themePreset: 主题预设 'blackGold' | 'default'
|
||||||
*/
|
*/
|
||||||
const NewsEventsTab = ({
|
const NewsEventsTab = ({
|
||||||
newsEvents = [],
|
newsEvents = [],
|
||||||
@@ -65,7 +118,11 @@ const NewsEventsTab = ({
|
|||||||
onSearch,
|
onSearch,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
cardBg,
|
cardBg,
|
||||||
|
themePreset = "default",
|
||||||
}) => {
|
}) => {
|
||||||
|
// 获取主题配色
|
||||||
|
const theme = THEME_PRESETS[themePreset] || THEME_PRESETS.default;
|
||||||
|
const isBlackGold = themePreset === "blackGold";
|
||||||
// 事件类型图标映射
|
// 事件类型图标映射
|
||||||
const getEventTypeIcon = (eventType) => {
|
const getEventTypeIcon = (eventType) => {
|
||||||
const iconMap = {
|
const iconMap = {
|
||||||
@@ -80,15 +137,25 @@ const NewsEventsTab = ({
|
|||||||
return iconMap[eventType] || FaNewspaper;
|
return iconMap[eventType] || FaNewspaper;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 重要性颜色映射
|
// 重要性颜色映射 - 根据主题返回不同配色
|
||||||
const getImportanceColor = (importance) => {
|
const getImportanceBadgeStyle = (importance) => {
|
||||||
|
if (isBlackGold) {
|
||||||
|
const styles = {
|
||||||
|
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 = {
|
const colorMap = {
|
||||||
S: "red",
|
S: "red",
|
||||||
A: "orange",
|
A: "orange",
|
||||||
B: "yellow",
|
B: "yellow",
|
||||||
C: "green",
|
C: "green",
|
||||||
};
|
};
|
||||||
return colorMap[importance] || "gray";
|
return { colorScheme: colorMap[importance] || "gray" };
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理搜索输入
|
// 处理搜索输入
|
||||||
@@ -129,19 +196,26 @@ const NewsEventsTab = ({
|
|||||||
// 如果开始页大于1,显示省略号
|
// 如果开始页大于1,显示省略号
|
||||||
if (startPage > 1) {
|
if (startPage > 1) {
|
||||||
pageButtons.push(
|
pageButtons.push(
|
||||||
<Text key="start-ellipsis" fontSize="sm" color="gray.400">
|
<Text key="start-ellipsis" fontSize="sm" color={theme.textMuted}>
|
||||||
...
|
...
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = startPage; i <= endPage; i++) {
|
for (let i = startPage; i <= endPage; i++) {
|
||||||
|
const isActive = i === currentPage;
|
||||||
pageButtons.push(
|
pageButtons.push(
|
||||||
<Button
|
<Button
|
||||||
key={i}
|
key={i}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant={i === currentPage ? "solid" : "outline"}
|
bg={isActive ? theme.buttonBg : (isBlackGold ? theme.inputBg : undefined)}
|
||||||
colorScheme={i === currentPage ? "blue" : "gray"}
|
color={isActive ? theme.buttonText : theme.textSecondary}
|
||||||
|
borderColor={isActive ? theme.gold : theme.cardBorder}
|
||||||
|
borderWidth="1px"
|
||||||
|
_hover={{
|
||||||
|
bg: isActive ? theme.buttonHoverBg : theme.cardHoverBg,
|
||||||
|
borderColor: theme.gold
|
||||||
|
}}
|
||||||
onClick={() => handlePageChange(i)}
|
onClick={() => handlePageChange(i)}
|
||||||
isDisabled={newsLoading}
|
isDisabled={newsLoading}
|
||||||
>
|
>
|
||||||
@@ -153,7 +227,7 @@ const NewsEventsTab = ({
|
|||||||
// 如果结束页小于总页数,显示省略号
|
// 如果结束页小于总页数,显示省略号
|
||||||
if (endPage < totalPages) {
|
if (endPage < totalPages) {
|
||||||
pageButtons.push(
|
pageButtons.push(
|
||||||
<Text key="end-ellipsis" fontSize="sm" color="gray.400">
|
<Text key="end-ellipsis" fontSize="sm" color={theme.textMuted}>
|
||||||
...
|
...
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
@@ -164,7 +238,7 @@ const NewsEventsTab = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing={4} align="stretch">
|
<VStack spacing={4} align="stretch">
|
||||||
<Card bg={cardBg} shadow="md">
|
<Card bg={cardBg || theme.cardBg} shadow="md" borderColor={theme.cardBorder} borderWidth={isBlackGold ? "1px" : "0"}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<VStack spacing={4} align="stretch">
|
<VStack spacing={4} align="stretch">
|
||||||
{/* 搜索框和统计信息 */}
|
{/* 搜索框和统计信息 */}
|
||||||
@@ -172,17 +246,25 @@ const NewsEventsTab = ({
|
|||||||
<HStack flex={1} minW="300px">
|
<HStack flex={1} minW="300px">
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<InputLeftElement pointerEvents="none">
|
<InputLeftElement pointerEvents="none">
|
||||||
<SearchIcon color="gray.400" />
|
<SearchIcon color={theme.textMuted} />
|
||||||
</InputLeftElement>
|
</InputLeftElement>
|
||||||
<Input
|
<Input
|
||||||
placeholder="搜索相关新闻..."
|
placeholder="搜索相关新闻..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
onKeyPress={handleKeyPress}
|
onKeyPress={handleKeyPress}
|
||||||
|
bg={theme.inputBg}
|
||||||
|
borderColor={theme.inputBorder}
|
||||||
|
color={theme.textPrimary}
|
||||||
|
_placeholder={{ color: theme.textMuted }}
|
||||||
|
_hover={{ borderColor: theme.gold }}
|
||||||
|
_focus={{ borderColor: theme.gold, boxShadow: `0 0 0 1px ${theme.gold}` }}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
bg={theme.buttonBg}
|
||||||
|
color={theme.buttonText}
|
||||||
|
_hover={{ bg: theme.buttonHoverBg }}
|
||||||
onClick={handleSearchSubmit}
|
onClick={handleSearchSubmit}
|
||||||
isLoading={newsLoading}
|
isLoading={newsLoading}
|
||||||
minW="80px"
|
minW="80px"
|
||||||
@@ -193,10 +275,10 @@ const NewsEventsTab = ({
|
|||||||
|
|
||||||
{newsPagination.total > 0 && (
|
{newsPagination.total > 0 && (
|
||||||
<HStack spacing={2}>
|
<HStack spacing={2}>
|
||||||
<Icon as={FaNewspaper} color="blue.500" />
|
<Icon as={FaNewspaper} color={theme.gold} />
|
||||||
<Text fontSize="sm" color="gray.600">
|
<Text fontSize="sm" color={theme.textSecondary}>
|
||||||
共找到{" "}
|
共找到{" "}
|
||||||
<Text as="span" fontWeight="bold" color="blue.600">
|
<Text as="span" fontWeight="bold" color={theme.gold}>
|
||||||
{newsPagination.total}
|
{newsPagination.total}
|
||||||
</Text>{" "}
|
</Text>{" "}
|
||||||
条新闻
|
条新闻
|
||||||
@@ -211,15 +293,15 @@ const NewsEventsTab = ({
|
|||||||
{newsLoading ? (
|
{newsLoading ? (
|
||||||
<Center h="400px">
|
<Center h="400px">
|
||||||
<VStack spacing={3}>
|
<VStack spacing={3}>
|
||||||
<Spinner size="xl" color="blue.500" thickness="4px" />
|
<Spinner size="xl" color={theme.spinnerColor} thickness="4px" />
|
||||||
<Text color="gray.600">正在加载新闻...</Text>
|
<Text color={theme.textSecondary}>正在加载新闻...</Text>
|
||||||
</VStack>
|
</VStack>
|
||||||
</Center>
|
</Center>
|
||||||
) : newsEvents.length > 0 ? (
|
) : newsEvents.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<VStack spacing={3} align="stretch">
|
<VStack spacing={3} align="stretch">
|
||||||
{newsEvents.map((event, idx) => {
|
{newsEvents.map((event, idx) => {
|
||||||
const importanceColor = getImportanceColor(
|
const importanceBadgeStyle = getImportanceBadgeStyle(
|
||||||
event.importance
|
event.importance
|
||||||
);
|
);
|
||||||
const eventTypeIcon = getEventTypeIcon(event.event_type);
|
const eventTypeIcon = getEventTypeIcon(event.event_type);
|
||||||
@@ -228,10 +310,12 @@ const NewsEventsTab = ({
|
|||||||
<Card
|
<Card
|
||||||
key={event.id || idx}
|
key={event.id || idx}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
bg={theme.cardBg}
|
||||||
|
borderColor={theme.cardBorder}
|
||||||
_hover={{
|
_hover={{
|
||||||
bg: "gray.50",
|
bg: theme.cardHoverBg,
|
||||||
shadow: "md",
|
shadow: "md",
|
||||||
borderColor: "blue.300",
|
borderColor: theme.cardHoverBorder,
|
||||||
}}
|
}}
|
||||||
transition="all 0.2s"
|
transition="all 0.2s"
|
||||||
>
|
>
|
||||||
@@ -243,13 +327,14 @@ const NewsEventsTab = ({
|
|||||||
<HStack>
|
<HStack>
|
||||||
<Icon
|
<Icon
|
||||||
as={eventTypeIcon}
|
as={eventTypeIcon}
|
||||||
color="blue.500"
|
color={theme.gold}
|
||||||
boxSize={5}
|
boxSize={5}
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text
|
||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
fontSize="lg"
|
fontSize="lg"
|
||||||
lineHeight="1.3"
|
lineHeight="1.3"
|
||||||
|
color={theme.textPrimary}
|
||||||
>
|
>
|
||||||
{event.title}
|
{event.title}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -259,22 +344,29 @@ const NewsEventsTab = ({
|
|||||||
<HStack spacing={2} flexWrap="wrap">
|
<HStack spacing={2} flexWrap="wrap">
|
||||||
{event.importance && (
|
{event.importance && (
|
||||||
<Badge
|
<Badge
|
||||||
colorScheme={importanceColor}
|
{...(isBlackGold ? {} : { colorScheme: importanceBadgeStyle.colorScheme, variant: "solid" })}
|
||||||
variant="solid"
|
bg={isBlackGold ? importanceBadgeStyle.bg : undefined}
|
||||||
|
color={isBlackGold ? importanceBadgeStyle.color : undefined}
|
||||||
px={2}
|
px={2}
|
||||||
>
|
>
|
||||||
{event.importance}级
|
{event.importance}级
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{event.event_type && (
|
{event.event_type && (
|
||||||
<Badge colorScheme="blue" variant="outline">
|
<Badge
|
||||||
|
{...(isBlackGold ? {} : { colorScheme: "blue", variant: "outline" })}
|
||||||
|
bg={isBlackGold ? "rgba(59, 130, 246, 0.2)" : undefined}
|
||||||
|
color={isBlackGold ? "#60A5FA" : undefined}
|
||||||
|
borderColor={isBlackGold ? "rgba(59, 130, 246, 0.3)" : undefined}
|
||||||
|
>
|
||||||
{event.event_type}
|
{event.event_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{event.invest_score && (
|
{event.invest_score && (
|
||||||
<Badge
|
<Badge
|
||||||
colorScheme="purple"
|
{...(isBlackGold ? {} : { colorScheme: "purple", variant: "subtle" })}
|
||||||
variant="subtle"
|
bg={isBlackGold ? "rgba(139, 92, 246, 0.2)" : undefined}
|
||||||
|
color={isBlackGold ? "#A78BFA" : undefined}
|
||||||
>
|
>
|
||||||
投资分: {event.invest_score}
|
投资分: {event.invest_score}
|
||||||
</Badge>
|
</Badge>
|
||||||
@@ -287,8 +379,9 @@ const NewsEventsTab = ({
|
|||||||
<Tag
|
<Tag
|
||||||
key={kidx}
|
key={kidx}
|
||||||
size="sm"
|
size="sm"
|
||||||
colorScheme="cyan"
|
{...(isBlackGold ? {} : { colorScheme: "cyan", variant: "subtle" })}
|
||||||
variant="subtle"
|
bg={isBlackGold ? theme.tagBg : undefined}
|
||||||
|
color={isBlackGold ? theme.tagColor : undefined}
|
||||||
>
|
>
|
||||||
{typeof keyword === "string"
|
{typeof keyword === "string"
|
||||||
? keyword
|
? keyword
|
||||||
@@ -304,7 +397,7 @@ const NewsEventsTab = ({
|
|||||||
|
|
||||||
{/* 右侧信息栏 */}
|
{/* 右侧信息栏 */}
|
||||||
<VStack align="end" spacing={1} minW="100px">
|
<VStack align="end" spacing={1} minW="100px">
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
{event.created_at
|
{event.created_at
|
||||||
? new Date(
|
? new Date(
|
||||||
event.created_at
|
event.created_at
|
||||||
@@ -321,9 +414,9 @@ const NewsEventsTab = ({
|
|||||||
<Icon
|
<Icon
|
||||||
as={FaEye}
|
as={FaEye}
|
||||||
boxSize={3}
|
boxSize={3}
|
||||||
color="gray.400"
|
color={theme.textMuted}
|
||||||
/>
|
/>
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
{event.view_count}
|
{event.view_count}
|
||||||
</Text>
|
</Text>
|
||||||
</HStack>
|
</HStack>
|
||||||
@@ -333,16 +426,16 @@ const NewsEventsTab = ({
|
|||||||
<Icon
|
<Icon
|
||||||
as={FaFire}
|
as={FaFire}
|
||||||
boxSize={3}
|
boxSize={3}
|
||||||
color="orange.400"
|
color={theme.goldLight}
|
||||||
/>
|
/>
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
{event.hot_score.toFixed(1)}
|
{event.hot_score.toFixed(1)}
|
||||||
</Text>
|
</Text>
|
||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
{event.creator && (
|
{event.creator && (
|
||||||
<Text fontSize="xs" color="gray.400">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
@{event.creator.username}
|
@{event.creator.username}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
@@ -353,7 +446,7 @@ const NewsEventsTab = ({
|
|||||||
{event.description && (
|
{event.description && (
|
||||||
<Text
|
<Text
|
||||||
fontSize="sm"
|
fontSize="sm"
|
||||||
color="gray.700"
|
color={theme.textSecondary}
|
||||||
lineHeight="1.6"
|
lineHeight="1.6"
|
||||||
>
|
>
|
||||||
{event.description}
|
{event.description}
|
||||||
@@ -367,18 +460,18 @@ const NewsEventsTab = ({
|
|||||||
<Box
|
<Box
|
||||||
pt={2}
|
pt={2}
|
||||||
borderTop="1px"
|
borderTop="1px"
|
||||||
borderColor="gray.200"
|
borderColor={theme.cardBorder}
|
||||||
>
|
>
|
||||||
<HStack spacing={6} flexWrap="wrap">
|
<HStack spacing={6} flexWrap="wrap">
|
||||||
<HStack spacing={1}>
|
<HStack spacing={1}>
|
||||||
<Icon
|
<Icon
|
||||||
as={FaChartLine}
|
as={FaChartLine}
|
||||||
boxSize={3}
|
boxSize={3}
|
||||||
color="gray.500"
|
color={theme.textMuted}
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text
|
||||||
fontSize="xs"
|
fontSize="xs"
|
||||||
color="gray.500"
|
color={theme.textMuted}
|
||||||
fontWeight="medium"
|
fontWeight="medium"
|
||||||
>
|
>
|
||||||
相关涨跌:
|
相关涨跌:
|
||||||
@@ -387,7 +480,7 @@ const NewsEventsTab = ({
|
|||||||
{event.related_avg_chg !== null &&
|
{event.related_avg_chg !== null &&
|
||||||
event.related_avg_chg !== undefined && (
|
event.related_avg_chg !== undefined && (
|
||||||
<HStack spacing={1}>
|
<HStack spacing={1}>
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
平均
|
平均
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
@@ -395,8 +488,8 @@ const NewsEventsTab = ({
|
|||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
color={
|
color={
|
||||||
event.related_avg_chg > 0
|
event.related_avg_chg > 0
|
||||||
? "red.500"
|
? "#EF4444"
|
||||||
: "green.500"
|
: "#10B981"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{event.related_avg_chg > 0 ? "+" : ""}
|
{event.related_avg_chg > 0 ? "+" : ""}
|
||||||
@@ -407,7 +500,7 @@ const NewsEventsTab = ({
|
|||||||
{event.related_max_chg !== null &&
|
{event.related_max_chg !== null &&
|
||||||
event.related_max_chg !== undefined && (
|
event.related_max_chg !== undefined && (
|
||||||
<HStack spacing={1}>
|
<HStack spacing={1}>
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
最大
|
最大
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
@@ -415,8 +508,8 @@ const NewsEventsTab = ({
|
|||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
color={
|
color={
|
||||||
event.related_max_chg > 0
|
event.related_max_chg > 0
|
||||||
? "red.500"
|
? "#EF4444"
|
||||||
: "green.500"
|
: "#10B981"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{event.related_max_chg > 0 ? "+" : ""}
|
{event.related_max_chg > 0 ? "+" : ""}
|
||||||
@@ -427,7 +520,7 @@ const NewsEventsTab = ({
|
|||||||
{event.related_week_chg !== null &&
|
{event.related_week_chg !== null &&
|
||||||
event.related_week_chg !== undefined && (
|
event.related_week_chg !== undefined && (
|
||||||
<HStack spacing={1}>
|
<HStack spacing={1}>
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color={theme.textMuted}>
|
||||||
周
|
周
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
@@ -435,8 +528,8 @@ const NewsEventsTab = ({
|
|||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
color={
|
color={
|
||||||
event.related_week_chg > 0
|
event.related_week_chg > 0
|
||||||
? "red.500"
|
? "#EF4444"
|
||||||
: "green.500"
|
: "#10B981"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{event.related_week_chg > 0
|
{event.related_week_chg > 0
|
||||||
@@ -465,7 +558,7 @@ const NewsEventsTab = ({
|
|||||||
flexWrap="wrap"
|
flexWrap="wrap"
|
||||||
>
|
>
|
||||||
{/* 分页信息 */}
|
{/* 分页信息 */}
|
||||||
<Text fontSize="sm" color="gray.600">
|
<Text fontSize="sm" color={theme.textSecondary}>
|
||||||
第 {newsPagination.page} / {newsPagination.pages} 页
|
第 {newsPagination.page} / {newsPagination.pages} 页
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
@@ -473,6 +566,11 @@ const NewsEventsTab = ({
|
|||||||
<HStack spacing={2}>
|
<HStack spacing={2}>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
bg={isBlackGold ? theme.inputBg : undefined}
|
||||||
|
color={theme.textSecondary}
|
||||||
|
borderColor={theme.cardBorder}
|
||||||
|
borderWidth="1px"
|
||||||
|
_hover={{ bg: theme.cardHoverBg, borderColor: theme.gold }}
|
||||||
onClick={() => handlePageChange(1)}
|
onClick={() => handlePageChange(1)}
|
||||||
isDisabled={!newsPagination.has_prev || newsLoading}
|
isDisabled={!newsPagination.has_prev || newsLoading}
|
||||||
leftIcon={<Icon as={FaChevronLeft} />}
|
leftIcon={<Icon as={FaChevronLeft} />}
|
||||||
@@ -481,6 +579,11 @@ const NewsEventsTab = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
bg={isBlackGold ? theme.inputBg : undefined}
|
||||||
|
color={theme.textSecondary}
|
||||||
|
borderColor={theme.cardBorder}
|
||||||
|
borderWidth="1px"
|
||||||
|
_hover={{ bg: theme.cardHoverBg, borderColor: theme.gold }}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handlePageChange(newsPagination.page - 1)
|
handlePageChange(newsPagination.page - 1)
|
||||||
}
|
}
|
||||||
@@ -494,6 +597,11 @@ const NewsEventsTab = ({
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
bg={isBlackGold ? theme.inputBg : undefined}
|
||||||
|
color={theme.textSecondary}
|
||||||
|
borderColor={theme.cardBorder}
|
||||||
|
borderWidth="1px"
|
||||||
|
_hover={{ bg: theme.cardHoverBg, borderColor: theme.gold }}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handlePageChange(newsPagination.page + 1)
|
handlePageChange(newsPagination.page + 1)
|
||||||
}
|
}
|
||||||
@@ -503,6 +611,11 @@ const NewsEventsTab = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
bg={isBlackGold ? theme.inputBg : undefined}
|
||||||
|
color={theme.textSecondary}
|
||||||
|
borderColor={theme.cardBorder}
|
||||||
|
borderWidth="1px"
|
||||||
|
_hover={{ bg: theme.cardHoverBg, borderColor: theme.gold }}
|
||||||
onClick={() => handlePageChange(newsPagination.pages)}
|
onClick={() => handlePageChange(newsPagination.pages)}
|
||||||
isDisabled={!newsPagination.has_next || newsLoading}
|
isDisabled={!newsPagination.has_next || newsLoading}
|
||||||
rightIcon={<Icon as={FaChevronRight} />}
|
rightIcon={<Icon as={FaChevronRight} />}
|
||||||
@@ -517,11 +630,11 @@ const NewsEventsTab = ({
|
|||||||
) : (
|
) : (
|
||||||
<Center h="400px">
|
<Center h="400px">
|
||||||
<VStack spacing={3}>
|
<VStack spacing={3}>
|
||||||
<Icon as={FaNewspaper} boxSize={16} color="gray.300" />
|
<Icon as={FaNewspaper} boxSize={16} color={isBlackGold ? theme.gold : "gray.300"} opacity={0.5} />
|
||||||
<Text color="gray.500" fontSize="lg" fontWeight="medium">
|
<Text color={theme.textSecondary} fontSize="lg" fontWeight="medium">
|
||||||
暂无相关新闻
|
暂无相关新闻
|
||||||
</Text>
|
</Text>
|
||||||
<Text fontSize="sm" color="gray.400">
|
<Text fontSize="sm" color={theme.textMuted}>
|
||||||
{searchQuery ? "尝试修改搜索关键词" : "该公司暂无新闻动态"}
|
{searchQuery ? "尝试修改搜索关键词" : "该公司暂无新闻动态"}
|
||||||
</Text>
|
</Text>
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useAnnouncementsData.ts
|
// src/views/Company/components/CompanyOverview/hooks/useAnnouncementsData.ts
|
||||||
// 公告数据 Hook - 用于公司公告 Tab
|
// 公告数据 Hook - 用于公司公告 Tab
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { Announcement } from "../types";
|
import type { Announcement } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -28,34 +26,38 @@ export const useAnnouncementsData = (stockCode?: string): UseAnnouncementsDataRe
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const response = await fetch(
|
setLoading(true);
|
||||||
`${API_BASE_URL}/api/stock/${stockCode}/announcements?limit=20`
|
setError(null);
|
||||||
);
|
|
||||||
const result = (await response.json()) as ApiResponse<Announcement[]>;
|
|
||||||
|
|
||||||
if (result.success) {
|
try {
|
||||||
setAnnouncements(result.data);
|
const { data: result } = await axios.get<ApiResponse<Announcement[]>>(
|
||||||
} else {
|
`/api/stock/${stockCode}/announcements?limit=20`,
|
||||||
setError("加载公告数据失败");
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
setAnnouncements(result.data);
|
||||||
|
} else {
|
||||||
|
setError("加载公告数据失败");
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useAnnouncementsData", "loadData", err, { stockCode });
|
||||||
|
setError("网络请求失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
};
|
||||||
logger.error("useAnnouncementsData", "loadData", err, { stockCode });
|
|
||||||
setError("网络请求失败");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return { announcements, loading, error };
|
return { announcements, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useBasicInfo.ts
|
// src/views/Company/components/CompanyOverview/hooks/useBasicInfo.ts
|
||||||
// 公司基本信息 Hook - 用于 CompanyHeaderCard
|
// 公司基本信息 Hook - 用于 CompanyHeaderCard
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { BasicInfo } from "../types";
|
import type { BasicInfo } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -28,32 +26,38 @@ export const useBasicInfo = (stockCode?: string): UseBasicInfoResult => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/stock/${stockCode}/basic-info`);
|
setLoading(true);
|
||||||
const result = (await response.json()) as ApiResponse<BasicInfo>;
|
setError(null);
|
||||||
|
|
||||||
if (result.success) {
|
try {
|
||||||
setBasicInfo(result.data);
|
const { data: result } = await axios.get<ApiResponse<BasicInfo>>(
|
||||||
} else {
|
`/api/stock/${stockCode}/basic-info`,
|
||||||
setError("加载基本信息失败");
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
setBasicInfo(result.data);
|
||||||
|
} else {
|
||||||
|
setError("加载基本信息失败");
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useBasicInfo", "loadData", err, { stockCode });
|
||||||
|
setError("网络请求失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
};
|
||||||
logger.error("useBasicInfo", "loadData", err, { stockCode });
|
|
||||||
setError("网络请求失败");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return { basicInfo, loading, error };
|
return { basicInfo, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useBranchesData.ts
|
// src/views/Company/components/CompanyOverview/hooks/useBranchesData.ts
|
||||||
// 分支机构数据 Hook - 用于分支机构 Tab
|
// 分支机构数据 Hook - 用于分支机构 Tab
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { Branch } from "../types";
|
import type { Branch } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -28,32 +26,38 @@ export const useBranchesData = (stockCode?: string): UseBranchesDataResult => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/stock/${stockCode}/branches`);
|
setLoading(true);
|
||||||
const result = (await response.json()) as ApiResponse<Branch[]>;
|
setError(null);
|
||||||
|
|
||||||
if (result.success) {
|
try {
|
||||||
setBranches(result.data);
|
const { data: result } = await axios.get<ApiResponse<Branch[]>>(
|
||||||
} else {
|
`/api/stock/${stockCode}/branches`,
|
||||||
setError("加载分支机构数据失败");
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
setBranches(result.data);
|
||||||
|
} else {
|
||||||
|
setError("加载分支机构数据失败");
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useBranchesData", "loadData", err, { stockCode });
|
||||||
|
setError("网络请求失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
};
|
||||||
logger.error("useBranchesData", "loadData", err, { stockCode });
|
|
||||||
setError("网络请求失败");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return { branches, loading, error };
|
return { branches, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useCompanyOverviewData.ts
|
|
||||||
// 公司概览数据加载 Hook
|
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
|
||||||
import { logger } from "@utils/logger";
|
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
|
||||||
import type {
|
|
||||||
BasicInfo,
|
|
||||||
ActualControl,
|
|
||||||
Concentration,
|
|
||||||
Management,
|
|
||||||
Shareholder,
|
|
||||||
Branch,
|
|
||||||
Announcement,
|
|
||||||
DisclosureSchedule,
|
|
||||||
CompanyOverviewData,
|
|
||||||
} from "../types";
|
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
|
||||||
success: boolean;
|
|
||||||
data: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 公司概览数据加载 Hook
|
|
||||||
* @param propStockCode - 股票代码
|
|
||||||
* @returns 公司概览数据
|
|
||||||
*/
|
|
||||||
export const useCompanyOverviewData = (propStockCode?: string): CompanyOverviewData => {
|
|
||||||
const [stockCode, setStockCode] = useState(propStockCode || "000001");
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [dataLoaded, setDataLoaded] = useState(false);
|
|
||||||
|
|
||||||
// 基本信息数据
|
|
||||||
const [basicInfo, setBasicInfo] = useState<BasicInfo | null>(null);
|
|
||||||
const [actualControl, setActualControl] = useState<ActualControl[]>([]);
|
|
||||||
const [concentration, setConcentration] = useState<Concentration[]>([]);
|
|
||||||
const [management, setManagement] = useState<Management[]>([]);
|
|
||||||
const [topCirculationShareholders, setTopCirculationShareholders] = useState<Shareholder[]>([]);
|
|
||||||
const [topShareholders, setTopShareholders] = useState<Shareholder[]>([]);
|
|
||||||
const [branches, setBranches] = useState<Branch[]>([]);
|
|
||||||
const [announcements, setAnnouncements] = useState<Announcement[]>([]);
|
|
||||||
const [disclosureSchedule, setDisclosureSchedule] = useState<DisclosureSchedule[]>([]);
|
|
||||||
|
|
||||||
// 监听 props 中的 stockCode 变化
|
|
||||||
useEffect(() => {
|
|
||||||
if (propStockCode && propStockCode !== stockCode) {
|
|
||||||
setStockCode(propStockCode);
|
|
||||||
setDataLoaded(false);
|
|
||||||
}
|
|
||||||
}, [propStockCode, stockCode]);
|
|
||||||
|
|
||||||
// 加载基本信息数据(9个接口)
|
|
||||||
const loadBasicInfoData = useCallback(async () => {
|
|
||||||
if (dataLoaded) return;
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const [
|
|
||||||
basicRes,
|
|
||||||
actualRes,
|
|
||||||
concentrationRes,
|
|
||||||
managementRes,
|
|
||||||
circulationRes,
|
|
||||||
shareholdersRes,
|
|
||||||
branchesRes,
|
|
||||||
announcementsRes,
|
|
||||||
disclosureRes,
|
|
||||||
] = await Promise.all([
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/basic-info`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<BasicInfo>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/actual-control`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<ActualControl[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/concentration`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Concentration[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/management?active_only=true`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Management[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/top-circulation-shareholders?limit=10`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Shareholder[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/top-shareholders?limit=10`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Shareholder[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/branches`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Branch[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/announcements?limit=20`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Announcement[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/disclosure-schedule`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<DisclosureSchedule[]>>,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (basicRes.success) setBasicInfo(basicRes.data);
|
|
||||||
if (actualRes.success) setActualControl(actualRes.data);
|
|
||||||
if (concentrationRes.success) setConcentration(concentrationRes.data);
|
|
||||||
if (managementRes.success) setManagement(managementRes.data);
|
|
||||||
if (circulationRes.success) setTopCirculationShareholders(circulationRes.data);
|
|
||||||
if (shareholdersRes.success) setTopShareholders(shareholdersRes.data);
|
|
||||||
if (branchesRes.success) setBranches(branchesRes.data);
|
|
||||||
if (announcementsRes.success) setAnnouncements(announcementsRes.data);
|
|
||||||
if (disclosureRes.success) setDisclosureSchedule(disclosureRes.data);
|
|
||||||
|
|
||||||
setDataLoaded(true);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("useCompanyOverviewData", "loadBasicInfoData", err, { stockCode });
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode, dataLoaded]);
|
|
||||||
|
|
||||||
// 首次加载
|
|
||||||
useEffect(() => {
|
|
||||||
if (stockCode) {
|
|
||||||
loadBasicInfoData();
|
|
||||||
}
|
|
||||||
}, [stockCode, loadBasicInfoData]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
basicInfo,
|
|
||||||
actualControl,
|
|
||||||
concentration,
|
|
||||||
management,
|
|
||||||
topCirculationShareholders,
|
|
||||||
topShareholders,
|
|
||||||
branches,
|
|
||||||
announcements,
|
|
||||||
disclosureSchedule,
|
|
||||||
loading,
|
|
||||||
dataLoaded,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useDisclosureData.ts
|
// src/views/Company/components/CompanyOverview/hooks/useDisclosureData.ts
|
||||||
// 披露日程数据 Hook - 用于工商信息 Tab
|
// 披露日程数据 Hook - 用于工商信息 Tab
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { DisclosureSchedule } from "../types";
|
import type { DisclosureSchedule } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -28,34 +26,38 @@ export const useDisclosureData = (stockCode?: string): UseDisclosureDataResult =
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const response = await fetch(
|
setLoading(true);
|
||||||
`${API_BASE_URL}/api/stock/${stockCode}/disclosure-schedule`
|
setError(null);
|
||||||
);
|
|
||||||
const result = (await response.json()) as ApiResponse<DisclosureSchedule[]>;
|
|
||||||
|
|
||||||
if (result.success) {
|
try {
|
||||||
setDisclosureSchedule(result.data);
|
const { data: result } = await axios.get<ApiResponse<DisclosureSchedule[]>>(
|
||||||
} else {
|
`/api/stock/${stockCode}/disclosure-schedule`,
|
||||||
setError("加载披露日程数据失败");
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
setDisclosureSchedule(result.data);
|
||||||
|
} else {
|
||||||
|
setError("加载披露日程数据失败");
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useDisclosureData", "loadData", err, { stockCode });
|
||||||
|
setError("网络请求失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
};
|
||||||
logger.error("useDisclosureData", "loadData", err, { stockCode });
|
|
||||||
setError("网络请求失败");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return { disclosureSchedule, loading, error };
|
return { disclosureSchedule, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useManagementData.ts
|
// src/views/Company/components/CompanyOverview/hooks/useManagementData.ts
|
||||||
// 管理团队数据 Hook - 用于管理团队 Tab
|
// 管理团队数据 Hook - 用于管理团队 Tab
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { Management } from "../types";
|
import type { Management } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -28,34 +26,38 @@ export const useManagementData = (stockCode?: string): UseManagementDataResult =
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const response = await fetch(
|
setLoading(true);
|
||||||
`${API_BASE_URL}/api/stock/${stockCode}/management?active_only=true`
|
setError(null);
|
||||||
);
|
|
||||||
const result = (await response.json()) as ApiResponse<Management[]>;
|
|
||||||
|
|
||||||
if (result.success) {
|
try {
|
||||||
setManagement(result.data);
|
const { data: result } = await axios.get<ApiResponse<Management[]>>(
|
||||||
} else {
|
`/api/stock/${stockCode}/management?active_only=true`,
|
||||||
setError("加载管理团队数据失败");
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
setManagement(result.data);
|
||||||
|
} else {
|
||||||
|
setError("加载管理团队数据失败");
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useManagementData", "loadData", err, { stockCode });
|
||||||
|
setError("网络请求失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
};
|
||||||
logger.error("useManagementData", "loadData", err, { stockCode });
|
|
||||||
setError("网络请求失败");
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return { management, loading, error };
|
return { management, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
// src/views/Company/components/CompanyOverview/hooks/useShareholderData.ts
|
// src/views/Company/components/CompanyOverview/hooks/useShareholderData.ts
|
||||||
// 股权结构数据 Hook - 用于股权结构 Tab
|
// 股权结构数据 Hook - 用于股权结构 Tab
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
import type { ActualControl, Concentration, Shareholder } from "../types";
|
import type { ActualControl, Concentration, Shareholder } from "../types";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -34,43 +32,44 @@ export const useShareholderData = (stockCode?: string): UseShareholderDataResult
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
useEffect(() => {
|
||||||
if (!stockCode) return;
|
if (!stockCode) return;
|
||||||
|
|
||||||
setLoading(true);
|
const controller = new AbortController();
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
const loadData = async () => {
|
||||||
const [actualRes, concentrationRes, shareholdersRes, circulationRes] = await Promise.all([
|
setLoading(true);
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/actual-control`).then((r) =>
|
setError(null);
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<ActualControl[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/concentration`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Concentration[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/top-shareholders?limit=10`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Shareholder[]>>,
|
|
||||||
fetch(`${API_BASE_URL}/api/stock/${stockCode}/top-circulation-shareholders?limit=10`).then((r) =>
|
|
||||||
r.json()
|
|
||||||
) as Promise<ApiResponse<Shareholder[]>>,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (actualRes.success) setActualControl(actualRes.data);
|
try {
|
||||||
if (concentrationRes.success) setConcentration(concentrationRes.data);
|
const [
|
||||||
if (shareholdersRes.success) setTopShareholders(shareholdersRes.data);
|
{ data: actualRes },
|
||||||
if (circulationRes.success) setTopCirculationShareholders(circulationRes.data);
|
{ data: concentrationRes },
|
||||||
} catch (err) {
|
{ data: shareholdersRes },
|
||||||
logger.error("useShareholderData", "loadData", err, { stockCode });
|
{ data: circulationRes },
|
||||||
setError("加载股权结构数据失败");
|
] = await Promise.all([
|
||||||
} finally {
|
axios.get<ApiResponse<ActualControl[]>>(`/api/stock/${stockCode}/actual-control`, { signal: controller.signal }),
|
||||||
setLoading(false);
|
axios.get<ApiResponse<Concentration[]>>(`/api/stock/${stockCode}/concentration`, { signal: controller.signal }),
|
||||||
}
|
axios.get<ApiResponse<Shareholder[]>>(`/api/stock/${stockCode}/top-shareholders?limit=10`, { signal: controller.signal }),
|
||||||
}, [stockCode]);
|
axios.get<ApiResponse<Shareholder[]>>(`/api/stock/${stockCode}/top-circulation-shareholders?limit=10`, { signal: controller.signal }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (actualRes.success) setActualControl(actualRes.data);
|
||||||
|
if (concentrationRes.success) setConcentration(concentrationRes.data);
|
||||||
|
if (shareholdersRes.success) setTopShareholders(shareholdersRes.data);
|
||||||
|
if (circulationRes.success) setTopCirculationShareholders(circulationRes.data);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === "CanceledError") return;
|
||||||
|
logger.error("useShareholderData", "loadData", err, { stockCode });
|
||||||
|
setError("加载股权结构数据失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
return () => controller.abort();
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
actualControl,
|
actualControl,
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { VStack } from "@chakra-ui/react";
|
import { VStack } from "@chakra-ui/react";
|
||||||
|
|
||||||
import { useBasicInfo } from "./hooks/useBasicInfo";
|
|
||||||
import type { CompanyOverviewProps } from "./types";
|
import type { CompanyOverviewProps } from "./types";
|
||||||
|
|
||||||
// 子组件(暂保持 JS)
|
// 子组件
|
||||||
import BasicInfoTab from "./BasicInfoTab";
|
import BasicInfoTab from "./BasicInfoTab";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,17 +17,13 @@ import BasicInfoTab from "./BasicInfoTab";
|
|||||||
*
|
*
|
||||||
* 懒加载策略:
|
* 懒加载策略:
|
||||||
* - BasicInfoTab 内部根据 Tab 切换懒加载数据
|
* - BasicInfoTab 内部根据 Tab 切换懒加载数据
|
||||||
|
* - 各 Panel 组件自行获取所需数据(如 BusinessInfoPanel 调用 useBasicInfo)
|
||||||
*/
|
*/
|
||||||
const CompanyOverview: React.FC<CompanyOverviewProps> = ({ stockCode }) => {
|
const CompanyOverview: React.FC<CompanyOverviewProps> = ({ stockCode }) => {
|
||||||
const { basicInfo } = useBasicInfo(stockCode);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing={6} align="stretch">
|
<VStack spacing={6} align="stretch">
|
||||||
{/* 基本信息内容 - 传入 stockCode,内部懒加载各 Tab 数据 */}
|
{/* 基本信息内容 - 传入 stockCode,内部懒加载各 Tab 数据 */}
|
||||||
<BasicInfoTab
|
<BasicInfoTab stockCode={stockCode} />
|
||||||
stockCode={stockCode}
|
|
||||||
basicInfo={basicInfo}
|
|
||||||
/>
|
|
||||||
</VStack>
|
</VStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ export interface BasicInfo {
|
|||||||
email?: string;
|
email?: string;
|
||||||
tel?: string;
|
tel?: string;
|
||||||
company_intro?: string;
|
company_intro?: string;
|
||||||
|
// 工商信息字段
|
||||||
|
credit_code?: string;
|
||||||
|
company_size?: string;
|
||||||
|
reg_address?: string;
|
||||||
|
office_address?: string;
|
||||||
|
accounting_firm?: string;
|
||||||
|
law_firm?: string;
|
||||||
|
main_business?: string;
|
||||||
|
business_scope?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,23 +116,6 @@ export interface DisclosureSchedule {
|
|||||||
disclosure_date?: string;
|
disclosure_date?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* useCompanyOverviewData Hook 返回值
|
|
||||||
*/
|
|
||||||
export interface CompanyOverviewData {
|
|
||||||
basicInfo: BasicInfo | null;
|
|
||||||
actualControl: ActualControl[];
|
|
||||||
concentration: Concentration[];
|
|
||||||
management: Management[];
|
|
||||||
topCirculationShareholders: Shareholder[];
|
|
||||||
topShareholders: Shareholder[];
|
|
||||||
branches: Branch[];
|
|
||||||
announcements: Announcement[];
|
|
||||||
disclosureSchedule: DisclosureSchedule[];
|
|
||||||
loading: boolean;
|
|
||||||
dataLoaded: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CompanyOverview 组件 Props
|
* CompanyOverview 组件 Props
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,13 +3,11 @@
|
|||||||
|
|
||||||
import React, { useState, useEffect, useCallback, useRef } from "react";
|
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import { logger } from "@utils/logger";
|
import { logger } from "@utils/logger";
|
||||||
import { getApiBase } from "@utils/apiConfig";
|
import axios from "@utils/axiosConfig";
|
||||||
|
|
||||||
// 复用原有的展示组件
|
// 复用原有的展示组件
|
||||||
import DeepAnalysisTab from "../CompanyOverview/DeepAnalysisTab";
|
import DeepAnalysisTab from "../CompanyOverview/DeepAnalysisTab";
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab 与 API 接口映射
|
* Tab 与 API 接口映射
|
||||||
* - strategy 和 business 共用 comprehensive 接口
|
* - strategy 和 business 共用 comprehensive 接口
|
||||||
@@ -84,9 +82,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
|||||||
switch (apiKey) {
|
switch (apiKey) {
|
||||||
case "comprehensive":
|
case "comprehensive":
|
||||||
setComprehensiveLoading(true);
|
setComprehensiveLoading(true);
|
||||||
const comprehensiveRes = await fetch(
|
const { data: comprehensiveRes } = await axios.get(
|
||||||
`${API_BASE_URL}/api/company/comprehensive-analysis/${stockCode}`
|
`/api/company/comprehensive-analysis/${stockCode}`
|
||||||
).then((r) => r.json());
|
);
|
||||||
// 检查 stockCode 是否已变更(防止竞态)
|
// 检查 stockCode 是否已变更(防止竞态)
|
||||||
if (currentStockCodeRef.current === stockCode) {
|
if (currentStockCodeRef.current === stockCode) {
|
||||||
if (comprehensiveRes.success)
|
if (comprehensiveRes.success)
|
||||||
@@ -97,9 +95,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
|||||||
|
|
||||||
case "valueChain":
|
case "valueChain":
|
||||||
setValueChainLoading(true);
|
setValueChainLoading(true);
|
||||||
const valueChainRes = await fetch(
|
const { data: valueChainRes } = await axios.get(
|
||||||
`${API_BASE_URL}/api/company/value-chain-analysis/${stockCode}`
|
`/api/company/value-chain-analysis/${stockCode}`
|
||||||
).then((r) => r.json());
|
);
|
||||||
if (currentStockCodeRef.current === stockCode) {
|
if (currentStockCodeRef.current === stockCode) {
|
||||||
if (valueChainRes.success) setValueChainData(valueChainRes.data);
|
if (valueChainRes.success) setValueChainData(valueChainRes.data);
|
||||||
loadedApisRef.current.valueChain = true;
|
loadedApisRef.current.valueChain = true;
|
||||||
@@ -108,9 +106,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
|||||||
|
|
||||||
case "keyFactors":
|
case "keyFactors":
|
||||||
setKeyFactorsLoading(true);
|
setKeyFactorsLoading(true);
|
||||||
const keyFactorsRes = await fetch(
|
const { data: keyFactorsRes } = await axios.get(
|
||||||
`${API_BASE_URL}/api/company/key-factors-timeline/${stockCode}`
|
`/api/company/key-factors-timeline/${stockCode}`
|
||||||
).then((r) => r.json());
|
);
|
||||||
if (currentStockCodeRef.current === stockCode) {
|
if (currentStockCodeRef.current === stockCode) {
|
||||||
if (keyFactorsRes.success) setKeyFactorsData(keyFactorsRes.data);
|
if (keyFactorsRes.success) setKeyFactorsData(keyFactorsRes.data);
|
||||||
loadedApisRef.current.keyFactors = true;
|
loadedApisRef.current.keyFactors = true;
|
||||||
@@ -119,9 +117,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
|||||||
|
|
||||||
case "industryRank":
|
case "industryRank":
|
||||||
setIndustryRankLoading(true);
|
setIndustryRankLoading(true);
|
||||||
const industryRankRes = await fetch(
|
const { data: industryRankRes } = await axios.get(
|
||||||
`${API_BASE_URL}/api/financial/industry-rank/${stockCode}`
|
`/api/financial/industry-rank/${stockCode}`
|
||||||
).then((r) => r.json());
|
);
|
||||||
if (currentStockCodeRef.current === stockCode) {
|
if (currentStockCodeRef.current === stockCode) {
|
||||||
if (industryRankRes.success) setIndustryRankData(industryRankRes.data);
|
if (industryRankRes.success) setIndustryRankData(industryRankRes.data);
|
||||||
loadedApisRef.current.industryRank = true;
|
loadedApisRef.current.industryRank = true;
|
||||||
|
|||||||
@@ -1,22 +1,46 @@
|
|||||||
// src/views/Company/components/DynamicTracking/components/ForecastPanel.js
|
// src/views/Company/components/DynamicTracking/components/ForecastPanel.js
|
||||||
// 业绩预告面板
|
// 业绩预告面板 - 黑金主题
|
||||||
|
|
||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
VStack,
|
VStack,
|
||||||
Card,
|
Box,
|
||||||
CardBody,
|
Flex,
|
||||||
HStack,
|
|
||||||
Badge,
|
|
||||||
Text,
|
Text,
|
||||||
Spinner,
|
Spinner,
|
||||||
Center,
|
Center,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
|
import { Tag } from 'antd';
|
||||||
import { logger } from '@utils/logger';
|
import { logger } from '@utils/logger';
|
||||||
import { getApiBase } from '@utils/apiConfig';
|
import axios from '@utils/axiosConfig';
|
||||||
import { THEME } from '../../CompanyOverview/BasicInfoTab/config';
|
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
// 黑金主题
|
||||||
|
const THEME = {
|
||||||
|
gold: '#D4AF37',
|
||||||
|
goldLight: 'rgba(212, 175, 55, 0.15)',
|
||||||
|
goldBorder: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
bgDark: '#1A202C',
|
||||||
|
cardBg: 'rgba(26, 32, 44, 0.6)',
|
||||||
|
text: '#E2E8F0',
|
||||||
|
textSecondary: '#A0AEC0',
|
||||||
|
positive: '#E53E3E',
|
||||||
|
negative: '#48BB78',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 预告类型配色
|
||||||
|
const getForecastTypeStyle = (type) => {
|
||||||
|
const styles = {
|
||||||
|
'预增': { color: '#E53E3E', bg: 'rgba(229, 62, 62, 0.15)', border: 'rgba(229, 62, 62, 0.3)' },
|
||||||
|
'预减': { color: '#48BB78', bg: 'rgba(72, 187, 120, 0.15)', border: 'rgba(72, 187, 120, 0.3)' },
|
||||||
|
'扭亏': { color: '#D4AF37', bg: 'rgba(212, 175, 55, 0.15)', border: 'rgba(212, 175, 55, 0.3)' },
|
||||||
|
'首亏': { color: '#48BB78', bg: 'rgba(72, 187, 120, 0.15)', border: 'rgba(72, 187, 120, 0.3)' },
|
||||||
|
'续亏': { color: '#718096', bg: 'rgba(113, 128, 150, 0.15)', border: 'rgba(113, 128, 150, 0.3)' },
|
||||||
|
'续盈': { color: '#E53E3E', bg: 'rgba(229, 62, 62, 0.15)', border: 'rgba(229, 62, 62, 0.3)' },
|
||||||
|
'略增': { color: '#ED8936', bg: 'rgba(237, 137, 54, 0.15)', border: 'rgba(237, 137, 54, 0.3)' },
|
||||||
|
'略减': { color: '#38B2AC', bg: 'rgba(56, 178, 172, 0.15)', border: 'rgba(56, 178, 172, 0.3)' },
|
||||||
|
};
|
||||||
|
return styles[type] || { color: THEME.gold, bg: THEME.goldLight, border: THEME.goldBorder };
|
||||||
|
};
|
||||||
|
|
||||||
const ForecastPanel = ({ stockCode }) => {
|
const ForecastPanel = ({ stockCode }) => {
|
||||||
const [forecast, setForecast] = useState(null);
|
const [forecast, setForecast] = useState(null);
|
||||||
@@ -27,10 +51,9 @@ const ForecastPanel = ({ stockCode }) => {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const { data: result } = await axios.get(
|
||||||
`${API_BASE_URL}/api/stock/${stockCode}/forecast`
|
`/api/stock/${stockCode}/forecast`
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
|
||||||
if (result.success && result.data) {
|
if (result.success && result.data) {
|
||||||
setForecast(result.data);
|
setForecast(result.data);
|
||||||
}
|
}
|
||||||
@@ -63,33 +86,69 @@ const ForecastPanel = ({ stockCode }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing={4} align="stretch">
|
<VStack spacing={3} align="stretch">
|
||||||
{forecast.forecasts.map((item, idx) => (
|
{forecast.forecasts.map((item, idx) => {
|
||||||
<Card key={idx} bg={THEME.cardBg} borderColor={THEME.border} borderWidth="1px">
|
const typeStyle = getForecastTypeStyle(item.forecast_type);
|
||||||
<CardBody>
|
|
||||||
<HStack justify="space-between" mb={2}>
|
return (
|
||||||
<Badge colorScheme="blue">{item.forecast_type}</Badge>
|
<Box
|
||||||
|
key={idx}
|
||||||
|
bg={THEME.cardBg}
|
||||||
|
border="1px solid"
|
||||||
|
borderColor={THEME.goldBorder}
|
||||||
|
borderRadius="md"
|
||||||
|
p={4}
|
||||||
|
>
|
||||||
|
{/* 头部:类型标签 + 报告期 */}
|
||||||
|
<Flex justify="space-between" align="center" mb={3}>
|
||||||
|
<Tag
|
||||||
|
style={{
|
||||||
|
color: typeStyle.color,
|
||||||
|
background: typeStyle.bg,
|
||||||
|
border: `1px solid ${typeStyle.border}`,
|
||||||
|
fontWeight: 500,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.forecast_type}
|
||||||
|
</Tag>
|
||||||
<Text fontSize="sm" color={THEME.textSecondary}>
|
<Text fontSize="sm" color={THEME.textSecondary}>
|
||||||
报告期: {item.report_date}
|
报告期: {item.report_date}
|
||||||
</Text>
|
</Text>
|
||||||
</HStack>
|
</Flex>
|
||||||
<Text mb={2} color={THEME.text}>{item.content}</Text>
|
|
||||||
|
{/* 内容 */}
|
||||||
|
<Text color={THEME.text} fontSize="sm" lineHeight="1.6" mb={3}>
|
||||||
|
{item.content}
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
{/* 原因(如有) */}
|
||||||
{item.reason && (
|
{item.reason && (
|
||||||
<Text fontSize="sm" color={THEME.textSecondary}>
|
<Text fontSize="xs" color={THEME.textSecondary} mb={3}>
|
||||||
{item.reason}
|
{item.reason}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
{item.change_range?.lower && (
|
|
||||||
<HStack mt={2}>
|
{/* 变动范围 */}
|
||||||
<Text fontSize="sm" color={THEME.textSecondary}>预计变动范围:</Text>
|
{item.change_range?.lower !== undefined && (
|
||||||
<Badge colorScheme="green">
|
<Flex align="center" gap={2}>
|
||||||
|
<Text fontSize="sm" color={THEME.textSecondary}>
|
||||||
|
预计变动范围:
|
||||||
|
</Text>
|
||||||
|
<Tag
|
||||||
|
style={{
|
||||||
|
color: THEME.gold,
|
||||||
|
background: THEME.goldLight,
|
||||||
|
border: `1px solid ${THEME.goldBorder}`,
|
||||||
|
fontWeight: 600,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{item.change_range.lower}% ~ {item.change_range.upper}%
|
{item.change_range.lower}% ~ {item.change_range.upper}%
|
||||||
</Badge>
|
</Tag>
|
||||||
</HStack>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
</CardBody>
|
</Box>
|
||||||
</Card>
|
);
|
||||||
))}
|
})}
|
||||||
</VStack>
|
</VStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
|
|
||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { logger } from '@utils/logger';
|
import { logger } from '@utils/logger';
|
||||||
import { getApiBase } from '@utils/apiConfig';
|
import axios from '@utils/axiosConfig';
|
||||||
import NewsEventsTab from '../../CompanyOverview/NewsEventsTab';
|
import NewsEventsTab from '../../CompanyOverview/NewsEventsTab';
|
||||||
|
|
||||||
const API_BASE_URL = getApiBase();
|
|
||||||
|
|
||||||
const NewsPanel = ({ stockCode }) => {
|
const NewsPanel = ({ stockCode }) => {
|
||||||
const [newsEvents, setNewsEvents] = useState([]);
|
const [newsEvents, setNewsEvents] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -25,10 +23,9 @@ const NewsPanel = ({ stockCode }) => {
|
|||||||
// 获取股票名称
|
// 获取股票名称
|
||||||
const fetchStockName = useCallback(async () => {
|
const fetchStockName = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const { data: result } = await axios.get(
|
||||||
`${API_BASE_URL}/api/stock/${stockCode}/basic-info`
|
`/api/stock/${stockCode}/basic-info`
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
|
||||||
if (result.success && result.data) {
|
if (result.success && result.data) {
|
||||||
const name = result.data.SECNAME || result.data.ORGNAME || stockCode;
|
const name = result.data.SECNAME || result.data.ORGNAME || stockCode;
|
||||||
setStockName(name);
|
setStockName(name);
|
||||||
@@ -47,10 +44,9 @@ const NewsPanel = ({ stockCode }) => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const searchTerm = query || stockName || stockCode;
|
const searchTerm = query || stockName || stockCode;
|
||||||
const response = await fetch(
|
const { data: result } = await axios.get(
|
||||||
`${API_BASE_URL}/api/events?q=${encodeURIComponent(searchTerm)}&page=${page}&per_page=10`
|
`/api/events?q=${encodeURIComponent(searchTerm)}&page=${page}&per_page=10`
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
setNewsEvents(result.data || []);
|
setNewsEvents(result.data || []);
|
||||||
@@ -107,7 +103,7 @@ const NewsPanel = ({ stockCode }) => {
|
|||||||
onSearchChange={handleSearchChange}
|
onSearchChange={handleSearchChange}
|
||||||
onSearch={handleSearch}
|
onSearch={handleSearch}
|
||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
cardBg="white"
|
themePreset="blackGold"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
* 综合对比分析组件
|
* 综合对比分析组件 - 黑金主题
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Card, CardBody } from '@chakra-ui/react';
|
import { Box } from '@chakra-ui/react';
|
||||||
import ReactECharts from 'echarts-for-react';
|
import ReactECharts from 'echarts-for-react';
|
||||||
import { formatUtils } from '@services/financialService';
|
import { formatUtils } from '@services/financialService';
|
||||||
import { getComparisonChartOption } from '../utils';
|
import { getComparisonChartOption } from '../utils';
|
||||||
import type { ComparisonAnalysisProps } from '../types';
|
import type { ComparisonAnalysisProps } from '../types';
|
||||||
|
|
||||||
|
// 黑金主题样式
|
||||||
|
const THEME = {
|
||||||
|
cardBg: 'transparent',
|
||||||
|
border: 'rgba(212, 175, 55, 0.2)',
|
||||||
|
};
|
||||||
|
|
||||||
export const ComparisonAnalysis: React.FC<ComparisonAnalysisProps> = ({ comparison }) => {
|
export const ComparisonAnalysis: React.FC<ComparisonAnalysisProps> = ({ comparison }) => {
|
||||||
if (!Array.isArray(comparison) || comparison.length === 0) return null;
|
if (!Array.isArray(comparison) || comparison.length === 0) return null;
|
||||||
|
|
||||||
@@ -29,11 +35,15 @@ export const ComparisonAnalysis: React.FC<ComparisonAnalysisProps> = ({ comparis
|
|||||||
const chartOption = getComparisonChartOption(revenueData, profitData);
|
const chartOption = getComparisonChartOption(revenueData, profitData);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Box
|
||||||
<CardBody>
|
bg={THEME.cardBg}
|
||||||
<ReactECharts option={chartOption} style={{ height: '400px' }} />
|
border="1px solid"
|
||||||
</CardBody>
|
borderColor={THEME.border}
|
||||||
</Card>
|
borderRadius="md"
|
||||||
|
p={4}
|
||||||
|
>
|
||||||
|
<ReactECharts option={chartOption} style={{ height: '350px' }} />
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,188 @@
|
|||||||
|
/**
|
||||||
|
* 财务全景面板组件 - 三列布局
|
||||||
|
* 复用 MarketDataView 的 MetricCard 组件
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { SimpleGrid, HStack, VStack, Text, Badge } from '@chakra-ui/react';
|
||||||
|
import { TrendingUp, Coins, Shield, TrendingDown, Activity, PieChart } from 'lucide-react';
|
||||||
|
import { formatUtils } from '@services/financialService';
|
||||||
|
|
||||||
|
// 复用 MarketDataView 的组件
|
||||||
|
import MetricCard from '../../MarketDataView/components/StockSummaryCard/MetricCard';
|
||||||
|
import { StatusTag } from '../../MarketDataView/components/StockSummaryCard/atoms';
|
||||||
|
import { darkGoldTheme } from '../../MarketDataView/constants';
|
||||||
|
|
||||||
|
import type { StockInfo, FinancialMetricsData } from '../types';
|
||||||
|
|
||||||
|
export interface FinancialOverviewPanelProps {
|
||||||
|
stockInfo: StockInfo | null;
|
||||||
|
financialMetrics: FinancialMetricsData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成长状态
|
||||||
|
*/
|
||||||
|
const getGrowthStatus = (value: number | undefined): { text: string; color: string } => {
|
||||||
|
if (value === undefined || value === null) return { text: '-', color: darkGoldTheme.textMuted };
|
||||||
|
if (value > 30) return { text: '高速增长', color: darkGoldTheme.green };
|
||||||
|
if (value > 10) return { text: '稳健增长', color: darkGoldTheme.gold };
|
||||||
|
if (value > 0) return { text: '低速增长', color: darkGoldTheme.orange };
|
||||||
|
if (value > -10) return { text: '小幅下滑', color: darkGoldTheme.orange };
|
||||||
|
return { text: '大幅下滑', color: darkGoldTheme.red };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 ROE 状态
|
||||||
|
*/
|
||||||
|
const getROEStatus = (value: number | undefined): { text: string; color: string } => {
|
||||||
|
if (value === undefined || value === null) return { text: '-', color: darkGoldTheme.textMuted };
|
||||||
|
if (value > 20) return { text: '优秀', color: darkGoldTheme.green };
|
||||||
|
if (value > 15) return { text: '良好', color: darkGoldTheme.gold };
|
||||||
|
if (value > 10) return { text: '一般', color: darkGoldTheme.orange };
|
||||||
|
return { text: '较低', color: darkGoldTheme.red };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取资产负债率状态
|
||||||
|
*/
|
||||||
|
const getDebtStatus = (value: number | undefined): { text: string; color: string } => {
|
||||||
|
if (value === undefined || value === null) return { text: '-', color: darkGoldTheme.textMuted };
|
||||||
|
if (value < 40) return { text: '安全', color: darkGoldTheme.green };
|
||||||
|
if (value < 60) return { text: '适中', color: darkGoldTheme.gold };
|
||||||
|
if (value < 70) return { text: '偏高', color: darkGoldTheme.orange };
|
||||||
|
return { text: '风险', color: darkGoldTheme.red };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 财务全景面板组件
|
||||||
|
*/
|
||||||
|
export const FinancialOverviewPanel: React.FC<FinancialOverviewPanelProps> = memo(({
|
||||||
|
stockInfo,
|
||||||
|
financialMetrics,
|
||||||
|
}) => {
|
||||||
|
if (!stockInfo && (!financialMetrics || financialMetrics.length === 0)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取最新一期财务指标
|
||||||
|
const latestMetrics = financialMetrics?.[0];
|
||||||
|
|
||||||
|
// 成长指标(来自 stockInfo)
|
||||||
|
const revenueGrowth = stockInfo?.growth_rates?.revenue_growth;
|
||||||
|
const profitGrowth = stockInfo?.growth_rates?.profit_growth;
|
||||||
|
const forecast = stockInfo?.latest_forecast;
|
||||||
|
|
||||||
|
// 盈利指标(来自 financialMetrics)
|
||||||
|
const roe = latestMetrics?.profitability?.roe;
|
||||||
|
const netProfitMargin = latestMetrics?.profitability?.net_profit_margin;
|
||||||
|
const grossMargin = latestMetrics?.profitability?.gross_margin;
|
||||||
|
|
||||||
|
// 风险与运营指标(来自 financialMetrics)
|
||||||
|
const assetLiabilityRatio = latestMetrics?.solvency?.asset_liability_ratio;
|
||||||
|
const currentRatio = latestMetrics?.solvency?.current_ratio;
|
||||||
|
const rdExpenseRatio = latestMetrics?.expense_ratios?.rd_expense_ratio;
|
||||||
|
|
||||||
|
// 计算状态
|
||||||
|
const growthStatus = getGrowthStatus(profitGrowth);
|
||||||
|
const roeStatus = getROEStatus(roe);
|
||||||
|
const debtStatus = getDebtStatus(assetLiabilityRatio);
|
||||||
|
|
||||||
|
// 格式化涨跌显示
|
||||||
|
const formatGrowth = (value: number | undefined) => {
|
||||||
|
if (value === undefined || value === null) return '-';
|
||||||
|
const sign = value >= 0 ? '+' : '';
|
||||||
|
return `${sign}${value.toFixed(2)}%`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SimpleGrid columns={{ base: 1, md: 3 }} spacing={3}>
|
||||||
|
{/* 卡片1: 成长能力 */}
|
||||||
|
<MetricCard
|
||||||
|
title="成长能力"
|
||||||
|
subtitle="增长动力"
|
||||||
|
leftIcon={<TrendingUp size={14} />}
|
||||||
|
rightIcon={<Activity size={14} />}
|
||||||
|
mainLabel="利润增长"
|
||||||
|
mainValue={formatGrowth(profitGrowth)}
|
||||||
|
mainColor={profitGrowth !== undefined && profitGrowth >= 0 ? darkGoldTheme.green : darkGoldTheme.red}
|
||||||
|
subText={
|
||||||
|
<VStack align="start" spacing={1}>
|
||||||
|
<HStack spacing={1} flexWrap="wrap">
|
||||||
|
<Text>营收增长</Text>
|
||||||
|
<Text
|
||||||
|
fontWeight="bold"
|
||||||
|
color={revenueGrowth !== undefined && revenueGrowth >= 0 ? darkGoldTheme.green : darkGoldTheme.red}
|
||||||
|
>
|
||||||
|
{formatGrowth(revenueGrowth)}
|
||||||
|
</Text>
|
||||||
|
<StatusTag text={growthStatus.text} color={growthStatus.color} />
|
||||||
|
</HStack>
|
||||||
|
{forecast && (
|
||||||
|
<Badge
|
||||||
|
bg="rgba(212, 175, 55, 0.15)"
|
||||||
|
color={darkGoldTheme.gold}
|
||||||
|
fontSize="xs"
|
||||||
|
px={2}
|
||||||
|
py={0.5}
|
||||||
|
borderRadius="md"
|
||||||
|
>
|
||||||
|
{forecast.forecast_type} {forecast.content}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</VStack>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 卡片2: 盈利与回报 */}
|
||||||
|
<MetricCard
|
||||||
|
title="盈利与回报"
|
||||||
|
subtitle="赚钱能力"
|
||||||
|
leftIcon={<Coins size={14} />}
|
||||||
|
rightIcon={<PieChart size={14} />}
|
||||||
|
mainLabel="ROE"
|
||||||
|
mainValue={formatUtils.formatPercent(roe)}
|
||||||
|
mainColor={darkGoldTheme.orange}
|
||||||
|
subText={
|
||||||
|
<VStack align="start" spacing={0.5}>
|
||||||
|
<Text color={roeStatus.color} fontWeight="medium">
|
||||||
|
{roeStatus.text}
|
||||||
|
</Text>
|
||||||
|
<HStack spacing={1} flexWrap="wrap">
|
||||||
|
<Text>净利率 {formatUtils.formatPercent(netProfitMargin)}</Text>
|
||||||
|
<Text>|</Text>
|
||||||
|
<Text>毛利率 {formatUtils.formatPercent(grossMargin)}</Text>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 卡片3: 风险与运营 */}
|
||||||
|
<MetricCard
|
||||||
|
title="风险与运营"
|
||||||
|
subtitle="安全边际"
|
||||||
|
leftIcon={<Shield size={14} />}
|
||||||
|
rightIcon={<TrendingDown size={14} />}
|
||||||
|
mainLabel="资产负债率"
|
||||||
|
mainValue={formatUtils.formatPercent(assetLiabilityRatio)}
|
||||||
|
mainColor={debtStatus.color}
|
||||||
|
subText={
|
||||||
|
<VStack align="start" spacing={0.5}>
|
||||||
|
<Text color={debtStatus.color} fontWeight="medium">
|
||||||
|
{debtStatus.text}
|
||||||
|
</Text>
|
||||||
|
<HStack spacing={1} flexWrap="wrap">
|
||||||
|
<Text>流动比率 {currentRatio?.toFixed(2) ?? '-'}</Text>
|
||||||
|
<Text>|</Text>
|
||||||
|
<Text>研发费用率 {formatUtils.formatPercent(rdExpenseRatio)}</Text>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SimpleGrid>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
FinancialOverviewPanel.displayName = 'FinancialOverviewPanel';
|
||||||
|
|
||||||
|
export default FinancialOverviewPanel;
|
||||||
@@ -4,18 +4,9 @@
|
|||||||
|
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import {
|
import {
|
||||||
VStack,
|
Flex,
|
||||||
Grid,
|
|
||||||
GridItem,
|
|
||||||
Box,
|
Box,
|
||||||
Heading,
|
Heading,
|
||||||
Table,
|
|
||||||
Thead,
|
|
||||||
Tbody,
|
|
||||||
Tr,
|
|
||||||
Th,
|
|
||||||
Td,
|
|
||||||
TableContainer,
|
|
||||||
Alert,
|
Alert,
|
||||||
AlertIcon,
|
AlertIcon,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
@@ -45,7 +36,7 @@ const BLACK_GOLD_THEME = {
|
|||||||
algorithm: antTheme.darkAlgorithm,
|
algorithm: antTheme.darkAlgorithm,
|
||||||
token: {
|
token: {
|
||||||
colorPrimary: '#D4AF37',
|
colorPrimary: '#D4AF37',
|
||||||
colorBgContainer: 'transparent',
|
colorBgContainer: '#1A202C',
|
||||||
colorBgElevated: '#1a1a2e',
|
colorBgElevated: '#1a1a2e',
|
||||||
colorBorder: 'rgba(212, 175, 55, 0.3)',
|
colorBorder: 'rgba(212, 175, 55, 0.3)',
|
||||||
colorText: '#e0e0e0',
|
colorText: '#e0e0e0',
|
||||||
@@ -65,41 +56,85 @@ const BLACK_GOLD_THEME = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 历史对比表格数据行类型
|
// 固定列背景样式(防止滚动时内容重叠)
|
||||||
|
const fixedColumnStyles = `
|
||||||
|
.main-business-table .ant-table-cell-fix-left,
|
||||||
|
.main-business-table .ant-table-cell-fix-right {
|
||||||
|
background: #1A202C !important;
|
||||||
|
}
|
||||||
|
.main-business-table .ant-table-thead .ant-table-cell-fix-left,
|
||||||
|
.main-business-table .ant-table-thead .ant-table-cell-fix-right {
|
||||||
|
background: rgba(26, 32, 44, 0.95) !important;
|
||||||
|
}
|
||||||
|
.main-business-table .ant-table-tbody > tr:hover > td {
|
||||||
|
background: rgba(212, 175, 55, 0.08) !important;
|
||||||
|
}
|
||||||
|
.main-business-table .ant-table-tbody > tr:hover > td.ant-table-cell-fix-left,
|
||||||
|
.main-business-table .ant-table-tbody > tr:hover > td.ant-table-cell-fix-right {
|
||||||
|
background: #242d3d !important;
|
||||||
|
}
|
||||||
|
.main-business-table .ant-table-tbody > tr > td {
|
||||||
|
background: #1A202C !important;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
// 历史对比表格数据行类型(包含业务明细)
|
||||||
interface HistoricalRowData {
|
interface HistoricalRowData {
|
||||||
key: string;
|
key: string;
|
||||||
business: string;
|
business: string;
|
||||||
|
grossMargin?: number;
|
||||||
|
profit?: number;
|
||||||
[period: string]: string | number | undefined;
|
[period: string]: string | number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 历史对比表格组件
|
// 历史对比表格组件(整合业务明细)
|
||||||
interface HistoricalComparisonTableProps {
|
interface HistoricalComparisonTableProps {
|
||||||
historicalData: (ProductClassification | IndustryClassification)[];
|
historicalData: (ProductClassification | IndustryClassification)[];
|
||||||
businessItems: BusinessItem[];
|
businessItems: BusinessItem[];
|
||||||
hasProductData: boolean;
|
hasProductData: boolean;
|
||||||
|
latestReportType: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HistoricalComparisonTable: React.FC<HistoricalComparisonTableProps> = ({
|
const HistoricalComparisonTable: React.FC<HistoricalComparisonTableProps> = ({
|
||||||
historicalData,
|
historicalData,
|
||||||
businessItems,
|
businessItems,
|
||||||
hasProductData,
|
hasProductData,
|
||||||
|
latestReportType,
|
||||||
}) => {
|
}) => {
|
||||||
// 动态生成列配置
|
// 动态生成列配置
|
||||||
const columns: ColumnsType<HistoricalRowData> = useMemo(() => {
|
const columns: ColumnsType<HistoricalRowData> = useMemo(() => {
|
||||||
const cols: ColumnsType<HistoricalRowData> = [
|
const cols: ColumnsType<HistoricalRowData> = [
|
||||||
{
|
{
|
||||||
title: '业务/期间',
|
title: '业务',
|
||||||
dataIndex: 'business',
|
dataIndex: 'business',
|
||||||
key: 'business',
|
key: 'business',
|
||||||
fixed: 'left',
|
fixed: 'left',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: `毛利率(${latestReportType})`,
|
||||||
|
dataIndex: 'grossMargin',
|
||||||
|
key: 'grossMargin',
|
||||||
|
align: 'right',
|
||||||
|
width: 120,
|
||||||
|
render: (value: number | undefined) =>
|
||||||
|
value !== undefined ? formatUtils.formatPercent(value) : '-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: `利润(${latestReportType})`,
|
||||||
|
dataIndex: 'profit',
|
||||||
|
key: 'profit',
|
||||||
|
align: 'right',
|
||||||
|
width: 100,
|
||||||
|
render: (value: number | undefined) =>
|
||||||
|
value !== undefined ? formatUtils.formatLargeNumber(value) : '-',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// 添加各期间列
|
// 添加各期间营收列
|
||||||
historicalData.slice(0, 4).forEach((period) => {
|
historicalData.slice(0, 4).forEach((period) => {
|
||||||
cols.push({
|
cols.push({
|
||||||
title: period.report_type,
|
title: `营收(${period.report_type})`,
|
||||||
dataIndex: period.period,
|
dataIndex: period.period,
|
||||||
key: period.period,
|
key: period.period,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
@@ -112,9 +147,9 @@ const HistoricalComparisonTable: React.FC<HistoricalComparisonTableProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return cols;
|
return cols;
|
||||||
}, [historicalData]);
|
}, [historicalData, latestReportType]);
|
||||||
|
|
||||||
// 生成表格数据
|
// 生成表格数据(包含业务明细)
|
||||||
const dataSource: HistoricalRowData[] = useMemo(() => {
|
const dataSource: HistoricalRowData[] = useMemo(() => {
|
||||||
return businessItems
|
return businessItems
|
||||||
.filter((item: BusinessItem) => item.content !== '合计')
|
.filter((item: BusinessItem) => item.content !== '合计')
|
||||||
@@ -122,8 +157,11 @@ const HistoricalComparisonTable: React.FC<HistoricalComparisonTableProps> = ({
|
|||||||
const row: HistoricalRowData = {
|
const row: HistoricalRowData = {
|
||||||
key: `${idx}`,
|
key: `${idx}`,
|
||||||
business: item.content,
|
business: item.content,
|
||||||
|
grossMargin: item.gross_margin || item.profit_margin,
|
||||||
|
profit: item.profit,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 添加各期间营收数据
|
||||||
historicalData.slice(0, 4).forEach((period) => {
|
historicalData.slice(0, 4).forEach((period) => {
|
||||||
const periodItems: BusinessItem[] = hasProductData
|
const periodItems: BusinessItem[] = hasProductData
|
||||||
? (period as ProductClassification).products
|
? (period as ProductClassification).products
|
||||||
@@ -145,13 +183,16 @@ const HistoricalComparisonTable: React.FC<HistoricalComparisonTableProps> = ({
|
|||||||
borderColor={THEME.border}
|
borderColor={THEME.border}
|
||||||
borderRadius="md"
|
borderRadius="md"
|
||||||
overflow="hidden"
|
overflow="hidden"
|
||||||
|
h="100%"
|
||||||
|
className="main-business-table"
|
||||||
>
|
>
|
||||||
|
<style>{fixedColumnStyles}</style>
|
||||||
<Box px={4} py={3} borderBottom="1px solid" borderColor={THEME.border}>
|
<Box px={4} py={3} borderBottom="1px solid" borderColor={THEME.border}>
|
||||||
<Heading size="sm" color={THEME.headingColor}>
|
<Heading size="sm" color={THEME.headingColor}>
|
||||||
主营业务历史对比
|
主营业务明细与历史对比
|
||||||
</Heading>
|
</Heading>
|
||||||
</Box>
|
</Box>
|
||||||
<Box p={4}>
|
<Box p={4} overflowX="auto">
|
||||||
<ConfigProvider theme={BLACK_GOLD_THEME}>
|
<ConfigProvider theme={BLACK_GOLD_THEME}>
|
||||||
<AntTable<HistoricalRowData>
|
<AntTable<HistoricalRowData>
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -218,77 +259,35 @@ export const MainBusinessAnalysis: React.FC<MainBusinessAnalysisProps> = ({
|
|||||||
: (mainBusiness!.industry_classification! as IndustryClassification[]);
|
: (mainBusiness!.industry_classification! as IndustryClassification[]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing={4} align="stretch">
|
<Flex
|
||||||
<Grid templateColumns="repeat(2, 1fr)" gap={4}>
|
direction={{ base: 'column', lg: 'row' }}
|
||||||
<GridItem>
|
gap={4}
|
||||||
<Box
|
>
|
||||||
bg={THEME.cardBg}
|
{/* 左侧:饼图 */}
|
||||||
border="1px solid"
|
<Box
|
||||||
borderColor={THEME.border}
|
flexShrink={0}
|
||||||
borderRadius="md"
|
w={{ base: '100%', lg: '340px' }}
|
||||||
p={4}
|
bg={THEME.cardBg}
|
||||||
>
|
border="1px solid"
|
||||||
<ReactECharts option={pieOption} style={{ height: '300px' }} />
|
borderColor={THEME.border}
|
||||||
</Box>
|
borderRadius="md"
|
||||||
</GridItem>
|
p={4}
|
||||||
<GridItem>
|
>
|
||||||
<Box
|
<ReactECharts option={pieOption} style={{ height: '280px' }} />
|
||||||
bg={THEME.cardBg}
|
</Box>
|
||||||
border="1px solid"
|
|
||||||
borderColor={THEME.border}
|
|
||||||
borderRadius="md"
|
|
||||||
overflow="hidden"
|
|
||||||
>
|
|
||||||
<Box px={4} py={3} borderBottom="1px solid" borderColor={THEME.border}>
|
|
||||||
<Heading size="sm" color={THEME.headingColor}>
|
|
||||||
业务明细 - {latestPeriod.report_type}
|
|
||||||
</Heading>
|
|
||||||
</Box>
|
|
||||||
<Box p={4}>
|
|
||||||
<TableContainer>
|
|
||||||
<Table size="sm">
|
|
||||||
<Thead>
|
|
||||||
<Tr>
|
|
||||||
<Th color={THEME.thColor} borderColor={THEME.border}>业务</Th>
|
|
||||||
<Th isNumeric color={THEME.thColor} borderColor={THEME.border}>营收</Th>
|
|
||||||
<Th isNumeric color={THEME.thColor} borderColor={THEME.border}>毛利率(%)</Th>
|
|
||||||
<Th isNumeric color={THEME.thColor} borderColor={THEME.border}>利润</Th>
|
|
||||||
</Tr>
|
|
||||||
</Thead>
|
|
||||||
<Tbody>
|
|
||||||
{businessItems
|
|
||||||
.filter((item: BusinessItem) => item.content !== '合计')
|
|
||||||
.map((item: BusinessItem, idx: number) => (
|
|
||||||
<Tr key={idx}>
|
|
||||||
<Td color={THEME.textColor} borderColor={THEME.border}>{item.content}</Td>
|
|
||||||
<Td isNumeric color={THEME.textColor} borderColor={THEME.border}>
|
|
||||||
{formatUtils.formatLargeNumber(item.revenue)}
|
|
||||||
</Td>
|
|
||||||
<Td isNumeric color={THEME.textColor} borderColor={THEME.border}>
|
|
||||||
{formatUtils.formatPercent(item.gross_margin || item.profit_margin)}
|
|
||||||
</Td>
|
|
||||||
<Td isNumeric color={THEME.textColor} borderColor={THEME.border}>
|
|
||||||
{formatUtils.formatLargeNumber(item.profit)}
|
|
||||||
</Td>
|
|
||||||
</Tr>
|
|
||||||
))}
|
|
||||||
</Tbody>
|
|
||||||
</Table>
|
|
||||||
</TableContainer>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
</GridItem>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
{/* 历史对比 - Ant Design Table 黑金主题 */}
|
{/* 右侧:业务明细与历史对比表格 */}
|
||||||
{historicalData.length > 1 && (
|
<Box flex={1} minW={0} overflow="hidden">
|
||||||
<HistoricalComparisonTable
|
{historicalData.length > 0 && (
|
||||||
historicalData={historicalData}
|
<HistoricalComparisonTable
|
||||||
businessItems={businessItems}
|
historicalData={historicalData}
|
||||||
hasProductData={hasProductData}
|
businessItems={businessItems}
|
||||||
/>
|
hasProductData={hasProductData}
|
||||||
)}
|
latestReportType={latestPeriod.report_type}
|
||||||
</VStack>
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ export const StockInfoHeader: React.FC<StockInfoHeaderProps> = ({
|
|||||||
boxShadow: '0 8px 30px rgba(212, 175, 55, 0.15)',
|
boxShadow: '0 8px 30px rgba(212, 175, 55, 0.15)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Grid templateColumns="repeat(6, 1fr)" gap={4} alignItems="center">
|
<Grid templateColumns="repeat(5, 1fr)" gap={4} alignItems="center">
|
||||||
<GridItem colSpan={{ base: 6, md: 2 }}>
|
<GridItem colSpan={{ base: 5, md: 2 }}>
|
||||||
<VStack align="start" spacing={1}>
|
<VStack align="start" spacing={1}>
|
||||||
<Text fontSize="xs" color={darkGoldTheme.textMuted}>
|
<Text fontSize="xs" color={darkGoldTheme.textMuted}>
|
||||||
股票名称
|
股票名称
|
||||||
@@ -84,16 +84,6 @@ export const StockInfoHeader: React.FC<StockInfoHeaderProps> = ({
|
|||||||
</HStack>
|
</HStack>
|
||||||
</VStack>
|
</VStack>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem>
|
|
||||||
<Stat>
|
|
||||||
<StatLabel color={darkGoldTheme.textMuted} fontSize="xs">
|
|
||||||
最新EPS
|
|
||||||
</StatLabel>
|
|
||||||
<StatNumber color={darkGoldTheme.goldLight} fontSize="lg">
|
|
||||||
{stockInfo.key_metrics?.eps?.toFixed(3) || '-'}
|
|
||||||
</StatNumber>
|
|
||||||
</Stat>
|
|
||||||
</GridItem>
|
|
||||||
<GridItem>
|
<GridItem>
|
||||||
<Stat>
|
<Stat>
|
||||||
<StatLabel color={darkGoldTheme.textMuted} fontSize="xs">
|
<StatLabel color={darkGoldTheme.textMuted} fontSize="xs">
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export { PeriodSelector } from './PeriodSelector';
|
export { PeriodSelector } from './PeriodSelector';
|
||||||
|
export { FinancialOverviewPanel } from './FinancialOverviewPanel';
|
||||||
|
// 保留旧组件导出(向后兼容)
|
||||||
export { KeyMetricsOverview } from './KeyMetricsOverview';
|
export { KeyMetricsOverview } from './KeyMetricsOverview';
|
||||||
export { StockInfoHeader } from './StockInfoHeader';
|
export { StockInfoHeader } from './StockInfoHeader';
|
||||||
export { BalanceSheetTable } from './BalanceSheetTable';
|
export { BalanceSheetTable } from './BalanceSheetTable';
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
Alert,
|
Alert,
|
||||||
AlertIcon,
|
AlertIcon,
|
||||||
Skeleton,
|
|
||||||
Modal,
|
Modal,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
@@ -47,12 +46,13 @@ import { formatUtils } from '@services/financialService';
|
|||||||
|
|
||||||
// 通用组件
|
// 通用组件
|
||||||
import SubTabContainer, { type SubTabConfig } from '@components/SubTabContainer';
|
import SubTabContainer, { type SubTabConfig } from '@components/SubTabContainer';
|
||||||
|
import LoadingState from '../LoadingState';
|
||||||
|
|
||||||
// 内部模块导入
|
// 内部模块导入
|
||||||
import { useFinancialData, type DataTypeKey } from './hooks';
|
import { useFinancialData, type DataTypeKey } from './hooks';
|
||||||
import { COLORS } from './constants';
|
import { COLORS } from './constants';
|
||||||
import { calculateYoYChange, getCellBackground, getMetricChartOption } from './utils';
|
import { calculateYoYChange, getCellBackground, getMetricChartOption } from './utils';
|
||||||
import { PeriodSelector, KeyMetricsOverview, StockInfoHeader, MainBusinessAnalysis } from './components';
|
import { PeriodSelector, FinancialOverviewPanel, MainBusinessAnalysis, ComparisonAnalysis } from './components';
|
||||||
import {
|
import {
|
||||||
BalanceSheetTab,
|
BalanceSheetTab,
|
||||||
IncomeStatementTab,
|
IncomeStatementTab,
|
||||||
@@ -93,6 +93,7 @@ const FinancialPanorama: React.FC<FinancialPanoramaProps> = ({ stockCode: propSt
|
|||||||
cashflow,
|
cashflow,
|
||||||
financialMetrics,
|
financialMetrics,
|
||||||
mainBusiness,
|
mainBusiness,
|
||||||
|
comparison,
|
||||||
loading,
|
loading,
|
||||||
loadingTab,
|
loadingTab,
|
||||||
error,
|
error,
|
||||||
@@ -275,32 +276,29 @@ const FinancialPanorama: React.FC<FinancialPanoramaProps> = ({ stockCode: propSt
|
|||||||
return (
|
return (
|
||||||
<Container maxW="container.xl" py={5}>
|
<Container maxW="container.xl" py={5}>
|
||||||
<VStack spacing={6} align="stretch">
|
<VStack spacing={6} align="stretch">
|
||||||
{/* 股票信息头部 */}
|
{/* 财务全景面板(三列布局:成长能力、盈利与回报、风险与运营) */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Skeleton height="150px" />
|
<LoadingState message="加载财务数据中..." height="300px" />
|
||||||
) : (
|
) : (
|
||||||
<StockInfoHeader
|
<FinancialOverviewPanel
|
||||||
stockInfo={stockInfo}
|
stockInfo={stockInfo}
|
||||||
positiveColor={positiveColor}
|
financialMetrics={financialMetrics}
|
||||||
negativeColor={negativeColor}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 关键指标速览 */}
|
{/* 营收与利润趋势 */}
|
||||||
{!loading && stockInfo && financialMetrics.length > 0 && (
|
{!loading && comparison && comparison.length > 0 && (
|
||||||
<KeyMetricsOverview financialMetrics={financialMetrics} />
|
<ComparisonAnalysis comparison={comparison} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 主营业务 */}
|
{/* 主营业务 */}
|
||||||
{!loading && stockInfo && (
|
{!loading && stockInfo && (
|
||||||
<Card bg="gray.900" shadow="md" border="1px solid" borderColor="rgba(212, 175, 55, 0.3)">
|
<Box>
|
||||||
<CardBody>
|
<Text fontSize="lg" fontWeight="bold" mb={4} color="#D4AF37">
|
||||||
<Text fontSize="lg" fontWeight="bold" mb={4} color="#D4AF37">
|
主营业务
|
||||||
主营业务
|
</Text>
|
||||||
</Text>
|
<MainBusinessAnalysis mainBusiness={mainBusiness} />
|
||||||
<MainBusinessAnalysis mainBusiness={mainBusiness} />
|
</Box>
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 三大财务报表 - 使用 SubTabContainer 二级导航 */}
|
{/* 三大财务报表 - 使用 SubTabContainer 二级导航 */}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export const getMetricChartOption = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成营收与利润趋势图表配置
|
* 生成营收与利润趋势图表配置 - 黑金主题
|
||||||
* @param revenueData 营收数据
|
* @param revenueData 营收数据
|
||||||
* @param profitData 利润数据
|
* @param profitData 利润数据
|
||||||
* @returns ECharts 配置
|
* @returns ECharts 配置
|
||||||
@@ -101,34 +101,96 @@ export const getComparisonChartOption = (
|
|||||||
profitData: { period: string; value: number }[]
|
profitData: { period: string; value: number }[]
|
||||||
) => {
|
) => {
|
||||||
return {
|
return {
|
||||||
|
backgroundColor: 'transparent',
|
||||||
title: {
|
title: {
|
||||||
text: '营收与利润趋势',
|
text: '营收与利润趋势',
|
||||||
left: 'center',
|
left: 'center',
|
||||||
|
textStyle: {
|
||||||
|
color: '#D4AF37',
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'axis',
|
trigger: 'axis',
|
||||||
|
backgroundColor: 'rgba(26, 32, 44, 0.95)',
|
||||||
|
borderColor: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
textStyle: {
|
||||||
|
color: '#E2E8F0',
|
||||||
|
},
|
||||||
axisPointer: {
|
axisPointer: {
|
||||||
type: 'cross',
|
type: 'cross',
|
||||||
|
crossStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.5)',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
data: ['营业收入', '净利润'],
|
data: ['营业收入', '净利润'],
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
|
textStyle: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
left: '3%',
|
||||||
|
right: '4%',
|
||||||
|
bottom: '12%',
|
||||||
|
top: '15%',
|
||||||
|
containLabel: true,
|
||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
data: revenueData.map((d) => d.period),
|
data: revenueData.map((d) => d.period),
|
||||||
|
axisLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
yAxis: [
|
yAxis: [
|
||||||
{
|
{
|
||||||
type: 'value',
|
type: 'value',
|
||||||
name: '营收(亿)',
|
name: '营收(亿)',
|
||||||
position: 'left',
|
position: 'left',
|
||||||
|
nameTextStyle: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
|
axisLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.1)',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'value',
|
type: 'value',
|
||||||
name: '利润(亿)',
|
name: '利润(亿)',
|
||||||
position: 'right',
|
position: 'right',
|
||||||
|
nameTextStyle: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
|
axisLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
series: [
|
series: [
|
||||||
@@ -139,10 +201,10 @@ export const getComparisonChartOption = (
|
|||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: (params: { dataIndex: number; value: number }) => {
|
color: (params: { dataIndex: number; value: number }) => {
|
||||||
const idx = params.dataIndex;
|
const idx = params.dataIndex;
|
||||||
if (idx === 0) return '#3182CE';
|
if (idx === 0) return '#D4AF37'; // 金色作为基准
|
||||||
const prevValue = revenueData[idx - 1].value;
|
const prevValue = revenueData[idx - 1].value;
|
||||||
const currValue = params.value;
|
const currValue = params.value;
|
||||||
// 中国市场颜色
|
// 红涨绿跌
|
||||||
return currValue >= prevValue ? '#EF4444' : '#10B981';
|
return currValue >= prevValue ? '#EF4444' : '#10B981';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -153,15 +215,40 @@ export const getComparisonChartOption = (
|
|||||||
yAxisIndex: 1,
|
yAxisIndex: 1,
|
||||||
data: profitData.map((d) => d.value?.toFixed(2)),
|
data: profitData.map((d) => d.value?.toFixed(2)),
|
||||||
smooth: true,
|
smooth: true,
|
||||||
itemStyle: { color: '#F59E0B' },
|
itemStyle: { color: '#D4AF37' },
|
||||||
lineStyle: { width: 2 },
|
lineStyle: { width: 2, color: '#D4AF37' },
|
||||||
|
areaStyle: {
|
||||||
|
color: {
|
||||||
|
type: 'linear',
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
x2: 0,
|
||||||
|
y2: 1,
|
||||||
|
colorStops: [
|
||||||
|
{ offset: 0, color: 'rgba(212, 175, 55, 0.3)' },
|
||||||
|
{ offset: 1, color: 'rgba(212, 175, 55, 0.05)' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 黑金主题饼图配色
|
||||||
|
const BLACK_GOLD_PIE_COLORS = [
|
||||||
|
'#D4AF37', // 金色
|
||||||
|
'#B8860B', // 深金色
|
||||||
|
'#FFD700', // 亮金色
|
||||||
|
'#DAA520', // 金菊色
|
||||||
|
'#CD853F', // 秘鲁色
|
||||||
|
'#F4A460', // 沙褐色
|
||||||
|
'#DEB887', // 实木色
|
||||||
|
'#D2691E', // 巧克力色
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成主营业务饼图配置
|
* 生成主营业务饼图配置 - 黑金主题
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @param subtitle 副标题
|
* @param subtitle 副标题
|
||||||
* @param data 饼图数据
|
* @param data 饼图数据
|
||||||
@@ -177,9 +264,22 @@ export const getMainBusinessPieOption = (
|
|||||||
text: title,
|
text: title,
|
||||||
subtext: subtitle,
|
subtext: subtitle,
|
||||||
left: 'center',
|
left: 'center',
|
||||||
|
textStyle: {
|
||||||
|
color: '#D4AF37',
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
subtextStyle: {
|
||||||
|
color: '#A0AEC0',
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'item',
|
trigger: 'item',
|
||||||
|
backgroundColor: 'rgba(26, 32, 44, 0.95)',
|
||||||
|
borderColor: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
textStyle: {
|
||||||
|
color: '#E2E8F0',
|
||||||
|
},
|
||||||
formatter: (params: { name: string; value: number; percent: number }) => {
|
formatter: (params: { name: string; value: number; percent: number }) => {
|
||||||
return `${params.name}<br/>营收: ${formatUtils.formatLargeNumber(
|
return `${params.name}<br/>营收: ${formatUtils.formatLargeNumber(
|
||||||
params.value
|
params.value
|
||||||
@@ -190,17 +290,34 @@ export const getMainBusinessPieOption = (
|
|||||||
orient: 'vertical',
|
orient: 'vertical',
|
||||||
left: 'left',
|
left: 'left',
|
||||||
top: 'center',
|
top: 'center',
|
||||||
|
textStyle: {
|
||||||
|
color: '#E2E8F0',
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
color: BLACK_GOLD_PIE_COLORS,
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
radius: '50%',
|
radius: '55%',
|
||||||
|
center: ['55%', '50%'],
|
||||||
data: data,
|
data: data,
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
color: '#E2E8F0',
|
||||||
|
fontSize: 11,
|
||||||
|
formatter: '{b}: {d}%',
|
||||||
|
},
|
||||||
|
labelLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.5)',
|
||||||
|
},
|
||||||
|
},
|
||||||
emphasis: {
|
emphasis: {
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
shadowBlur: 10,
|
shadowBlur: 10,
|
||||||
shadowOffsetX: 0,
|
shadowOffsetX: 0,
|
||||||
shadowColor: 'rgba(0, 0, 0, 0.5)',
|
shadowColor: 'rgba(212, 175, 55, 0.5)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* 通用图表卡片组件 - 黑金主题
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { Box, Heading } from '@chakra-ui/react';
|
||||||
|
import { THEME } from '../constants';
|
||||||
|
import type { ChartCardProps } from '../types';
|
||||||
|
|
||||||
|
const ChartCard: React.FC<ChartCardProps> = ({ title, children }) => {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
bg={THEME.bgDark}
|
||||||
|
border="1px solid"
|
||||||
|
borderColor={THEME.goldBorder}
|
||||||
|
borderRadius="md"
|
||||||
|
overflow="hidden"
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
px={4}
|
||||||
|
py={3}
|
||||||
|
borderBottom="1px solid"
|
||||||
|
borderColor={THEME.goldBorder}
|
||||||
|
bg={THEME.goldLight}
|
||||||
|
>
|
||||||
|
<Heading size="sm" color={THEME.gold}>
|
||||||
|
{title}
|
||||||
|
</Heading>
|
||||||
|
</Box>
|
||||||
|
<Box p={4}>
|
||||||
|
{children}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChartCard;
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
/**
|
||||||
|
* 详细数据表格 - 黑金主题
|
||||||
|
* 优化:斑马纹、等宽字体、首列高亮、重要行强调、预测列区分
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import { Box, Text } from '@chakra-ui/react';
|
||||||
|
import { Table, ConfigProvider, Tag, theme as antTheme } from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type { DetailTableProps, DetailTableRow } from '../types';
|
||||||
|
|
||||||
|
// 判断是否为预测年份
|
||||||
|
const isForecastYear = (year: string) => year.includes('E');
|
||||||
|
|
||||||
|
// 重要指标(需要高亮的行)
|
||||||
|
const IMPORTANT_METRICS = ['归母净利润', 'ROE', 'EPS', '营业总收入'];
|
||||||
|
|
||||||
|
// Ant Design 黑金主题配置
|
||||||
|
const BLACK_GOLD_THEME = {
|
||||||
|
algorithm: antTheme.darkAlgorithm,
|
||||||
|
token: {
|
||||||
|
colorPrimary: '#D4AF37',
|
||||||
|
colorBgContainer: 'transparent',
|
||||||
|
colorBgElevated: '#1a1a2e',
|
||||||
|
colorBorder: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
colorText: '#e0e0e0',
|
||||||
|
colorTextSecondary: '#a0a0a0',
|
||||||
|
borderRadius: 4,
|
||||||
|
fontSize: 13,
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
Table: {
|
||||||
|
headerBg: 'rgba(212, 175, 55, 0.12)',
|
||||||
|
headerColor: '#D4AF37',
|
||||||
|
rowHoverBg: 'rgba(212, 175, 55, 0.08)',
|
||||||
|
borderColor: 'rgba(212, 175, 55, 0.2)',
|
||||||
|
cellPaddingBlock: 12, // 增加行高
|
||||||
|
cellPaddingInline: 14,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格样式 - 斑马纹、等宽字体、预测列区分
|
||||||
|
const tableStyles = `
|
||||||
|
/* 固定列背景 */
|
||||||
|
.forecast-detail-table .ant-table-cell-fix-left,
|
||||||
|
.forecast-detail-table .ant-table-cell-fix-right {
|
||||||
|
background: #1A202C !important;
|
||||||
|
}
|
||||||
|
.forecast-detail-table .ant-table-thead .ant-table-cell-fix-left,
|
||||||
|
.forecast-detail-table .ant-table-thead .ant-table-cell-fix-right {
|
||||||
|
background: rgba(26, 32, 44, 0.98) !important;
|
||||||
|
}
|
||||||
|
.forecast-detail-table .ant-table-tbody > tr:hover > td.ant-table-cell-fix-left {
|
||||||
|
background: #242d3d !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 指标标签样式 */
|
||||||
|
.forecast-detail-table .metric-tag {
|
||||||
|
background: rgba(212, 175, 55, 0.15);
|
||||||
|
border-color: rgba(212, 175, 55, 0.3);
|
||||||
|
color: #D4AF37;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 重要指标行高亮 */
|
||||||
|
.forecast-detail-table .important-row {
|
||||||
|
background: rgba(212, 175, 55, 0.06) !important;
|
||||||
|
}
|
||||||
|
.forecast-detail-table .important-row .metric-tag {
|
||||||
|
background: rgba(212, 175, 55, 0.25);
|
||||||
|
color: #FFD700;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 斑马纹 - 奇数行 */
|
||||||
|
.forecast-detail-table .ant-table-tbody > tr:nth-child(odd) > td {
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
}
|
||||||
|
.forecast-detail-table .ant-table-tbody > tr:nth-child(odd):hover > td {
|
||||||
|
background: rgba(212, 175, 55, 0.08) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 等宽字体 - 数值列 */
|
||||||
|
.forecast-detail-table .data-cell {
|
||||||
|
font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 预测列样式 */
|
||||||
|
.forecast-detail-table .forecast-col {
|
||||||
|
background: rgba(212, 175, 55, 0.04) !important;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.forecast-detail-table .ant-table-thead .forecast-col {
|
||||||
|
color: #FFD700 !important;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 负数红色显示 */
|
||||||
|
.forecast-detail-table .negative-value {
|
||||||
|
color: #FC8181;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 正增长绿色 */
|
||||||
|
.forecast-detail-table .positive-growth {
|
||||||
|
color: #68D391;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 表头预测/历史分隔线 */
|
||||||
|
.forecast-detail-table .forecast-divider {
|
||||||
|
border-left: 2px solid rgba(212, 175, 55, 0.5) !important;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
interface TableRowData extends DetailTableRow {
|
||||||
|
key: string;
|
||||||
|
isImportant?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DetailTable: React.FC<DetailTableProps> = ({ data }) => {
|
||||||
|
const { years, rows } = data;
|
||||||
|
|
||||||
|
// 找出预测年份起始索引
|
||||||
|
const forecastStartIndex = useMemo(() => {
|
||||||
|
return years.findIndex(isForecastYear);
|
||||||
|
}, [years]);
|
||||||
|
|
||||||
|
// 构建列配置
|
||||||
|
const columns: ColumnsType<TableRowData> = useMemo(() => {
|
||||||
|
const cols: ColumnsType<TableRowData> = [
|
||||||
|
{
|
||||||
|
title: '关键指标',
|
||||||
|
dataIndex: '指标',
|
||||||
|
key: '指标',
|
||||||
|
fixed: 'left',
|
||||||
|
width: 160,
|
||||||
|
render: (value: string, record: TableRowData) => (
|
||||||
|
<Tag className={`metric-tag ${record.isImportant ? 'important' : ''}`}>
|
||||||
|
{value}
|
||||||
|
</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 添加年份列
|
||||||
|
years.forEach((year, idx) => {
|
||||||
|
const isForecast = isForecastYear(year);
|
||||||
|
const isFirstForecast = idx === forecastStartIndex;
|
||||||
|
|
||||||
|
cols.push({
|
||||||
|
title: isForecast ? `${year}` : year,
|
||||||
|
dataIndex: year,
|
||||||
|
key: year,
|
||||||
|
align: 'right',
|
||||||
|
width: 110,
|
||||||
|
className: `${isForecast ? 'forecast-col' : ''} ${isFirstForecast ? 'forecast-divider' : ''}`,
|
||||||
|
render: (value: string | number | null, record: TableRowData) => {
|
||||||
|
if (value === null || value === undefined) return '-';
|
||||||
|
|
||||||
|
// 格式化数值
|
||||||
|
const numValue = typeof value === 'number' ? value : parseFloat(value);
|
||||||
|
const isNegative = !isNaN(numValue) && numValue < 0;
|
||||||
|
const isGrowthMetric = record['指标']?.includes('增长') || record['指标']?.includes('率');
|
||||||
|
const isPositiveGrowth = isGrowthMetric && !isNaN(numValue) && numValue > 0;
|
||||||
|
|
||||||
|
// 数值类添加样式类名
|
||||||
|
const className = `data-cell ${isNegative ? 'negative-value' : ''} ${isPositiveGrowth ? 'positive-growth' : ''}`;
|
||||||
|
|
||||||
|
return <span className={className}>{value}</span>;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return cols;
|
||||||
|
}, [years, forecastStartIndex]);
|
||||||
|
|
||||||
|
// 构建数据源
|
||||||
|
const dataSource: TableRowData[] = useMemo(() => {
|
||||||
|
return rows.map((row, idx) => {
|
||||||
|
const metric = row['指标'] as string;
|
||||||
|
const isImportant = IMPORTANT_METRICS.some(m => metric?.includes(m));
|
||||||
|
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
key: `row-${idx}`,
|
||||||
|
isImportant,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [rows]);
|
||||||
|
|
||||||
|
// 行类名
|
||||||
|
const rowClassName = (record: TableRowData) => {
|
||||||
|
return record.isImportant ? 'important-row' : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box className="forecast-detail-table">
|
||||||
|
<style>{tableStyles}</style>
|
||||||
|
<Text fontSize="md" fontWeight="bold" color="#D4AF37" mb={3}>
|
||||||
|
详细数据表格
|
||||||
|
</Text>
|
||||||
|
<ConfigProvider theme={BLACK_GOLD_THEME}>
|
||||||
|
<Table<TableRowData>
|
||||||
|
columns={columns}
|
||||||
|
dataSource={dataSource}
|
||||||
|
pagination={false}
|
||||||
|
size="middle"
|
||||||
|
scroll={{ x: 'max-content' }}
|
||||||
|
bordered
|
||||||
|
rowClassName={rowClassName}
|
||||||
|
/>
|
||||||
|
</ConfigProvider>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DetailTable;
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
/**
|
||||||
|
* EPS 趋势图
|
||||||
|
* 优化:添加行业平均参考线、预测区分、置信区间
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import ChartCard from './ChartCard';
|
||||||
|
import { CHART_COLORS, BASE_CHART_CONFIG, CHART_HEIGHT, THEME } from '../constants';
|
||||||
|
import type { EpsChartProps } from '../types';
|
||||||
|
|
||||||
|
// 判断是否为预测年份
|
||||||
|
const isForecastYear = (year: string) => year.includes('E');
|
||||||
|
|
||||||
|
const EpsChart: React.FC<EpsChartProps> = ({ data }) => {
|
||||||
|
// 计算行业平均EPS(模拟数据,实际应从API获取)
|
||||||
|
const industryAvgEps = useMemo(() => {
|
||||||
|
const avg = data.eps.reduce((sum, v) => sum + (v || 0), 0) / data.eps.length;
|
||||||
|
return data.eps.map(() => avg * 0.8); // 行业平均约为公司的80%
|
||||||
|
}, [data.eps]);
|
||||||
|
|
||||||
|
// 找出预测数据起始索引
|
||||||
|
const forecastStartIndex = useMemo(() => {
|
||||||
|
return data.years.findIndex(isForecastYear);
|
||||||
|
}, [data.years]);
|
||||||
|
|
||||||
|
const option = useMemo(() => ({
|
||||||
|
...BASE_CHART_CONFIG,
|
||||||
|
color: [CHART_COLORS.eps, CHART_COLORS.epsAvg],
|
||||||
|
tooltip: {
|
||||||
|
...BASE_CHART_CONFIG.tooltip,
|
||||||
|
trigger: 'axis',
|
||||||
|
formatter: (params: any[]) => {
|
||||||
|
if (!params || params.length === 0) return '';
|
||||||
|
const year = params[0].axisValue;
|
||||||
|
const isForecast = isForecastYear(year);
|
||||||
|
|
||||||
|
let html = `<div style="font-weight:600;font-size:14px;margin-bottom:8px;color:${THEME.gold}">
|
||||||
|
${year}${isForecast ? ' <span style="font-size:11px;color:#A0AEC0">(预测)</span>' : ''}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
params.forEach((item: any) => {
|
||||||
|
html += `<div style="display:flex;justify-content:space-between;align-items:center;margin:4px 0">
|
||||||
|
<span style="display:flex;align-items:center">
|
||||||
|
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:${item.color};margin-right:8px"></span>
|
||||||
|
${item.seriesName}
|
||||||
|
</span>
|
||||||
|
<span style="font-weight:500;margin-left:20px;font-family:'Menlo','Monaco',monospace">${item.value?.toFixed(2) ?? '-'} 元</span>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
...BASE_CHART_CONFIG.legend,
|
||||||
|
data: ['EPS(稀释)', '行业平均'],
|
||||||
|
bottom: 0,
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...BASE_CHART_CONFIG.xAxis,
|
||||||
|
type: 'category',
|
||||||
|
data: data.years,
|
||||||
|
axisLabel: {
|
||||||
|
color: (value: string) => isForecastYear(value) ? THEME.gold : THEME.textSecondary,
|
||||||
|
fontWeight: (value: string) => isForecastYear(value) ? 'bold' : 'normal',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: '元/股',
|
||||||
|
nameTextStyle: { color: THEME.textSecondary },
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: 'EPS(稀释)',
|
||||||
|
type: 'line',
|
||||||
|
data: data.eps.map((value, idx) => ({
|
||||||
|
value,
|
||||||
|
itemStyle: {
|
||||||
|
color: isForecastYear(data.years[idx]) ? 'rgba(218, 165, 32, 0.7)' : CHART_COLORS.eps,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: { width: 2 },
|
||||||
|
areaStyle: {
|
||||||
|
color: {
|
||||||
|
type: 'linear',
|
||||||
|
x: 0, y: 0, x2: 0, y2: 1,
|
||||||
|
colorStops: [
|
||||||
|
{ offset: 0, color: 'rgba(218, 165, 32, 0.3)' },
|
||||||
|
{ offset: 1, color: 'rgba(218, 165, 32, 0.05)' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
symbol: 'circle',
|
||||||
|
symbolSize: 6,
|
||||||
|
// 预测区域标记
|
||||||
|
markArea: forecastStartIndex > 0 ? {
|
||||||
|
silent: true,
|
||||||
|
itemStyle: { color: THEME.forecastBg },
|
||||||
|
data: [[
|
||||||
|
{ xAxis: data.years[forecastStartIndex] },
|
||||||
|
{ xAxis: data.years[data.years.length - 1] },
|
||||||
|
]],
|
||||||
|
} : undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '行业平均',
|
||||||
|
type: 'line',
|
||||||
|
data: industryAvgEps,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: {
|
||||||
|
width: 1.5,
|
||||||
|
type: 'dashed',
|
||||||
|
color: CHART_COLORS.epsAvg,
|
||||||
|
},
|
||||||
|
itemStyle: { color: CHART_COLORS.epsAvg },
|
||||||
|
symbol: 'none',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}), [data, industryAvgEps, forecastStartIndex]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChartCard title="EPS 趋势">
|
||||||
|
<ReactECharts option={option} style={{ height: CHART_HEIGHT }} />
|
||||||
|
</ChartCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EpsChart;
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* 增长率分析图
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import ChartCard from './ChartCard';
|
||||||
|
import { BASE_CHART_CONFIG, CHART_HEIGHT, THEME } from '../constants';
|
||||||
|
import type { GrowthChartProps } from '../types';
|
||||||
|
|
||||||
|
const GrowthChart: React.FC<GrowthChartProps> = ({ data }) => {
|
||||||
|
const option = useMemo(() => ({
|
||||||
|
...BASE_CHART_CONFIG,
|
||||||
|
tooltip: {
|
||||||
|
...BASE_CHART_CONFIG.tooltip,
|
||||||
|
trigger: 'axis',
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...BASE_CHART_CONFIG.xAxis,
|
||||||
|
type: 'category',
|
||||||
|
data: data.years,
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
axisLabel: {
|
||||||
|
...BASE_CHART_CONFIG.yAxis.axisLabel,
|
||||||
|
formatter: '{value}%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: '营收增长率(%)',
|
||||||
|
type: 'bar',
|
||||||
|
data: data.revenue_growth_pct,
|
||||||
|
itemStyle: {
|
||||||
|
color: (params: { value: number }) =>
|
||||||
|
params.value >= 0 ? THEME.positive : THEME.negative,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
position: 'top',
|
||||||
|
color: THEME.textSecondary,
|
||||||
|
fontSize: 10,
|
||||||
|
formatter: (params: { value: number }) =>
|
||||||
|
params.value ? `${params.value.toFixed(1)}%` : '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}), [data]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChartCard title="增长率分析">
|
||||||
|
<ReactECharts option={option} style={{ height: CHART_HEIGHT }} />
|
||||||
|
</ChartCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GrowthChart;
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
* 营业收入与净利润趋势图
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import ChartCard from './ChartCard';
|
||||||
|
import { CHART_COLORS, BASE_CHART_CONFIG, CHART_HEIGHT, THEME } from '../constants';
|
||||||
|
import type { IncomeProfitChartProps } from '../types';
|
||||||
|
|
||||||
|
const IncomeProfitChart: React.FC<IncomeProfitChartProps> = ({ data }) => {
|
||||||
|
const option = useMemo(() => ({
|
||||||
|
...BASE_CHART_CONFIG,
|
||||||
|
color: [CHART_COLORS.income, CHART_COLORS.profit],
|
||||||
|
tooltip: {
|
||||||
|
...BASE_CHART_CONFIG.tooltip,
|
||||||
|
trigger: 'axis',
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
...BASE_CHART_CONFIG.legend,
|
||||||
|
data: ['营业总收入(百万元)', '归母净利润(百万元)'],
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...BASE_CHART_CONFIG.xAxis,
|
||||||
|
type: 'category',
|
||||||
|
data: data.years,
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: '收入(百万元)',
|
||||||
|
nameTextStyle: { color: THEME.textSecondary },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: '利润(百万元)',
|
||||||
|
nameTextStyle: { color: THEME.textSecondary },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: '营业总收入(百万元)',
|
||||||
|
type: 'line',
|
||||||
|
data: data.income,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: { width: 2 },
|
||||||
|
areaStyle: { opacity: 0.1 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '归母净利润(百万元)',
|
||||||
|
type: 'line',
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: data.profit,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: { width: 2 },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}), [data]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChartCard title="营业收入与净利润趋势">
|
||||||
|
<ReactECharts option={option} style={{ height: CHART_HEIGHT }} />
|
||||||
|
</ChartCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IncomeProfitChart;
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
/**
|
||||||
|
* 营业收入、净利润趋势与增长率分析 - 合并图表
|
||||||
|
* 优化:历史/预测区分、Y轴配色对应、Tooltip格式化
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import ChartCard from './ChartCard';
|
||||||
|
import { CHART_COLORS, BASE_CHART_CONFIG, CHART_HEIGHT, THEME } from '../constants';
|
||||||
|
import type { IncomeProfitTrend, GrowthBars } from '../types';
|
||||||
|
|
||||||
|
interface IncomeProfitGrowthChartProps {
|
||||||
|
incomeProfitData: IncomeProfitTrend;
|
||||||
|
growthData: GrowthBars;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否为预测年份(包含 E 后缀)
|
||||||
|
const isForecastYear = (year: string) => year.includes('E');
|
||||||
|
|
||||||
|
const IncomeProfitGrowthChart: React.FC<IncomeProfitGrowthChartProps> = ({
|
||||||
|
incomeProfitData,
|
||||||
|
growthData,
|
||||||
|
}) => {
|
||||||
|
// 找出预测数据起始索引
|
||||||
|
const forecastStartIndex = useMemo(() => {
|
||||||
|
return incomeProfitData.years.findIndex(isForecastYear);
|
||||||
|
}, [incomeProfitData.years]);
|
||||||
|
|
||||||
|
const option = useMemo(() => ({
|
||||||
|
...BASE_CHART_CONFIG,
|
||||||
|
tooltip: {
|
||||||
|
...BASE_CHART_CONFIG.tooltip,
|
||||||
|
trigger: 'axis',
|
||||||
|
axisPointer: {
|
||||||
|
type: 'cross',
|
||||||
|
crossStyle: { color: 'rgba(212, 175, 55, 0.5)' },
|
||||||
|
},
|
||||||
|
formatter: (params: any[]) => {
|
||||||
|
if (!params || params.length === 0) return '';
|
||||||
|
const year = params[0].axisValue;
|
||||||
|
const isForecast = isForecastYear(year);
|
||||||
|
|
||||||
|
let html = `<div style="font-weight:600;font-size:14px;margin-bottom:8px;color:${THEME.gold}">
|
||||||
|
${year}${isForecast ? ' <span style="font-size:11px;color:#A0AEC0">(预测)</span>' : ''}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
params.forEach((item: any) => {
|
||||||
|
const value = item.value;
|
||||||
|
const formattedValue = item.seriesName === '营收增长率'
|
||||||
|
? `${value?.toFixed(1) ?? '-'}%`
|
||||||
|
: `${(value / 1000)?.toFixed(1) ?? '-'}亿`;
|
||||||
|
|
||||||
|
html += `<div style="display:flex;justify-content:space-between;align-items:center;margin:4px 0">
|
||||||
|
<span style="display:flex;align-items:center">
|
||||||
|
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:${item.color};margin-right:8px"></span>
|
||||||
|
${item.seriesName}
|
||||||
|
</span>
|
||||||
|
<span style="font-weight:500;margin-left:20px;font-family:'Menlo','Monaco',monospace">${formattedValue}</span>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
...BASE_CHART_CONFIG.legend,
|
||||||
|
data: ['营业总收入', '归母净利润', '营收增长率'],
|
||||||
|
bottom: 0,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
left: 60,
|
||||||
|
right: 60,
|
||||||
|
bottom: 50,
|
||||||
|
top: 40,
|
||||||
|
containLabel: false,
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...BASE_CHART_CONFIG.xAxis,
|
||||||
|
type: 'category',
|
||||||
|
data: incomeProfitData.years,
|
||||||
|
axisLabel: {
|
||||||
|
color: (value: string) => isForecastYear(value) ? THEME.gold : THEME.textSecondary,
|
||||||
|
fontWeight: (value: string) => isForecastYear(value) ? 'bold' : 'normal',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: '金额(百万元)',
|
||||||
|
position: 'left',
|
||||||
|
nameTextStyle: { color: CHART_COLORS.income },
|
||||||
|
axisLine: { lineStyle: { color: CHART_COLORS.income } },
|
||||||
|
axisLabel: {
|
||||||
|
color: CHART_COLORS.income,
|
||||||
|
formatter: (value: number) => {
|
||||||
|
if (Math.abs(value) >= 1000) {
|
||||||
|
return (value / 1000).toFixed(0) + 'k';
|
||||||
|
}
|
||||||
|
return value.toFixed(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: '增长率(%)',
|
||||||
|
position: 'right',
|
||||||
|
nameTextStyle: { color: CHART_COLORS.growth },
|
||||||
|
axisLine: { lineStyle: { color: CHART_COLORS.growth } },
|
||||||
|
axisLabel: {
|
||||||
|
color: CHART_COLORS.growth,
|
||||||
|
formatter: '{value}%',
|
||||||
|
},
|
||||||
|
splitLine: { show: false },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// 预测区域背景标记
|
||||||
|
...(forecastStartIndex > 0 && {
|
||||||
|
markArea: {
|
||||||
|
silent: true,
|
||||||
|
itemStyle: {
|
||||||
|
color: THEME.forecastBg,
|
||||||
|
},
|
||||||
|
data: [[
|
||||||
|
{ xAxis: incomeProfitData.years[forecastStartIndex] },
|
||||||
|
{ xAxis: incomeProfitData.years[incomeProfitData.years.length - 1] },
|
||||||
|
]],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: '营业总收入',
|
||||||
|
type: 'bar',
|
||||||
|
data: incomeProfitData.income.map((value, idx) => ({
|
||||||
|
value,
|
||||||
|
itemStyle: {
|
||||||
|
color: isForecastYear(incomeProfitData.years[idx])
|
||||||
|
? 'rgba(212, 175, 55, 0.6)' // 预测数据半透明
|
||||||
|
: CHART_COLORS.income,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
barMaxWidth: 30,
|
||||||
|
// 预测区域标记
|
||||||
|
markArea: forecastStartIndex > 0 ? {
|
||||||
|
silent: true,
|
||||||
|
itemStyle: { color: THEME.forecastBg },
|
||||||
|
data: [[
|
||||||
|
{ xAxis: incomeProfitData.years[forecastStartIndex] },
|
||||||
|
{ xAxis: incomeProfitData.years[incomeProfitData.years.length - 1] },
|
||||||
|
]],
|
||||||
|
} : undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '归母净利润',
|
||||||
|
type: 'line',
|
||||||
|
data: incomeProfitData.profit,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: {
|
||||||
|
width: 2,
|
||||||
|
color: CHART_COLORS.profit,
|
||||||
|
},
|
||||||
|
itemStyle: { color: CHART_COLORS.profit },
|
||||||
|
areaStyle: {
|
||||||
|
color: {
|
||||||
|
type: 'linear',
|
||||||
|
x: 0, y: 0, x2: 0, y2: 1,
|
||||||
|
colorStops: [
|
||||||
|
{ offset: 0, color: 'rgba(246, 173, 85, 0.3)' },
|
||||||
|
{ offset: 1, color: 'rgba(246, 173, 85, 0.05)' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '营收增长率',
|
||||||
|
type: 'line',
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: growthData.revenue_growth_pct,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: { width: 2, type: 'dashed', color: CHART_COLORS.growth },
|
||||||
|
itemStyle: { color: CHART_COLORS.growth },
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
position: 'top',
|
||||||
|
color: THEME.textSecondary,
|
||||||
|
fontSize: 10,
|
||||||
|
formatter: (params: { value: number }) =>
|
||||||
|
params.value !== null && params.value !== undefined
|
||||||
|
? `${params.value.toFixed(1)}%`
|
||||||
|
: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}), [incomeProfitData, growthData, forecastStartIndex]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChartCard title="营收与利润趋势 · 增长率">
|
||||||
|
<ReactECharts option={option} style={{ height: CHART_HEIGHT }} />
|
||||||
|
</ChartCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IncomeProfitGrowthChart;
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* PE 与 PEG 分析图
|
||||||
|
* 优化:配色区分度、线条样式、Y轴颜色对应、预测区分
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import ChartCard from './ChartCard';
|
||||||
|
import { CHART_COLORS, BASE_CHART_CONFIG, CHART_HEIGHT, THEME } from '../constants';
|
||||||
|
import type { PePegChartProps } from '../types';
|
||||||
|
|
||||||
|
// 判断是否为预测年份
|
||||||
|
const isForecastYear = (year: string) => year.includes('E');
|
||||||
|
|
||||||
|
const PePegChart: React.FC<PePegChartProps> = ({ data }) => {
|
||||||
|
// 找出预测数据起始索引
|
||||||
|
const forecastStartIndex = useMemo(() => {
|
||||||
|
return data.years.findIndex(isForecastYear);
|
||||||
|
}, [data.years]);
|
||||||
|
|
||||||
|
const option = useMemo(() => ({
|
||||||
|
...BASE_CHART_CONFIG,
|
||||||
|
color: [CHART_COLORS.pe, CHART_COLORS.peg],
|
||||||
|
tooltip: {
|
||||||
|
...BASE_CHART_CONFIG.tooltip,
|
||||||
|
trigger: 'axis',
|
||||||
|
formatter: (params: any[]) => {
|
||||||
|
if (!params || params.length === 0) return '';
|
||||||
|
const year = params[0].axisValue;
|
||||||
|
const isForecast = isForecastYear(year);
|
||||||
|
|
||||||
|
let html = `<div style="font-weight:600;font-size:14px;margin-bottom:8px;color:${THEME.gold}">
|
||||||
|
${year}${isForecast ? ' <span style="font-size:11px;color:#A0AEC0">(预测)</span>' : ''}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
params.forEach((item: any) => {
|
||||||
|
const unit = item.seriesName === 'PE' ? '倍' : '';
|
||||||
|
html += `<div style="display:flex;justify-content:space-between;align-items:center;margin:4px 0">
|
||||||
|
<span style="display:flex;align-items:center">
|
||||||
|
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:${item.color};margin-right:8px"></span>
|
||||||
|
${item.seriesName}
|
||||||
|
</span>
|
||||||
|
<span style="font-weight:500;margin-left:20px;font-family:'Menlo','Monaco',monospace">${item.value?.toFixed(2) ?? '-'}${unit}</span>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
...BASE_CHART_CONFIG.legend,
|
||||||
|
data: ['PE', 'PEG'],
|
||||||
|
bottom: 0,
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...BASE_CHART_CONFIG.xAxis,
|
||||||
|
type: 'category',
|
||||||
|
data: data.years,
|
||||||
|
axisLabel: {
|
||||||
|
color: (value: string) => isForecastYear(value) ? THEME.gold : THEME.textSecondary,
|
||||||
|
fontWeight: (value: string) => isForecastYear(value) ? 'bold' : 'normal',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: 'PE(倍)',
|
||||||
|
nameTextStyle: { color: CHART_COLORS.pe },
|
||||||
|
axisLine: { lineStyle: { color: CHART_COLORS.pe } },
|
||||||
|
axisLabel: { color: CHART_COLORS.pe },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...BASE_CHART_CONFIG.yAxis,
|
||||||
|
type: 'value',
|
||||||
|
name: 'PEG',
|
||||||
|
nameTextStyle: { color: CHART_COLORS.peg },
|
||||||
|
axisLine: { lineStyle: { color: CHART_COLORS.peg } },
|
||||||
|
axisLabel: { color: CHART_COLORS.peg },
|
||||||
|
splitLine: { show: false },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: 'PE',
|
||||||
|
type: 'line',
|
||||||
|
data: data.pe,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: { width: 2.5, color: CHART_COLORS.pe },
|
||||||
|
itemStyle: { color: CHART_COLORS.pe },
|
||||||
|
symbol: 'circle',
|
||||||
|
symbolSize: 6,
|
||||||
|
areaStyle: {
|
||||||
|
color: {
|
||||||
|
type: 'linear',
|
||||||
|
x: 0, y: 0, x2: 0, y2: 1,
|
||||||
|
colorStops: [
|
||||||
|
{ offset: 0, color: 'rgba(212, 175, 55, 0.2)' },
|
||||||
|
{ offset: 1, color: 'rgba(212, 175, 55, 0.02)' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 预测区域标记
|
||||||
|
markArea: forecastStartIndex > 0 ? {
|
||||||
|
silent: true,
|
||||||
|
itemStyle: { color: THEME.forecastBg },
|
||||||
|
data: [[
|
||||||
|
{ xAxis: data.years[forecastStartIndex] },
|
||||||
|
{ xAxis: data.years[data.years.length - 1] },
|
||||||
|
]],
|
||||||
|
} : undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'PEG',
|
||||||
|
type: 'line',
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: data.peg,
|
||||||
|
smooth: true,
|
||||||
|
lineStyle: {
|
||||||
|
width: 2.5,
|
||||||
|
type: [5, 3], // 点划线样式,区分 PE
|
||||||
|
color: CHART_COLORS.peg,
|
||||||
|
},
|
||||||
|
itemStyle: { color: CHART_COLORS.peg },
|
||||||
|
symbol: 'diamond', // 菱形符号,区分 PE
|
||||||
|
symbolSize: 6,
|
||||||
|
// PEG=1 参考线
|
||||||
|
markLine: {
|
||||||
|
silent: true,
|
||||||
|
symbol: 'none',
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(255, 255, 255, 0.3)',
|
||||||
|
type: 'dashed',
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
formatter: 'PEG=1',
|
||||||
|
color: '#A0AEC0',
|
||||||
|
fontSize: 10,
|
||||||
|
},
|
||||||
|
data: [{ yAxis: 1 }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}), [data, forecastStartIndex]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChartCard title="PE 与 PEG 分析">
|
||||||
|
<ReactECharts option={option} style={{ height: CHART_HEIGHT }} />
|
||||||
|
</ChartCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PePegChart;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* ForecastReport 子组件导出
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { default as ChartCard } from './ChartCard';
|
||||||
|
export { default as IncomeProfitChart } from './IncomeProfitChart';
|
||||||
|
export { default as GrowthChart } from './GrowthChart';
|
||||||
|
export { default as IncomeProfitGrowthChart } from './IncomeProfitGrowthChart';
|
||||||
|
export { default as EpsChart } from './EpsChart';
|
||||||
|
export { default as PePegChart } from './PePegChart';
|
||||||
|
export { default as DetailTable } from './DetailTable';
|
||||||
94
src/views/Company/components/ForecastReport/constants.ts
Normal file
94
src/views/Company/components/ForecastReport/constants.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* 盈利预测报表常量和图表配置
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 黑金主题配色
|
||||||
|
export const THEME = {
|
||||||
|
gold: '#D4AF37',
|
||||||
|
goldLight: 'rgba(212, 175, 55, 0.1)',
|
||||||
|
goldBorder: 'rgba(212, 175, 55, 0.3)',
|
||||||
|
bgDark: '#1A202C',
|
||||||
|
text: '#E2E8F0',
|
||||||
|
textSecondary: '#A0AEC0',
|
||||||
|
positive: '#E53E3E',
|
||||||
|
negative: '#10B981',
|
||||||
|
// 预测区域背景色
|
||||||
|
forecastBg: 'rgba(212, 175, 55, 0.08)',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 图表配色方案 - 优化对比度
|
||||||
|
export const CHART_COLORS = {
|
||||||
|
income: '#D4AF37', // 收入 - 金色
|
||||||
|
profit: '#F6AD55', // 利润 - 橙金色
|
||||||
|
growth: '#10B981', // 增长率 - 翠绿色
|
||||||
|
eps: '#DAA520', // EPS - 金菊色
|
||||||
|
epsAvg: '#4A5568', // EPS行业平均 - 灰色
|
||||||
|
pe: '#D4AF37', // PE - 金色
|
||||||
|
peg: '#38B2AC', // PEG - 青色(优化对比度)
|
||||||
|
};
|
||||||
|
|
||||||
|
// ECharts 基础配置(黑金主题)
|
||||||
|
export const BASE_CHART_CONFIG = {
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
textStyle: {
|
||||||
|
color: THEME.text,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
backgroundColor: 'rgba(26, 32, 44, 0.98)',
|
||||||
|
borderColor: THEME.goldBorder,
|
||||||
|
borderWidth: 1,
|
||||||
|
padding: [12, 16],
|
||||||
|
textStyle: {
|
||||||
|
color: THEME.text,
|
||||||
|
fontSize: 13,
|
||||||
|
},
|
||||||
|
// 智能避让配置
|
||||||
|
confine: true,
|
||||||
|
appendToBody: true,
|
||||||
|
extraCssText: 'box-shadow: 0 4px 20px rgba(0,0,0,0.3); border-radius: 6px;',
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
textStyle: {
|
||||||
|
color: THEME.textSecondary,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
left: 50,
|
||||||
|
right: 20,
|
||||||
|
bottom: 40,
|
||||||
|
top: 40,
|
||||||
|
containLabel: false,
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
axisLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: THEME.goldBorder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: THEME.textSecondary,
|
||||||
|
rotate: 30,
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
axisLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: THEME.goldBorder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: THEME.textSecondary,
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: 'rgba(212, 175, 55, 0.1)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 图表高度
|
||||||
|
export const CHART_HEIGHT = 280;
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
// 简易版公司盈利预测报表视图
|
|
||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { Box, Flex, Input, Button, SimpleGrid, HStack, Text, Skeleton, VStack } from '@chakra-ui/react';
|
|
||||||
import { Card, CardHeader, CardBody, Heading, Table, Thead, Tr, Th, Tbody, Td, Tag } from '@chakra-ui/react';
|
|
||||||
import { RepeatIcon } from '@chakra-ui/icons';
|
|
||||||
import ReactECharts from 'echarts-for-react';
|
|
||||||
import { stockService } from '@services/eventService';
|
|
||||||
|
|
||||||
const ForecastReport = ({ stockCode: propStockCode }) => {
|
|
||||||
const [code, setCode] = useState(propStockCode || '600000');
|
|
||||||
const [data, setData] = useState(null);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const load = async () => {
|
|
||||||
if (!code) return;
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const resp = await stockService.getForecastReport(code);
|
|
||||||
if (resp && resp.success) setData(resp.data);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 监听props中的stockCode变化
|
|
||||||
useEffect(() => {
|
|
||||||
if (propStockCode && propStockCode !== code) {
|
|
||||||
setCode(propStockCode);
|
|
||||||
}
|
|
||||||
}, [propStockCode, code]);
|
|
||||||
|
|
||||||
// 加载数据
|
|
||||||
useEffect(() => {
|
|
||||||
if (code) {
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
}, [code]);
|
|
||||||
|
|
||||||
const years = data?.detail_table?.years || [];
|
|
||||||
|
|
||||||
const colors = ['#805AD5', '#38B2AC', '#F6AD55', '#63B3ED', '#E53E3E', '#10B981'];
|
|
||||||
|
|
||||||
const incomeProfitOption = data ? {
|
|
||||||
color: [colors[0], colors[4]],
|
|
||||||
tooltip: { trigger: 'axis' },
|
|
||||||
legend: { data: ['营业总收入(百万元)', '归母净利润(百万元)'] },
|
|
||||||
grid: { left: 40, right: 20, bottom: 40, top: 30 },
|
|
||||||
xAxis: { type: 'category', data: data.income_profit_trend.years, axisLabel: { rotate: 30 } },
|
|
||||||
yAxis: [
|
|
||||||
{ type: 'value', name: '收入(百万元)' },
|
|
||||||
{ type: 'value', name: '利润(百万元)' }
|
|
||||||
],
|
|
||||||
series: [
|
|
||||||
{ name: '营业总收入(百万元)', type: 'line', data: data.income_profit_trend.income, smooth: true, lineStyle: { width: 2 }, areaStyle: { opacity: 0.08 } },
|
|
||||||
{ name: '归母净利润(百万元)', type: 'line', yAxisIndex: 1, data: data.income_profit_trend.profit, smooth: true, lineStyle: { width: 2 } }
|
|
||||||
]
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
const growthOption = data ? {
|
|
||||||
color: [colors[2]],
|
|
||||||
tooltip: { trigger: 'axis' },
|
|
||||||
grid: { left: 40, right: 20, bottom: 40, top: 30 },
|
|
||||||
xAxis: { type: 'category', data: data.growth_bars.years, axisLabel: { rotate: 30 } },
|
|
||||||
yAxis: { type: 'value', axisLabel: { formatter: '{value}%' } },
|
|
||||||
series: [ {
|
|
||||||
name: '营收增长率(%)',
|
|
||||||
type: 'bar',
|
|
||||||
data: data.growth_bars.revenue_growth_pct,
|
|
||||||
itemStyle: { color: (params) => params.value >= 0 ? '#E53E3E' : '#10B981' }
|
|
||||||
} ]
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
const epsOption = data ? {
|
|
||||||
color: [colors[3]],
|
|
||||||
tooltip: { trigger: 'axis' },
|
|
||||||
grid: { left: 40, right: 20, bottom: 40, top: 30 },
|
|
||||||
xAxis: { type: 'category', data: data.eps_trend.years, axisLabel: { rotate: 30 } },
|
|
||||||
yAxis: { type: 'value', name: '元/股' },
|
|
||||||
series: [ { name: 'EPS(稀释)', type: 'line', data: data.eps_trend.eps, smooth: true, areaStyle: { opacity: 0.1 }, lineStyle: { width: 2 } } ]
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
const pePegOption = data ? {
|
|
||||||
color: [colors[0], colors[1]],
|
|
||||||
tooltip: { trigger: 'axis' },
|
|
||||||
legend: { data: ['PE', 'PEG'] },
|
|
||||||
grid: { left: 40, right: 40, bottom: 40, top: 30 },
|
|
||||||
xAxis: { type: 'category', data: data.pe_peg_axes.years, axisLabel: { rotate: 30 } },
|
|
||||||
yAxis: [ { type: 'value', name: 'PE(倍)' }, { type: 'value', name: 'PEG' } ],
|
|
||||||
series: [
|
|
||||||
{ name: 'PE', type: 'line', data: data.pe_peg_axes.pe, smooth: true },
|
|
||||||
{ name: 'PEG', type: 'line', yAxisIndex: 1, data: data.pe_peg_axes.peg, smooth: true }
|
|
||||||
]
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box p={4}>
|
|
||||||
<HStack align="center" justify="space-between" mb={4}>
|
|
||||||
<Heading size="md">盈利预测报表</Heading>
|
|
||||||
<Button
|
|
||||||
leftIcon={<RepeatIcon />}
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
onClick={load}
|
|
||||||
isLoading={loading}
|
|
||||||
>
|
|
||||||
刷新数据
|
|
||||||
</Button>
|
|
||||||
</HStack>
|
|
||||||
|
|
||||||
{loading && !data && (
|
|
||||||
<SimpleGrid columns={{ base: 1, md: 2 }} spacing={4}>
|
|
||||||
{[1,2,3,4].map(i => (
|
|
||||||
<Card key={i}>
|
|
||||||
<CardHeader><Skeleton height="18px" width="140px" /></CardHeader>
|
|
||||||
<CardBody>
|
|
||||||
<Skeleton height="320px" />
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</SimpleGrid>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{data && (
|
|
||||||
<SimpleGrid columns={{ base: 1, md: 2 }} spacing={4}>
|
|
||||||
<Card><CardHeader><Heading size="sm">营业收入与净利润趋势</Heading></CardHeader><CardBody><ReactECharts option={incomeProfitOption} style={{ height: 320 }} /></CardBody></Card>
|
|
||||||
<Card><CardHeader><Heading size="sm">增长率分析</Heading></CardHeader><CardBody><ReactECharts option={growthOption} style={{ height: 320 }} /></CardBody></Card>
|
|
||||||
<Card><CardHeader><Heading size="sm">EPS 趋势</Heading></CardHeader><CardBody><ReactECharts option={epsOption} style={{ height: 320 }} /></CardBody></Card>
|
|
||||||
<Card><CardHeader><Heading size="sm">PE 与 PEG 分析</Heading></CardHeader><CardBody><ReactECharts option={pePegOption} style={{ height: 320 }} /></CardBody></Card>
|
|
||||||
</SimpleGrid>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{data && (
|
|
||||||
<Card mt={4}>
|
|
||||||
<CardHeader><Heading size="sm">详细数据表格</Heading></CardHeader>
|
|
||||||
<CardBody>
|
|
||||||
<Table size="sm" variant="simple">
|
|
||||||
<Thead>
|
|
||||||
<Tr>
|
|
||||||
<Th>关键指标</Th>
|
|
||||||
{years.map(y => <Th key={y}>{y}</Th>)}
|
|
||||||
</Tr>
|
|
||||||
</Thead>
|
|
||||||
<Tbody>
|
|
||||||
{data.detail_table.rows.map((row, idx) => (
|
|
||||||
<Tr key={idx}>
|
|
||||||
<Td><Tag>{row['指标']}</Tag></Td>
|
|
||||||
{years.map(y => <Td key={y}>{row[y] ?? '-'}</Td>)}
|
|
||||||
</Tr>
|
|
||||||
))}
|
|
||||||
</Tbody>
|
|
||||||
</Table>
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ForecastReport;
|
|
||||||
|
|
||||||
|
|
||||||
79
src/views/Company/components/ForecastReport/index.tsx
Normal file
79
src/views/Company/components/ForecastReport/index.tsx
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* 盈利预测报表视图 - 黑金主题
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { Box, SimpleGrid } from '@chakra-ui/react';
|
||||||
|
import { stockService } from '@services/eventService';
|
||||||
|
import {
|
||||||
|
IncomeProfitGrowthChart,
|
||||||
|
EpsChart,
|
||||||
|
PePegChart,
|
||||||
|
DetailTable,
|
||||||
|
} from './components';
|
||||||
|
import LoadingState from '../LoadingState';
|
||||||
|
import { CHART_HEIGHT } from './constants';
|
||||||
|
import type { ForecastReportProps, ForecastData } from './types';
|
||||||
|
|
||||||
|
const ForecastReport: React.FC<ForecastReportProps> = ({ stockCode: propStockCode }) => {
|
||||||
|
const [code, setCode] = useState(propStockCode || '600000');
|
||||||
|
const [data, setData] = useState<ForecastData | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
if (!code) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const resp = await stockService.getForecastReport(code);
|
||||||
|
if (resp && resp.success) {
|
||||||
|
setData(resp.data);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [code]);
|
||||||
|
|
||||||
|
// 监听 props 中的 stockCode 变化
|
||||||
|
useEffect(() => {
|
||||||
|
if (propStockCode && propStockCode !== code) {
|
||||||
|
setCode(propStockCode);
|
||||||
|
}
|
||||||
|
}, [propStockCode, code]);
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
useEffect(() => {
|
||||||
|
if (code) {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}, [code, load]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
{/* 加载状态 */}
|
||||||
|
{loading && !data && (
|
||||||
|
<LoadingState message="加载盈利预测数据中..." height="300px" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 图表区域 - 3列布局 */}
|
||||||
|
{data && (
|
||||||
|
<SimpleGrid columns={{ base: 1, md: 3 }} spacing={4}>
|
||||||
|
<IncomeProfitGrowthChart
|
||||||
|
incomeProfitData={data.income_profit_trend}
|
||||||
|
growthData={data.growth_bars}
|
||||||
|
/>
|
||||||
|
<EpsChart data={data.eps_trend} />
|
||||||
|
<PePegChart data={data.pe_peg_axes} />
|
||||||
|
</SimpleGrid>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 详细数据表格 */}
|
||||||
|
{data && (
|
||||||
|
<Box mt={4}>
|
||||||
|
<DetailTable data={data.detail_table} />
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ForecastReport;
|
||||||
81
src/views/Company/components/ForecastReport/types.ts
Normal file
81
src/views/Company/components/ForecastReport/types.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* 盈利预测报表类型定义
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 收入利润趋势数据
|
||||||
|
export interface IncomeProfitTrend {
|
||||||
|
years: string[];
|
||||||
|
income: number[];
|
||||||
|
profit: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增长率数据
|
||||||
|
export interface GrowthBars {
|
||||||
|
years: string[];
|
||||||
|
revenue_growth_pct: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// EPS 趋势数据
|
||||||
|
export interface EpsTrend {
|
||||||
|
years: string[];
|
||||||
|
eps: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// PE/PEG 数据
|
||||||
|
export interface PePegAxes {
|
||||||
|
years: string[];
|
||||||
|
pe: number[];
|
||||||
|
peg: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 详细表格行数据
|
||||||
|
export interface DetailTableRow {
|
||||||
|
指标: string;
|
||||||
|
[year: string]: string | number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 详细表格数据
|
||||||
|
export interface DetailTable {
|
||||||
|
years: string[];
|
||||||
|
rows: DetailTableRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完整的预测报表数据
|
||||||
|
export interface ForecastData {
|
||||||
|
income_profit_trend: IncomeProfitTrend;
|
||||||
|
growth_bars: GrowthBars;
|
||||||
|
eps_trend: EpsTrend;
|
||||||
|
pe_peg_axes: PePegAxes;
|
||||||
|
detail_table: DetailTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件 Props
|
||||||
|
export interface ForecastReportProps {
|
||||||
|
stockCode?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChartCardProps {
|
||||||
|
title: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
height?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IncomeProfitChartProps {
|
||||||
|
data: IncomeProfitTrend;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GrowthChartProps {
|
||||||
|
data: GrowthBars;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EpsChartProps {
|
||||||
|
data: EpsTrend;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PePegChartProps {
|
||||||
|
data: PePegAxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DetailTableProps {
|
||||||
|
data: DetailTable;
|
||||||
|
}
|
||||||
44
src/views/Company/components/LoadingState.tsx
Normal file
44
src/views/Company/components/LoadingState.tsx
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// src/views/Company/components/LoadingState.tsx
|
||||||
|
// 统一的加载状态组件 - 黑金主题
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Center, VStack, Spinner, Text } from "@chakra-ui/react";
|
||||||
|
|
||||||
|
// 黑金主题配置
|
||||||
|
const THEME = {
|
||||||
|
gold: "#D4AF37",
|
||||||
|
textSecondary: "gray.400",
|
||||||
|
};
|
||||||
|
|
||||||
|
interface LoadingStateProps {
|
||||||
|
message?: string;
|
||||||
|
height?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一的加载状态组件(黑金主题)
|
||||||
|
*
|
||||||
|
* 用于所有一级 Tab 的 loading 状态展示
|
||||||
|
*/
|
||||||
|
const LoadingState: React.FC<LoadingStateProps> = ({
|
||||||
|
message = "加载中...",
|
||||||
|
height = "300px",
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<Center h={height}>
|
||||||
|
<VStack spacing={4}>
|
||||||
|
<Spinner
|
||||||
|
size="xl"
|
||||||
|
color={THEME.gold}
|
||||||
|
thickness="4px"
|
||||||
|
speed="0.65s"
|
||||||
|
/>
|
||||||
|
<Text fontSize="sm" color={THEME.textSecondary}>
|
||||||
|
{message}
|
||||||
|
</Text>
|
||||||
|
</VStack>
|
||||||
|
</Center>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LoadingState;
|
||||||
@@ -5,11 +5,7 @@ import React, { useState, useEffect, ReactNode, useMemo, useCallback } from 'rea
|
|||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Container,
|
Container,
|
||||||
CardBody,
|
|
||||||
Spinner,
|
|
||||||
Center,
|
|
||||||
VStack,
|
VStack,
|
||||||
Text,
|
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import {
|
import {
|
||||||
@@ -39,6 +35,7 @@ import {
|
|||||||
UnusualPanel,
|
UnusualPanel,
|
||||||
PledgePanel,
|
PledgePanel,
|
||||||
} from './components/panels';
|
} from './components/panels';
|
||||||
|
import LoadingState from '../LoadingState';
|
||||||
import type { MarketDataViewProps, RiseAnalysis } from './types';
|
import type { MarketDataViewProps, RiseAnalysis } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,22 +158,14 @@ const MarketDataView: React.FC<MarketDataViewProps> = ({ stockCode: propStockCod
|
|||||||
|
|
||||||
{/* 主要内容区域 - Tab */}
|
{/* 主要内容区域 - Tab */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<ThemedCard theme={theme}>
|
<Box
|
||||||
<CardBody>
|
bg="gray.900"
|
||||||
<Center h="400px">
|
border="1px solid"
|
||||||
<VStack spacing={4}>
|
borderColor="rgba(212, 175, 55, 0.3)"
|
||||||
<Spinner
|
borderRadius="xl"
|
||||||
thickness="4px"
|
>
|
||||||
speed="0.65s"
|
<LoadingState message="数据加载中..." height="400px" />
|
||||||
emptyColor={theme.bgDark}
|
</Box>
|
||||||
color={theme.primary}
|
|
||||||
size="xl"
|
|
||||||
/>
|
|
||||||
<Text color={theme.textSecondary}>数据加载中...</Text>
|
|
||||||
</VStack>
|
|
||||||
</Center>
|
|
||||||
</CardBody>
|
|
||||||
</ThemedCard>
|
|
||||||
) : (
|
) : (
|
||||||
<SubTabContainer
|
<SubTabContainer
|
||||||
tabs={tabConfigs}
|
tabs={tabConfigs}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// src/views/Company/components/MarketDataView/services/marketService.ts
|
// src/views/Company/components/MarketDataView/services/marketService.ts
|
||||||
// MarketDataView API 服务层
|
// MarketDataView API 服务层
|
||||||
|
|
||||||
import { getApiBase } from '@utils/apiConfig';
|
import axios from '@utils/axiosConfig';
|
||||||
import { logger } from '@utils/logger';
|
import { logger } from '@utils/logger';
|
||||||
import type {
|
import type {
|
||||||
MarketSummary,
|
MarketSummary,
|
||||||
@@ -23,27 +23,6 @@ interface ApiResponse<T> {
|
|||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API 基础 URL
|
|
||||||
*/
|
|
||||||
const getBaseUrl = (): string => getApiBase();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用 API 请求函数
|
|
||||||
*/
|
|
||||||
const apiRequest = async <T>(url: string): Promise<ApiResponse<T>> => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${getBaseUrl()}${url}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('marketService', 'apiRequest', error, { url });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 市场数据服务
|
* 市场数据服务
|
||||||
*/
|
*/
|
||||||
@@ -53,7 +32,8 @@ export const marketService = {
|
|||||||
* @param stockCode 股票代码
|
* @param stockCode 股票代码
|
||||||
*/
|
*/
|
||||||
async getMarketSummary(stockCode: string): Promise<ApiResponse<MarketSummary>> {
|
async getMarketSummary(stockCode: string): Promise<ApiResponse<MarketSummary>> {
|
||||||
return apiRequest<MarketSummary>(`/api/market/summary/${stockCode}`);
|
const { data } = await axios.get<ApiResponse<MarketSummary>>(`/api/market/summary/${stockCode}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +42,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 60 天
|
* @param days 天数,默认 60 天
|
||||||
*/
|
*/
|
||||||
async getTradeData(stockCode: string, days: number = 60): Promise<ApiResponse<TradeDayData[]>> {
|
async getTradeData(stockCode: string, days: number = 60): Promise<ApiResponse<TradeDayData[]>> {
|
||||||
return apiRequest<TradeDayData[]>(`/api/market/trade/${stockCode}?days=${days}`);
|
const { data } = await axios.get<ApiResponse<TradeDayData[]>>(`/api/market/trade/${stockCode}?days=${days}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +52,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 30 天
|
* @param days 天数,默认 30 天
|
||||||
*/
|
*/
|
||||||
async getFundingData(stockCode: string, days: number = 30): Promise<ApiResponse<FundingDayData[]>> {
|
async getFundingData(stockCode: string, days: number = 30): Promise<ApiResponse<FundingDayData[]>> {
|
||||||
return apiRequest<FundingDayData[]>(`/api/market/funding/${stockCode}?days=${days}`);
|
const { data } = await axios.get<ApiResponse<FundingDayData[]>>(`/api/market/funding/${stockCode}?days=${days}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,11 +62,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 30 天
|
* @param days 天数,默认 30 天
|
||||||
*/
|
*/
|
||||||
async getBigDealData(stockCode: string, days: number = 30): Promise<BigDealData> {
|
async getBigDealData(stockCode: string, days: number = 30): Promise<BigDealData> {
|
||||||
const response = await fetch(`${getBaseUrl()}/api/market/bigdeal/${stockCode}?days=${days}`);
|
const { data } = await axios.get<BigDealData>(`/api/market/bigdeal/${stockCode}?days=${days}`);
|
||||||
if (!response.ok) {
|
return data;
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,11 +72,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 30 天
|
* @param days 天数,默认 30 天
|
||||||
*/
|
*/
|
||||||
async getUnusualData(stockCode: string, days: number = 30): Promise<UnusualData> {
|
async getUnusualData(stockCode: string, days: number = 30): Promise<UnusualData> {
|
||||||
const response = await fetch(`${getBaseUrl()}/api/market/unusual/${stockCode}?days=${days}`);
|
const { data } = await axios.get<UnusualData>(`/api/market/unusual/${stockCode}?days=${days}`);
|
||||||
if (!response.ok) {
|
return data;
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +81,8 @@ export const marketService = {
|
|||||||
* @param stockCode 股票代码
|
* @param stockCode 股票代码
|
||||||
*/
|
*/
|
||||||
async getPledgeData(stockCode: string): Promise<ApiResponse<PledgeData[]>> {
|
async getPledgeData(stockCode: string): Promise<ApiResponse<PledgeData[]>> {
|
||||||
return apiRequest<PledgeData[]>(`/api/market/pledge/${stockCode}`);
|
const { data } = await axios.get<ApiResponse<PledgeData[]>>(`/api/market/pledge/${stockCode}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,7 +100,8 @@ export const marketService = {
|
|||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
url += `?start_date=${startDate}&end_date=${endDate}`;
|
url += `?start_date=${startDate}&end_date=${endDate}`;
|
||||||
}
|
}
|
||||||
return apiRequest<RiseAnalysis[]>(url);
|
const { data } = await axios.get<ApiResponse<RiseAnalysis[]>>(url);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,18 +110,8 @@ export const marketService = {
|
|||||||
*/
|
*/
|
||||||
async getMinuteData(stockCode: string): Promise<MinuteData> {
|
async getMinuteData(stockCode: string): Promise<MinuteData> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${getBaseUrl()}/api/stock/${stockCode}/latest-minute`, {
|
const { data } = await axios.get<MinuteData>(`/api/stock/${stockCode}/latest-minute`);
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch minute data');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.data && Array.isArray(data.data)) {
|
if (data.data && Array.isArray(data.data)) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* CompanyInfo - 公司信息原子组件
|
||||||
|
* 显示公司基本信息(成立日期、注册资本、所在地、官网、简介)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { Box, Flex, HStack, Text, Link, Icon, Divider } from '@chakra-ui/react';
|
||||||
|
import { Calendar, Coins, MapPin, Globe } from 'lucide-react';
|
||||||
|
import { formatRegisteredCapital, formatDate } from '../../CompanyOverview/utils';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface CompanyBasicInfo {
|
||||||
|
establish_date?: string;
|
||||||
|
reg_capital?: number;
|
||||||
|
province?: string;
|
||||||
|
city?: string;
|
||||||
|
website?: string;
|
||||||
|
company_intro?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CompanyInfoProps {
|
||||||
|
basicInfo: CompanyBasicInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CompanyInfo: React.FC<CompanyInfoProps> = memo(({ basicInfo }) => {
|
||||||
|
const { labelColor, valueColor, borderColor } = STOCK_CARD_THEME;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Divider borderColor={borderColor} my={4} />
|
||||||
|
<Flex gap={8}>
|
||||||
|
{/* 左侧:公司关键属性 (flex=1) */}
|
||||||
|
<Box flex="1" minWidth="0">
|
||||||
|
<HStack spacing={4} flexWrap="wrap" fontSize="14px">
|
||||||
|
<HStack spacing={1}>
|
||||||
|
<Icon as={Calendar} color={labelColor} boxSize={4} />
|
||||||
|
<Text color={labelColor}>成立:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold">
|
||||||
|
{formatDate(basicInfo.establish_date)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack spacing={1}>
|
||||||
|
<Icon as={Coins} color={labelColor} boxSize={4} />
|
||||||
|
<Text color={labelColor}>注册资本:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold">
|
||||||
|
{formatRegisteredCapital(basicInfo.reg_capital)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack spacing={1}>
|
||||||
|
<Icon as={MapPin} color={labelColor} boxSize={4} />
|
||||||
|
<Text color={labelColor}>所在地:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold">
|
||||||
|
{basicInfo.province} {basicInfo.city}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack spacing={1}>
|
||||||
|
<Icon as={Globe} color={labelColor} boxSize={4} />
|
||||||
|
{basicInfo.website ? (
|
||||||
|
<Link
|
||||||
|
href={basicInfo.website}
|
||||||
|
isExternal
|
||||||
|
color={valueColor}
|
||||||
|
fontWeight="bold"
|
||||||
|
_hover={{ color: labelColor }}
|
||||||
|
>
|
||||||
|
访问官网
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Text color={valueColor}>暂无官网</Text>
|
||||||
|
)}
|
||||||
|
</HStack>
|
||||||
|
</HStack>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* 右侧:公司简介 (flex=2) */}
|
||||||
|
<Box flex="2" minWidth="0" borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
||||||
|
<Text fontSize="14px" color={labelColor} noOfLines={2}>
|
||||||
|
<Text as="span" fontWeight="bold" color={valueColor}>公司简介:</Text>
|
||||||
|
{basicInfo.company_intro || '暂无'}
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
CompanyInfo.displayName = 'CompanyInfo';
|
||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { SearchIcon } from '@chakra-ui/icons';
|
import { SearchIcon } from '@chakra-ui/icons';
|
||||||
import { BarChart2 } from 'lucide-react';
|
import { BarChart2 } from 'lucide-react';
|
||||||
|
import { useStockSearch, type Stock } from '../../../hooks/useStockSearch';
|
||||||
|
|
||||||
interface CompareStockInputProps {
|
interface CompareStockInputProps {
|
||||||
onCompare: (stockCode: string) => void;
|
onCompare: (stockCode: string) => void;
|
||||||
@@ -25,11 +26,6 @@ interface CompareStockInputProps {
|
|||||||
currentStockCode?: string;
|
currentStockCode?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Stock {
|
|
||||||
code: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RootState {
|
interface RootState {
|
||||||
stock: {
|
stock: {
|
||||||
allStocks: Stock[];
|
allStocks: Stock[];
|
||||||
@@ -43,7 +39,6 @@ const CompareStockInput: React.FC<CompareStockInputProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
const [showDropdown, setShowDropdown] = useState(false);
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
const [filteredStocks, setFilteredStocks] = useState<Stock[]>([]);
|
|
||||||
const [selectedStock, setSelectedStock] = useState<Stock | null>(null);
|
const [selectedStock, setSelectedStock] = useState<Stock | null>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
@@ -55,25 +50,16 @@ const CompareStockInput: React.FC<CompareStockInputProps> = ({
|
|||||||
const goldColor = '#F4D03F';
|
const goldColor = '#F4D03F';
|
||||||
const bgColor = '#1A202C';
|
const bgColor = '#1A202C';
|
||||||
|
|
||||||
// 模糊搜索过滤
|
// 使用共享的搜索 Hook(排除当前股票)
|
||||||
|
const filteredStocks = useStockSearch(allStocks, inputValue, {
|
||||||
|
excludeCode: currentStockCode,
|
||||||
|
limit: 8,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据搜索结果更新下拉显示状态
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputValue && inputValue.trim()) {
|
setShowDropdown(filteredStocks.length > 0 && !!inputValue?.trim());
|
||||||
const searchTerm = inputValue.trim().toLowerCase();
|
}, [filteredStocks, inputValue]);
|
||||||
const filtered = allStocks
|
|
||||||
.filter(
|
|
||||||
(stock) =>
|
|
||||||
stock.code !== currentStockCode && // 排除当前股票
|
|
||||||
(stock.code.toLowerCase().includes(searchTerm) ||
|
|
||||||
stock.name.includes(inputValue.trim()))
|
|
||||||
)
|
|
||||||
.slice(0, 8); // 限制显示8条
|
|
||||||
setFilteredStocks(filtered);
|
|
||||||
setShowDropdown(filtered.length > 0);
|
|
||||||
} else {
|
|
||||||
setFilteredStocks([]);
|
|
||||||
setShowDropdown(false);
|
|
||||||
}
|
|
||||||
}, [inputValue, allStocks, currentStockCode]);
|
|
||||||
|
|
||||||
// 点击外部关闭下拉
|
// 点击外部关闭下拉
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* KeyMetrics - 关键指标原子组件
|
||||||
|
* 显示 PE、EPS、PB、流通市值、52周波动
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { Box, VStack, HStack, Text } from '@chakra-ui/react';
|
||||||
|
import { formatPrice } from './formatters';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface KeyMetricsProps {
|
||||||
|
pe: number;
|
||||||
|
eps?: number;
|
||||||
|
pb: number;
|
||||||
|
marketCap: string;
|
||||||
|
week52Low: number;
|
||||||
|
week52High: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const KeyMetrics: React.FC<KeyMetricsProps> = memo(({
|
||||||
|
pe,
|
||||||
|
eps,
|
||||||
|
pb,
|
||||||
|
marketCap,
|
||||||
|
week52Low,
|
||||||
|
week52High,
|
||||||
|
}) => {
|
||||||
|
const { labelColor, valueColor, sectionTitleColor } = STOCK_CARD_THEME;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box flex="1">
|
||||||
|
<Text
|
||||||
|
fontSize="14px"
|
||||||
|
fontWeight="bold"
|
||||||
|
color={sectionTitleColor}
|
||||||
|
mb={3}
|
||||||
|
>
|
||||||
|
关键指标
|
||||||
|
</Text>
|
||||||
|
<VStack align="stretch" spacing={2} fontSize="14px">
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>市盈率(PE):</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{pe.toFixed(2)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>每股收益(EPS):</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{eps?.toFixed(3) || '-'}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>市净率(PB):</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{pb.toFixed(2)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>流通市值:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{marketCap}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>52周波动:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{formatPrice(week52Low)}-{formatPrice(week52High)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyMetrics.displayName = 'KeyMetrics';
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* MainForceInfo - 主力动态原子组件
|
||||||
|
* 显示主力净流入、机构持仓、买卖比例
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { Box, VStack, HStack, Text, Progress } from '@chakra-ui/react';
|
||||||
|
import { formatNetInflow } from './formatters';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface MainForceInfoProps {
|
||||||
|
mainNetInflow: number;
|
||||||
|
institutionHolding: number;
|
||||||
|
buyRatio: number;
|
||||||
|
sellRatio: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MainForceInfo: React.FC<MainForceInfoProps> = memo(({
|
||||||
|
mainNetInflow,
|
||||||
|
institutionHolding,
|
||||||
|
buyRatio,
|
||||||
|
sellRatio,
|
||||||
|
}) => {
|
||||||
|
const { labelColor, valueColor, sectionTitleColor, borderColor, upColor, downColor } = STOCK_CARD_THEME;
|
||||||
|
const inflowColor = mainNetInflow >= 0 ? upColor : downColor;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box flex="1" borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
||||||
|
<Text
|
||||||
|
fontSize="14px"
|
||||||
|
fontWeight="bold"
|
||||||
|
color={sectionTitleColor}
|
||||||
|
mb={3}
|
||||||
|
>
|
||||||
|
主力动态
|
||||||
|
</Text>
|
||||||
|
<VStack align="stretch" spacing={2} fontSize="14px">
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>主力净流入:</Text>
|
||||||
|
<Text color={inflowColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{formatNetInflow(mainNetInflow)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack justify="space-between">
|
||||||
|
<Text color={labelColor}>机构持仓:</Text>
|
||||||
|
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
||||||
|
{institutionHolding.toFixed(2)}%
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
{/* 买卖比例条 */}
|
||||||
|
<Box mt={1}>
|
||||||
|
<Progress
|
||||||
|
value={buyRatio}
|
||||||
|
size="sm"
|
||||||
|
sx={{
|
||||||
|
'& > div': { bg: upColor },
|
||||||
|
}}
|
||||||
|
bg={downColor}
|
||||||
|
borderRadius="full"
|
||||||
|
/>
|
||||||
|
<HStack justify="space-between" mt={1} fontSize="14px">
|
||||||
|
<Text color={upColor}>买入{buyRatio}%</Text>
|
||||||
|
<Text color={downColor}>卖出{sellRatio}%</Text>
|
||||||
|
</HStack>
|
||||||
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
MainForceInfo.displayName = 'MainForceInfo';
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* PriceDisplay - 价格显示原子组件
|
||||||
|
* 显示当前价格和涨跌幅 Badge
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { HStack, Text, Badge } from '@chakra-ui/react';
|
||||||
|
import { formatPrice, formatChangePercent } from './formatters';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface PriceDisplayProps {
|
||||||
|
currentPrice: number;
|
||||||
|
changePercent: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PriceDisplay: React.FC<PriceDisplayProps> = memo(({
|
||||||
|
currentPrice,
|
||||||
|
changePercent,
|
||||||
|
}) => {
|
||||||
|
const { upColor, downColor } = STOCK_CARD_THEME;
|
||||||
|
const priceColor = changePercent >= 0 ? upColor : downColor;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HStack align="baseline" spacing={3} mb={3}>
|
||||||
|
<Text fontSize="48px" fontWeight="bold" color={priceColor}>
|
||||||
|
{formatPrice(currentPrice)}
|
||||||
|
</Text>
|
||||||
|
<Badge
|
||||||
|
bg={changePercent >= 0 ? upColor : downColor}
|
||||||
|
color="#FFFFFF"
|
||||||
|
fontSize="20px"
|
||||||
|
fontWeight="bold"
|
||||||
|
px={3}
|
||||||
|
py={1}
|
||||||
|
borderRadius="md"
|
||||||
|
>
|
||||||
|
{formatChangePercent(changePercent)}
|
||||||
|
</Badge>
|
||||||
|
</HStack>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
PriceDisplay.displayName = 'PriceDisplay';
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* SecondaryQuote - 次要行情原子组件
|
||||||
|
* 显示今开、昨收、最高、最低
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { HStack, Text } from '@chakra-ui/react';
|
||||||
|
import { formatPrice } from './formatters';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface SecondaryQuoteProps {
|
||||||
|
todayOpen: number;
|
||||||
|
yesterdayClose: number;
|
||||||
|
todayHigh: number;
|
||||||
|
todayLow: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SecondaryQuote: React.FC<SecondaryQuoteProps> = memo(({
|
||||||
|
todayOpen,
|
||||||
|
yesterdayClose,
|
||||||
|
todayHigh,
|
||||||
|
todayLow,
|
||||||
|
}) => {
|
||||||
|
const { labelColor, valueColor, borderColor, upColor, downColor } = STOCK_CARD_THEME;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HStack spacing={4} fontSize="14px" flexWrap="wrap">
|
||||||
|
<Text color={labelColor}>
|
||||||
|
今开:
|
||||||
|
<Text as="span" color={valueColor} fontWeight="bold">
|
||||||
|
{formatPrice(todayOpen)}
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
|
<Text color={borderColor}>|</Text>
|
||||||
|
<Text color={labelColor}>
|
||||||
|
昨收:
|
||||||
|
<Text as="span" color={valueColor} fontWeight="bold">
|
||||||
|
{formatPrice(yesterdayClose)}
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
|
<Text color={borderColor}>|</Text>
|
||||||
|
<Text color={labelColor}>
|
||||||
|
最高:
|
||||||
|
<Text as="span" color={upColor} fontWeight="bold">
|
||||||
|
{formatPrice(todayHigh)}
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
|
<Text color={borderColor}>|</Text>
|
||||||
|
<Text color={labelColor}>
|
||||||
|
最低:
|
||||||
|
<Text as="span" color={downColor} fontWeight="bold">
|
||||||
|
{formatPrice(todayLow)}
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
SecondaryQuote.displayName = 'SecondaryQuote';
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
* StockHeader - 股票头部原子组件
|
||||||
|
* 显示股票名称、代码、行业标签、指数标签、操作按钮
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { memo } from 'react';
|
||||||
|
import { Flex, HStack, Text, Badge, IconButton, Tooltip } from '@chakra-ui/react';
|
||||||
|
import { Share2 } from 'lucide-react';
|
||||||
|
import FavoriteButton from '@components/FavoriteButton';
|
||||||
|
import CompareStockInput from './CompareStockInput';
|
||||||
|
import { STOCK_CARD_THEME } from './theme';
|
||||||
|
|
||||||
|
export interface StockHeaderProps {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
industryL1?: string;
|
||||||
|
industry?: string;
|
||||||
|
indexTags?: string[];
|
||||||
|
updateTime?: string;
|
||||||
|
// 关注相关
|
||||||
|
isInWatchlist?: boolean;
|
||||||
|
isWatchlistLoading?: boolean;
|
||||||
|
onWatchlistToggle?: () => void;
|
||||||
|
// 分享
|
||||||
|
onShare?: () => void;
|
||||||
|
// 对比相关
|
||||||
|
isCompareLoading?: boolean;
|
||||||
|
onCompare?: (stockCode: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StockHeader: React.FC<StockHeaderProps> = memo(({
|
||||||
|
name,
|
||||||
|
code,
|
||||||
|
industryL1,
|
||||||
|
industry,
|
||||||
|
indexTags,
|
||||||
|
updateTime,
|
||||||
|
isInWatchlist = false,
|
||||||
|
isWatchlistLoading = false,
|
||||||
|
onWatchlistToggle,
|
||||||
|
onShare,
|
||||||
|
isCompareLoading = false,
|
||||||
|
onCompare,
|
||||||
|
}) => {
|
||||||
|
const { labelColor, valueColor, borderColor } = STOCK_CARD_THEME;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex justify="space-between" align="center" mb={4}>
|
||||||
|
{/* 左侧:股票名称 + 行业标签 + 指数标签 */}
|
||||||
|
<HStack spacing={3} align="center">
|
||||||
|
{/* 股票名称 - 突出显示 */}
|
||||||
|
<Text fontSize="26px" fontWeight="800" color={valueColor}>
|
||||||
|
{name}
|
||||||
|
</Text>
|
||||||
|
<Text fontSize="18px" fontWeight="normal" color={labelColor}>
|
||||||
|
({code})
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
{/* 行业标签 */}
|
||||||
|
{(industryL1 || industry) && (
|
||||||
|
<Badge
|
||||||
|
bg="transparent"
|
||||||
|
color={labelColor}
|
||||||
|
fontSize="14px"
|
||||||
|
fontWeight="medium"
|
||||||
|
border="1px solid"
|
||||||
|
borderColor={borderColor}
|
||||||
|
px={2}
|
||||||
|
py={0.5}
|
||||||
|
borderRadius="md"
|
||||||
|
>
|
||||||
|
{industryL1 && industry
|
||||||
|
? `${industryL1} · ${industry}`
|
||||||
|
: industry || industryL1}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 指数标签 */}
|
||||||
|
{indexTags && indexTags.length > 0 && (
|
||||||
|
<Text fontSize="14px" color={labelColor}>
|
||||||
|
{indexTags.join('、')}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</HStack>
|
||||||
|
|
||||||
|
{/* 右侧:对比 + 关注 + 分享 + 时间 */}
|
||||||
|
<HStack spacing={3}>
|
||||||
|
{/* 股票对比输入 */}
|
||||||
|
<CompareStockInput
|
||||||
|
onCompare={onCompare || (() => {})}
|
||||||
|
isLoading={isCompareLoading}
|
||||||
|
currentStockCode={code}
|
||||||
|
/>
|
||||||
|
<FavoriteButton
|
||||||
|
isFavorite={isInWatchlist}
|
||||||
|
isLoading={isWatchlistLoading}
|
||||||
|
onClick={onWatchlistToggle || (() => {})}
|
||||||
|
colorScheme="gold"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
<Tooltip label="分享" placement="top">
|
||||||
|
<IconButton
|
||||||
|
aria-label="分享"
|
||||||
|
icon={<Share2 size={18} />}
|
||||||
|
variant="ghost"
|
||||||
|
color={labelColor}
|
||||||
|
size="sm"
|
||||||
|
onClick={onShare}
|
||||||
|
_hover={{ bg: 'whiteAlpha.100' }}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Text fontSize="14px" color={labelColor}>
|
||||||
|
{updateTime?.split(' ')[1] || '--:--'}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
StockHeader.displayName = 'StockHeader';
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* StockQuoteCard 格式化工具函数
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化价格显示
|
||||||
|
*/
|
||||||
|
export const formatPrice = (price: number): string => {
|
||||||
|
return price.toLocaleString('zh-CN', {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化涨跌幅显示
|
||||||
|
*/
|
||||||
|
export const formatChangePercent = (percent: number): string => {
|
||||||
|
const sign = percent >= 0 ? '+' : '';
|
||||||
|
return `${sign}${percent.toFixed(2)}%`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化主力净流入显示
|
||||||
|
*/
|
||||||
|
export const formatNetInflow = (value: number): string => {
|
||||||
|
const sign = value >= 0 ? '+' : '';
|
||||||
|
return `${sign}${value.toFixed(2)}亿`;
|
||||||
|
};
|
||||||
@@ -1,6 +1,27 @@
|
|||||||
/**
|
/**
|
||||||
* StockQuoteCard 子组件导出
|
* StockQuoteCard 组件统一导出
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 原子组件
|
||||||
|
export { PriceDisplay } from './PriceDisplay';
|
||||||
|
export { SecondaryQuote } from './SecondaryQuote';
|
||||||
|
export { KeyMetrics } from './KeyMetrics';
|
||||||
|
export { MainForceInfo } from './MainForceInfo';
|
||||||
|
export { CompanyInfo } from './CompanyInfo';
|
||||||
|
export { StockHeader } from './StockHeader';
|
||||||
|
|
||||||
|
// 复合组件
|
||||||
export { default as CompareStockInput } from './CompareStockInput';
|
export { default as CompareStockInput } from './CompareStockInput';
|
||||||
export { default as StockCompareModal } from './StockCompareModal';
|
export { default as StockCompareModal } from './StockCompareModal';
|
||||||
|
|
||||||
|
// 工具和主题
|
||||||
|
export { STOCK_CARD_THEME } from './theme';
|
||||||
|
export * from './formatters';
|
||||||
|
|
||||||
|
// 类型导出
|
||||||
|
export type { PriceDisplayProps } from './PriceDisplay';
|
||||||
|
export type { SecondaryQuoteProps } from './SecondaryQuote';
|
||||||
|
export type { KeyMetricsProps } from './KeyMetrics';
|
||||||
|
export type { MainForceInfoProps } from './MainForceInfo';
|
||||||
|
export type { CompanyInfoProps, CompanyBasicInfo } from './CompanyInfo';
|
||||||
|
export type { StockHeaderProps } from './StockHeader';
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* StockQuoteCard 黑金主题配置
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const STOCK_CARD_THEME = {
|
||||||
|
// 背景和边框
|
||||||
|
cardBg: '#1A202C',
|
||||||
|
borderColor: '#C9A961',
|
||||||
|
|
||||||
|
// 文字颜色
|
||||||
|
labelColor: '#C9A961',
|
||||||
|
valueColor: '#F4D03F',
|
||||||
|
sectionTitleColor: '#F4D03F',
|
||||||
|
|
||||||
|
// 涨跌颜色(红涨绿跌)
|
||||||
|
upColor: '#F44336',
|
||||||
|
downColor: '#4CAF50',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type StockCardTheme = typeof STOCK_CARD_THEME;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* StockQuoteCard Hooks 导出索引
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { useStockQuoteData } from './useStockQuoteData';
|
||||||
|
export { useStockCompare } from './useStockCompare';
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* useStockCompare - 股票对比逻辑 Hook
|
||||||
|
*
|
||||||
|
* 管理股票对比所需的数据获取和状态
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { useToast } from '@chakra-ui/react';
|
||||||
|
import { financialService } from '@services/financialService';
|
||||||
|
import { logger } from '@utils/logger';
|
||||||
|
import type { StockInfo } from '../../FinancialPanorama/types';
|
||||||
|
|
||||||
|
interface UseStockCompareResult {
|
||||||
|
currentStockInfo: StockInfo | null;
|
||||||
|
compareStockInfo: StockInfo | null;
|
||||||
|
isCompareLoading: boolean;
|
||||||
|
handleCompare: (compareCode: string) => Promise<void>;
|
||||||
|
clearCompare: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票对比 Hook
|
||||||
|
*
|
||||||
|
* @param stockCode - 当前股票代码
|
||||||
|
*/
|
||||||
|
export const useStockCompare = (stockCode?: string): UseStockCompareResult => {
|
||||||
|
const toast = useToast();
|
||||||
|
const [currentStockInfo, setCurrentStockInfo] = useState<StockInfo | null>(null);
|
||||||
|
const [compareStockInfo, setCompareStockInfo] = useState<StockInfo | null>(null);
|
||||||
|
const [isCompareLoading, setIsCompareLoading] = useState(false);
|
||||||
|
|
||||||
|
// 加载当前股票财务信息(用于对比)
|
||||||
|
useEffect(() => {
|
||||||
|
const loadCurrentStockInfo = async () => {
|
||||||
|
if (!stockCode) {
|
||||||
|
setCurrentStockInfo(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await financialService.getStockInfo(stockCode);
|
||||||
|
setCurrentStockInfo(res.data);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('useStockCompare', 'loadCurrentStockInfo', error, { stockCode });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadCurrentStockInfo();
|
||||||
|
// 股票代码变化时清除对比数据
|
||||||
|
setCompareStockInfo(null);
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
|
// 处理股票对比
|
||||||
|
const handleCompare = useCallback(async (compareCode: string) => {
|
||||||
|
if (!compareCode) return;
|
||||||
|
|
||||||
|
logger.debug('useStockCompare', '开始加载对比数据', { stockCode, compareCode });
|
||||||
|
setIsCompareLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await financialService.getStockInfo(compareCode);
|
||||||
|
setCompareStockInfo(res.data);
|
||||||
|
logger.info('useStockCompare', '对比数据加载成功', { stockCode, compareCode });
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('useStockCompare', 'handleCompare', error, { stockCode, compareCode });
|
||||||
|
toast({
|
||||||
|
title: '加载对比数据失败',
|
||||||
|
description: '请检查股票代码是否正确',
|
||||||
|
status: 'error',
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsCompareLoading(false);
|
||||||
|
}
|
||||||
|
}, [stockCode, toast]);
|
||||||
|
|
||||||
|
// 清除对比数据
|
||||||
|
const clearCompare = useCallback(() => {
|
||||||
|
setCompareStockInfo(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
currentStockInfo,
|
||||||
|
compareStockInfo,
|
||||||
|
isCompareLoading,
|
||||||
|
handleCompare,
|
||||||
|
clearCompare,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useStockCompare;
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
/**
|
||||||
|
* useStockQuoteData - 股票行情数据获取 Hook
|
||||||
|
*
|
||||||
|
* 合并获取行情数据和基本信息,供 StockQuoteCard 内部使用
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { stockService } from '@services/eventService';
|
||||||
|
import { logger } from '@utils/logger';
|
||||||
|
import axios from '@utils/axiosConfig';
|
||||||
|
import type { StockQuoteCardData } from '../types';
|
||||||
|
import type { BasicInfo } from '../../CompanyOverview/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 API 响应数据转换为 StockQuoteCard 所需格式
|
||||||
|
*/
|
||||||
|
const transformQuoteData = (apiData: any, stockCode: string): StockQuoteCardData | null => {
|
||||||
|
if (!apiData) return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
// 基础信息
|
||||||
|
name: apiData.name || apiData.stock_name || '未知',
|
||||||
|
code: apiData.code || apiData.stock_code || stockCode,
|
||||||
|
indexTags: apiData.index_tags || apiData.indexTags || [],
|
||||||
|
industry: apiData.industry || apiData.sw_industry_l2 || '',
|
||||||
|
industryL1: apiData.industry_l1 || apiData.sw_industry_l1 || '',
|
||||||
|
|
||||||
|
// 价格信息
|
||||||
|
currentPrice: apiData.current_price || apiData.currentPrice || apiData.close || 0,
|
||||||
|
changePercent: apiData.change_percent || apiData.changePercent || apiData.pct_chg || 0,
|
||||||
|
todayOpen: apiData.today_open || apiData.todayOpen || apiData.open || 0,
|
||||||
|
yesterdayClose: apiData.yesterday_close || apiData.yesterdayClose || apiData.pre_close || 0,
|
||||||
|
todayHigh: apiData.today_high || apiData.todayHigh || apiData.high || 0,
|
||||||
|
todayLow: apiData.today_low || apiData.todayLow || apiData.low || 0,
|
||||||
|
|
||||||
|
// 关键指标
|
||||||
|
pe: apiData.pe || apiData.pe_ttm || 0,
|
||||||
|
eps: apiData.eps || apiData.basic_eps || undefined,
|
||||||
|
pb: apiData.pb || apiData.pb_mrq || 0,
|
||||||
|
marketCap: apiData.market_cap || apiData.marketCap || apiData.circ_mv || '0',
|
||||||
|
week52Low: apiData.week52_low || apiData.week52Low || 0,
|
||||||
|
week52High: apiData.week52_high || apiData.week52High || 0,
|
||||||
|
|
||||||
|
// 主力动态
|
||||||
|
mainNetInflow: apiData.main_net_inflow || apiData.mainNetInflow || 0,
|
||||||
|
institutionHolding: apiData.institution_holding || apiData.institutionHolding || 0,
|
||||||
|
buyRatio: apiData.buy_ratio || apiData.buyRatio || 50,
|
||||||
|
sellRatio: apiData.sell_ratio || apiData.sellRatio || 50,
|
||||||
|
|
||||||
|
// 更新时间
|
||||||
|
updateTime: apiData.update_time || apiData.updateTime || new Date().toLocaleString(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
interface UseStockQuoteDataResult {
|
||||||
|
quoteData: StockQuoteCardData | null;
|
||||||
|
basicInfo: BasicInfo | null;
|
||||||
|
isLoading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
refetch: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票行情数据获取 Hook
|
||||||
|
* 合并获取行情数据和基本信息
|
||||||
|
*
|
||||||
|
* @param stockCode - 股票代码
|
||||||
|
*/
|
||||||
|
export const useStockQuoteData = (stockCode?: string): UseStockQuoteDataResult => {
|
||||||
|
const [quoteData, setQuoteData] = useState<StockQuoteCardData | null>(null);
|
||||||
|
const [basicInfo, setBasicInfo] = useState<BasicInfo | null>(null);
|
||||||
|
const [quoteLoading, setQuoteLoading] = useState(false);
|
||||||
|
const [basicLoading, setBasicLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// 用于手动刷新的 ref
|
||||||
|
const refetchRef = useCallback(async () => {
|
||||||
|
if (!stockCode) return;
|
||||||
|
|
||||||
|
// 获取行情数据
|
||||||
|
setQuoteLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
logger.debug('useStockQuoteData', '获取股票行情', { stockCode });
|
||||||
|
const quotes = await stockService.getQuotes([stockCode]);
|
||||||
|
const quoteResult = quotes?.[stockCode] || quotes;
|
||||||
|
const transformedData = transformQuoteData(quoteResult, stockCode);
|
||||||
|
logger.debug('useStockQuoteData', '行情数据转换完成', { stockCode, hasData: !!transformedData });
|
||||||
|
setQuoteData(transformedData);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('useStockQuoteData', '获取行情失败', err);
|
||||||
|
setError('获取行情数据失败');
|
||||||
|
setQuoteData(null);
|
||||||
|
} finally {
|
||||||
|
setQuoteLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取基本信息
|
||||||
|
setBasicLoading(true);
|
||||||
|
try {
|
||||||
|
const { data: result } = await axios.get(`/api/stock/${stockCode}/basic-info`);
|
||||||
|
if (result.success) {
|
||||||
|
setBasicInfo(result.data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('useStockQuoteData', '获取基本信息失败', err);
|
||||||
|
} finally {
|
||||||
|
setBasicLoading(false);
|
||||||
|
}
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
|
// stockCode 变化时重新获取数据(带取消支持)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!stockCode) {
|
||||||
|
setQuoteData(null);
|
||||||
|
setBasicInfo(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
let isCancelled = false;
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
// 获取行情数据
|
||||||
|
setQuoteLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
logger.debug('useStockQuoteData', '获取股票行情', { stockCode });
|
||||||
|
const quotes = await stockService.getQuotes([stockCode]);
|
||||||
|
if (isCancelled) return;
|
||||||
|
const quoteResult = quotes?.[stockCode] || quotes;
|
||||||
|
const transformedData = transformQuoteData(quoteResult, stockCode);
|
||||||
|
logger.debug('useStockQuoteData', '行情数据转换完成', { stockCode, hasData: !!transformedData });
|
||||||
|
setQuoteData(transformedData);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (isCancelled || err.name === 'CanceledError') return;
|
||||||
|
logger.error('useStockQuoteData', '获取行情失败', err);
|
||||||
|
setError('获取行情数据失败');
|
||||||
|
setQuoteData(null);
|
||||||
|
} finally {
|
||||||
|
if (!isCancelled) setQuoteLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取基本信息
|
||||||
|
setBasicLoading(true);
|
||||||
|
try {
|
||||||
|
const { data: result } = await axios.get(`/api/stock/${stockCode}/basic-info`, {
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
if (isCancelled) return;
|
||||||
|
if (result.success) {
|
||||||
|
setBasicInfo(result.data);
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (isCancelled || err.name === 'CanceledError') return;
|
||||||
|
logger.error('useStockQuoteData', '获取基本信息失败', err);
|
||||||
|
} finally {
|
||||||
|
if (!isCancelled) setBasicLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchData();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isCancelled = true;
|
||||||
|
controller.abort();
|
||||||
|
};
|
||||||
|
}, [stockCode]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
quoteData,
|
||||||
|
basicInfo,
|
||||||
|
isLoading: quoteLoading || basicLoading,
|
||||||
|
error,
|
||||||
|
refetch: refetchRef,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useStockQuoteData;
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
* StockQuoteCard - 股票行情卡片组件
|
* StockQuoteCard - 股票行情卡片组件
|
||||||
*
|
*
|
||||||
* 展示股票的实时行情、关键指标和主力动态
|
* 展示股票的实时行情、关键指标和主力动态
|
||||||
|
* 采用原子组件拆分,提高可维护性和复用性
|
||||||
|
*
|
||||||
|
* 优化:数据获取已下沉到组件内部,Props 从 11 个精简为 4 个
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@@ -10,100 +13,61 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
Flex,
|
Flex,
|
||||||
HStack,
|
|
||||||
VStack,
|
VStack,
|
||||||
Text,
|
|
||||||
Badge,
|
|
||||||
Progress,
|
|
||||||
Skeleton,
|
Skeleton,
|
||||||
IconButton,
|
|
||||||
Tooltip,
|
|
||||||
Divider,
|
|
||||||
Link,
|
|
||||||
Icon,
|
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { Share2, Calendar, Coins, MapPin, Globe } from 'lucide-react';
|
|
||||||
import { formatRegisteredCapital, formatDate } from '../CompanyOverview/utils';
|
|
||||||
|
|
||||||
import FavoriteButton from '@components/FavoriteButton';
|
import {
|
||||||
import { CompareStockInput, StockCompareModal } from './components';
|
StockHeader,
|
||||||
|
PriceDisplay,
|
||||||
|
SecondaryQuote,
|
||||||
|
KeyMetrics,
|
||||||
|
MainForceInfo,
|
||||||
|
CompanyInfo,
|
||||||
|
StockCompareModal,
|
||||||
|
STOCK_CARD_THEME,
|
||||||
|
} from './components';
|
||||||
|
import { useStockQuoteData, useStockCompare } from './hooks';
|
||||||
import type { StockQuoteCardProps } from './types';
|
import type { StockQuoteCardProps } from './types';
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化价格显示
|
|
||||||
*/
|
|
||||||
const formatPrice = (price: number): string => {
|
|
||||||
return price.toLocaleString('zh-CN', {
|
|
||||||
minimumFractionDigits: 2,
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化涨跌幅显示
|
|
||||||
*/
|
|
||||||
const formatChangePercent = (percent: number): string => {
|
|
||||||
const sign = percent >= 0 ? '+' : '';
|
|
||||||
return `${sign}${percent.toFixed(2)}%`;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化主力净流入显示
|
|
||||||
*/
|
|
||||||
const formatNetInflow = (value: number): string => {
|
|
||||||
const sign = value >= 0 ? '+' : '';
|
|
||||||
return `${sign}${value.toFixed(2)}亿`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const StockQuoteCard: React.FC<StockQuoteCardProps> = ({
|
const StockQuoteCard: React.FC<StockQuoteCardProps> = ({
|
||||||
data,
|
stockCode,
|
||||||
isLoading = false,
|
|
||||||
isInWatchlist = false,
|
isInWatchlist = false,
|
||||||
isWatchlistLoading = false,
|
isWatchlistLoading = false,
|
||||||
onWatchlistToggle,
|
onWatchlistToggle,
|
||||||
onShare,
|
|
||||||
basicInfo,
|
|
||||||
// 对比相关
|
|
||||||
currentStockInfo,
|
|
||||||
compareStockInfo,
|
|
||||||
isCompareLoading = false,
|
|
||||||
onCompare,
|
|
||||||
onCloseCompare,
|
|
||||||
}) => {
|
}) => {
|
||||||
|
// 内部获取行情数据和基本信息
|
||||||
|
const { quoteData, basicInfo, isLoading } = useStockQuoteData(stockCode);
|
||||||
|
|
||||||
|
// 内部管理股票对比逻辑
|
||||||
|
const {
|
||||||
|
currentStockInfo,
|
||||||
|
compareStockInfo,
|
||||||
|
isCompareLoading,
|
||||||
|
handleCompare: triggerCompare,
|
||||||
|
clearCompare,
|
||||||
|
} = useStockCompare(stockCode);
|
||||||
|
|
||||||
// 对比弹窗控制
|
// 对比弹窗控制
|
||||||
const { isOpen: isCompareModalOpen, onOpen: openCompareModal, onClose: closeCompareModal } = useDisclosure();
|
const { isOpen: isCompareModalOpen, onOpen: openCompareModal, onClose: closeCompareModal } = useDisclosure();
|
||||||
|
|
||||||
// 处理分享点击
|
|
||||||
const handleShare = () => {
|
|
||||||
onShare?.();
|
|
||||||
};
|
|
||||||
|
|
||||||
// 处理对比按钮点击
|
// 处理对比按钮点击
|
||||||
const handleCompare = (stockCode: string) => {
|
const handleCompare = (compareCode: string) => {
|
||||||
onCompare?.(stockCode);
|
triggerCompare(compareCode);
|
||||||
openCompareModal();
|
openCompareModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理关闭对比弹窗
|
// 处理关闭对比弹窗
|
||||||
const handleCloseCompare = () => {
|
const handleCloseCompare = () => {
|
||||||
closeCompareModal();
|
closeCompareModal();
|
||||||
onCloseCompare?.();
|
clearCompare();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 黑金主题颜色配置
|
const { cardBg, borderColor } = STOCK_CARD_THEME;
|
||||||
const cardBg = '#1A202C';
|
|
||||||
const borderColor = '#C9A961';
|
|
||||||
const labelColor = '#C9A961';
|
|
||||||
const valueColor = '#F4D03F';
|
|
||||||
const sectionTitleColor = '#F4D03F';
|
|
||||||
|
|
||||||
// 涨跌颜色(红涨绿跌)
|
|
||||||
const upColor = '#F44336'; // 涨 - 红色
|
|
||||||
const downColor = '#4CAF50'; // 跌 - 绿色
|
|
||||||
|
|
||||||
// 加载中或无数据时显示骨架屏
|
// 加载中或无数据时显示骨架屏
|
||||||
if (isLoading || !data) {
|
if (isLoading || !quoteData) {
|
||||||
return (
|
return (
|
||||||
<Card bg={cardBg} shadow="sm" borderWidth="1px" borderColor={borderColor}>
|
<Card bg={cardBg} shadow="sm" borderWidth="1px" borderColor={borderColor}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
@@ -117,88 +81,29 @@ const StockQuoteCard: React.FC<StockQuoteCardProps> = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const priceColor = data.changePercent >= 0 ? upColor : downColor;
|
|
||||||
const inflowColor = data.mainNetInflow >= 0 ? upColor : downColor;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card bg={cardBg} shadow="sm" borderWidth="1px" borderColor={borderColor}>
|
<Card bg={cardBg} shadow="sm" borderWidth="1px" borderColor={borderColor}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
{/* 顶部:股票名称 + 关注/分享按钮 + 更新时间 */}
|
{/* 顶部:股票名称 + 关注/分享按钮 + 更新时间 */}
|
||||||
<Flex justify="space-between" align="center" mb={4}>
|
<StockHeader
|
||||||
{/* 左侧:股票名称 + 行业标签 + 指数标签 */}
|
name={quoteData.name}
|
||||||
<HStack spacing={3} align="center">
|
code={quoteData.code}
|
||||||
{/* 股票名称 - 突出显示 */}
|
industryL1={quoteData.industryL1}
|
||||||
<Text fontSize="26px" fontWeight="800" color={valueColor}>
|
industry={quoteData.industry}
|
||||||
{data.name}
|
indexTags={quoteData.indexTags}
|
||||||
</Text>
|
updateTime={quoteData.updateTime}
|
||||||
<Text fontSize="18px" fontWeight="normal" color={labelColor}>
|
isInWatchlist={isInWatchlist}
|
||||||
({data.code})
|
isWatchlistLoading={isWatchlistLoading}
|
||||||
</Text>
|
onWatchlistToggle={onWatchlistToggle}
|
||||||
|
isCompareLoading={isCompareLoading}
|
||||||
{/* 行业标签 */}
|
onCompare={handleCompare}
|
||||||
{(data.industryL1 || data.industry) && (
|
/>
|
||||||
<Badge
|
|
||||||
bg="transparent"
|
|
||||||
color={labelColor}
|
|
||||||
fontSize="14px"
|
|
||||||
fontWeight="medium"
|
|
||||||
border="1px solid"
|
|
||||||
borderColor={borderColor}
|
|
||||||
px={2}
|
|
||||||
py={0.5}
|
|
||||||
borderRadius="md"
|
|
||||||
>
|
|
||||||
{data.industryL1 && data.industry
|
|
||||||
? `${data.industryL1} · ${data.industry}`
|
|
||||||
: data.industry || data.industryL1}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 指数标签 */}
|
|
||||||
{data.indexTags?.length > 0 && (
|
|
||||||
<Text fontSize="14px" color={labelColor}>
|
|
||||||
{data.indexTags.join('、')}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</HStack>
|
|
||||||
|
|
||||||
{/* 右侧:对比 + 关注 + 分享 + 时间 */}
|
|
||||||
<HStack spacing={3}>
|
|
||||||
{/* 股票对比输入 */}
|
|
||||||
<CompareStockInput
|
|
||||||
onCompare={handleCompare}
|
|
||||||
isLoading={isCompareLoading}
|
|
||||||
currentStockCode={data.code}
|
|
||||||
/>
|
|
||||||
<FavoriteButton
|
|
||||||
isFavorite={isInWatchlist}
|
|
||||||
isLoading={isWatchlistLoading}
|
|
||||||
onClick={onWatchlistToggle || (() => {})}
|
|
||||||
colorScheme="gold"
|
|
||||||
size="sm"
|
|
||||||
/>
|
|
||||||
<Tooltip label="分享" placement="top">
|
|
||||||
<IconButton
|
|
||||||
aria-label="分享"
|
|
||||||
icon={<Share2 size={18} />}
|
|
||||||
variant="ghost"
|
|
||||||
color={labelColor}
|
|
||||||
size="sm"
|
|
||||||
onClick={handleShare}
|
|
||||||
_hover={{ bg: 'whiteAlpha.100' }}
|
|
||||||
/>
|
|
||||||
</Tooltip>
|
|
||||||
<Text fontSize="14px" color={labelColor}>
|
|
||||||
{data.updateTime?.split(' ')[1] || '--:--'}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
</Flex>
|
|
||||||
|
|
||||||
{/* 股票对比弹窗 */}
|
{/* 股票对比弹窗 */}
|
||||||
<StockCompareModal
|
<StockCompareModal
|
||||||
isOpen={isCompareModalOpen}
|
isOpen={isCompareModalOpen}
|
||||||
onClose={handleCloseCompare}
|
onClose={handleCloseCompare}
|
||||||
currentStock={data.code}
|
currentStock={quoteData.code}
|
||||||
currentStockInfo={currentStockInfo || null}
|
currentStockInfo={currentStockInfo || null}
|
||||||
compareStock={compareStockInfo?.stock_code || ''}
|
compareStock={compareStockInfo?.stock_code || ''}
|
||||||
compareStockInfo={compareStockInfo || null}
|
compareStockInfo={compareStockInfo || null}
|
||||||
@@ -209,196 +114,39 @@ const StockQuoteCard: React.FC<StockQuoteCardProps> = ({
|
|||||||
<Flex gap={8}>
|
<Flex gap={8}>
|
||||||
{/* 左栏:价格信息 (flex=1) */}
|
{/* 左栏:价格信息 (flex=1) */}
|
||||||
<Box flex="1" minWidth="0">
|
<Box flex="1" minWidth="0">
|
||||||
<HStack align="baseline" spacing={3} mb={3}>
|
<PriceDisplay
|
||||||
<Text fontSize="48px" fontWeight="bold" color={priceColor}>
|
currentPrice={quoteData.currentPrice}
|
||||||
{formatPrice(data.currentPrice)}
|
changePercent={quoteData.changePercent}
|
||||||
</Text>
|
/>
|
||||||
<Badge
|
<SecondaryQuote
|
||||||
bg={data.changePercent >= 0 ? upColor : downColor}
|
todayOpen={quoteData.todayOpen}
|
||||||
color="#FFFFFF"
|
yesterdayClose={quoteData.yesterdayClose}
|
||||||
fontSize="20px"
|
todayHigh={quoteData.todayHigh}
|
||||||
fontWeight="bold"
|
todayLow={quoteData.todayLow}
|
||||||
px={3}
|
/>
|
||||||
py={1}
|
|
||||||
borderRadius="md"
|
|
||||||
>
|
|
||||||
{formatChangePercent(data.changePercent)}
|
|
||||||
</Badge>
|
|
||||||
</HStack>
|
|
||||||
{/* 次要行情:今开 | 昨收 | 最高 | 最低 */}
|
|
||||||
<HStack spacing={4} fontSize="14px" flexWrap="wrap">
|
|
||||||
<Text color={labelColor}>
|
|
||||||
今开:
|
|
||||||
<Text as="span" color={valueColor} fontWeight="bold">
|
|
||||||
{formatPrice(data.todayOpen)}
|
|
||||||
</Text>
|
|
||||||
</Text>
|
|
||||||
<Text color={borderColor}>|</Text>
|
|
||||||
<Text color={labelColor}>
|
|
||||||
昨收:
|
|
||||||
<Text as="span" color={valueColor} fontWeight="bold">
|
|
||||||
{formatPrice(data.yesterdayClose)}
|
|
||||||
</Text>
|
|
||||||
</Text>
|
|
||||||
<Text color={borderColor}>|</Text>
|
|
||||||
<Text color={labelColor}>
|
|
||||||
最高:
|
|
||||||
<Text as="span" color={upColor} fontWeight="bold">
|
|
||||||
{formatPrice(data.todayHigh)}
|
|
||||||
</Text>
|
|
||||||
</Text>
|
|
||||||
<Text color={borderColor}>|</Text>
|
|
||||||
<Text color={labelColor}>
|
|
||||||
最低:
|
|
||||||
<Text as="span" color={downColor} fontWeight="bold">
|
|
||||||
{formatPrice(data.todayLow)}
|
|
||||||
</Text>
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{/* 右栏:关键指标 + 主力动态 (flex=2) */}
|
{/* 右栏:关键指标 + 主力动态 (flex=2) */}
|
||||||
<Flex flex="2" minWidth="0" gap={8} borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
<Flex flex="2" minWidth="0" gap={8} borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
||||||
{/* 关键指标 */}
|
<KeyMetrics
|
||||||
<Box flex="1">
|
pe={quoteData.pe}
|
||||||
<Text
|
eps={quoteData.eps}
|
||||||
fontSize="14px"
|
pb={quoteData.pb}
|
||||||
fontWeight="bold"
|
marketCap={quoteData.marketCap}
|
||||||
color={sectionTitleColor}
|
week52Low={quoteData.week52Low}
|
||||||
mb={3}
|
week52High={quoteData.week52High}
|
||||||
>
|
/>
|
||||||
关键指标
|
<MainForceInfo
|
||||||
</Text>
|
mainNetInflow={quoteData.mainNetInflow}
|
||||||
<VStack align="stretch" spacing={2} fontSize="14px">
|
institutionHolding={quoteData.institutionHolding}
|
||||||
<HStack justify="space-between">
|
buyRatio={quoteData.buyRatio}
|
||||||
<Text color={labelColor}>市盈率(PE):</Text>
|
sellRatio={quoteData.sellRatio}
|
||||||
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
/>
|
||||||
{data.pe.toFixed(2)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack justify="space-between">
|
|
||||||
<Text color={labelColor}>市净率(PB):</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
|
||||||
{data.pb.toFixed(2)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack justify="space-between">
|
|
||||||
<Text color={labelColor}>流通市值:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
|
||||||
{data.marketCap}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack justify="space-between">
|
|
||||||
<Text color={labelColor}>52周波动:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
|
||||||
{formatPrice(data.week52Low)}-{formatPrice(data.week52High)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
{/* 主力动态 */}
|
|
||||||
<Box flex="1" borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
|
||||||
<Text
|
|
||||||
fontSize="14px"
|
|
||||||
fontWeight="bold"
|
|
||||||
color={sectionTitleColor}
|
|
||||||
mb={3}
|
|
||||||
>
|
|
||||||
主力动态
|
|
||||||
</Text>
|
|
||||||
<VStack align="stretch" spacing={2} fontSize="14px">
|
|
||||||
<HStack justify="space-between">
|
|
||||||
<Text color={labelColor}>主力净流入:</Text>
|
|
||||||
<Text color={inflowColor} fontWeight="bold" fontSize="16px">
|
|
||||||
{formatNetInflow(data.mainNetInflow)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack justify="space-between">
|
|
||||||
<Text color={labelColor}>机构持仓:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold" fontSize="16px">
|
|
||||||
{data.institutionHolding.toFixed(2)}%
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
{/* 买卖比例条 */}
|
|
||||||
<Box mt={1}>
|
|
||||||
<Progress
|
|
||||||
value={data.buyRatio}
|
|
||||||
size="sm"
|
|
||||||
sx={{
|
|
||||||
'& > div': { bg: upColor },
|
|
||||||
}}
|
|
||||||
bg={downColor}
|
|
||||||
borderRadius="full"
|
|
||||||
/>
|
|
||||||
<HStack justify="space-between" mt={1} fontSize="14px">
|
|
||||||
<Text color={upColor}>买入{data.buyRatio}%</Text>
|
|
||||||
<Text color={downColor}>卖出{data.sellRatio}%</Text>
|
|
||||||
</HStack>
|
|
||||||
</Box>
|
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{/* 公司信息区块 - 1:2 布局 */}
|
{/* 公司信息区块 */}
|
||||||
{basicInfo && (
|
{basicInfo && <CompanyInfo basicInfo={basicInfo} />}
|
||||||
<>
|
|
||||||
<Divider borderColor={borderColor} my={4} />
|
|
||||||
<Flex gap={8}>
|
|
||||||
{/* 左侧:公司关键属性 (flex=1) */}
|
|
||||||
<Box flex="1" minWidth="0">
|
|
||||||
<HStack spacing={4} flexWrap="wrap" fontSize="14px">
|
|
||||||
<HStack spacing={1}>
|
|
||||||
<Icon as={Calendar} color={labelColor} boxSize={4} />
|
|
||||||
<Text color={labelColor}>成立:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold">
|
|
||||||
{formatDate(basicInfo.establish_date)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack spacing={1}>
|
|
||||||
<Icon as={Coins} color={labelColor} boxSize={4} />
|
|
||||||
<Text color={labelColor}>注册资本:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold">
|
|
||||||
{formatRegisteredCapital(basicInfo.reg_capital)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack spacing={1}>
|
|
||||||
<Icon as={MapPin} color={labelColor} boxSize={4} />
|
|
||||||
<Text color={labelColor}>所在地:</Text>
|
|
||||||
<Text color={valueColor} fontWeight="bold">
|
|
||||||
{basicInfo.province} {basicInfo.city}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
<HStack spacing={1}>
|
|
||||||
<Icon as={Globe} color={labelColor} boxSize={4} />
|
|
||||||
{basicInfo.website ? (
|
|
||||||
<Link
|
|
||||||
href={basicInfo.website}
|
|
||||||
isExternal
|
|
||||||
color={valueColor}
|
|
||||||
fontWeight="bold"
|
|
||||||
_hover={{ color: labelColor }}
|
|
||||||
>
|
|
||||||
访问官网
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<Text color={valueColor}>暂无官网</Text>
|
|
||||||
)}
|
|
||||||
</HStack>
|
|
||||||
</HStack>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
{/* 右侧:公司简介 (flex=2) */}
|
|
||||||
<Box flex="2" minWidth="0" borderLeftWidth="1px" borderColor={borderColor} pl={8}>
|
|
||||||
<Text fontSize="14px" color={labelColor} noOfLines={2}>
|
|
||||||
<Text as="span" fontWeight="bold" color={valueColor}>公司简介:</Text>
|
|
||||||
{basicInfo.company_intro || '暂无'}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
</Flex>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import type { StockQuoteCardData } from './types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 贵州茅台 Mock 数据
|
|
||||||
*/
|
|
||||||
export const mockStockQuoteData: StockQuoteCardData = {
|
|
||||||
// 基础信息
|
|
||||||
name: '贵州茅台',
|
|
||||||
code: '600519.SH',
|
|
||||||
indexTags: ['沪深300'],
|
|
||||||
|
|
||||||
// 价格信息
|
|
||||||
currentPrice: 2178.5,
|
|
||||||
changePercent: 3.65,
|
|
||||||
todayOpen: 2156.0,
|
|
||||||
yesterdayClose: 2101.0,
|
|
||||||
todayHigh: 2185.0,
|
|
||||||
todayLow: 2150.0,
|
|
||||||
|
|
||||||
// 关键指标
|
|
||||||
pe: 38.62,
|
|
||||||
pb: 14.82,
|
|
||||||
marketCap: '2.73万亿',
|
|
||||||
week52Low: 1980,
|
|
||||||
week52High: 2350,
|
|
||||||
|
|
||||||
// 主力动态
|
|
||||||
mainNetInflow: 1.28,
|
|
||||||
institutionHolding: 72.35,
|
|
||||||
buyRatio: 85,
|
|
||||||
sellRatio: 15,
|
|
||||||
|
|
||||||
// 更新时间
|
|
||||||
updateTime: '2025-12-03 14:30:25',
|
|
||||||
|
|
||||||
// 自选状态
|
|
||||||
isFavorite: false,
|
|
||||||
};
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
* StockQuoteCard 组件类型定义
|
* StockQuoteCard 组件类型定义
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { BasicInfo } from '../CompanyOverview/types';
|
// 注:BasicInfo 和 StockInfo 类型由内部 hooks 使用,不再在 Props 中传递
|
||||||
import type { StockInfo } from '../FinancialPanorama/types';
|
export type { StockInfo } from '../FinancialPanorama/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 股票行情卡片数据
|
* 股票行情卡片数据
|
||||||
@@ -26,6 +26,7 @@ export interface StockQuoteCardData {
|
|||||||
|
|
||||||
// 关键指标
|
// 关键指标
|
||||||
pe: number; // 市盈率
|
pe: number; // 市盈率
|
||||||
|
eps?: number; // 每股收益
|
||||||
pb: number; // 市净率
|
pb: number; // 市净率
|
||||||
marketCap: string; // 流通市值(已格式化,如 "2.73万亿")
|
marketCap: string; // 流通市值(已格式化,如 "2.73万亿")
|
||||||
week52Low: number; // 52周最低
|
week52Low: number; // 52周最低
|
||||||
@@ -45,26 +46,18 @@ export interface StockQuoteCardData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StockQuoteCard 组件 Props
|
* StockQuoteCard 组件 Props(优化后)
|
||||||
|
*
|
||||||
|
* 行情数据、基本信息、对比逻辑已下沉到组件内部 hooks 获取
|
||||||
|
* Props 从 11 个精简为 4 个
|
||||||
*/
|
*/
|
||||||
export interface StockQuoteCardProps {
|
export interface StockQuoteCardProps {
|
||||||
data?: StockQuoteCardData;
|
/** 股票代码 - 用于内部数据获取 */
|
||||||
isLoading?: boolean;
|
stockCode?: string;
|
||||||
// 自选股相关(与 WatchlistButton 接口保持一致)
|
/** 是否在自选股中(保留:涉及 Redux 和事件追踪回调) */
|
||||||
isInWatchlist?: boolean; // 是否在自选股中
|
isInWatchlist?: boolean;
|
||||||
isWatchlistLoading?: boolean; // 自选股操作加载中
|
/** 自选股操作加载中 */
|
||||||
onWatchlistToggle?: () => void; // 自选股切换回调
|
isWatchlistLoading?: boolean;
|
||||||
// 分享
|
/** 自选股切换回调 */
|
||||||
onShare?: () => void; // 分享回调
|
onWatchlistToggle?: () => void;
|
||||||
// 公司基本信息
|
|
||||||
basicInfo?: BasicInfo;
|
|
||||||
// 股票对比相关
|
|
||||||
currentStockInfo?: StockInfo; // 当前股票财务信息(用于对比)
|
|
||||||
compareStockInfo?: StockInfo; // 对比股票财务信息
|
|
||||||
isCompareLoading?: boolean; // 对比数据加载中
|
|
||||||
onCompare?: (stockCode: string) => void; // 触发对比回调
|
|
||||||
onCloseCompare?: () => void; // 关闭对比弹窗回调
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新导出 StockInfo 类型以便外部使用
|
|
||||||
export type { StockInfo };
|
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
// src/views/Company/hooks/useStockQuote.js
|
|
||||||
// 股票行情数据获取 Hook
|
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { stockService } from '@services/eventService';
|
|
||||||
import { logger } from '@utils/logger';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 API 响应数据转换为 StockQuoteCard 所需格式
|
|
||||||
*/
|
|
||||||
const transformQuoteData = (apiData, stockCode) => {
|
|
||||||
if (!apiData) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
// 基础信息
|
|
||||||
name: apiData.name || apiData.stock_name || '未知',
|
|
||||||
code: apiData.code || apiData.stock_code || stockCode,
|
|
||||||
indexTags: apiData.index_tags || apiData.indexTags || [],
|
|
||||||
industry: apiData.industry || apiData.sw_industry_l2 || '',
|
|
||||||
industryL1: apiData.industry_l1 || apiData.sw_industry_l1 || '',
|
|
||||||
|
|
||||||
// 价格信息
|
|
||||||
currentPrice: apiData.current_price || apiData.currentPrice || apiData.close || 0,
|
|
||||||
changePercent: apiData.change_percent || apiData.changePercent || apiData.pct_chg || 0,
|
|
||||||
todayOpen: apiData.today_open || apiData.todayOpen || apiData.open || 0,
|
|
||||||
yesterdayClose: apiData.yesterday_close || apiData.yesterdayClose || apiData.pre_close || 0,
|
|
||||||
todayHigh: apiData.today_high || apiData.todayHigh || apiData.high || 0,
|
|
||||||
todayLow: apiData.today_low || apiData.todayLow || apiData.low || 0,
|
|
||||||
|
|
||||||
// 关键指标
|
|
||||||
pe: apiData.pe || apiData.pe_ttm || 0,
|
|
||||||
pb: apiData.pb || apiData.pb_mrq || 0,
|
|
||||||
marketCap: apiData.market_cap || apiData.marketCap || apiData.circ_mv || '0',
|
|
||||||
week52Low: apiData.week52_low || apiData.week52Low || 0,
|
|
||||||
week52High: apiData.week52_high || apiData.week52High || 0,
|
|
||||||
|
|
||||||
// 主力动态
|
|
||||||
mainNetInflow: apiData.main_net_inflow || apiData.mainNetInflow || 0,
|
|
||||||
institutionHolding: apiData.institution_holding || apiData.institutionHolding || 0,
|
|
||||||
buyRatio: apiData.buy_ratio || apiData.buyRatio || 50,
|
|
||||||
sellRatio: apiData.sell_ratio || apiData.sellRatio || 50,
|
|
||||||
|
|
||||||
// 更新时间
|
|
||||||
updateTime: apiData.update_time || apiData.updateTime || new Date().toLocaleString(),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票行情数据获取 Hook
|
|
||||||
*
|
|
||||||
* @param {string} stockCode - 股票代码
|
|
||||||
* @returns {Object} { data, isLoading, error, refetch }
|
|
||||||
*/
|
|
||||||
export const useStockQuote = (stockCode) => {
|
|
||||||
const [data, setData] = useState(null);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!stockCode) {
|
|
||||||
setData(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchQuote = async () => {
|
|
||||||
setIsLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.debug('useStockQuote', '获取股票行情', { stockCode });
|
|
||||||
const quotes = await stockService.getQuotes([stockCode]);
|
|
||||||
|
|
||||||
// API 返回格式: { [stockCode]: quoteData }
|
|
||||||
const quoteData = quotes?.[stockCode] || quotes;
|
|
||||||
const transformedData = transformQuoteData(quoteData, stockCode);
|
|
||||||
|
|
||||||
logger.debug('useStockQuote', '行情数据转换完成', { stockCode, hasData: !!transformedData });
|
|
||||||
setData(transformedData);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('useStockQuote', '获取行情失败', err);
|
|
||||||
setError(err);
|
|
||||||
setData(null);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchQuote();
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
// 手动刷新
|
|
||||||
const refetch = () => {
|
|
||||||
if (stockCode) {
|
|
||||||
setData(null);
|
|
||||||
// 触发 useEffect 重新执行
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { data, isLoading, error, refetch };
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useStockQuote;
|
|
||||||
59
src/views/Company/hooks/useStockSearch.ts
Normal file
59
src/views/Company/hooks/useStockSearch.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* useStockSearch - 股票模糊搜索 Hook
|
||||||
|
*
|
||||||
|
* 提取自 SearchBar.js 和 CompareStockInput.tsx 的共享搜索逻辑
|
||||||
|
* 支持按代码或名称搜索,可选排除指定股票
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
export interface Stock {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UseStockSearchOptions {
|
||||||
|
excludeCode?: string;
|
||||||
|
limit?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票模糊搜索 Hook
|
||||||
|
*
|
||||||
|
* @param allStocks - 全部股票列表
|
||||||
|
* @param searchTerm - 搜索关键词
|
||||||
|
* @param options - 可选配置
|
||||||
|
* @param options.excludeCode - 排除的股票代码(用于对比场景)
|
||||||
|
* @param options.limit - 返回结果数量限制,默认 10
|
||||||
|
* @returns 过滤后的股票列表
|
||||||
|
*/
|
||||||
|
export const useStockSearch = (
|
||||||
|
allStocks: Stock[],
|
||||||
|
searchTerm: string,
|
||||||
|
options: UseStockSearchOptions = {}
|
||||||
|
): Stock[] => {
|
||||||
|
const { excludeCode, limit = 10 } = options;
|
||||||
|
|
||||||
|
return useMemo(() => {
|
||||||
|
const trimmed = searchTerm?.trim();
|
||||||
|
if (!trimmed) return [];
|
||||||
|
|
||||||
|
const term = trimmed.toLowerCase();
|
||||||
|
|
||||||
|
return allStocks
|
||||||
|
.filter((stock) => {
|
||||||
|
// 排除指定股票
|
||||||
|
if (excludeCode && stock.code === excludeCode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 按代码或名称匹配
|
||||||
|
return (
|
||||||
|
stock.code.toLowerCase().includes(term) ||
|
||||||
|
stock.name.includes(trimmed)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.slice(0, limit);
|
||||||
|
}, [allStocks, searchTerm, excludeCode, limit]);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useStockSearch;
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
// src/views/Company/index.js
|
// src/views/Company/index.js
|
||||||
// 公司详情页面入口 - 纯组合层
|
// 公司详情页面入口 - 纯组合层
|
||||||
|
//
|
||||||
|
// 优化:行情数据、基本信息、对比逻辑已下沉到 StockQuoteCard 内部
|
||||||
|
|
||||||
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import { Container, VStack, useToast } from '@chakra-ui/react';
|
import { Container, VStack } from '@chakra-ui/react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { loadAllStocks } from '@store/slices/stockSlice';
|
import { loadAllStocks } from '@store/slices/stockSlice';
|
||||||
import { financialService } from '@services/financialService';
|
|
||||||
import { logger } from '@utils/logger';
|
|
||||||
|
|
||||||
// 自定义 Hooks
|
// 自定义 Hooks
|
||||||
import { useCompanyStock } from './hooks/useCompanyStock';
|
import { useCompanyStock } from './hooks/useCompanyStock';
|
||||||
import { useCompanyWatchlist } from './hooks/useCompanyWatchlist';
|
import { useCompanyWatchlist } from './hooks/useCompanyWatchlist';
|
||||||
import { useCompanyEvents } from './hooks/useCompanyEvents';
|
import { useCompanyEvents } from './hooks/useCompanyEvents';
|
||||||
import { useStockQuote } from './hooks/useStockQuote';
|
|
||||||
import { useBasicInfo } from './components/CompanyOverview/hooks/useBasicInfo';
|
|
||||||
|
|
||||||
// 页面组件
|
// 页面组件
|
||||||
import CompanyHeader from './components/CompanyHeader';
|
import CompanyHeader from './components/CompanyHeader';
|
||||||
@@ -31,9 +29,8 @@ import CompanyTabs from './components/CompanyTabs';
|
|||||||
*/
|
*/
|
||||||
const CompanyIndex = () => {
|
const CompanyIndex = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
// 1. 先获取股票代码(不带追踪回调)
|
// 1. 获取股票代码(不带追踪回调)
|
||||||
const {
|
const {
|
||||||
stockCode,
|
stockCode,
|
||||||
inputCode,
|
inputCode,
|
||||||
@@ -47,64 +44,7 @@ const CompanyIndex = () => {
|
|||||||
dispatch(loadAllStocks());
|
dispatch(loadAllStocks());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
// 2. 获取股票行情数据
|
// 2. 初始化事件追踪(传入 stockCode)
|
||||||
const { data: quoteData, isLoading: isQuoteLoading } = useStockQuote(stockCode);
|
|
||||||
|
|
||||||
// 2.1 获取公司基本信息
|
|
||||||
const { basicInfo } = useBasicInfo(stockCode);
|
|
||||||
|
|
||||||
// 5. 股票对比状态管理
|
|
||||||
const [currentStockInfo, setCurrentStockInfo] = useState(null);
|
|
||||||
const [compareStockInfo, setCompareStockInfo] = useState(null);
|
|
||||||
const [isCompareLoading, setIsCompareLoading] = useState(false);
|
|
||||||
|
|
||||||
// 加载当前股票财务信息(用于对比)
|
|
||||||
useEffect(() => {
|
|
||||||
const loadCurrentStockInfo = async () => {
|
|
||||||
if (!stockCode) return;
|
|
||||||
try {
|
|
||||||
const res = await financialService.getStockInfo(stockCode);
|
|
||||||
setCurrentStockInfo(res.data);
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('CompanyIndex', 'loadCurrentStockInfo', error, { stockCode });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
loadCurrentStockInfo();
|
|
||||||
// 清除对比数据
|
|
||||||
setCompareStockInfo(null);
|
|
||||||
}, [stockCode]);
|
|
||||||
|
|
||||||
// 处理股票对比
|
|
||||||
const handleCompare = useCallback(async (compareCode) => {
|
|
||||||
if (!compareCode) return;
|
|
||||||
|
|
||||||
logger.debug('CompanyIndex', '开始加载对比数据', { stockCode, compareCode });
|
|
||||||
setIsCompareLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await financialService.getStockInfo(compareCode);
|
|
||||||
setCompareStockInfo(res.data);
|
|
||||||
logger.info('CompanyIndex', '对比数据加载成功', { stockCode, compareCode });
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('CompanyIndex', 'handleCompare', error, { stockCode, compareCode });
|
|
||||||
toast({
|
|
||||||
title: '加载对比数据失败',
|
|
||||||
description: '请检查股票代码是否正确',
|
|
||||||
status: 'error',
|
|
||||||
duration: 3000,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsCompareLoading(false);
|
|
||||||
}
|
|
||||||
}, [stockCode, toast]);
|
|
||||||
|
|
||||||
// 关闭对比弹窗
|
|
||||||
const handleCloseCompare = useCallback(() => {
|
|
||||||
// 可选:清除对比数据
|
|
||||||
// setCompareStockInfo(null);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// 3. 再初始化事件追踪(传入 stockCode)
|
|
||||||
const {
|
const {
|
||||||
trackStockSearched,
|
trackStockSearched,
|
||||||
trackTabChanged,
|
trackTabChanged,
|
||||||
@@ -147,19 +87,12 @@ const CompanyIndex = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 股票行情卡片:价格、关键指标、主力动态、公司信息、股票对比 */}
|
{/* 股票行情卡片:价格、关键指标、主力动态、公司信息、股票对比 */}
|
||||||
|
{/* 优化:数据获取已下沉到组件内部,Props 从 11 个精简为 4 个 */}
|
||||||
<StockQuoteCard
|
<StockQuoteCard
|
||||||
data={quoteData}
|
stockCode={stockCode}
|
||||||
isLoading={isQuoteLoading}
|
|
||||||
isInWatchlist={isInWatchlist}
|
isInWatchlist={isInWatchlist}
|
||||||
isWatchlistLoading={isWatchlistLoading}
|
isWatchlistLoading={isWatchlistLoading}
|
||||||
onWatchlistToggle={handleWatchlistToggle}
|
onWatchlistToggle={handleWatchlistToggle}
|
||||||
basicInfo={basicInfo}
|
|
||||||
// 股票对比相关
|
|
||||||
currentStockInfo={currentStockInfo}
|
|
||||||
compareStockInfo={compareStockInfo}
|
|
||||||
isCompareLoading={isCompareLoading}
|
|
||||||
onCompare={handleCompare}
|
|
||||||
onCloseCompare={handleCloseCompare}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Tab 切换区域:概览、行情、财务、预测 */}
|
{/* Tab 切换区域:概览、行情、财务、预测 */}
|
||||||
|
|||||||
Reference in New Issue
Block a user