Files
012-kaopeilian/tests/test_login.html
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

178 lines
5.8 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>登录测试</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 400px;
margin: 50px auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
color: #666;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 12px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: #0056b3;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.result {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
display: none;
}
.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
pre {
background: #f8f9fa;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>登录测试</h1>
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" value="testuser" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" value="123456" placeholder="请输入密码">
</div>
<button id="loginBtn" onclick="login()">登录</button>
<div id="result" class="result"></div>
</div>
<script>
async function login() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const resultDiv = document.getElementById('result');
const loginBtn = document.getElementById('loginBtn');
// 显示加载状态
loginBtn.disabled = true;
loginBtn.textContent = '登录中...';
resultDiv.style.display = 'none';
try {
const response = await fetch('/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
password: password
})
});
const data = await response.json();
if (response.ok && data.code === 200) {
// 登录成功
resultDiv.className = 'result success';
resultDiv.innerHTML = `
<h3>✅ 登录成功!</h3>
<p><strong>用户:</strong> ${data.data.user.username}</p>
<p><strong>角色:</strong> ${data.data.user.role}</p>
<p><strong>Token类型:</strong> ${data.data.token.token_type}</p>
<p><strong>Access Token:</strong> ${data.data.token.access_token.substring(0, 50)}...</p>
<p><strong>Refresh Token:</strong> ${data.data.token.refresh_token.substring(0, 50)}...</p>
`;
} else {
// 登录失败
resultDiv.className = 'result error';
resultDiv.innerHTML = `
<h3>❌ 登录失败</h3>
<p><strong>状态码:</strong> ${response.status}</p>
<p><strong>错误信息:</strong> ${data.message || data.detail || '未知错误'}</p>
<p><strong>完整响应:</strong></p>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
}
} catch (error) {
// 网络错误
resultDiv.className = 'result error';
resultDiv.innerHTML = `
<h3>❌ 网络错误</h3>
<p><strong>错误信息:</strong> ${error.message}</p>
<p>请检查:</p>
<ul>
<li>前端服务是否运行 (http://localhost:3001)</li>
<li>后端服务是否运行 (http://localhost:8000)</li>
<li>代理配置是否正确</li>
</ul>
`;
} finally {
// 恢复按钮状态
loginBtn.disabled = false;
loginBtn.textContent = '登录';
resultDiv.style.display = 'block';
}
}
// 页面加载时自动测试
window.addEventListener('load', function() {
console.log('页面加载完成');
});
</script>
</body>
</html>