对话逻辑修复
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<!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>
|
||||
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
||||
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
|
||||
.test-button { background: #1890ff; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin: 5px; }
|
||||
.result { background: #f5f5f5; padding: 10px; border-radius: 4px; margin-top: 10px; white-space: pre-wrap; font-family: monospace; }
|
||||
.error { background: #fff2f0; border: 1px solid #ffccc7; color: #ff4d4f; }
|
||||
.success { background: #f6ffed; border: 1px solid #b7eb8f; color: #52c41a; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>消息API测试</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>Token设置</h3>
|
||||
<input type="text" id="tokenInput" placeholder="请输入JWT Token" style="width: 500px; padding: 5px;">
|
||||
<button class="test-button" onclick="loadToken()">从localStorage加载</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>API测试</h3>
|
||||
<button class="test-button" onclick="testGetUserMessages()">测试分页查询</button>
|
||||
<button class="test-button" onclick="testSearchMessages()">测试搜索消息</button>
|
||||
<button class="test-button" onclick="testRecentMessages()">测试最近消息</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>测试结果</h3>
|
||||
<div id="result" class="result">等待测试...</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function loadToken() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
document.getElementById('tokenInput').value = token;
|
||||
showResult('Token已加载', 'success');
|
||||
} else {
|
||||
showResult('localStorage中没有token', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function showResult(message, type = 'success') {
|
||||
const resultDiv = document.getElementById('result');
|
||||
resultDiv.textContent = message;
|
||||
resultDiv.className = `result ${type}`;
|
||||
}
|
||||
|
||||
async function makeRequest(url, options = {}) {
|
||||
const token = document.getElementById('tokenInput').value.trim();
|
||||
if (!token) {
|
||||
throw new Error('请先输入Token');
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
};
|
||||
|
||||
const response = await fetch(url, { ...options, headers });
|
||||
const data = await response.json();
|
||||
|
||||
return { status: response.status, data };
|
||||
}
|
||||
|
||||
async function testGetUserMessages() {
|
||||
try {
|
||||
showResult('正在测试分页查询...', 'success');
|
||||
|
||||
const result = await makeRequest('/message/user/page?current=1&size=5');
|
||||
|
||||
const message = `分页查询结果:
|
||||
状态码: ${result.status}
|
||||
响应: ${JSON.stringify(result.data, null, 2)}`;
|
||||
|
||||
showResult(message, result.status === 200 ? 'success' : 'error');
|
||||
} catch (error) {
|
||||
showResult(`分页查询错误: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function testSearchMessages() {
|
||||
try {
|
||||
showResult('正在测试搜索消息...', 'success');
|
||||
|
||||
const result = await makeRequest('/message/user/search', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ keyword: '测试', limit: 5 })
|
||||
});
|
||||
|
||||
const message = `搜索消息结果:
|
||||
状态码: ${result.status}
|
||||
响应: ${JSON.stringify(result.data, null, 2)}`;
|
||||
|
||||
showResult(message, result.status === 200 ? 'success' : 'error');
|
||||
} catch (error) {
|
||||
showResult(`搜索消息错误: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function testRecentMessages() {
|
||||
try {
|
||||
showResult('正在测试最近消息...', 'success');
|
||||
|
||||
const result = await makeRequest('/message/user/recent', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ limit: 5 })
|
||||
});
|
||||
|
||||
const message = `最近消息结果:
|
||||
状态码: ${result.status}
|
||||
响应: ${JSON.stringify(result.data, null, 2)}`;
|
||||
|
||||
showResult(message, result.status === 200 ? 'success' : 'error');
|
||||
} catch (error) {
|
||||
showResult(`最近消息错误: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时自动加载token
|
||||
window.onload = loadToken;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user