Files
nxxmdata/bank-frontend/test-personal-center.html

243 lines
8.2 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: 800px;
margin: 0 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 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.test-section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 6px;
}
.test-section h2 {
color: #1890ff;
margin-top: 0;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #1890ff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #40a9ff;
}
.result {
margin-top: 15px;
padding: 10px;
border-radius: 4px;
white-space: pre-wrap;
}
.success {
background-color: #f6ffed;
border: 1px solid #b7eb8f;
color: #52c41a;
}
.error {
background-color: #fff2f0;
border: 1px solid #ffccc7;
color: #ff4d4f;
}
.info {
background-color: #e6f7ff;
border: 1px solid #91d5ff;
color: #1890ff;
}
</style>
</head>
<body>
<div class="container">
<h1>个人中心功能测试</h1>
<!-- 登录测试 -->
<div class="test-section">
<h2>1. 用户登录测试</h2>
<div class="form-group">
<label>用户名:</label>
<input type="text" id="loginUsername" value="admin" placeholder="请输入用户名">
</div>
<div class="form-group">
<label>密码:</label>
<input type="password" id="loginPassword" value="NewPassword123" placeholder="请输入密码">
</div>
<button onclick="testLogin()">登录</button>
<div id="loginResult" class="result" style="display: none;"></div>
</div>
<!-- 获取用户信息测试 -->
<div class="test-section">
<h2>2. 获取用户信息测试</h2>
<button onclick="testGetUserInfo()">获取用户信息</button>
<div id="userInfoResult" class="result" style="display: none;"></div>
</div>
<!-- 修改密码测试 -->
<div class="test-section">
<h2>3. 修改密码测试</h2>
<div class="form-group">
<label>旧密码:</label>
<input type="password" id="oldPassword" value="NewPassword123" placeholder="请输入旧密码">
</div>
<div class="form-group">
<label>新密码:</label>
<input type="password" id="newPassword" value="Admin123456" placeholder="请输入新密码">
</div>
<button onclick="testChangePassword()">修改密码</button>
<div id="changePasswordResult" class="result" style="display: none;"></div>
</div>
<!-- 测试说明 -->
<div class="test-section">
<h2>测试说明</h2>
<div class="info">
<strong>测试账号:</strong><br>
• 管理员: admin / NewPassword123 (已修改)<br>
• 经理: manager001 / Manager123456<br>
• 员工: employee001 / Employee123456<br><br>
<strong>测试步骤:</strong><br>
1. 先使用管理员账号登录<br>
2. 获取用户信息验证API<br>
3. 测试修改密码功能<br>
4. 重新登录验证密码修改是否生效
</div>
</div>
</div>
<script>
const API_BASE = 'http://localhost:5351/api';
let authToken = '';
// 显示结果
function showResult(elementId, message, type = 'info') {
const element = document.getElementById(elementId);
element.style.display = 'block';
element.className = `result ${type}`;
element.textContent = message;
}
// 登录测试
async function testLogin() {
const username = document.getElementById('loginUsername').value;
const password = document.getElementById('loginPassword').value;
try {
const response = await fetch(`${API_BASE}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});
const data = await response.json();
if (data.success) {
authToken = data.data.token;
showResult('loginResult', `登录成功!\nToken: ${authToken.substring(0, 50)}...`, 'success');
} else {
showResult('loginResult', `登录失败: ${data.message}`, 'error');
}
} catch (error) {
showResult('loginResult', `请求失败: ${error.message}`, 'error');
}
}
// 获取用户信息测试
async function testGetUserInfo() {
if (!authToken) {
showResult('userInfoResult', '请先登录', 'error');
return;
}
try {
const response = await fetch(`${API_BASE}/auth/me`, {
headers: {
'Authorization': `Bearer ${authToken}`,
},
});
const data = await response.json();
if (data.success) {
showResult('userInfoResult', `获取用户信息成功!\n${JSON.stringify(data.data, null, 2)}`, 'success');
} else {
showResult('userInfoResult', `获取失败: ${data.message}`, 'error');
}
} catch (error) {
showResult('userInfoResult', `请求失败: ${error.message}`, 'error');
}
}
// 修改密码测试
async function testChangePassword() {
if (!authToken) {
showResult('changePasswordResult', '请先登录', 'error');
return;
}
const oldPassword = document.getElementById('oldPassword').value;
const newPassword = document.getElementById('newPassword').value;
try {
const response = await fetch(`${API_BASE}/auth/change-password`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ oldPassword, newPassword }),
});
const data = await response.json();
if (data.success) {
showResult('changePasswordResult', `密码修改成功!\n${data.message}`, 'success');
} else {
showResult('changePasswordResult', `修改失败: ${data.message}`, 'error');
}
} catch (error) {
showResult('changePasswordResult', `请求失败: ${error.message}`, 'error');
}
}
</script>
</body>
</html>