Feat: Complete UI redesign, backend optimization, and Docker deployment support

This commit is contained in:
2026-01-10 18:54:14 +08:00
commit fd8f6f7a02
9 changed files with 1856 additions and 0 deletions
+646
View File
@@ -0,0 +1,646 @@
/* Modern Color Palette & Reset */
:root {
--primary-color: #6366f1;
/* Indigo */
--secondary-color: #8b5cf6;
/* Violet */
--accent-color: #ec4899;
/* Pink */
--bg-color: #f8fafc;
--text-primary: #1e293b;
--text-secondary: #64748b;
--card-bg: rgba(255, 255, 255, 0.9);
--glass-border: 1px solid rgba(255, 255, 255, 0.4);
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--radius-lg: 16px;
--radius-md: 12px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background: var(--bg-color);
background-image:
radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.15) 0px, transparent 50%);
background-attachment: fixed;
color: var(--text-primary);
line-height: 1.5;
min-height: 100vh;
}
/* Glassmorphism Utilities */
.glass-card {
background: var(--card-bg);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: var(--glass-border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
}
/* Layout */
.app-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Header */
.main-header {
text-align: center;
padding: 40px 0 30px;
}
.logo {
display: inline-flex;
align-items: center;
gap: 12px;
color: var(--primary-color);
margin-bottom: 8px;
}
.logo i {
font-size: 28px;
}
.logo h1 {
font-size: 28px;
font-weight: 800;
letter-spacing: -0.5px;
}
.subtitle {
color: var(--text-secondary);
font-size: 14px;
font-weight: 500;
}
/* Upload Section */
.upload-section {
padding: 24px;
margin-bottom: 24px;
transition: transform 0.3s ease;
}
.upload-section:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.section-header h2 {
font-size: 18px;
font-weight: 600;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 20px;
}
.section-header h2 i {
color: var(--accent-color);
}
.upload-controls {
display: flex;
flex-wrap: wrap;
gap: 16px;
align-items: center;
}
.btn {
border: none;
cursor: pointer;
font-weight: 600;
font-size: 14px;
border-radius: 50px;
padding: 10px 20px;
transition: all 0.2s;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn-lg {
padding: 12px 28px;
font-size: 15px;
}
.btn-primary {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: white;
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:active {
transform: scale(0.98);
}
.btn-text {
background: transparent;
color: var(--text-secondary);
padding: 8px 12px;
}
.btn-text:hover {
color: var(--accent-color);
background: rgba(236, 72, 153, 0.05);
}
.btn-outline {
border: 1px solid #e2e8f0;
background: white;
color: var(--text-secondary);
}
.btn-outline:hover {
border-color: var(--primary-color);
color: var(--primary-color);
}
/* File List Tags */
.file-selector-wrapper {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
overflow-x: auto;
padding-bottom: 4px;
}
.file-selector-wrapper .label {
font-size: 12px;
color: var(--text-secondary);
white-space: nowrap;
}
.file-tags {
display: flex;
gap: 8px;
}
.file-tag {
font-size: 12px;
padding: 4px 12px;
background: rgba(255, 255, 255, 0.6);
border: 1px solid #e2e8f0;
border-radius: 20px;
color: var(--text-secondary);
cursor: pointer;
white-space: nowrap;
transition: all 0.2s;
}
.file-tag.active {
background: rgba(99, 102, 241, 0.1);
color: var(--primary-color);
border-color: rgba(99, 102, 241, 0.3);
font-weight: 500;
}
/* Dashboard Grid */
.summary-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: white;
padding: 20px;
border-radius: var(--radius-md);
box-shadow: var(--shadow-sm);
display: flex;
align-items: center;
gap: 16px;
border: 1px solid #f1f5f9;
}
.icon-circle {
width: 48px;
height: 48px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
flex-shrink: 0;
}
.total-sales .icon-circle {
background: rgba(99, 102, 241, 0.1);
color: var(--primary-color);
}
.total-count .icon-circle {
background: rgba(236, 72, 153, 0.1);
color: var(--accent-color);
}
.total-days .icon-circle {
background: rgba(16, 185, 129, 0.1);
color: #10b981;
}
.total-products .icon-circle {
background: rgba(245, 158, 11, 0.1);
color: #f59e0b;
}
.stat-content {
display: flex;
flex-direction: column;
}
.stat-label {
font-size: 12px;
color: var(--text-secondary);
margin-bottom: 2px;
}
.stat-value {
font-size: 18px;
font-weight: 700;
color: var(--text-primary);
}
/* Toolbar */
.toolbar {
padding: 12px 16px;
display: flex;
flex-wrap: wrap;
gap: 16px;
align-items: center;
justify-content: space-between;
margin-bottom: 24px;
}
.search-wrapper {
position: relative;
flex: 1;
min-width: 200px;
}
.search-wrapper i {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
color: var(--text-secondary);
font-size: 14px;
}
.search-wrapper input {
width: 100%;
padding: 10px 10px 10px 36px;
border: 1px solid #e2e8f0;
border-radius: 20px;
background: white;
font-size: 14px;
transition: all 0.2s;
}
.search-wrapper input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}
.filter-group {
display: flex;
gap: 8px;
overflow-x: auto;
padding-bottom: 2px;
}
.filter-chip {
padding: 6px 16px;
border-radius: 20px;
font-size: 13px;
border: 1px solid transparent;
background: transparent;
color: var(--text-secondary);
cursor: pointer;
white-space: nowrap;
}
.filter-chip.active {
background: white;
color: var(--primary-color);
box-shadow: var(--shadow-sm);
font-weight: 600;
}
/* Daily List */
.day-card {
margin-bottom: 16px;
border: 1px solid rgba(255, 255, 255, 0.5);
overflow: hidden;
}
.day-header {
padding: 16px 20px;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
background: rgba(255, 255, 255, 0.4);
}
.day-info {
display: flex;
flex-direction: row;
/* Changed from column */
align-items: center;
/* Align vertically */
gap: 12px;
}
.day-info .date {
font-weight: 600;
color: var(--text-primary);
font-size: 15px;
}
.day-info .summary {
font-size: 12px;
color: var(--text-secondary);
}
.toggle-icon {
transition: transform 0.3s;
color: var(--text-secondary);
font-size: 12px;
}
.day-card.expanded .toggle-icon {
transform: rotate(180deg);
}
.day-details {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out;
background: rgba(255, 255, 255, 0.3);
}
.day-card.expanded .day-details {
max-height: 2000px;
}
.product-item {
padding: 12px 20px;
border-top: 1px solid rgba(226, 232, 240, 0.6);
display: flex;
justify-content: space-between;
align-items: center;
font-size: 13px;
}
.p-name {
font-weight: 500;
color: var(--text-primary);
flex: 1;
padding-right: 12px;
}
.p-meta {
display: flex;
align-items: center;
gap: 12px;
color: var(--text-secondary);
}
.p-price {
font-size: 12px;
color: #94a3b8;
}
.p-total {
font-weight: 600;
color: var(--primary-color);
min-width: 60px;
text-align: right;
}
/* Empty State */
.empty-state {
text-align: center;
padding: 60px 20px;
color: var(--text-secondary);
}
.illustration {
font-size: 64px;
color: #cbd5e1;
margin-bottom: 16px;
}
.empty-state h3 {
color: var(--text-primary);
margin-bottom: 8px;
}
/* Modals & Overlays */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
z-index: 1000;
}
.modal-overlay.active {
opacity: 1;
pointer-events: auto;
}
.modal-card {
background: white;
width: 90%;
max-width: 400px;
border-radius: 24px;
padding: 24px;
transform: scale(0.9);
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .modal-card {
transform: scale(1);
}
.modal-header {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.modal-header h3 {
font-size: 18px;
}
.btn-close {
background: none;
border: none;
font-size: 18px;
cursor: pointer;
color: var(--text-secondary);
}
.drop-zone {
border: 2px dashed #e2e8f0;
border-radius: 16px;
padding: 40px 20px;
text-align: center;
cursor: pointer;
transition: all 0.2s;
}
.drop-zone:hover,
.drop-zone.active {
border-color: var(--primary-color);
background: rgba(99, 102, 241, 0.05);
}
.drop-zone .icon-wrapper {
font-size: 32px;
color: var(--primary-color);
margin-bottom: 12px;
}
.support-text {
display: block;
font-size: 12px;
color: #94a3b8;
margin-top: 8px;
}
/* Loading */
.loading-overlay {
position: fixed;
inset: 0;
background: rgba(255, 255, 255, 0.9);
z-index: 2000;
display: none;
align-items: center;
justify-content: center;
flex-direction: column;
}
.loader-dots div {
width: 10px;
height: 10px;
background: var(--primary-color);
border-radius: 50%;
display: inline-block;
animation: bounce 1.4s infinite ease-in-out both;
margin: 0 3px;
}
.loader-dots div:nth-child(1) {
animation-delay: -0.32s;
}
.loader-dots div:nth-child(2) {
animation-delay: -0.16s;
}
@keyframes bounce {
0%,
80%,
100% {
transform: scale(0);
}
40% {
transform: scale(1);
}
}
/* Mobile Response */
@media (max-width: 640px) {
.app-container {
padding: 12px;
}
.main-header {
padding: 24px 0 20px;
}
.logo h1 {
font-size: 24px;
}
.upload-controls {
flex-direction: column;
align-items: stretch;
}
.btn-block {
width: 100%;
justify-content: center;
}
.summary-cards {
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.stat-card {
padding: 16px;
flex-direction: column;
text-align: center;
gap: 8px;
}
.stat-value {
font-size: 16px;
}
.icon-circle {
width: 36px;
height: 36px;
font-size: 16px;
margin-bottom: 4px;
}
.toolbar {
flex-direction: column;
align-items: stretch;
gap: 16px;
}
.search-wrapper {
width: 100%;
}
.filter-group {
justify-content: space-between;
}
.p-meta {
flex-direction: row;
align-items: center;
gap: 8px;
}
}
+340
View File
@@ -0,0 +1,340 @@
// DOM Elements
const elements = {
uploadArea: document.getElementById('uploadArea'),
fileInput: document.getElementById('fileInput'),
loadingOverlay: document.getElementById('loadingOverlay'),
loadingText: document.getElementById('loadingText'),
noData: document.getElementById('noData'),
dataDisplay: document.getElementById('dataDisplay'),
uploadModal: document.getElementById('uploadModal'),
fileList: document.getElementById('fileList'),
fileSelector: document.getElementById('fileSelector'),
dailyData: document.getElementById('dailyData'),
searchInput: document.getElementById('searchInput'),
// Stats
totalAmount: document.getElementById('totalAmount'),
totalQuantity: document.getElementById('totalQuantity'),
totalDays: document.getElementById('totalDays'),
totalProducts: document.getElementById('totalProducts')
};
// State
let state = {
allData: null,
filteredData: null,
currentFilter: 'all',
searchTerm: '',
currentFile: null,
fileList: [],
currentPage: 1,
itemsPerPage: 50
};
// --- Event Listeners ---
document.addEventListener('DOMContentLoaded', () => {
loadFileList();
if (elements.searchInput) {
elements.searchInput.addEventListener('input', (e) => {
state.searchTerm = e.target.value.toLowerCase();
applyFilters();
});
}
});
if (elements.fileInput) {
elements.fileInput.addEventListener('change', (e) => handleFile(e.target.files[0]));
}
if (elements.uploadArea) {
elements.uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
elements.uploadArea.classList.add('active');
});
elements.uploadArea.addEventListener('dragleave', () => {
elements.uploadArea.classList.remove('active');
});
elements.uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
elements.uploadArea.classList.remove('active');
if (e.dataTransfer.files.length > 0) {
handleFile(e.dataTransfer.files[0]);
}
});
elements.uploadArea.addEventListener('click', () => {
elements.fileInput.click();
});
}
// --- Core Functions ---
function handleFile(file) {
if (!file) return;
if (!file.name.match(/\.(xlsx|xls)$/i)) {
alert('请选择 Excel 文件 (.xlsx 或 .xls)');
return;
}
closeUploadModal();
uploadFile(file);
}
function uploadFile(file) {
const formData = new FormData();
formData.append('file', file);
showLoading(true, '正在上传并分析...');
fetch('/upload', { method: 'POST', body: formData })
.then(res => res.json())
.then(data => {
setTimeout(() => {
showLoading(false);
if (data.success) {
state.currentFile = data.filename;
displayData(data.data);
loadFileList();
} else {
alert(data.error || '上传失败');
}
}, 500);
})
.catch(err => {
showLoading(false);
alert('上传错误: ' + err.message);
});
}
function loadFileList() {
fetch('/files')
.then(res => res.json())
.then(data => {
if (data.files && data.files.length > 0) {
state.fileList = data.files;
renderFileList(data.files);
if (!state.currentFile) {
loadFile(data.files[0].filename);
}
} else {
elements.fileSelector.style.display = 'none';
}
});
}
function loadFile(filename) {
showLoading(true, '加载数据中...');
fetch(`/load/${filename}`)
.then(res => res.json())
.then(data => {
setTimeout(() => {
showLoading(false);
if (data.success) {
state.currentFile = filename;
displayData(data.data);
renderFileList(state.fileList); // Update active state
} else {
elements.noData.style.display = 'flex';
elements.dataDisplay.style.display = 'none';
}
}, 300);
})
.catch(() => {
showLoading(false);
elements.noData.style.display = 'flex';
});
}
function displayData(data) {
state.allData = data;
elements.noData.style.display = 'none';
elements.dataDisplay.style.display = 'block';
applyFilters();
}
function renderStats(data) {
let totalQty = 0;
let totalAmt = 0;
const days = data.daily_summary.length;
const uniqueProducts = new Set(); // Simplified unique product count logic based on daily summary data structure might differ, here we approximate or iterate raw if needed.
// Correction: Use raw_data for unique products count if available, or iterate all dailies.
data.daily_summary.forEach(day => {
if (day.summary_info) {
totalQty += day.summary_info.total_quantity;
totalAmt += day.summary_info.total_amount;
} else {
totalQty += day.total_quantity;
totalAmt += day.total_amount;
}
day.products.forEach(p => uniqueProducts.add(p.product));
});
// Count Animation
animateValue(elements.totalAmount, totalAmt, '¥');
animateValue(elements.totalQuantity, totalQty, '');
animateValue(elements.totalDays, days, '');
animateValue(elements.totalProducts, uniqueProducts.size, '');
}
function animateValue(obj, end, prefix = '') {
if (!obj) return;
let startTimestamp = null;
const duration = 1000;
const start = 0;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
const value = Math.floor(progress * (end - start) + start);
if (prefix === '¥') {
obj.innerHTML = prefix + (progress * end).toFixed(2);
} else {
obj.innerHTML = prefix + value;
}
if (progress < 1) {
window.requestAnimationFrame(step);
} else {
if (prefix === '¥') {
obj.innerHTML = prefix + end.toFixed(2);
} else {
obj.innerHTML = prefix + end;
}
}
};
window.requestAnimationFrame(step);
}
function renderDailyList(data) {
elements.dailyData.innerHTML = data.daily_summary.map(day => {
const totalAmt = day.summary_info ? day.summary_info.total_amount : day.total_amount;
const totalQty = day.summary_info ? day.summary_info.total_quantity : day.total_quantity;
return `
<div class="day-card glass-card expanded">
<div class="day-header" onclick="toggleDayDetails(this)">
<div class="day-info">
<span class="date">${day.date}</span>
<span class="summary">¥${totalAmt.toFixed(2)} / ${totalQty}件</span>
</div>
<i class="fas fa-chevron-down toggle-icon"></i>
</div>
<div class="day-details">
<div class="product-list">
${day.products.map(p => `
<div class="product-item">
<div class="p-name">${p.product}</div>
<div class="p-meta">
<span class="p-price">¥${p.price.toFixed(2)}</span>
<span class="p-qty">x${p.quantity}</span>
<span class="p-total">¥${p.amount.toFixed(2)}</span>
</div>
</div>
`).join('')}
</div>
</div>
</div>
`;
}).join('');
}
function toggleDayDetails(header) {
const card = header.parentElement;
card.classList.toggle('expanded');
}
function applyFilters() {
if (!state.allData) return;
let filtered = JSON.parse(JSON.stringify(state.allData));
// Search Filter
if (state.searchTerm) {
filtered.daily_summary = filtered.daily_summary.map(day => {
const matchedProducts = day.products.filter(p => p.product.toLowerCase().includes(state.searchTerm));
if (matchedProducts.length > 0) {
const tQty = matchedProducts.reduce((a, b) => a + b.quantity, 0);
const tAmt = matchedProducts.reduce((a, b) => a + b.amount, 0);
return { ...day, products: matchedProducts, total_quantity: tQty, total_amount: tAmt, summary_info: null };
}
return null;
}).filter(d => d);
}
// Amount Filter
if (state.currentFilter !== 'all') {
filtered.daily_summary = filtered.daily_summary.filter(day => {
const amt = day.summary_info ? day.summary_info.total_amount : day.total_amount;
if (state.currentFilter === 'high') return amt >= 1000;
if (state.currentFilter === 'medium') return amt >= 100 && amt < 1000;
if (state.currentFilter === 'low') return amt < 100;
return true;
});
}
state.filteredData = filtered;
renderStats(filtered);
renderDailyList(filtered);
}
function filterByAmount(type) {
state.currentFilter = type;
document.querySelectorAll('.filter-chip').forEach(btn => btn.classList.remove('active'));
event.target.classList.add('active');
applyFilters();
}
function renderFileList(files) {
elements.fileSelector.style.display = 'flex';
elements.fileList.innerHTML = files.map(f => `
<div class="file-tag ${f.filename === state.currentFile ? 'active' : ''}" onclick="loadFile('${f.filename}')">
${f.original_name}
</div>
`).join('');
}
// --- Utils ---
function openUploadModal() {
elements.uploadModal.classList.add('active');
}
function closeUploadModal() {
elements.uploadModal.classList.remove('active');
}
function showLoading(show, text) {
elements.loadingOverlay.style.display = show ? 'flex' : 'none';
if (text) elements.loadingText.textContent = text;
}
function cleanupFiles() {
if (!confirm('确认清理旧文件?')) return;
fetch('/cleanup', { method: 'POST' })
.then(res => res.json())
.then(data => {
alert(data.message);
loadFileList();
if (data.deleted_count > 0 && state.currentFile) {
// Check if current file still exists? Simple approach: reload list
// Logic omitted for brevity, user can re-upload
}
});
}
function exportData() {
if (!state.allData) return;
const data = state.filteredData || state.allData;
let csv = "Date,Product,Quantity,Price,Amount\n";
data.daily_summary.forEach(day => {
day.products.forEach(p => {
csv += `${day.date},${p.product},${p.quantity},${p.price},${p.amount}\n`;
});
});
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'sales_data.csv';
a.click();
}