45 lines
1.5 KiB
HTML
45 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>API测试</title>
|
|
</head>
|
|
<body>
|
|
<h1>API测试页面</h1>
|
|
<button onclick="testStatistics()">测试统计API</button>
|
|
<div id="result"></div>
|
|
|
|
<script>
|
|
const API_BASE = '/api/v1';
|
|
|
|
async function testStatistics() {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.innerHTML = '加载中...';
|
|
|
|
try {
|
|
// 先登录
|
|
const loginResponse = await fetch(`${API_BASE}/auth/login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username: 'admin', password: 'admin123' })
|
|
});
|
|
const loginData = await loginResponse.json();
|
|
const token = loginData.data.token;
|
|
|
|
// 调用统计API
|
|
const statsResponse = await fetch(`${API_BASE}/projects/statistics/basic`, {
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
});
|
|
const statsData = await statsResponse.json();
|
|
|
|
resultDiv.innerHTML = `
|
|
<h2>统计结果:</h2>
|
|
<pre>${JSON.stringify(statsData, null, 2)}</pre>
|
|
<h3>项目总数:${statsData.data.total_count}</h3>
|
|
`;
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `<p style="color: red;">错误:${error.message}</p>`;
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |