Files
algorithm/frontend/public/test_algorithm_api.html

117 lines
4.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>测试算法API</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
.section {
margin-bottom: 20px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
.success {
color: green;
font-weight: bold;
}
.error {
color: red;
font-weight: bold;
}
.info {
color: blue;
}
pre {
background: #f5f5f5;
padding: 10px;
border-radius: 3px;
overflow-x: auto;
}
button {
padding: 10px 20px;
margin: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>测试算法API</h1>
<div class="section">
<h2>1. 测试GET /api/algorithms</h2>
<button onclick="testAlgorithmsApi()">测试算法API</button>
<div id="algorithmsResult"></div>
</div>
<div class="section">
<h2>2. 测试GET /api/v1/algorithms</h2>
<button onclick="testAlgorithmsApiV1()">测试算法API V1</button>
<div id="algorithmsResultV1"></div>
</div>
<script>
async function testAlgorithmsApi() {
const resultDiv = document.getElementById('algorithmsResult');
resultDiv.innerHTML = '<p class="info">正在测试...</p>';
try {
const response = await fetch('/api/algorithms', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = '<p class="success">✅ 算法API调用成功!</p>';
resultDiv.innerHTML += '<p>算法数量: ' + data.algorithms.length + '</p>';
resultDiv.innerHTML += '<pre>' + JSON.stringify(data.algorithms.map(a => ({name: a.name, id: a.id})), null, 2) + '</pre>';
} else {
resultDiv.innerHTML = '<p class="error">❌ 算法API调用失败!</p>';
resultDiv.innerHTML += '<p>状态码: ' + response.status + '</p>';
resultDiv.innerHTML += '<p>错误: ' + JSON.stringify(data) + '</p>';
}
} catch (error) {
resultDiv.innerHTML = '<p class="error">❌ 算法API请求失败!</p>';
resultDiv.innerHTML += '<p>错误: ' + error.message + '</p>';
}
}
async function testAlgorithmsApiV1() {
const resultDiv = document.getElementById('algorithmsResultV1');
resultDiv.innerHTML = '<p class="info">正在测试...</p>';
try {
const response = await fetch('/api/v1/algorithms', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = '<p class="success">✅ 算法API V1调用成功!</p>';
resultDiv.innerHTML += '<p>算法数量: ' + data.algorithms.length + '</p>';
resultDiv.innerHTML += '<pre>' + JSON.stringify(data.algorithms.map(a => ({name: a.name, id: a.id})), null, 2) + '</pre>';
} else {
resultDiv.innerHTML = '<p class="error">❌ 算法API V1调用失败!</p>';
resultDiv.innerHTML += '<p>状态码: ' + response.status + '</p>';
resultDiv.innerHTML += '<p>错误: ' + JSON.stringify(data) + '</p>';
}
} catch (error) {
resultDiv.innerHTML = '<p class="error">❌ 算法API V1请求失败!</p>';
resultDiv.innerHTML += '<p>错误: ' + error.message + '</p>';
}
}
</script>
</body>
</html>