feat: 新增自动下载 API 和设置页面 UI

This commit is contained in:
2026-04-29 16:18:31 +08:00
parent 89b01bb522
commit 75bdc94cfe
5 changed files with 808 additions and 0 deletions
+257
View File
@@ -681,6 +681,248 @@ body {
}
}
/* Accent Button */
.btn-accent {
background: linear-gradient(135deg, #10b981, #059669);
color: white;
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-accent:hover {
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.5);
transform: translateY(-2px);
}
.btn-accent:active {
transform: scale(0.98);
}
/* Settings Page */
.settings-nav {
margin-bottom: 20px;
}
.settings-section {
padding: 24px;
margin-bottom: 20px;
}
.settings-section .section-header {
margin-bottom: 20px;
}
.settings-section .section-header h2 {
font-size: 18px;
font-weight: 600;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 8px;
}
.settings-section .section-header h2 i {
color: var(--primary-color);
}
.settings-form {
display: flex;
flex-direction: column;
gap: 16px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 13px;
font-weight: 500;
color: var(--text-secondary);
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="time"],
.form-input {
padding: 10px 14px;
border: 1px solid #e2e8f0;
border-radius: 10px;
font-size: 14px;
background: white;
transition: all 0.2s;
}
.form-group input:focus,
.form-input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}
.form-row {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.password-wrapper {
position: relative;
display: flex;
align-items: center;
}
.password-wrapper input {
flex: 1;
padding-right: 40px;
}
.btn-toggle-pwd {
position: absolute;
right: 10px;
background: none;
border: none;
cursor: pointer;
color: var(--text-tertiary);
font-size: 14px;
padding: 4px;
}
.btn-toggle-pwd:hover {
color: var(--primary-color);
}
/* Toggle Switch */
.switch {
position: relative;
display: inline-block;
width: 44px;
height: 24px;
flex-shrink: 0;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #cbd5e1;
transition: 0.3s;
border-radius: 24px;
}
.slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: 0.3s;
border-radius: 50%;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
input:checked + .slider {
background-color: var(--primary-color);
}
input:checked + .slider:before {
transform: translateX(20px);
}
.form-hint {
font-size: 12px;
color: var(--text-tertiary);
display: flex;
align-items: center;
gap: 6px;
padding: 8px 0;
}
.form-hint i {
color: var(--primary-light);
}
/* Status Panel */
.status-panel {
display: flex;
flex-direction: column;
gap: 12px;
}
.status-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}
.status-item:last-child {
border-bottom: none;
}
.status-label {
font-size: 13px;
color: var(--text-secondary);
}
.status-value {
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
}
.status-ok {
color: #10b981;
}
.status-off {
color: #94a3b8;
}
.settings-actions {
text-align: center;
padding: 20px 0 40px;
}
/* Auto Download Modal */
.download-status {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
background: rgba(99, 102, 241, 0.05);
border-radius: 10px;
margin-top: 12px;
font-size: 13px;
color: var(--text-secondary);
}
.loader-dots.small div {
width: 6px;
height: 6px;
}
.modal-actions {
display: flex;
gap: 12px;
justify-content: flex-end;
margin-top: 20px;
}
/* Mobile Response */
@media (max-width: 640px) {
.app-container {
@@ -747,4 +989,19 @@ body {
align-items: center;
gap: 8px;
}
.form-row {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.modal-actions {
flex-direction: column;
}
.modal-actions .btn {
width: 100%;
justify-content: center;
}
}
+103
View File
@@ -395,6 +395,109 @@ function closeUploadModal() {
elements.uploadModal.classList.remove('active');
}
// --- Auto Download ---
let autoDownloadPollTimer = null;
function openAutoDownloadModal() {
const modal = document.getElementById('autoDownloadModal');
// 默认日期为昨天
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const dateStr = yesterday.toISOString().split('T')[0];
document.getElementById('autoStartDate').value = dateStr;
document.getElementById('autoEndDate').value = dateStr;
document.getElementById('autoDownloadStatus').style.display = 'none';
document.getElementById('autoDownloadBtn').disabled = false;
modal.classList.add('active');
}
function closeAutoDownloadModal() {
const modal = document.getElementById('autoDownloadModal');
modal.classList.remove('active');
if (autoDownloadPollTimer) {
clearInterval(autoDownloadPollTimer);
autoDownloadPollTimer = null;
}
}
function startAutoDownload() {
const startDate = document.getElementById('autoStartDate').value;
const endDate = document.getElementById('autoEndDate').value;
if (!startDate) {
alert('请选择开始日期');
return;
}
const btn = document.getElementById('autoDownloadBtn');
btn.disabled = true;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 下载中...';
const statusDiv = document.getElementById('autoDownloadStatus');
const statusText = document.getElementById('autoDownloadStatusText');
statusDiv.style.display = 'flex';
statusText.textContent = '正在启动下载任务...';
fetch('/api/auto-download', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ start_date: startDate, end_date: endDate || startDate })
})
.then(res => res.json())
.then(data => {
if (data.success) {
statusText.textContent = data.message;
// 开始轮询状态
pollAutoDownloadStatus();
} else {
statusText.textContent = data.error || '启动失败';
btn.disabled = false;
btn.innerHTML = '<i class="fas fa-download"></i> 重试';
}
})
.catch(err => {
statusText.textContent = '请求失败: ' + err.message;
btn.disabled = false;
btn.innerHTML = '<i class="fas fa-download"></i> 重试';
});
}
function pollAutoDownloadStatus() {
if (autoDownloadPollTimer) clearInterval(autoDownloadPollTimer);
autoDownloadPollTimer = setInterval(() => {
fetch('/api/auto-download/status')
.then(res => res.json())
.then(data => {
if (data.success) {
const status = data.status;
const statusText = document.getElementById('autoDownloadStatusText');
const btn = document.getElementById('autoDownloadBtn');
statusText.textContent = status.message;
if (!status.running) {
clearInterval(autoDownloadPollTimer);
autoDownloadPollTimer = null;
btn.disabled = false;
btn.innerHTML = '<i class="fas fa-download"></i> 开始下载';
if (status.last_file) {
// 下载成功,刷新文件列表
setTimeout(() => {
closeAutoDownloadModal();
loadFileList();
}, 1500);
}
}
}
})
.catch(() => { });
}, 2000);
}
function showLoading(show, text) {
elements.loadingOverlay.style.display = show ? 'flex' : 'none';
if (text) elements.loadingText.textContent = text;