You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.6 KiB
122 lines
4.6 KiB
@{
|
|
ViewData["Title"] = "统计测试";
|
|
}
|
|
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">统计功能测试</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h5>API测试</h5>
|
|
<button class="btn btn-primary mb-2" onclick="testGetAllStats()">获取所有统计数据</button>
|
|
<button class="btn btn-info mb-2" onclick="testGetLatestStats()">获取最新统计数据</button>
|
|
<button class="btn btn-success mb-2" onclick="testGetSummary()">获取统计摘要</button>
|
|
<button class="btn btn-warning mb-2" onclick="testClearStats()">清空统计数据</button>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h5>SSE测试</h5>
|
|
<button class="btn btn-primary mb-2" onclick="testSSE()">测试SSE连接</button>
|
|
<button class="btn btn-danger mb-2" onclick="stopSSE()">停止SSE</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mt-3">
|
|
<div class="col-12">
|
|
<h5>测试结果</h5>
|
|
<pre id="testResult" style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; max-height: 400px; overflow-y: auto;"></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@section Scripts {
|
|
<script>
|
|
let sseConnection = null;
|
|
|
|
function logResult(message) {
|
|
const result = document.getElementById('testResult');
|
|
const timestamp = new Date().toLocaleTimeString();
|
|
result.textContent += `[${timestamp}] ${message}\n`;
|
|
result.scrollTop = result.scrollHeight;
|
|
}
|
|
|
|
function testGetAllStats() {
|
|
logResult('测试获取所有统计数据...');
|
|
$.get('/Statistics/GetAllStats', function(response) {
|
|
logResult('响应: ' + JSON.stringify(response, null, 2));
|
|
}).fail(function(xhr, status, error) {
|
|
logResult('错误: ' + error);
|
|
});
|
|
}
|
|
|
|
function testGetLatestStats() {
|
|
logResult('测试获取最新统计数据...');
|
|
$.get('/Statistics/GetLatestStats', function(response) {
|
|
logResult('响应: ' + JSON.stringify(response, null, 2));
|
|
}).fail(function(xhr, status, error) {
|
|
logResult('错误: ' + error);
|
|
});
|
|
}
|
|
|
|
function testGetSummary() {
|
|
logResult('测试获取统计摘要...');
|
|
$.get('/Statistics/GetSummary', function(response) {
|
|
logResult('响应: ' + JSON.stringify(response, null, 2));
|
|
}).fail(function(xhr, status, error) {
|
|
logResult('错误: ' + error);
|
|
});
|
|
}
|
|
|
|
function testClearStats() {
|
|
logResult('测试清空统计数据...');
|
|
$.post('/Statistics/ClearStats', function(response) {
|
|
logResult('响应: ' + JSON.stringify(response, null, 2));
|
|
}).fail(function(xhr, status, error) {
|
|
logResult('错误: ' + error);
|
|
});
|
|
}
|
|
|
|
function testSSE() {
|
|
logResult('测试SSE连接...');
|
|
if (sseConnection) {
|
|
sseConnection.close();
|
|
}
|
|
|
|
sseConnection = new EventSource('/Statistics/SSEStats');
|
|
|
|
sseConnection.onopen = function(event) {
|
|
logResult('SSE连接已建立');
|
|
};
|
|
|
|
sseConnection.onmessage = function(event) {
|
|
logResult('SSE消息: ' + event.data);
|
|
};
|
|
|
|
sseConnection.onerror = function(event) {
|
|
logResult('SSE错误: ' + JSON.stringify(event));
|
|
};
|
|
}
|
|
|
|
function stopSSE() {
|
|
logResult('停止SSE连接...');
|
|
if (sseConnection) {
|
|
sseConnection.close();
|
|
sseConnection = null;
|
|
logResult('SSE连接已关闭');
|
|
}
|
|
}
|
|
|
|
// 页面加载时清空结果
|
|
$(document).ready(function() {
|
|
document.getElementById('testResult').textContent = '';
|
|
});
|
|
</script>
|
|
}
|