feat: 大盘指数刷新问题

This commit is contained in:
hzm
2026-03-16 10:02:35 +08:00
parent d05002fd86
commit ce559664f1
2 changed files with 20 additions and 2 deletions

View File

@@ -198,6 +198,7 @@ export default function MarketIndexAccordion({
onHeightChange,
isMobile,
onCustomSettingsChange,
refreshing = false,
}) {
const [indices, setIndices] = useState([]);
const [loading, setLoading] = useState(true);
@@ -222,8 +223,9 @@ export default function MarketIndexAccordion({
};
}, [onHeightChange, loading, indices.length]);
useEffect(() => {
const loadIndices = () => {
let cancelled = false;
setLoading(true);
fetchMarketIndices()
.then((data) => {
if (!cancelled) setIndices(Array.isArray(data) ? data : []);
@@ -234,9 +236,24 @@ export default function MarketIndexAccordion({
.finally(() => {
if (!cancelled) setLoading(false);
});
return () => { cancelled = true; };
return () => {
cancelled = true;
};
};
useEffect(() => {
// 初次挂载时加载一次指数
const cleanup = loadIndices();
return cleanup;
}, []);
useEffect(() => {
// 跟随基金刷新节奏:每次开始刷新时重新拉取指数
if (!refreshing) return;
const cleanup = loadIndices();
return cleanup;
}, [refreshing]);
// 初始化选中指数(本地偏好 > 默认集合)
useEffect(() => {
if (!indices.length || typeof window === 'undefined') return;

View File

@@ -3923,6 +3923,7 @@ export default function HomePage() {
onHeightChange={setMarketIndexAccordionHeight}
isMobile={isMobile}
onCustomSettingsChange={triggerCustomSettingsSync}
refreshing={refreshing}
/>
<div className="grid">
<div className="col-12">