为项目增加了一个后台页面, 用于显示IP代理的使用情况统计. 主要包括: - 新增 `backend` 目录, 包含 `index.html` 和 `script.js` 文件, 用于展示统计数据. - 在 `main.go` 中增加了 `setBackendRoute` 函数, 用于提供后台页面的路由. - 将后台页面路由设置为 `/admin`. 注意: 当前代码存在编译错误, 因为无法确定 `ipfilter.NewIPFilter` 的正确返回类型. 错误信息为 `undefined: ipfilter.IPFilter`. 提交此代码是为了让用户能够检查问题.
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
fetch('/api/stats')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const tableBody = document.getElementById('stats-table-body');
|
|
tableBody.innerHTML = ''; // 清空现有内容
|
|
|
|
for (const ip in data) {
|
|
const stats = data[ip];
|
|
const row = document.createElement('tr');
|
|
|
|
const ipCell = document.createElement('td');
|
|
ipCell.textContent = stats.ip;
|
|
row.appendChild(ipCell);
|
|
|
|
const callCountCell = document.createElement('td');
|
|
callCountCell.textContent = stats.call_count;
|
|
row.appendChild(callCountCell);
|
|
|
|
const transferredCell = document.createElement('td');
|
|
transferredCell.textContent = stats.total_transferred;
|
|
row.appendChild(transferredCell);
|
|
|
|
const lastCalledCell = document.createElement('td');
|
|
lastCalledCell.textContent = new Date(stats.last_called).toLocaleString();
|
|
row.appendChild(lastCalledCell);
|
|
|
|
tableBody.appendChild(row);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('获取统计数据时出错:', error);
|
|
const tableBody = document.getElementById('stats-table-body');
|
|
tableBody.innerHTML = '<tr><td colspan="4" class="text-center">加载统计数据失败</td></tr>';
|
|
});
|
|
});
|