feat: K线图默认展示近3个月,拖动回看更早数据;自定义日期格式;主图加高成交量压低

This commit is contained in:
Sakurasan
2026-09-02 01:13:26 +08:00
parent 9a72f0bbf6
commit 375d196fef
3 changed files with 95 additions and 17 deletions
+19 -10
View File
@@ -137,6 +137,22 @@ export function KLineCard({ code, addedAt, ready }: Props) {
const displayData = chartPeriod === "d" ? dailyData : minuteData;
const currentLoading = chartPeriod === "d" ? chartLoading : minuteLoading;
// 传给图表的数据引用需稳定(仅随 displayData 变化),
// 否则切换指标/显示方式时 KLineChart 会把新数组当成新数据集重置视口
const chartData = useMemo(
() =>
displayData.map((d) => ({
time: d.dateMs,
open: d.open,
close: d.close,
high: d.high,
low: d.low,
volume: d.volume,
isAddedDate: d.isAddedDate,
})),
[displayData],
);
return (
<Card className="shadow-lg">
<CardHeader className="pb-2 md:pb-4 px-3 md:px-6 pt-4 md:pt-6">
@@ -213,7 +229,7 @@ export function KLineCard({ code, addedAt, ready }: Props) {
</CardHeader>
<CardContent className="px-2 md:px-6 pb-2 md:pb-6">
{currentLoading ? (
<div className="h-[320px] sm:h-[380px] md:h-[440px] w-full flex items-center justify-center">
<div className="h-[390px] w-full flex items-center justify-center">
<div className="flex items-center text-muted-foreground text-sm">
<div className="animate-pulse mr-2 h-2 w-2 rounded-full bg-primary"></div>
K线数据加载中...
@@ -221,18 +237,11 @@ export function KLineCard({ code, addedAt, ready }: Props) {
</div>
) : (
<KLineChart
data={displayData.map((d) => ({
time: d.dateMs,
open: d.open,
close: d.close,
high: d.high,
low: d.low,
volume: d.volume,
isAddedDate: d.isAddedDate,
}))}
data={chartData}
mode={chartMode}
hasAddedDate={ready}
indicators={indicators}
defaultVisibleDays={chartPeriod === "d" ? 90 : undefined}
/>
)}
</CardContent>