更新BK缓存策略

This commit is contained in:
Sakurasan
2026-07-08 00:33:15 +08:00
parent 1a50f7680a
commit 015aeb989a
3 changed files with 55 additions and 22 deletions
+2 -2
View File
@@ -458,12 +458,12 @@ export interface SectorResponse {
* 获取东方财富板块列表(按主力净流入排序)
* @param type industry=行业板块, concept=概念板块
*/
export async function fetchSectors(type: SectorType): Promise<SectorItem[]> {
export async function fetchSectors(type: SectorType, signal?: AbortSignal): Promise<SectorItem[]> {
const baseUrl = getApiBaseUrl();
const url = `${baseUrl}/api/sectors?type=${type}`;
try {
const resp = await fetch(url, { method: "GET" });
const resp = await fetch(url, { method: "GET", signal });
if (!resp.ok) return [];
const result: SectorResponse = await resp.json();
return result.data || [];
+12 -4
View File
@@ -1,5 +1,5 @@
import { createFileRoute } from "@tanstack/react-router";
import { useState, useEffect, useMemo } from "react";
import { useState, useEffect, useMemo, useRef } from "react";
import { fetchSectors, type SectorItem, type SectorType } from "@/lib/stock-api";
import { Card, CardContent } from "@/components/ui/card";
import { ArrowLeft, TrendingUp, TrendingDown, RefreshCw } from "lucide-react";
@@ -21,17 +21,25 @@ function SectorsPage() {
const [data, setData] = useState<SectorItem[]>([]);
const [loading, setLoading] = useState(true);
const [sort, setSort] = useState<SortMode>("mainNetInflow");
const abortRef = useRef<AbortController | null>(null);
const loadData = (t: SectorType) => {
// 取消上次未完成的请求
abortRef.current?.abort();
const controller = new AbortController();
abortRef.current = controller;
setLoading(true);
fetchSectors(t).then((items) => {
setData(items);
setLoading(false);
fetchSectors(t, controller.signal).then((items) => {
if (!controller.signal.aborted) {
setData(items);
setLoading(false);
}
});
};
useEffect(() => {
loadData(tab);
return () => abortRef.current?.abort();
}, [tab]);
const sorted = useMemo(() => {