45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
// src/mocks/handlers/industry.js
|
|
// 行业分类相关的 Mock API Handlers
|
|
|
|
import { http, HttpResponse } from 'msw';
|
|
import { industryData } from '../../data/industryData';
|
|
|
|
// 模拟网络延迟
|
|
const delay = (ms = 300) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
export const industryHandlers = [
|
|
// 获取行业分类完整树形结构
|
|
http.get('/api/classifications', async ({ request }) => {
|
|
await delay(500);
|
|
|
|
const url = new URL(request.url);
|
|
const classification = url.searchParams.get('classification');
|
|
|
|
console.log('[Mock] 获取行业分类树形数据(真实数据)', { classification });
|
|
|
|
try {
|
|
let data = industryData;
|
|
|
|
// 如果指定了分类体系,只返回该体系的数据
|
|
if (classification) {
|
|
data = industryData.filter(item => item.value === classification);
|
|
}
|
|
|
|
return HttpResponse.json({
|
|
success: true,
|
|
data: data
|
|
});
|
|
} catch (error) {
|
|
console.error('[Mock] 获取行业分类失败:', error);
|
|
return HttpResponse.json(
|
|
{
|
|
success: false,
|
|
error: '获取行业分类失败',
|
|
data: []
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
})
|
|
];
|