feat(MarketDataView): K线图优化 - 按需刷新 + 黑金主题
- useMarketData: 新增 refreshTradeData,切换时间范围只刷新K线数据 - chartOptions: 新增黑金主题配置函数 - 优化 useEffect,避免切换周期时全量刷新
This commit is contained in:
@@ -45,6 +45,8 @@ export const useMarketData = (
|
|||||||
const isInitializedRef = useRef(false);
|
const isInitializedRef = useRef(false);
|
||||||
// 记录上一次的 stockCode,用于判断是否需要重新加载所有数据
|
// 记录上一次的 stockCode,用于判断是否需要重新加载所有数据
|
||||||
const prevStockCodeRef = useRef(stockCode);
|
const prevStockCodeRef = useRef(stockCode);
|
||||||
|
// 记录上一次的 period,用于判断是否需要刷新交易数据
|
||||||
|
const prevPeriodRef = useRef(period);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载所有市场数据
|
* 加载所有市场数据
|
||||||
@@ -224,16 +226,18 @@ export const useMarketData = (
|
|||||||
loadMarketData();
|
loadMarketData();
|
||||||
loadMinuteData();
|
loadMinuteData();
|
||||||
prevStockCodeRef.current = stockCode;
|
prevStockCodeRef.current = stockCode;
|
||||||
|
prevPeriodRef.current = period; // 同步重置 period ref,避免切换股票后误触发 refreshTradeData
|
||||||
isInitializedRef.current = true;
|
isInitializedRef.current = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [stockCode, loadMarketData, loadMinuteData]);
|
}, [stockCode, period, loadMarketData, loadMinuteData]);
|
||||||
|
|
||||||
// 监听时间周期变化,只刷新日K线数据
|
// 监听时间周期变化,只刷新日K线数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 只有在已初始化后,period 变化时才单独刷新交易数据
|
// 只有在已初始化后,且 period 真正变化时才单独刷新交易数据
|
||||||
if (stockCode && isInitializedRef.current) {
|
if (stockCode && isInitializedRef.current && period !== prevPeriodRef.current) {
|
||||||
refreshTradeData();
|
refreshTradeData();
|
||||||
|
prevPeriodRef.current = period;
|
||||||
}
|
}
|
||||||
}, [period, refreshTradeData, stockCode]);
|
}, [period, refreshTradeData, stockCode]);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import {
|
import {
|
||||||
ChevronUp,
|
|
||||||
Unlock,
|
Unlock,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
Star,
|
Star,
|
||||||
@@ -97,9 +96,8 @@ const MarketDataView: React.FC<MarketDataViewProps> = ({ stockCode: propStockCod
|
|||||||
[analysisMap, theme, onOpen]
|
[analysisMap, theme, onOpen]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tab 配置 - 使用通用 SubTabContainer
|
// Tab 配置 - 使用通用 SubTabContainer(不含交易数据,交易数据单独显示在上方)
|
||||||
const tabConfigs: SubTabConfig[] = [
|
const tabConfigs: SubTabConfig[] = [
|
||||||
{ key: 'trade', name: '交易数据', icon: ChevronUp, component: TradeDataPanel },
|
|
||||||
{ key: 'funding', name: '融资融券', icon: Unlock, component: FundingPanel },
|
{ key: 'funding', name: '融资融券', icon: Unlock, component: FundingPanel },
|
||||||
{ key: 'bigDeal', name: '大宗交易', icon: ArrowUp, component: BigDealPanel },
|
{ key: 'bigDeal', name: '大宗交易', icon: ArrowUp, component: BigDealPanel },
|
||||||
{ key: 'unusual', name: '龙虎榜', icon: Star, component: UnusualPanel },
|
{ key: 'unusual', name: '龙虎榜', icon: Star, component: UnusualPanel },
|
||||||
@@ -142,11 +140,26 @@ const MarketDataView: React.FC<MarketDataViewProps> = ({ stockCode: propStockCod
|
|||||||
return (
|
return (
|
||||||
<Box bg={'#1A202C'} minH="100vh" color={theme.textPrimary}>
|
<Box bg={'#1A202C'} minH="100vh" color={theme.textPrimary}>
|
||||||
<Container maxW="container.xl" py={6}>
|
<Container maxW="container.xl" py={6}>
|
||||||
<VStack align="stretch">
|
<VStack align="stretch" spacing={6}>
|
||||||
{/* 股票概览 */}
|
{/* 股票概览 */}
|
||||||
{summary && <StockSummaryCard summary={summary} theme={theme} />}
|
{summary && <StockSummaryCard summary={summary} theme={theme} />}
|
||||||
|
|
||||||
{/* 主要内容区域 */}
|
{/* 交易数据 - 日K/分钟K线(独立显示在 Tab 上方) */}
|
||||||
|
{!loading && (
|
||||||
|
<TradeDataPanel
|
||||||
|
theme={theme}
|
||||||
|
tradeData={tradeData}
|
||||||
|
minuteData={minuteData}
|
||||||
|
minuteLoading={minuteLoading}
|
||||||
|
analysisMap={analysisMap}
|
||||||
|
onLoadMinuteData={loadMinuteData}
|
||||||
|
onChartClick={handleChartClick}
|
||||||
|
selectedPeriod={selectedPeriod}
|
||||||
|
onPeriodChange={setSelectedPeriod}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 主要内容区域 - Tab */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<ThemedCard theme={theme}>
|
<ThemedCard theme={theme}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
|
|||||||
@@ -557,14 +557,15 @@ export const getKLineDarkGoldOption = (
|
|||||||
{
|
{
|
||||||
left: '3%',
|
left: '3%',
|
||||||
right: '3%',
|
right: '3%',
|
||||||
height: '50%',
|
top: '8%',
|
||||||
|
height: '55%',
|
||||||
containLabel: true,
|
containLabel: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
left: '3%',
|
left: '3%',
|
||||||
right: '3%',
|
right: '3%',
|
||||||
top: '65%',
|
top: '68%',
|
||||||
height: '20%',
|
height: '28%',
|
||||||
containLabel: true,
|
containLabel: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -623,24 +624,29 @@ export const getKLineDarkGoldOption = (
|
|||||||
name: '涨幅分析',
|
name: '涨幅分析',
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
data: scatterData,
|
data: scatterData,
|
||||||
symbolSize: 30,
|
symbolSize: [80, 36],
|
||||||
symbol: 'pin',
|
symbol: 'roundRect',
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: goldLight,
|
color: 'rgba(26, 26, 46, 0.9)',
|
||||||
shadowBlur: 10,
|
borderColor: gold,
|
||||||
shadowColor: 'rgba(244, 208, 63, 0.5)',
|
borderWidth: 1,
|
||||||
|
shadowBlur: 8,
|
||||||
|
shadowColor: 'rgba(212, 175, 55, 0.4)',
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
show: true,
|
show: true,
|
||||||
formatter: '★',
|
formatter: '涨幅分析\n(点击查看)',
|
||||||
fontSize: 20,
|
fontSize: 10,
|
||||||
|
lineHeight: 12,
|
||||||
position: 'inside',
|
position: 'inside',
|
||||||
color: '#FF6B6B',
|
color: gold,
|
||||||
|
fontWeight: 'bold',
|
||||||
},
|
},
|
||||||
emphasis: {
|
emphasis: {
|
||||||
scale: 1.5,
|
scale: false,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: orange,
|
borderColor: goldLight,
|
||||||
|
borderWidth: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
z: 100,
|
z: 100,
|
||||||
|
|||||||
Reference in New Issue
Block a user