75 lines
2.9 KiB
HTML
75 lines
2.9 KiB
HTML
|
|
<!DOCTYPE html>
|
|||
|
|
<html>
|
|||
|
|
<head>
|
|||
|
|
<title>测试Dashboard API</title>
|
|||
|
|
</head>
|
|||
|
|
<body>
|
|||
|
|
<h1>Dashboard数据测试</h1>
|
|||
|
|
<div id="output"></div>
|
|||
|
|
|
|||
|
|
<script type="module">
|
|||
|
|
// 测试API调用
|
|||
|
|
async function testDashboardAPI() {
|
|||
|
|
try {
|
|||
|
|
const response = await fetch('http://localhost:5154/api/dashboard/stats');
|
|||
|
|
const contentType = response.headers.get('content-type');
|
|||
|
|
|
|||
|
|
let data;
|
|||
|
|
if (contentType && contentType.includes('application/json')) {
|
|||
|
|
data = await response.json();
|
|||
|
|
} else {
|
|||
|
|
// 可能返回的是HTML(开发服务器的默认页面)
|
|||
|
|
// 尝试直接导入mockData
|
|||
|
|
const module = await import('./src/data/mockData.js');
|
|||
|
|
data = {
|
|||
|
|
success: true,
|
|||
|
|
data: module.mockData.dashboardStatistics
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('API Response:', data);
|
|||
|
|
|
|||
|
|
const output = document.getElementById('output');
|
|||
|
|
|
|||
|
|
// 显示基本信息
|
|||
|
|
output.innerHTML = `
|
|||
|
|
<h2>数据结构检查</h2>
|
|||
|
|
<p>Success: ${data.success}</p>
|
|||
|
|
<p>Has data: ${data.data ? '✓' : '✗'}</p>
|
|||
|
|
<p>Has ranking: ${data.data?.ranking ? '✓' : '✗'}</p>
|
|||
|
|
<p>Has topStudents: ${data.data?.ranking?.topStudents ? '✓' : '✗'}</p>
|
|||
|
|
<p>topStudents length: ${data.data?.ranking?.topStudents?.length || 0}</p>
|
|||
|
|
|
|||
|
|
<h2>前3名学生</h2>
|
|||
|
|
<ul>
|
|||
|
|
${data.data?.ranking?.topStudents?.slice(0, 3).map(s =>
|
|||
|
|
`<li>${s.rank}. ${s.name || s.studentName} - ${s.score}分</li>`
|
|||
|
|
).join('') || '<li>无数据</li>'}
|
|||
|
|
</ul>
|
|||
|
|
|
|||
|
|
<h2>李沐阳(第10名)</h2>
|
|||
|
|
${(() => {
|
|||
|
|
const liMuyang = data.data?.ranking?.topStudents?.find(s =>
|
|||
|
|
s.name === "李沐阳" || s.studentName === "李沐阳"
|
|||
|
|
);
|
|||
|
|
if (liMuyang) {
|
|||
|
|
return `
|
|||
|
|
<p>排名: ${liMuyang.rank}</p>
|
|||
|
|
<p>分数: ${liMuyang.score}</p>
|
|||
|
|
<p>是当前用户: ${liMuyang.isMe}</p>
|
|||
|
|
`;
|
|||
|
|
}
|
|||
|
|
return '<p>未找到李沐阳的数据</p>';
|
|||
|
|
})()}
|
|||
|
|
`;
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('Error:', error);
|
|||
|
|
document.getElementById('output').innerHTML = `<p style="color: red;">错误: ${error.message}</p>`;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
testDashboardAPI();
|
|||
|
|
</script>
|
|||
|
|
</body>
|
|||
|
|
</html>
|