feat(DynamicNewsDetailPanel): 升级为实时数据,移除模拟数据生成
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
// src/views/Community/components/DynamicNewsDetail/DynamicNewsDetailPanel.js
|
// src/views/Community/components/DynamicNewsDetail/DynamicNewsDetailPanel.js
|
||||||
// 动态新闻详情面板主组件(组装所有子组件)
|
// 动态新闻详情面板主组件(组装所有子组件)
|
||||||
|
|
||||||
import React, { useState, useMemo, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
VStack,
|
VStack,
|
||||||
Text,
|
Text,
|
||||||
|
Spinner,
|
||||||
|
Center,
|
||||||
useColorModeValue,
|
useColorModeValue,
|
||||||
useToast,
|
useToast,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { getImportanceConfig } from '../../../../constants/importanceLevels';
|
import { getImportanceConfig } from '../../../../constants/importanceLevels';
|
||||||
import { eventService } from '../../../../services/eventService';
|
import { eventService } from '../../../../services/eventService';
|
||||||
|
import { useEventStocks } from '../StockDetailPanel/hooks/useEventStocks';
|
||||||
import EventHeaderInfo from './EventHeaderInfo';
|
import EventHeaderInfo from './EventHeaderInfo';
|
||||||
import EventDescriptionSection from './EventDescriptionSection';
|
import EventDescriptionSection from './EventDescriptionSection';
|
||||||
import RelatedConceptsSection from './RelatedConceptsSection';
|
import RelatedConceptsSection from './RelatedConceptsSection';
|
||||||
@@ -31,6 +34,16 @@ const DynamicNewsDetailPanel = ({ event }) => {
|
|||||||
const textColor = useColorModeValue('gray.600', 'gray.400');
|
const textColor = useColorModeValue('gray.600', 'gray.400');
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
|
// 使用 Hook 获取实时数据
|
||||||
|
const {
|
||||||
|
stocks,
|
||||||
|
quotes,
|
||||||
|
eventDetail,
|
||||||
|
historicalEvents,
|
||||||
|
expectationScore,
|
||||||
|
loading
|
||||||
|
} = useEventStocks(event?.id, event?.created_at);
|
||||||
|
|
||||||
// 折叠状态管理
|
// 折叠状态管理
|
||||||
const [isStocksOpen, setIsStocksOpen] = useState(true);
|
const [isStocksOpen, setIsStocksOpen] = useState(true);
|
||||||
const [isHistoricalOpen, setIsHistoricalOpen] = useState(false);
|
const [isHistoricalOpen, setIsHistoricalOpen] = useState(false);
|
||||||
@@ -50,26 +63,6 @@ const DynamicNewsDetailPanel = ({ event }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 生成模拟行情数据
|
|
||||||
const quotes = useMemo(() => {
|
|
||||||
if (!event?.related_stocks) return {};
|
|
||||||
|
|
||||||
const quotesData = {};
|
|
||||||
event.related_stocks.forEach(stock => {
|
|
||||||
// 优先使用 stock.daily_change,否则生成随机涨跌幅
|
|
||||||
const change = stock.daily_change
|
|
||||||
? parseFloat(stock.daily_change)
|
|
||||||
: (Math.random() * 10 - 3); // -3% ~ +7%
|
|
||||||
|
|
||||||
quotesData[stock.stock_code] = {
|
|
||||||
change: change,
|
|
||||||
price: 10 + Math.random() * 90 // 模拟价格 10-100
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return quotesData;
|
|
||||||
}, [event?.related_stocks]);
|
|
||||||
|
|
||||||
// 切换关注状态
|
// 切换关注状态
|
||||||
const handleToggleFollow = async () => {
|
const handleToggleFollow = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -165,8 +158,14 @@ const DynamicNewsDetailPanel = ({ event }) => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 相关股票(可折叠) */}
|
{/* 相关股票(可折叠) */}
|
||||||
|
{loading.stocks || loading.quotes ? (
|
||||||
|
<Center py={4}>
|
||||||
|
<Spinner size="md" color="blue.500" />
|
||||||
|
<Text ml={2} color={textColor}>加载股票数据中...</Text>
|
||||||
|
</Center>
|
||||||
|
) : (
|
||||||
<RelatedStocksSection
|
<RelatedStocksSection
|
||||||
stocks={event.related_stocks}
|
stocks={stocks}
|
||||||
quotes={quotes}
|
quotes={quotes}
|
||||||
eventTime={event.created_at}
|
eventTime={event.created_at}
|
||||||
watchlistSet={watchlistSet}
|
watchlistSet={watchlistSet}
|
||||||
@@ -174,17 +173,25 @@ const DynamicNewsDetailPanel = ({ event }) => {
|
|||||||
onToggle={() => setIsStocksOpen(!isStocksOpen)}
|
onToggle={() => setIsStocksOpen(!isStocksOpen)}
|
||||||
onWatchlistToggle={handleWatchlistToggle}
|
onWatchlistToggle={handleWatchlistToggle}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 历史事件对比(可折叠) */}
|
{/* 历史事件对比(可折叠) */}
|
||||||
<CollapsibleSection
|
<CollapsibleSection
|
||||||
title="历史事件对比"
|
title="历史事件对比"
|
||||||
isOpen={isHistoricalOpen}
|
isOpen={isHistoricalOpen}
|
||||||
onToggle={() => setIsHistoricalOpen(!isHistoricalOpen)}
|
onToggle={() => setIsHistoricalOpen(!isHistoricalOpen)}
|
||||||
count={event.historical_events?.length || 0}
|
count={historicalEvents?.length || 0}
|
||||||
>
|
>
|
||||||
|
{loading.historicalEvents ? (
|
||||||
|
<Center py={4}>
|
||||||
|
<Spinner size="sm" color="blue.500" />
|
||||||
|
<Text ml={2} color={textColor} fontSize="sm">加载历史事件...</Text>
|
||||||
|
</Center>
|
||||||
|
) : (
|
||||||
<HistoricalEvents
|
<HistoricalEvents
|
||||||
events={event.historical_events || []}
|
events={historicalEvents || []}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
{/* 传导链分析(可折叠) */}
|
{/* 传导链分析(可折叠) */}
|
||||||
|
|||||||
Reference in New Issue
Block a user