gongxiangp2/test-viewable-types.html

97 lines
3.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试素材类型 API</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 50px auto;
padding: 20px;
}
.result {
background: #f5f5f5;
padding: 20px;
border-radius: 5px;
margin-top: 20px;
white-space: pre-wrap;
font-family: monospace;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background: #007bff;
color: white;
border: none;
border-radius: 5px;
}
button:hover {
background: #0056b3;
}
.error {
color: red;
}
.success {
color: green;
}
</style>
</head>
<body>
<h1>测试素材类型 API</h1>
<p>这个页面用于测试 <code>/api/materials/viewable-types</code> API</p>
<button onclick="testAPI()">测试 API</button>
<div id="result" class="result"></div>
<script>
async function testAPI() {
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = '正在请求...';
try {
const response = await fetch('http://192.168.58.20:5320/api/materials/viewable-types', {
method: 'GET',
credentials: 'include', // 包含 cookies
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `<div class="success">✅ 请求成功</div>\n\n`;
resultDiv.innerHTML += `状态码: ${response.status}\n\n`;
resultDiv.innerHTML += `返回数据:\n${JSON.stringify(data, null, 2)}\n\n`;
if (data.materialTypes && Array.isArray(data.materialTypes)) {
resultDiv.innerHTML += `\n素材类型数量: ${data.materialTypes.length}\n\n`;
resultDiv.innerHTML += `包含"任务-"的类型:\n`;
const taskTypes = data.materialTypes.filter(t => t.startsWith('任务-'));
resultDiv.innerHTML += JSON.stringify(taskTypes, null, 2);
}
} else {
resultDiv.innerHTML = `<div class="error">❌ 请求失败</div>\n\n`;
resultDiv.innerHTML += `状态码: ${response.status}\n\n`;
resultDiv.innerHTML += `错误信息:\n${JSON.stringify(data, null, 2)}`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error">❌ 请求异常</div>\n\n`;
resultDiv.innerHTML += `错误: ${error.message}\n\n`;
resultDiv.innerHTML += `提示: 请确保你已经登录影子系统(http://192.168.58.20:5320)`;
}
}
// 页面加载时自动测试
window.addEventListener('load', () => {
document.getElementById('result').innerHTML = '点击按钮开始测试,或者等待自动测试...';
// 延迟 2 秒自动测试
setTimeout(testAPI, 2000);
});
</script>
</body>
</html>