Initial commit: Flutter 无书应用项目
This commit is contained in:
422
ht/test/index.html
Normal file
422
ht/test/index.html
Normal file
@@ -0,0 +1,422 @@
|
||||
<!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>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 25px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
font-size: 1.4rem;
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 14px 20px;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f7;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #e8e8ed;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e5e5ea;
|
||||
border-radius: 10px;
|
||||
font-size: 1rem;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.input-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.url-display {
|
||||
background: #f5f5f7;
|
||||
padding: 12px 16px;
|
||||
border-radius: 10px;
|
||||
font-family: 'SF Mono', Monaco, 'Courier New', monospace;
|
||||
font-size: 0.85rem;
|
||||
word-break: break-all;
|
||||
margin-bottom: 15px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.response-area {
|
||||
background: #1a1a2e;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
overflow: auto;
|
||||
max-height: 400px;
|
||||
}
|
||||
|
||||
.response-area pre {
|
||||
margin: 0;
|
||||
color: #a8e6cf;
|
||||
font-family: 'SF Mono', Monaco, 'Courier New', monospace;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 10px 15px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 0.9rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.status-loading {
|
||||
background: #cce5ff;
|
||||
color: #004085;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 25px;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.question-card .question {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.question-card .meta {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.question-card .meta span {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
padding: 5px 12px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.option-btn {
|
||||
background: white;
|
||||
border: 2px solid #e5e5ea;
|
||||
padding: 15px 20px;
|
||||
border-radius: 12px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.option-btn:hover {
|
||||
border-color: #667eea;
|
||||
background: #f8f9ff;
|
||||
}
|
||||
|
||||
.option-btn.correct {
|
||||
border-color: #34c759;
|
||||
background: #d4edda;
|
||||
}
|
||||
|
||||
.option-btn.wrong {
|
||||
border-color: #ff3b30;
|
||||
background: #f8d7da;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📚 诗词答题 API 测试</h1>
|
||||
<p>测试所有接口功能</p>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="card">
|
||||
<h2>🎯 接口测试</h2>
|
||||
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-primary" onclick="testQuestion()">📖 获取题目</button>
|
||||
<button class="btn btn-primary" onclick="testNext()">➡️ 下一题</button>
|
||||
<button class="btn btn-primary" onclick="testFetch()">🔄 获取新题</button>
|
||||
<button class="btn btn-primary" onclick="testList()">📋 题目列表</button>
|
||||
<button class="btn btn-primary" onclick="testRefresh()">🔃 刷新缓存</button>
|
||||
<button class="btn btn-primary" onclick="testStats()">📊 状态统计</button>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>题目 ID</label>
|
||||
<input type="number" id="questionId" value="0" placeholder="输入题目ID">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>答案 (1-4)</label>
|
||||
<input type="number" id="answer" value="1" placeholder="输入答案">
|
||||
</div>
|
||||
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-secondary" onclick="testAnswer()">✅ 提交答案</button>
|
||||
<button class="btn btn-secondary" onclick="testHint()">💡 获取提示</button>
|
||||
</div>
|
||||
|
||||
<div class="url-display" id="urlDisplay">等待请求...</div>
|
||||
|
||||
<div id="status"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>📤 响应结果</h2>
|
||||
<div id="questionPreview"></div>
|
||||
<div class="response-area">
|
||||
<pre id="response">点击左侧按钮开始测试...</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentQuestion = null;
|
||||
|
||||
function showStatus(msg, type) {
|
||||
const statusDiv = document.getElementById('status');
|
||||
const icons = {
|
||||
success: '✅',
|
||||
error: '❌',
|
||||
loading: '⏳'
|
||||
};
|
||||
statusDiv.innerHTML = `<div class="status status-${type}">${icons[type]} ${msg}</div>`;
|
||||
}
|
||||
|
||||
function showUrl(url) {
|
||||
document.getElementById('urlDisplay').textContent = url;
|
||||
}
|
||||
|
||||
function showResponse(data) {
|
||||
document.getElementById('response').textContent = JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
function showQuestion(data) {
|
||||
const preview = document.getElementById('questionPreview');
|
||||
if (!data || data.error) {
|
||||
preview.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
preview.innerHTML = `
|
||||
<div class="question-card">
|
||||
<div class="question">${data.question}</div>
|
||||
<div class="meta">
|
||||
<span>👤 ${data.author || '未知'}</span>
|
||||
<span>📅 ${data.dynasty || '未知'}</span>
|
||||
<span>📚 ${data.type || '未知'}</span>
|
||||
<span>🎓 ${data.grade || '未知'}</span>
|
||||
<span>📊 ${data.id + 1}/${data.total}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="options-list">
|
||||
${(data.options || []).map(opt => `
|
||||
<button class="option-btn" onclick="selectOption(${opt.index})">
|
||||
${opt.index}. ${opt.content}
|
||||
</button>
|
||||
`).join('')}
|
||||
</div>
|
||||
`;
|
||||
currentQuestion = data;
|
||||
}
|
||||
|
||||
function selectOption(index) {
|
||||
if (!currentQuestion) return;
|
||||
document.getElementById('answer').value = index;
|
||||
testAnswer();
|
||||
}
|
||||
|
||||
async function apiRequest(action, params = {}) {
|
||||
const query = new URLSearchParams({ action, ...params }).toString();
|
||||
const url = `api.php?${query}`;
|
||||
showUrl(url);
|
||||
showStatus('请求中...', 'loading');
|
||||
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
showStatus('请求成功', 'success');
|
||||
showResponse(data);
|
||||
|
||||
if (data.data && data.data.question) {
|
||||
showQuestion(data.data);
|
||||
} else {
|
||||
document.getElementById('questionPreview').innerHTML = '';
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (err) {
|
||||
showStatus('请求失败: ' + err.message, 'error');
|
||||
showResponse({ error: err.message });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function testQuestion() {
|
||||
const id = document.getElementById('questionId').value;
|
||||
apiRequest('question', { id });
|
||||
}
|
||||
|
||||
function testNext() {
|
||||
apiRequest('next');
|
||||
}
|
||||
|
||||
function testFetch() {
|
||||
apiRequest('fetch');
|
||||
}
|
||||
|
||||
function testAnswer() {
|
||||
const id = document.getElementById('questionId').value;
|
||||
const answer = document.getElementById('answer').value;
|
||||
apiRequest('answer', { id, answer });
|
||||
}
|
||||
|
||||
function testHint() {
|
||||
const id = document.getElementById('questionId').value;
|
||||
apiRequest('hint', { id });
|
||||
}
|
||||
|
||||
function testList() {
|
||||
apiRequest('list');
|
||||
}
|
||||
|
||||
function testRefresh() {
|
||||
apiRequest('refresh');
|
||||
}
|
||||
|
||||
function testStats() {
|
||||
apiRequest('stats');
|
||||
}
|
||||
|
||||
window.onload = () => {
|
||||
testQuestion();
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user