更改总计逻辑
This commit is contained in:
@@ -193,7 +193,7 @@ function stopGeneratePolling() {
|
||||
function initGenerateState() {
|
||||
const state = getGenerateState();
|
||||
if (state) {
|
||||
const { startTime } = state;
|
||||
const { startTime, configIds } = state;
|
||||
const now = Date.now();
|
||||
const elapsed = now - startTime;
|
||||
|
||||
@@ -208,11 +208,73 @@ function initGenerateState() {
|
||||
|
||||
const resultDiv = document.getElementById('generate-result');
|
||||
if (resultDiv) {
|
||||
resultDiv.innerHTML = '<div class="alert alert-info">检测到有正在生成的报表,请稍候...</div>';
|
||||
let html = '<div class="generate-loading">';
|
||||
html += '<div class="generate-loading-header">';
|
||||
html += '<div class="spinner"></div>';
|
||||
html += '<span class="generate-loading-title">检测到有正在生成的报表</span>';
|
||||
html += `<span class="generate-loading-progress">${configIds.length}个配置</span>`;
|
||||
html += '</div>';
|
||||
html += '<div class="generate-progress-bar">';
|
||||
html += '<div class="generate-progress-fill" style="width: 100%; animation: pulse 1.5s ease-in-out infinite;"></div>';
|
||||
html += '</div>';
|
||||
html += '<div style="font-size: 13px; color: #31708f; margin-top: 4px;">';
|
||||
html += '正在后台生成中,完成后将自动恢复...';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染生成中动态效果
|
||||
function renderGenerateLoading(configNames, currentIndex) {
|
||||
const total = configNames.length;
|
||||
const progress = Math.round((currentIndex / total) * 100);
|
||||
|
||||
let html = '<div class="generate-loading">';
|
||||
|
||||
html += '<div class="generate-loading-header">';
|
||||
html += '<div class="spinner"></div>';
|
||||
html += '<span class="generate-loading-title">正在生成日报</span>';
|
||||
html += `<span class="generate-loading-progress">${currentIndex}/${total}</span>`;
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="generate-progress-bar">';
|
||||
html += `<div class="generate-progress-fill" style="width: ${progress}%"></div>`;
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="generate-item-list">';
|
||||
configNames.forEach((name, index) => {
|
||||
let status = 'pending';
|
||||
let icon = '○';
|
||||
let statusText = '等待中';
|
||||
|
||||
if (index < currentIndex) {
|
||||
status = 'success';
|
||||
icon = '✓';
|
||||
statusText = '已完成';
|
||||
} else if (index === currentIndex) {
|
||||
status = 'running';
|
||||
icon = '●';
|
||||
statusText = '生成中...';
|
||||
}
|
||||
|
||||
html += `<div class="generate-item ${status}">`;
|
||||
html += `<span class="generate-item-icon ${status}">${icon}</span>`;
|
||||
html += `<span class="generate-item-name">${name}</span>`;
|
||||
html += `<span class="generate-item-status">${statusText}</span>`;
|
||||
html += '</div>';
|
||||
});
|
||||
html += '</div>';
|
||||
|
||||
html += '</div>';
|
||||
|
||||
const resultDiv = document.getElementById('generate-result');
|
||||
if (resultDiv) {
|
||||
resultDiv.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成日报(支持多选)
|
||||
async function generateReport() {
|
||||
if (isGenerating) {
|
||||
@@ -237,20 +299,23 @@ async function generateReport() {
|
||||
setGenerateControlsDisabled(true);
|
||||
|
||||
const configIds = Array.from(checkboxes).map(cb => parseInt(cb.value));
|
||||
const configNames = Array.from(checkboxes).map(cb => cb.dataset.name);
|
||||
const generateStartTime = Date.now();
|
||||
saveGenerateState(configIds, generateStartTime);
|
||||
startGeneratePolling();
|
||||
|
||||
const resultDiv = document.getElementById('generate-result');
|
||||
resultDiv.innerHTML = '<div class="alert alert-info">正在批量生成日报,请稍候...</div>';
|
||||
|
||||
renderGenerateLoading(configNames, 0);
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
let results = [];
|
||||
|
||||
for (const cb of checkboxes) {
|
||||
for (let i = 0; i < checkboxes.length; i++) {
|
||||
const cb = checkboxes[i];
|
||||
const configId = parseInt(cb.value);
|
||||
const configName = cb.dataset.name;
|
||||
|
||||
renderGenerateLoading(configNames, i);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/report/generate', {
|
||||
@@ -298,7 +363,10 @@ async function generateReport() {
|
||||
});
|
||||
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
const resultDiv = document.getElementById('generate-result');
|
||||
if (resultDiv) {
|
||||
resultDiv.innerHTML = html;
|
||||
}
|
||||
|
||||
isGenerating = false;
|
||||
setGenerateControlsDisabled(false);
|
||||
|
||||
Reference in New Issue
Block a user