177 lines
5.9 KiB
HTML
177 lines
5.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>专业API测试</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 1000px;
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
.container {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
margin-bottom: 20px;
|
|
}
|
|
button {
|
|
background-color: #409EFF;
|
|
color: white;
|
|
padding: 10px 15px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
margin: 5px;
|
|
}
|
|
button:hover {
|
|
background-color: #337ecc;
|
|
}
|
|
.result {
|
|
margin-top: 10px;
|
|
padding: 15px;
|
|
background-color: #f0f9ff;
|
|
border-left: 4px solid #409EFF;
|
|
white-space: pre-wrap;
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
}
|
|
.error {
|
|
background-color: #fef0f0;
|
|
border-left-color: #f56c6c;
|
|
color: #f56c6c;
|
|
}
|
|
.success {
|
|
background-color: #f0f9ff;
|
|
border-left-color: #409EFF;
|
|
color: #409EFF;
|
|
}
|
|
.loading {
|
|
color: #666;
|
|
font-style: italic;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>专业管理API测试</h1>
|
|
<p>测试专业相关的API接口</p>
|
|
|
|
<h3>基础接口测试</h3>
|
|
<button onclick="testGetActiveMajors()">获取启用专业列表</button>
|
|
<button onclick="testGetAllMajors()">获取所有专业列表</button>
|
|
<button onclick="testGetStats()">获取统计信息</button>
|
|
|
|
<h3>搜索接口测试</h3>
|
|
<input type="text" id="searchName" placeholder="输入专业名称搜索" value="计算机">
|
|
<button onclick="testSearchMajors()">搜索专业</button>
|
|
|
|
<h3>分类接口测试</h3>
|
|
<select id="category">
|
|
<option value="工学">工学</option>
|
|
<option value="理学">理学</option>
|
|
<option value="文学">文学</option>
|
|
<option value="管理学">管理学</option>
|
|
<option value="经济学">经济学</option>
|
|
<option value="法学">法学</option>
|
|
<option value="教育学">教育学</option>
|
|
<option value="医学">医学</option>
|
|
</select>
|
|
<button onclick="testGetByCategory()">按类别查询</button>
|
|
|
|
<div id="result" class="result" style="display: none;"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_BASE = 'http://localhost:20006/api/major';
|
|
|
|
function showResult(message, isError = false) {
|
|
const result = document.getElementById('result');
|
|
result.textContent = message;
|
|
result.className = 'result ' + (isError ? 'error' : 'success');
|
|
result.style.display = 'block';
|
|
}
|
|
|
|
function showLoading() {
|
|
const result = document.getElementById('result');
|
|
result.textContent = '正在请求中...';
|
|
result.className = 'result loading';
|
|
result.style.display = 'block';
|
|
}
|
|
|
|
async function testGetActiveMajors() {
|
|
showLoading();
|
|
try {
|
|
const response = await fetch(`${API_BASE}/active`);
|
|
const data = await response.json();
|
|
showResult(JSON.stringify(data, null, 2));
|
|
} catch (error) {
|
|
showResult('请求失败: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
async function testGetAllMajors() {
|
|
showLoading();
|
|
try {
|
|
const response = await fetch(`${API_BASE}/list`);
|
|
const data = await response.json();
|
|
showResult(JSON.stringify(data, null, 2));
|
|
} catch (error) {
|
|
showResult('请求失败: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
async function testGetStats() {
|
|
showLoading();
|
|
try {
|
|
const response = await fetch(`${API_BASE}/stats`);
|
|
const data = await response.json();
|
|
showResult(JSON.stringify(data, null, 2));
|
|
} catch (error) {
|
|
showResult('请求失败: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
async function testSearchMajors() {
|
|
const searchName = document.getElementById('searchName').value;
|
|
if (!searchName) {
|
|
showResult('请输入搜索关键词', true);
|
|
return;
|
|
}
|
|
|
|
showLoading();
|
|
try {
|
|
const response = await fetch(`${API_BASE}/search?name=${encodeURIComponent(searchName)}`);
|
|
const data = await response.json();
|
|
showResult(JSON.stringify(data, null, 2));
|
|
} catch (error) {
|
|
showResult('请求失败: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
async function testGetByCategory() {
|
|
const category = document.getElementById('category').value;
|
|
showLoading();
|
|
try {
|
|
const response = await fetch(`${API_BASE}/category/${encodeURIComponent(category)}`);
|
|
const data = await response.json();
|
|
showResult(JSON.stringify(data, null, 2));
|
|
} catch (error) {
|
|
showResult('请求失败: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
// 页面加载时自动测试获取启用专业
|
|
window.onload = function() {
|
|
testGetActiveMajors();
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|