添加银行政府后端接口
This commit is contained in:
52
government-admin/test-api.js
Normal file
52
government-admin/test-api.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// 从前端目录测试API访问
|
||||
const axios = require('axios');
|
||||
|
||||
// 创建axios实例,使用与前端相同的配置
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:5352/api',
|
||||
timeout: 5000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
async function testApi() {
|
||||
try {
|
||||
console.log('开始从前端目录测试API...');
|
||||
|
||||
// 测试行政人员列表API
|
||||
console.log('\n测试行政人员列表API:');
|
||||
const adminStaffResponse = await api.get('/government/admin-staff');
|
||||
console.log(`✅ 行政人员列表API调用成功,返回${adminStaffResponse.data.length}条数据`);
|
||||
|
||||
// 测试部门列表API
|
||||
console.log('\n测试部门列表API:');
|
||||
const departmentResponse = await api.get('/government/departments');
|
||||
console.log(`✅ 部门列表API调用成功,返回${departmentResponse.data.length}条数据`);
|
||||
|
||||
// 测试岗位列表API
|
||||
console.log('\n测试岗位列表API:');
|
||||
const positionResponse = await api.get('/government/positions');
|
||||
console.log(`✅ 岗位列表API调用成功,返回${positionResponse.data.length}条数据`);
|
||||
|
||||
// 测试带有查询参数的API
|
||||
console.log('\n测试带查询参数的API:');
|
||||
const filteredResponse = await api.get('/government/admin-staff?page=1&pageSize=3');
|
||||
console.log(`✅ 带查询参数的API调用成功,返回${filteredResponse.data.length}条数据`);
|
||||
|
||||
console.log('\n✅ 所有API测试成功完成!');
|
||||
} catch (error) {
|
||||
console.error('❌ API测试失败:', error.message);
|
||||
if (error.response) {
|
||||
console.error('错误状态码:', error.response.status);
|
||||
console.error('错误数据:', error.response.data);
|
||||
} else if (error.request) {
|
||||
console.error('没有收到响应:', error.request);
|
||||
} else {
|
||||
console.error('请求配置错误:', error.message);
|
||||
}
|
||||
console.error('错误详情:', error);
|
||||
}
|
||||
}
|
||||
|
||||
testApi();
|
||||
Reference in New Issue
Block a user