test-api.html
5.95 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
190
191
192
193
194
195
<!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);
}
.test-item {
margin: 15px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 8px;
}
.test-item.success {
border-color: #4caf50;
background: #f1f8e9;
}
.test-item.error {
border-color: #f44336;
background: #ffebee;
}
.test-item.loading {
border-color: #2196f3;
background: #e3f2fd;
}
.btn {
background: #2196f3;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
.btn:hover {
background: #1976d2;
}
.status {
margin-top: 10px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>🌱 绿纤协同平台 - API连接测试</h1>
<div class="test-item">
<h3>当前配置信息</h3>
<p><strong>当前环境:</strong> <span id="currentEnv">-</span></p>
<p><strong>API地址:</strong> <span id="currentApiUrl">-</span></p>
<p><strong>环境描述:</strong> <span id="currentDesc">-</span></p>
</div>
<div class="test-item">
<h3>环境切换</h3>
<button class="btn" onclick="switchEnv('development')">切换到开发环境</button>
<button class="btn" onclick="switchEnv('production')">切换到正式环境</button>
</div>
<div class="test-item">
<h3>登录API测试</h3>
<button class="btn" onclick="testLoginAPI()">测试登录API</button>
<div class="status" id="loginStatus">-</div>
</div>
<div class="test-item">
<h3>拓客API测试</h3>
<button class="btn" onclick="testExpansionAPI()">测试拓客API</button>
<div class="status" id="expansionStatus">-</div>
</div>
<div class="test-item">
<h3>连接历史</h3>
<div id="connectionHistory"></div>
</div>
</div>
<script>
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
updateConfigInfo();
});
// 更新配置信息显示
function updateConfigInfo() {
if (window.APP_CONFIG) {
document.getElementById('currentEnv').textContent = window.APP_CONFIG.getEnvName();
document.getElementById('currentApiUrl').textContent = window.APP_CONFIG.getApiBaseUrl();
document.getElementById('currentDesc').textContent = window.APP_CONFIG.getEnvDescription();
}
}
// 切换环境
function switchEnv(env) {
if (window.APP_CONFIG && window.APP_CONFIG.switchEnvironment(env)) {
updateConfigInfo();
addHistory(`✅ 已切换到${window.APP_CONFIG.getEnvName()}`);
}
}
// 测试登录API
async function testLoginAPI() {
const statusEl = document.getElementById('loginStatus');
statusEl.textContent = '🔄 正在测试...';
try {
const apiBaseUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : '';
if (!apiBaseUrl) {
throw new Error('API地址未配置');
}
const response = await fetch(`${apiBaseUrl}/api/oauth/Login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'test',
password: 'test'
})
});
if (response.ok) {
statusEl.textContent = '✅ 登录API连接成功';
addHistory(`✅ 登录API测试成功: ${apiBaseUrl}/api/oauth/Login`);
} else {
statusEl.textContent = `❌ 登录API响应错误: HTTP ${response.status}`;
addHistory(`❌ 登录API测试失败: HTTP ${response.status}`);
}
} catch (error) {
statusEl.textContent = `❌ 登录API连接失败: ${error.message}`;
addHistory(`❌ 登录API测试失败: ${error.message}`);
}
}
// 测试拓客API
async function testExpansionAPI() {
const statusEl = document.getElementById('expansionStatus');
statusEl.textContent = '🔄 正在测试...';
try {
const apiBaseUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : '';
if (!apiBaseUrl) {
throw new Error('API地址未配置');
}
const response = await fetch(`${apiBaseUrl}/api/Extend/LqTkjlb`, {
method: 'GET'
});
if (response.ok) {
statusEl.textContent = '✅ 拓客API连接成功';
addHistory(`✅ 拓客API测试成功: ${apiBaseUrl}/api/Extend/LqTkjlb`);
} else {
statusEl.textContent = `❌ 拓客API响应错误: HTTP ${response.status}`;
addHistory(`❌ 拓客API测试失败: HTTP ${response.status}`);
}
} catch (error) {
statusEl.textContent = `❌ 拓客API连接失败: ${error.message}`;
addHistory(`❌ 拓客API测试失败: ${error.message}`);
}
}
// 添加连接历史
function addHistory(message) {
const historyEl = document.getElementById('connectionHistory');
const timestamp = new Date().toLocaleTimeString();
const historyItem = document.createElement('div');
historyItem.innerHTML = `<small>[${timestamp}]</small> ${message}`;
historyItem.style.marginBottom = '5px';
historyEl.appendChild(historyItem);
// 保持最多10条记录
if (historyEl.children.length > 10) {
historyEl.removeChild(historyEl.firstChild);
}
}
</script>
</body>
</html>