// 调试性别和学历显示问题 const axios = require('axios'); async function testGenderEducationData() { try { // 使用GraphQL查询获取实际的参赛人详情数据 const query = ` query GetActivityPlayerDetail($id: ID!) { activityPlayerDetail(id: $id) { id projectName description playerInfo { id name gender birthday education userInfo { avatarUrl } } regionInfo { id name } } } `; // 测试几个不同的参赛人ID const testIds = [1, 2, 3]; // 可以根据实际数据调整 for (const id of testIds) { console.log(`\n=== 测试参赛人ID: ${id} ===`); try { const response = await axios.post('http://localhost:8080/api/graphql', { query: query, variables: { id: id.toString() } }, { headers: { 'Content-Type': 'application/json' } }); if (response.data.errors) { console.log('GraphQL错误:', response.data.errors); continue; } const detail = response.data.data?.activityPlayerDetail; if (!detail) { console.log('未找到数据'); continue; } console.log('原始后端数据:'); console.log(' 姓名:', detail.playerInfo.name); console.log(' 性别 (原始值):', detail.playerInfo.gender, typeof detail.playerInfo.gender); console.log(' 学历 (原始值):', detail.playerInfo.education, typeof detail.playerInfo.education); console.log(' 生日:', detail.playerInfo.birthday); console.log(' 地区:', detail.regionInfo?.name); // 模拟前端的性别转换逻辑 function getGenderText(gender) { console.log(' 性别转换输入:', gender, typeof gender); if (gender === 0) return '女' if (gender === 1) return '男' return '未填写' } const convertedGender = getGenderText(detail.playerInfo.gender); console.log(' 性别转换结果:', convertedGender); // 检查学历处理 const education = detail.playerInfo.education || ''; console.log(' 学历处理结果:', education || '未填写'); } catch (error) { console.log(`ID ${id} 查询失败:`, error.message); } } } catch (error) { console.error('测试失败:', error.message); } } testGenderEducationData();