Files
SmartChat/static/js/daily_report.js
lychang 43cb0ff431 init
2025-11-05 01:43:15 +08:00

86 lines
3.0 KiB
JavaScript

// 设置默认日期为今天
document.getElementById('date').value = new Date().toISOString().split('T')[0];
function showLoading() {
document.getElementById('loading').style.display = 'block';
document.getElementById('report-container').style.display = 'none';
document.getElementById('error').style.display = 'none';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
function showError(message) {
document.getElementById('error').style.display = 'block';
document.getElementById('error').textContent = message;
}
function generateTodayReport() {
document.getElementById('date').value = new Date().toISOString().split('T')[0];
generateReport();
}
function generateReport() {
const date = document.getElementById('date').value;
if (!date) {
showError('请选择日期');
return;
}
showLoading();
fetch(`/api/reports/daily?date=${date}`)
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
document.getElementById('report-content').textContent = data.report;
document.getElementById('report-container').style.display = 'block';
// 显示统计数据
if (data.statistics) {
displayStatistics(data.statistics);
document.getElementById('statistics').style.display = 'block';
}
} else {
showError('生成日报失败:' + data.error);
}
})
.catch(error => {
hideLoading();
showError('网络错误:' + error.message);
});
}
function displayStatistics(stats) {
const statGrid = document.getElementById('stat-grid');
statGrid.innerHTML = '';
const statistics = [
{label: '今日消息量', value: stats.today_message_count, unit: '条'},
{label: '昨日消息量', value: stats.yesterday_message_count, unit: '条'},
{label: '消息变化率', value: stats.message_change_rate.toFixed(1), unit: '%'},
{label: '今日活跃用户', value: stats.today_active_users, unit: '人'},
{label: '昨日活跃用户', value: stats.yesterday_active_users, unit: '人'},
{label: '用户变化率', value: stats.user_change_rate.toFixed(1), unit: '%'},
{label: '群组数量', value: stats.group_count, unit: '个'},
{label: '成员总数', value: stats.member_count, unit: '人'}
];
statistics.forEach(stat => {
const statItem = document.createElement('div');
statItem.className = 'stat-item';
statItem.innerHTML = `
<div class="stat-value">${stat.value}${stat.unit}</div>
<div class="stat-label">${stat.label}</div>
`;
statGrid.appendChild(statItem);
});
}
// 页面加载时自动生成今日日报
window.addEventListener('load', function () {
generateTodayReport();
});