login-test.html
5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!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>
<script src="config.js"></script>
<style>
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
margin: 20px;
background: #f5f5f5;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.form-group {
margin: 15px 0;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}
.btn {
background: #2196f3;
color: white;
border: none;
padding: 12px 24px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
.btn:hover {
background: #1976d2;
}
.result {
margin-top: 20px;
padding: 15px;
border-radius: 5px;
white-space: pre-wrap;
font-family: monospace;
}
.result.success {
background: #e8f5e9;
border: 1px solid #4caf50;
color: #2e7d32;
}
.result.error {
background: #ffebee;
border: 1px solid #f44336;
color: #c62828;
}
.result.info {
background: #e3f2fd;
border: 1px solid #2196f3;
color: #1565c0;
}
</style>
</head>
<body>
<div class="container">
<h1>🔐 登录API测试页面</h1>
<div class="form-group">
<label for="username">用户名:</label>
<input type="text" id="username" value="admin" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" id="password" value="123456" placeholder="请输入密码">
</div>
<div class="form-group">
<button class="btn" onclick="testLogin()">测试登录</button>
<button class="btn" onclick="testConnection()">测试连接</button>
<button class="btn" onclick="clearResult()">清除结果</button>
</div>
<div id="result" class="result info" style="display: none;"></div>
</div>
<script>
// 测试登录
async function testLogin() {
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value.trim();
if (!username || !password) {
showResult('请输入用户名和密码', 'error');
return;
}
try {
const apiBaseUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : '';
if (!apiBaseUrl) {
throw new Error('API地址未配置');
}
showResult('正在测试登录...', 'info');
const formData = new URLSearchParams();
formData.append('account', username);
formData.append('password', password);
const response = await fetch(`${apiBaseUrl}/api/oauth/Login`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
},
body: formData
});
const result = await response.json();
if (response.ok) {
showResult(`✅ 登录成功!\n\n响应数据:\n${JSON.stringify(result, null, 2)}`, 'success');
} else {
showResult(`❌ 登录失败 (HTTP ${response.status})\n\n错误信息:\n${JSON.stringify(result, null, 2)}`, 'error');
}
} catch (error) {
showResult(`❌ 请求失败:\n${error.message}`, 'error');
}
}
// 测试连接
async function testConnection() {
try {
const apiBaseUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : '';
if (!apiBaseUrl) {
throw new Error('API地址未配置');
}
showResult('正在测试连接...', 'info');
const response = await fetch(`${apiBaseUrl}/api/oauth/Login`, {
method: 'GET'
});
if (response.status === 405) {
showResult('✅ 连接成功!API端点存在,但GET方法不被允许(这是正常的,因为登录需要POST方法)', 'success');
} else {
showResult(`连接状态: HTTP ${response.status}`, 'info');
}
} catch (error) {
showResult(`❌ 连接失败:\n${error.message}`, 'error');
}
}
// 显示结果
function showResult(message, type) {
const resultEl = document.getElementById('result');
resultEl.textContent = message;
resultEl.className = `result ${type}`;
resultEl.style.display = 'block';
}
// 清除结果
function clearResult() {
document.getElementById('result').style.display = 'none';
}
// 页面加载完成后显示配置信息
document.addEventListener('DOMContentLoaded', function() {
if (window.APP_CONFIG) {
const info = `当前环境: ${window.APP_CONFIG.getEnvName()}\nAPI地址: ${window.APP_CONFIG.getApiBaseUrl()}`;
showResult(info, 'info');
}
});
</script>
</body>
</html>