diff --git a/src/mocks/handlers/stock.js b/src/mocks/handlers/stock.js index 623702c2..701c97f0 100644 --- a/src/mocks/handlers/stock.js +++ b/src/mocks/handlers/stock.js @@ -224,4 +224,59 @@ export const stockHandlers = [ ); } }), + + // 批量获取股票K线数据 + http.post('/api/stock/batch-kline', async ({ request }) => { + await delay(400); + + try { + const body = await request.json(); + const { codes, type = 'timeline', event_time } = body; + + console.log('[Mock Stock] 批量获取K线数据:', { + stockCount: codes?.length, + type, + eventTime: event_time + }); + + if (!codes || !Array.isArray(codes) || codes.length === 0) { + return HttpResponse.json( + { error: '股票代码列表不能为空' }, + { status: 400 } + ); + } + + // 为每只股票生成数据 + const batchData = {}; + codes.forEach(stockCode => { + let data; + if (type === 'timeline') { + data = generateTimelineData('000001.SH'); + } else if (type === 'daily') { + data = generateDailyData('000001.SH', 60); + } else { + data = []; + } + + batchData[stockCode] = { + success: true, + data: data, + stock_code: stockCode + }; + }); + + return HttpResponse.json({ + success: true, + data: batchData, + type: type, + message: '批量获取成功' + }); + } catch (error) { + console.error('[Mock Stock] 批量获取K线数据失败:', error); + return HttpResponse.json( + { error: '批量获取K线数据失败' }, + { status: 500 } + ); + } + }), ];