Codex Assistant
1 天以前 58d9f460b2f8c34430285115e2557d18333c5cab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 调试性别和学历显示问题
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();