|
|
@@ -7,7 +7,7 @@ import { useEffect } from 'react';
|
|
|
import type { InferResponseType } from 'hono/client';
|
|
|
|
|
|
// 定义响应类型
|
|
|
-type StockDataListResponse = InferResponseType<typeof stockDataClient.$get, 200>;
|
|
|
+type StockHistoryResponse = InferResponseType<typeof stockDataClient.history[':code']['$get'], 200>;
|
|
|
type DateNotesListResponse = InferResponseType<typeof dateNotesClient.$get, 200>;
|
|
|
|
|
|
export function useStockQueries(code?: string) {
|
|
|
@@ -17,16 +17,19 @@ export function useStockQueries(code?: string) {
|
|
|
isLoading: isLoadingStock,
|
|
|
error: stockError,
|
|
|
refetch: refetchStock
|
|
|
- } = useQuery<StockDataListResponse>({
|
|
|
+ } = useQuery<StockHistoryResponse>({
|
|
|
queryKey: ['stockHistory', code],
|
|
|
- queryFn: () => stockDataClient.$get({
|
|
|
- query: {
|
|
|
- filters: JSON.stringify(code ? { code } : {}),
|
|
|
- page: 1,
|
|
|
- pageSize: 1000
|
|
|
+ queryFn: async () => {
|
|
|
+ if (!code) throw new Error('股票代码不能为空');
|
|
|
+ const response = await stockDataClient.history[':code'].$get({
|
|
|
+ param: { code }
|
|
|
+ });
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('获取股票历史数据失败');
|
|
|
}
|
|
|
- }).then(res => res.json()),
|
|
|
- enabled: false,
|
|
|
+ return response.json();
|
|
|
+ },
|
|
|
+ enabled: !!code,
|
|
|
retry: 0,
|
|
|
});
|
|
|
|
|
|
@@ -49,16 +52,7 @@ export function useStockQueries(code?: string) {
|
|
|
});
|
|
|
|
|
|
// 转换数据格式
|
|
|
- const stockData = stockDataResponse?.data?.map(item => ({
|
|
|
- o: String(item.data.o),
|
|
|
- c: String(item.data.c),
|
|
|
- h: String(item.data.h),
|
|
|
- l: String(item.data.l),
|
|
|
- v: String(item.data.v),
|
|
|
- d: String(item.data.d),
|
|
|
- zd: String(item.data.zd),
|
|
|
- pc: item.data.pc ? String(item.data.pc) : undefined,
|
|
|
- })) as StockData[] || [];
|
|
|
+ const stockData = stockDataResponse?.data || [] as StockData[];
|
|
|
|
|
|
const memoData = memoDataResponse?.data?.map(item => ({
|
|
|
_id: item.id,
|