Преглед изворни кода

♻️ refactor(stock): fix type assertion syntax in stock queries

- correct type assertion position for stockData array to avoid potential type errors
- fix memoData type assertion to ensure proper array typing

📝 docs(server): add detailed API schema for stock history data

- define StockHistoryItemSchema with all stock data fields and descriptions
- update GetStockHistoryResponse to use typed array with example data
- add field descriptions and examples for better API documentation
yourname пре 4 месеци
родитељ
комит
81b59433de

+ 3 - 3
src/client/mobile/components/stock/components/stock-chart/src/hooks/useStockQueries.ts

@@ -52,14 +52,14 @@ export function useStockQueries(code?: string) {
   });
 
   // 转换数据格式
-  const stockData = stockDataResponse?.data || [] as StockData[];
+  const stockData = (stockDataResponse?.data || []) as StockData[];
 
-  const memoData = memoDataResponse?.data?.map(item => ({
+  const memoData = (memoDataResponse?.data?.map(item => ({
     _id: item.id,
     代码: item.code,
     日期: item.noteDate,
     提示: item.note,
-  })) as DateMemo[] || [];
+  })) || []) as DateMemo[];
 
   const isLoading = isLoadingStock || isLoadingMemo;
   const error = stockError || memoError;

+ 70 - 3
src/server/api/stock-data/history/[code]/get.ts

@@ -15,11 +15,78 @@ const GetStockHistoryParams = z.object({
   })
 });
 
+// 股票历史数据项Schema
+const StockHistoryItemSchema = z.object({
+  d: z.string().openapi({
+    description: '日期',
+    example: '2007-09-13'
+  }),
+  o: z.number().openapi({
+    description: '开盘价',
+    example: 40.99
+  }),
+  h: z.number().openapi({
+    description: '最高价',
+    example: 59
+  }),
+  l: z.number().openapi({
+    description: '最低价',
+    example: 40.99
+  }),
+  c: z.number().openapi({
+    description: '收盘价',
+    example: 53.11
+  }),
+  v: z.number().openapi({
+    description: '成交量',
+    example: 78854
+  }),
+  e: z.number().openapi({
+    description: '成交额',
+    example: 369834688.13
+  }),
+  zf: z.number().openapi({
+    description: '振幅',
+    example: 202.13
+  }),
+  hs: z.number().openapi({
+    description: '换手率',
+    example: 78.85
+  }),
+  zd: z.number().openapi({
+    description: '涨跌额',
+    example: 496.07
+  }),
+  zde: z.number().openapi({
+    description: '涨跌幅',
+    example: 44.2
+  }),
+  ud: z.string().openapi({
+    description: '最后更新时间',
+    example: '2025-06-29 02:13:11'
+  })
+});
+
 // 响应Schema
 const GetStockHistoryResponse = z.object({
-  data: z.any().openapi({
-    description: '股票历史数据',
-    example: []
+  data: z.array(StockHistoryItemSchema).openapi({
+    description: '股票历史K线数据列表',
+    example: [
+      {
+        d: "2007-09-13",
+        o: 40.99,
+        h: 59,
+        l: 40.99,
+        c: 53.11,
+        v: 78854,
+        e: 369834688.13,
+        zf: 202.13,
+        hs: 78.85,
+        zd: 496.07,
+        zde: 44.2,
+        ud: "2025-06-29 02:13:11"
+      }
+    ]
   })
 });