// 测试行政人员管理API接口 import axios from 'axios'; // 创建axios实例 const instance = axios.create({ baseURL: 'http://localhost:5352/api', timeout: 10000, headers: { 'Content-Type': 'application/json' } }); // 登录获取token const login = async () => { try { const response = await instance.post('/auth/login', { username: 'admin', password: '123456' }); console.log('登录成功,获取到token'); return response.data.token; } catch (error) { console.error('登录失败:', error.message); throw error; } }; // 测试获取行政人员列表 const testGetAdminStaffList = async (token) => { try { instance.defaults.headers.common['Authorization'] = `Bearer ${token}`; const response = await instance.get('/personnel'); console.log('\n获取行政人员列表成功:'); console.log('- 状态码:', response.status); console.log('- 返回数据结构:', Object.keys(response.data)); console.log('- 行政人员总数:', response.data.total); console.log('- 返回的行政人员列表长度:', response.data.data.length); if (response.data.data.length > 0) { console.log('- 第一条行政人员数据:', response.data.data[0]); } return response.data; } catch (error) { console.error('获取行政人员列表失败:', error.message); throw error; } }; // 主测试函数 const runTests = async () => { console.log('开始测试行政人员管理API...'); try { // 1. 登录获取token const token = await login(); // 2. 测试获取行政人员列表 await testGetAdminStaffList(token); console.log('\n所有测试完成!'); } catch (error) { console.error('测试失败:', error); } }; // 运行测试 runTests();