50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
|
|
// 测试行政人员列表接口
|
|||
|
|
const axios = require('axios');
|
|||
|
|
|
|||
|
|
// 政府后端服务地址
|
|||
|
|
const BASE_URL = 'http://localhost:5352/api';
|
|||
|
|
|
|||
|
|
// 测试行政人员列表接口
|
|||
|
|
async function testAdminStaffList() {
|
|||
|
|
try {
|
|||
|
|
// 先登录获取token
|
|||
|
|
const loginResponse = await axios.post(`${BASE_URL}/auth/login`, {
|
|||
|
|
username: 'admin',
|
|||
|
|
password: '123456'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const token = loginResponse.data.token;
|
|||
|
|
console.log('登录成功,获取到token');
|
|||
|
|
|
|||
|
|
// 使用token访问行政人员列表接口
|
|||
|
|
const response = await axios.get(`${BASE_URL}/personnel`, {
|
|||
|
|
headers: {
|
|||
|
|
'Authorization': `Bearer ${token}`
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log('行政人员列表接口测试结果:');
|
|||
|
|
console.log(`- 状态码: ${response.status}`);
|
|||
|
|
console.log(`- 返回数据结构:`, Object.keys(response.data));
|
|||
|
|
console.log(`- 行政人员总数: ${response.data.total}`);
|
|||
|
|
console.log(`- 返回的行政人员列表长度: ${response.data.data ? response.data.data.length : 0}`);
|
|||
|
|
|
|||
|
|
if (response.data.data && response.data.data.length > 0) {
|
|||
|
|
console.log(`- 第一条行政人员数据:`, response.data.data[0]);
|
|||
|
|
} else {
|
|||
|
|
console.log('- 行政人员列表为空');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('\n测试完成!');
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('测试失败:', error.message);
|
|||
|
|
if (error.response) {
|
|||
|
|
console.error('错误状态码:', error.response.status);
|
|||
|
|
console.error('错误数据:', error.response.data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 执行测试
|
|||
|
|
console.log('开始测试行政人员列表接口...');
|
|||
|
|
testAdminStaffList();
|