buliangMap/public/mock/mockConfig.js
2025-06-24 18:58:59 +08:00

41 lines
2.1 KiB
JavaScript

// 模拟API拦截器配置
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
// 创建一个新的mock适配器实例
const mock = new MockAdapter(axios);
// 配置模拟的API响应
// 总分数API
mock.onGet('/api/settings/getAllCourse').reply(200, require('./getAllCourse.json').data);
// 各区域数据API
mock.onGet('/api/settings/getAllData').reply(200, require('./getAllData.json').data);
// 六大表格相关API
mock.onGet('/api/settings/getCheckMonitoringValue').reply(200, require('./getCheckMonitoringValue.json').data);
mock.onGet('/api/settings/getCheckAssessmentValue').reply(200, require('./getCheckAssessmentValue.json').data);
mock.onGet('/api/settings/getIstrativeSanctionValue').reply(200, require('./getIstrativeSanctionValue.json').data);
mock.onGet('/api/settings/getComplaintReportValue').reply(200, require('./getComplaintReportValue.json').data);
mock.onGet('/api/settings/getInformationTracingValue').reply(200, require('./getInformationTracingValue.json').data);
mock.onGet('/api/settings/getLawEnforcementInspectionValue').reply(200, require('./getLawEnforcementInspectionValue.json').data);
// 辅助函数: 支持URL参数的模拟请求
function mockWithParams(url, mockDataFile) {
mock.onGet(new RegExp(url)).reply(config => {
return [200, require(mockDataFile).data];
});
}
// 添加参数化的模拟API
mockWithParams('/api/settings/getAllCourse\\?.*', './getAllCourse.json');
mockWithParams('/api/settings/getAllData\\?.*', './getAllData.json');
mockWithParams('/api/settings/getCheckMonitoringValue\\?.*', './getCheckMonitoringValue.json');
mockWithParams('/api/settings/getCheckAssessmentValue\\?.*', './getCheckAssessmentValue.json');
mockWithParams('/api/settings/getIstrativeSanctionValue\\?.*', './getIstrativeSanctionValue.json');
mockWithParams('/api/settings/getComplaintReportValue\\?.*', './getComplaintReportValue.json');
mockWithParams('/api/settings/getInformationTracingValue\\?.*', './getInformationTracingValue.json');
mockWithParams('/api/settings/getLawEnforcementInspectionValue\\?.*', './getLawEnforcementInspectionValue.json');
export default mock;