Compare commits

...

2 Commits

Author SHA1 Message Date
zzh
6b2e2d6635 新增兔喜和美团的审计数据展示 2026-01-22 10:06:53 +08:00
zzh
e5a2be8aa6 界面布局优化 2026-01-15 14:48:40 +08:00
12 changed files with 449 additions and 135 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -2572,8 +2572,10 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
.topnav-item{position:relative;display:flex;align-items:center;gap:4px;padding:8px 14px;color:var(--text-2);text-decoration:none;font-size:14px;font-weight:500;border-radius:6px;cursor:pointer;transition:all 0.2s ease;white-space:nowrap}
.topnav-item:hover,.topnav-item.active{background:rgba(79,140,255,0.1);color:var(--text)}
.topnav-item.active{color:var(--primary);background:rgba(79,140,255,0.15)}
.topnav-caret{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;font-size:14px;line-height:1;transition:transform 0.2s ease;opacity:.85}
.topnav-item.has-dropdown:hover .topnav-caret,.topnav-item.has-dropdown.open .topnav-caret{transform:rotate(180deg)}
.topnav-caret{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;font-size:0;line-height:1;transition:all 0.2s ease;opacity:.85}
.topnav-caret::before{content:'';position:absolute;width:6px;height:6px;background:var(--primary);border-radius:50%;box-shadow:0 0 6px var(--primary),0 0 12px var(--primary);opacity:0.6;transition:all 0.2s ease}
.topnav-item.has-dropdown:hover .topnav-caret::before,.topnav-item.has-dropdown.open .topnav-caret::before{opacity:1;box-shadow:0 0 8px var(--primary),0 0 16px var(--primary),0 0 24px var(--primary)}
.topnav-item.has-dropdown:hover .topnav-caret,.topnav-item.has-dropdown.open .topnav-caret{transform:none}
.topnav-dropdown{position:absolute;top:100%;left:0;min-width:180px;background:var(--surface);border:1px solid var(--border);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,0.3);padding:6px 0;opacity:0;visibility:hidden;transform:translateY(8px);transition:all 0.2s ease;z-index:1000}
.topnav-item.has-dropdown:hover .topnav-dropdown,.topnav-item.has-dropdown.open .topnav-dropdown{opacity:1;visibility:visible;transform:translateY(0)}
.dropdown-item{display:block;padding:10px 16px;color:var(--text-2);text-decoration:none;font-size:13px;transition:all 0.15s ease}
@ -2622,7 +2624,7 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
@media(max-width:768px){.product-card{flex-direction:column}.product-image-wrapper{flex:none;width:100%}.product-features{grid-template-columns:1fr}}
[data-theme="light"] body{background:#f1f5f9}
#app.trackit-layout{margin:16px;height:calc(100vh - 32px);border-radius:40px;overflow:hidden;background:#ffffff;border:1px solid rgba(255,255,255,.4);box-shadow:0 24px 64px rgba(15,23,42,.14);display:flex;flex-direction:row}
#app.trackit-layout{margin:0;height:100vh;border-radius:0;overflow:hidden;background:#ffffff;border:none;box-shadow:none;display:flex;flex-direction:row}
#app.trackit-layout .content{background:rgba(248,250,252,.6);height:100%}
#app.trackit-layout .content.topbar-layout{height:100%;display:flex;flex-direction:column}
#app.trackit-layout .content.topbar-layout .view{padding:24px;height:100%;overflow:hidden}
@ -2651,14 +2653,17 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
#app.trackit-layout > #sidebar .topnav{flex:1;min-height:0;overflow:visible;padding-right:2px}
#app.trackit-layout > #sidebar .sidebar-footer{margin-top:auto;display:flex;flex-direction:column;gap:12px}
#app.trackit-layout > #sidebar .sidebar-actions{display:flex;align-items:center;justify-content:space-between;gap:14px;padding:12px 6px 2px;border-top:1px solid rgba(226,232,240,.85)}
#app.trackit-layout > #sidebar .sidebar-actions{display:flex;align-items:center;justify-content:flex-end;gap:14px;padding:12px 6px 2px;border-top:1px solid rgba(226,232,240,.85)}
[data-theme="dark"] #app.trackit-layout > #sidebar .sidebar-actions{border-top:1px solid rgba(255,255,255,.08)}
#app.trackit-layout > #sidebar .sidebar-actions .notification-bell-btn{position:relative;background:none;border:none;cursor:pointer;padding:6px;border-radius:10px;display:flex;align-items:center;justify-content:center;transition:all 0.2s ease;color:var(--text-2)}
#app.trackit-layout > #sidebar .sidebar-actions .notification-bell-btn:hover{background:rgba(79,140,255,0.1);color:var(--primary)}
#app.trackit-layout > #sidebar .sidebar-actions .notification-bell-btn .notification-badge{position:absolute;top:-2px;right:-2px;background:var(--danger);color:#fff;border-radius:10px;padding:2px 6px;font-size:10px;font-weight:700;min-width:18px;text-align:center;line-height:1.2;box-shadow:0 2px 4px rgba(239,68,68,0.3)}
#app.trackit-layout > #sidebar .sidebar-actions .user-avatar-btn{padding:0;opacity:1}
#app.trackit-layout > #sidebar .sidebar-actions .user-avatar-img{width:36px;height:36px}
#app.trackit-layout > #sidebar .sidebar-actions .user-name-display{display:none}
#app.trackit-layout > #sidebar .sidebar-actions .user-dropdown{top:auto;bottom:100%;margin-top:0;margin-bottom:8px}
#app.trackit-layout > #sidebar .sidebar-notification-card{position:relative;background:rgba(255,255,255,.78);border:1px solid rgba(226,232,240,.9);border-radius:18px;padding:12px 6px 10px;box-shadow:0 10px 30px rgba(15,23,42,.06),0 0 0 2px rgba(0,0,0,.15);height:220px;display:flex;flex-direction:column;cursor:default;margin:0 -12px;width:calc(100% + 24px)}
#app.trackit-layout > #sidebar .sidebar-notification-card{position:relative;background:rgba(255,255,255,.78);border:1px solid rgba(226,232,240,.9);border-radius:18px;padding:12px 6px 10px;box-shadow:0 10px 30px rgba(15,23,42,.06),0 0 0 2px rgba(0,0,0,.15);height:220px;display:flex;flex-direction:column;cursor:default;margin:12px 0 0 0;width:100%;z-index:1}
[data-theme="dark"] #app.trackit-layout > #sidebar .sidebar-notification-card{background:rgba(15,23,42,.25);border-color:rgba(255,255,255,.08);box-shadow:0 0 0 2px rgba(0,0,0,.4)}
#app.trackit-layout > #sidebar .sidebar-notification-header{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;margin-bottom:10px;padding:0 6px;cursor:pointer}
#app.trackit-layout > #sidebar .sidebar-notification-title{font-size:12px;font-weight:800;color:var(--text);letter-spacing:.02em}
@ -2792,10 +2797,14 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
.notification-modal .notification-modal-backdrop{position:absolute;inset:0;background:rgba(2,6,23,.38);backdrop-filter:blur(6px)}
.notification-modal .notification-modal-content{position:relative;width:min(720px,calc(100vw - 32px));max-height:min(80vh,680px);margin:10vh auto 0;background:rgba(255,255,255,.92);border:1px solid rgba(226,232,240,.95);border-radius:22px;box-shadow:0 30px 90px rgba(15,23,42,.25);overflow:hidden;display:flex;flex-direction:column}
[data-theme="dark"] .notification-modal .notification-modal-content{background:rgba(15,23,42,.88);border-color:rgba(255,255,255,.12);box-shadow:none}
.notification-modal .notification-modal-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid rgba(226,232,240,.9)}
.notification-modal .notification-modal-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid rgba(226,232,240,.9);gap:12px}
[data-theme="dark"] .notification-modal .notification-modal-header{border-bottom:1px solid rgba(255,255,255,.10)}
.notification-modal .notification-modal-title{font-size:14px;font-weight:800;color:var(--text)}
.notification-modal .notification-modal-close{background:none;border:0;cursor:pointer;font-size:22px;line-height:1;color:var(--text);width:34px;height:34px;border-radius:10px}
.notification-modal .notification-modal-title{font-size:14px;font-weight:800;color:var(--text);flex:1}
.notification-modal .notification-modal-actions{display:flex;align-items:center;gap:8px}
.notification-modal .notification-modal-actions .btn-text{padding:6px 12px;border-radius:8px;font-size:12px;background:none;border:1px solid var(--border);color:var(--text);cursor:pointer;transition:all 0.2s ease;font-weight:600}
.notification-modal .notification-modal-actions .btn-text:hover{background:rgba(79,140,255,0.1);border-color:var(--primary);color:var(--primary)}
.notification-modal .notification-modal-actions .btn-text.btn-danger:hover{background:rgba(239,68,68,0.1);border-color:var(--danger);color:var(--danger)}
.notification-modal .notification-modal-close{background:none;border:0;cursor:pointer;font-size:22px;line-height:1;color:var(--text);width:34px;height:34px;border-radius:10px;flex-shrink:0}
.notification-modal .notification-modal-close:hover{background:rgba(79,140,255,.12)}
.notification-modal .notification-modal-list{padding:14px 8px;overflow:auto}
.notification-modal .notification-modal-list::-webkit-scrollbar{width:8px}
@ -2808,3 +2817,12 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
.notification-modal .notification-modal-list .notification-item{padding:12px 12px;border-radius:16px;border:1px solid transparent;background:rgba(248,250,252,.9);margin-bottom:10px;cursor:pointer}
[data-theme="dark"] .notification-modal .notification-modal-list .notification-item{background:rgba(2,6,23,.35)}
.notification-modal .notification-modal-list .notification-item.unread{border-color:rgba(79,140,255,.22)}
/* Dashboard scrollbar */
.dashboard-container::-webkit-scrollbar{width:8px}
.dashboard-container::-webkit-scrollbar-track{background:var(--bg);border-radius:4px}
.dashboard-container::-webkit-scrollbar-thumb{background:rgba(79,140,255,0.3);border-radius:4px;transition:background 0.2s}
.dashboard-container::-webkit-scrollbar-thumb:hover{background:rgba(79,140,255,0.5)}
[data-theme="dark"] .dashboard-container::-webkit-scrollbar-track{background:var(--bg)}
[data-theme="dark"] .dashboard-container::-webkit-scrollbar-thumb{background:rgba(79,140,255,0.4)}
[data-theme="dark"] .dashboard-container::-webkit-scrollbar-thumb:hover{background:rgba(79,140,255,0.6)}

View File

@ -91,7 +91,7 @@
</span>
<span class="topnav-text">上传</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/upload/mac" class="dropdown-item" data-route="upload-mac">MAC与批次</a>
<a href="#/upload/stats" class="dropdown-item" data-route="upload-stats">良/不良统计</a>
@ -110,7 +110,7 @@
</span>
<span class="topnav-text">出货查询</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/shipments/query" class="dropdown-item" data-route="shipments-query">详细记录查询</a>
<a href="#/shipments/summary" class="dropdown-item" data-route="shipments-summary">汇总信息查询</a>
@ -126,7 +126,7 @@
</span>
<span class="topnav-text">生产管理</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/production-mgmt/work-order" class="dropdown-item" data-route="production-mgmt-work-order">生产工单下发中心</a>
</div>
@ -143,7 +143,7 @@
</span>
<span class="topnav-text">计划管理</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/plan-mgmt/bom" class="dropdown-item" data-route="plan-mgmt-bom">BOM物料清单</a>
<a href="#/plan-mgmt/initial-stock" class="dropdown-item" data-route="plan-mgmt-initial-stock">期初库存</a>
@ -163,7 +163,7 @@
</span>
<span class="topnav-text">采集</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/devices" class="dropdown-item" data-route="devices">设备状态</a>
<a href="#/environment" class="dropdown-item" data-route="environment">环境参数</a>
@ -185,7 +185,7 @@
</span>
<span class="topnav-text">基站测试</span>
</span>
<span class="topnav-caret"></span>
<span class="topnav-caret"></span>
<div class="topnav-dropdown">
<a href="#/test/meituan" class="dropdown-item" data-route="test-meituan">美团基站测试</a>
</div>
@ -229,20 +229,6 @@
</a>
</nav>
<div class="sidebar-footer">
<div id="sidebar-notification-card" class="sidebar-notification-card" style="display:none;">
<span id="notification-badge" class="notification-badge" style="display:none;">0</span>
<div class="sidebar-notification-header">
<div class="sidebar-notification-title"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg> </div>
<div class="sidebar-notification-actions">
<button id="mark-all-read" class="btn-text" type="button">全部已读</button>
<button id="delete-read" class="btn-text btn-danger" type="button">删除已读</button>
</div>
</div>
<div id="notification-list" class="sidebar-notification-list">
<div class="notification-empty">暂无消息通知</div>
</div>
</div>
<div class="sidebar-actions">
<!-- 主题切换按钮已隐藏 -->
<label class="switch" style="display: none;">
@ -260,6 +246,13 @@
</svg>
</span>
</label>
<button id="notification-bell-btn" class="notification-bell-btn" title="消息通知">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/>
<path d="M13.73 21a2 2 0 0 1-3.46 0"/>
</svg>
<span id="notification-badge" class="notification-badge" style="display:none;">0</span>
</button>
<div class="user-menu-container">
<button id="user-avatar-btn" class="user-avatar-btn">
<img id="user-avatar-img" src="./assets/user-avatar.svg" alt="用户头像" class="user-avatar-img" />
@ -300,7 +293,11 @@
<div class="notification-modal-backdrop" data-close="1"></div>
<div class="notification-modal-content" role="dialog" aria-modal="true" aria-label="🔔">
<div class="notification-modal-header">
<div class="notification-modal-title">🔔</div>
<div class="notification-modal-title">🔔 消息通知</div>
<div class="notification-modal-actions">
<button id="modal-mark-all-read" class="btn-text" type="button">全部已读</button>
<button id="modal-delete-read" class="btn-text btn-danger" type="button">删除已读</button>
</div>
<button id="notification-modal-close" class="notification-modal-close" type="button" aria-label="关闭">×</button>
</div>
<div id="notification-modal-list" class="notification-modal-list"></div>

View File

@ -173,8 +173,12 @@ const API = (() => {
listShipments: () => request('/list/shipments'),
auditPdd: (params={}) => request('/audit/pdd' + buildQuery(params)),
auditYt: (params={}) => request('/audit/yt' + buildQuery(params)),
auditTx: (params={}) => request('/audit/tx' + buildQuery(params)),
auditMt: (params={}) => request('/audit/mt' + buildQuery(params)),
auditPddQuiet: (params={}) => requestQuiet('/audit/pdd' + buildQuery(params)),
auditYtQuiet: (params={}) => requestQuiet('/audit/yt' + buildQuery(params)),
auditTxQuiet: (params={}) => requestQuiet('/audit/tx' + buildQuery(params)),
auditMtQuiet: (params={}) => requestQuiet('/audit/mt' + buildQuery(params)),
exportExcel: params => request('/export/excel', { method: 'POST', body: JSON.stringify(params) }),
exportPdf: params => request('/export/pdf', { method: 'POST', body: JSON.stringify(params) }),
toast,

View File

@ -2,7 +2,7 @@ const AIReport = (() => {
// 生成AI报表卡片的HTML
const generateAICard = () => {
return `
<div class="card" style="flex:1;display:flex;flex-direction:column;background:var(--surface);cursor:pointer;position:relative;overflow:hidden" onclick="AIReport.generateReport()">
<div class="card" style="flex:1;display:flex;flex-direction:column;background:var(--surface);cursor:pointer;position:relative;overflow:hidden;min-height:400px" onclick="AIReport.generateReport()">
<!-- AI图标 -->
<div style="position:absolute;top:12px;right:12px;width:24px;height:24px;z-index:1">
<img src="./assets/大模型.png" style="width:24px;height:24px" alt="AI" />

View File

@ -67,8 +67,6 @@ const Dashboard = (() => {
<span style="font-size: 18px; color: #ef4444; font-weight: 700;" id="bad-rate-value">${badRate}</span>
</div>
<div style="display: flex; align-items: center; gap: 8px; margin-top: 4px;">
<span style="font-size: 15px; font-weight: 700; color: ${trendColor};">${trendValue}</span>
<span style="font-size: 14px; color: #bfbfbf; font-weight: 500;">较昨日</span>
</div>
</div>
@ -143,8 +141,6 @@ const Dashboard = (() => {
<span style="font-size: 16px; font-weight: 600; color: #a0a0a0;">pcs</span>
</div>
<div style="display: flex; align-items: center; gap: 8px; margin-top: 4px;">
<span class="metrics-percent" style="font-size: 15px; font-weight: 700; color: ${platformColor};">${trendValue}</span>
<span style="font-size: 14px; color: #bfbfbf; font-weight: 500;">较昨日</span>
</div>
</div>
@ -182,7 +178,7 @@ const Dashboard = (() => {
if (title === '良品 / 不良率') {
// 良品率趋势(简化处理,显示固定趋势)
return { value: "+2.4%", color: "#10b981", text: "较昨日" };
return { value: "", color: "#10b981", text: "" };
} else if (title.includes('今日产量')) {
// 获取平台特定产量
const platform = title.includes('拼多多') ? 'pdd' : 'yt';
@ -198,7 +194,7 @@ const Dashboard = (() => {
// 计算趋势
if (yesterdayValue === 0) {
return { value: todayValue > 0 ? "+100%" : "0%", color: "#10b981", text: "较昨日" };
return { value: "", color: "#10b981", text: "" };
}
const change = ((todayValue - yesterdayValue) / yesterdayValue * 100).toFixed(1);
@ -211,9 +207,9 @@ const Dashboard = (() => {
}
return {
value: (isUp ? "+" : "") + change + "%",
value: "",
color: color,
text: "较昨日"
text: ""
};
};
@ -245,8 +241,6 @@ const Dashboard = (() => {
<span style="font-size: 16px; font-weight: 600; color: #a0a0a0;">pcs</span>
</div>
<div style="display: flex; align-items: center; gap: 8px; margin-top: 4px;">
<span style="font-size: 15px; font-weight: 700; color: ${trendColor};">${trendValue}</span>
<span style="font-size: 14px; color: #bfbfbf; font-weight: 500;">${trendText}</span>
</div>
</div>
@ -476,14 +470,18 @@ const Dashboard = (() => {
});
async function render() {
const [dRes,pRes,yRes] = await Promise.allSettled([
const [dRes,pRes,yRes,tRes,mRes] = await Promise.allSettled([
API.dashboard(),
API.auditPddQuiet(),
API.auditYtQuiet()
API.auditYtQuiet(),
API.auditTxQuiet(),
API.auditMtQuiet()
]);
const data = dRes.status==='fulfilled' ? dRes.value : { goodRate: '—', shipments: '—', defects: '—', badCount: '—' };
const pdd = pRes.status==='fulfilled' ? pRes.value : { list: [] };
const yt = yRes.status==='fulfilled' ? yRes.value : { list: [] };
const tx = tRes.status==='fulfilled' ? tRes.value : { list: [] };
const mt = mRes.status==='fulfilled' ? mRes.value : { list: [] };
// 优化:默认只显示少量数据,完整数据在点击模态框时加载
const pddList = (pdd.list||[]).slice(0, 10).map(r=>`<li><span style="display:inline-flex;align-items:center;gap:4px;min-width:180px"><img src="assets/pdd.svg" style="width:16px;height:16px" />${r.ts_cn||'—'}</span><span class="badge">${r.batch||''}</span><span class="badge">${r.mac||''}</span><span class="badge">${r.note||''}</span></li>`).join('')||'<li>暂无数据</li>';
@ -514,6 +512,8 @@ const Dashboard = (() => {
window.__pddParams = window.__pddParams || {};
window.__ytParams = window.__ytParams || {};
window.__txParams = window.__txParams || {};
window.__mtParams = window.__mtParams || {};
window.__auditBusy=false;
const toEpoch=(s)=>{try{if(!s)return null;let t=s.trim();
if(/Z$/.test(t) || /[\+\-]\d{2}:\d{2}$/.test(t)) return Date.parse(t);
@ -551,7 +551,7 @@ const Dashboard = (() => {
// 绘制趋势图
let chartData = null;
const drawTrendChart = (pddData, ytData) => {
const drawTrendChart = (pddData, ytData, txData, mtData) => {
const canvas = document.getElementById('trend-chart');
if(!canvas) return;
const ctx = canvas.getContext('2d');
@ -639,10 +639,15 @@ const Dashboard = (() => {
const pddCounts = countByTime(pddData);
const ytCounts = countByTime(ytData);
const maxCount = Math.max(...pddCounts, ...ytCounts, 1);
// 绘制参数(使用逻辑尺寸而非物理像素)
// 根据最大值动态调整左边距确保Y轴标签不被截断
const txCounts = countByTime(txData);
const mtCounts = countByTime(mtData);
const actualMax = Math.max(...pddCounts, ...ytCounts, ...txCounts, ...mtCounts, 0);
// 动态调整Y轴让小数据更明显
let maxCount;
if (actualMax <= 2) maxCount = 3; // 数据是1-2时Y轴最大值设为3让数据占据1/3到2/3的高度
else if (actualMax <= 5) maxCount = 8; // 数据是3-5时Y轴最大值设为8
else if (actualMax <= 10) maxCount = 15; // 数据是6-10时Y轴最大值设为15
else maxCount = actualMax;
const maxDigits = Math.max(maxCount.toString().length, 2);
const dynamicLeftPadding = Math.max(50, 25 + maxDigits * 10);
const padding = {left: dynamicLeftPadding, right: 20, top: 20, bottom: 30};
@ -654,7 +659,7 @@ const Dashboard = (() => {
const effectiveChartHeight = chartHeight - yAxisMargin;
// 保存图表数据供鼠标事件使用
chartData = {timePoints, pddCounts, ytCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight};
chartData = {timePoints, pddCounts, ytCounts, txCounts, mtCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight};
// 清空画布
ctx.fillStyle = colors.bg;
@ -751,9 +756,13 @@ const Dashboard = (() => {
// 收集今日标签位置
const todayLabels = [];
const drawAreaLine = (counts, gradientColors, fillColors, labelKey) => {
// 为每个平台单独计算最大值
const platformMax = Math.max(...counts, 1);
const platformScale = platformMax <= 2 ? 10 : (platformMax <= 5 ? 15 : platformMax);
const points = counts.map((count, i) => ({
x: padding.left + (chartWidth / (timePoints.length - 1)) * i,
y: padding.top + chartHeight - yAxisMargin - (count / maxCount) * effectiveChartHeight
y: padding.top + chartHeight - yAxisMargin - (count / platformScale) * effectiveChartHeight
}));
// 1. 绘制填充区域
@ -837,8 +846,10 @@ const Dashboard = (() => {
});
};
// 先绘制圆通(紫色在下层),再绘制拼多多(橙色在上层
// 绘制4条曲线圆通、美团、兔喜、拼多多从下到上
drawAreaLine(ytCounts, colors.ytGradient, colors.ytFill, 'yt');
drawAreaLine(mtCounts, ['rgba(255, 184, 0, 0.8)', 'rgba(255, 184, 0, 1)', 'rgba(255, 200, 50, 1)'], ['rgba(255, 184, 0, 0.25)', 'rgba(255, 184, 0, 0.05)'], 'mt');
drawAreaLine(txCounts, ['rgba(255, 107, 129, 0.8)', 'rgba(255, 107, 129, 1)', 'rgba(255, 130, 150, 1)'], ['rgba(255, 107, 129, 0.25)', 'rgba(255, 107, 129, 0.05)'], 'tx');
drawAreaLine(pddCounts, colors.pddGradient, colors.pddFill, 'pdd');
// 智能绘制今日标签显示在高亮点的左边数字为0时不显示
@ -879,12 +890,14 @@ const Dashboard = (() => {
};
// 初始化缓存数据
window.__auditCache = window.__auditCache || {pdd: [], yt: []};
window.__auditCache = window.__auditCache || {pdd: [], yt: [], tx: [], mt: []};
if(pdd.list && pdd.list.length > 0) window.__auditCache.pdd = pdd.list;
if(yt.list && yt.list.length > 0) window.__auditCache.yt = yt.list;
if(tx.list && tx.list.length > 0) window.__auditCache.tx = tx.list;
if(mt.list && mt.list.length > 0) window.__auditCache.mt = mt.list;
// 初始绘制
drawTrendChart(pdd.list, yt.list);
drawTrendChart(pdd.list, yt.list, tx.list, mt.list);
// 监听主题切换事件,立即重绘图表
const themeChangeHandler = () => {
@ -895,7 +908,13 @@ const Dashboard = (() => {
const ytData = (window.__auditCache && window.__auditCache.yt && window.__auditCache.yt.length > 0)
? window.__auditCache.yt
: yt.list;
drawTrendChart(pddData, ytData);
const txData = (window.__auditCache && window.__auditCache.tx && window.__auditCache.tx.length > 0)
? window.__auditCache.tx
: tx.list;
const mtData = (window.__auditCache && window.__auditCache.mt && window.__auditCache.mt.length > 0)
? window.__auditCache.mt
: mt.list;
drawTrendChart(pddData, ytData, txData, mtData);
};
window.addEventListener('themeChanged', themeChangeHandler);
@ -914,7 +933,7 @@ const Dashboard = (() => {
const rect = canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const {timePoints, pddCounts, ytCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight} = chartData;
const {timePoints, pddCounts, ytCounts, txCounts, mtCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight} = chartData;
// 查找最近的数据点
let nearestIndex = -1;
@ -923,9 +942,13 @@ const Dashboard = (() => {
const x = padding.left + (chartWidth / (timePoints.length - 1)) * i;
const pddY = padding.top + chartHeight - yAxisMargin - (pddCounts[i] / maxCount) * effectiveChartHeight;
const ytY = padding.top + chartHeight - yAxisMargin - (ytCounts[i] / maxCount) * effectiveChartHeight;
const txY = padding.top + chartHeight - yAxisMargin - (txCounts[i] / maxCount) * effectiveChartHeight;
const mtY = padding.top + chartHeight - yAxisMargin - (mtCounts[i] / maxCount) * effectiveChartHeight;
const distPdd = Math.sqrt((mouseX - x) ** 2 + (mouseY - pddY) ** 2);
const distYt = Math.sqrt((mouseX - x) ** 2 + (mouseY - ytY) ** 2);
const dist = Math.min(distPdd, distYt);
const distTx = Math.sqrt((mouseX - x) ** 2 + (mouseY - txY) ** 2);
const distMt = Math.sqrt((mouseX - x) ** 2 + (mouseY - mtY) ** 2);
const dist = Math.min(distPdd, distYt, distTx, distMt);
if(dist < minDist){
minDist = dist;
nearestIndex = i;
@ -936,10 +959,12 @@ const Dashboard = (() => {
const point = timePoints[nearestIndex];
const pddCount = pddCounts[nearestIndex];
const ytCount = ytCounts[nearestIndex];
const txCount = txCounts[nearestIndex];
const mtCount = mtCounts[nearestIndex];
let label = point;
if(timeRange === 'week') label = point + ' 周';
else if(timeRange === 'month') label = point + ' 月';
tooltip.innerHTML = `<div style="margin-bottom:2px">${label}</div><div style="color:#3B82F6">拼多多: ${pddCount}</div><div style="color:#10B981">圆通: ${ytCount}</div>`;
tooltip.innerHTML = `<div style="margin-bottom:2px">${label}</div><div style="color:#3B82F6">拼多多: ${pddCount}</div><div style="color:#FF6B81">兔喜: ${txCount}</div><div style="color:#FFB800">美团: ${mtCount}</div><div style="color:#10B981">圆通: ${ytCount}</div>`;
tooltip.style.display = 'block';
// 获取提示框宽度以便放在鼠标左侧
@ -973,8 +998,10 @@ const Dashboard = (() => {
window.__trendTimeRange = tab.dataset.range;
const pddData = window.__auditCache?.pdd || pdd.list;
const ytData = window.__auditCache?.yt || yt.list;
drawTrendChart(pddData, ytData);
updateTrendStats(pddData, ytData);
const txData = window.__auditCache?.tx || tx.list;
const mtData = window.__auditCache?.mt || mt.list;
drawTrendChart(pddData, ytData, txData, mtData);
updateTrendStats(pddData, ytData, txData, mtData);
};
});
// 初始化active样式
@ -986,7 +1013,7 @@ const Dashboard = (() => {
}
// 更新趋势统计数据
const updateTrendStats = (pddData, ytData) => {
const updateTrendStats = (pddData, ytData, txData, mtData) => {
const now = new Date();
const today = now.toISOString().split('T')[0];
const thisMonth = today.slice(0, 7);
@ -1029,6 +1056,8 @@ const Dashboard = (() => {
// 保存今日各平台产量
history[today].pdd = countTodayUnique(pddData);
history[today].yt = countTodayUnique(ytData);
history[today].tx = countTodayUnique(txData);
history[today].mt = countTodayUnique(mtData);
// 计算并保存不良数量(假设不良数据在某个字段中)
// 这里需要根据实际数据结构调整
@ -1057,9 +1086,13 @@ const Dashboard = (() => {
const pddMonth = countMonthUnique(pddData);
const ytMonth = countMonthUnique(ytData);
const txMonth = countMonthUnique(txData);
const mtMonth = countMonthUnique(mtData);
const pddToday = countTodayUnique(pddData);
const ytToday = countTodayUnique(ytData);
const weekTotal = countWeekUnique(pddData) + countWeekUnique(ytData);
const txToday = countTodayUnique(txData);
const mtToday = countTodayUnique(mtData);
const weekTotal = countWeekUnique(pddData) + countWeekUnique(ytData) + countWeekUnique(txData) + countWeekUnique(mtData);
// 更新DOM
const el = (id) => document.getElementById(id);
@ -1067,12 +1100,14 @@ const Dashboard = (() => {
if(el('trend-total-yt')) el('trend-total-yt').textContent = ytMonth.toLocaleString();
if(el('trend-today-pdd')) el('trend-today-pdd').textContent = pddToday.toLocaleString();
if(el('trend-today-yt')) el('trend-today-yt').textContent = ytToday.toLocaleString();
if(el('trend-today-tx')) el('trend-today-tx').textContent = txToday.toLocaleString();
if(el('trend-today-mt')) el('trend-today-mt').textContent = mtToday.toLocaleString();
if(el('trend-week-total')) el('trend-week-total').textContent = weekTotal.toLocaleString();
// 状态判断
const statusEl = el('trend-status');
if(statusEl){
if(pddToday + ytToday > 0){
if(pddToday + ytToday + txToday + mtToday > 0){
statusEl.textContent = '生产中';
statusEl.style.color = '#10b981';
} else {
@ -1706,16 +1741,33 @@ const Dashboard = (() => {
// 更新整合看板显示
const updateAuditDisplay = () => {
const platform = window.__currentAuditPlatform;
const params = platform === 'pdd' ? window.__pddParams : window.__ytParams;
let params, cacheData, platformIcon;
if (platform === 'pdd') {
params = window.__pddParams;
cacheData = window.__auditCache.pdd;
platformIcon = '<img src="assets/pdd.svg" style="width:16px;height:16px" />';
} else if (platform === 'yt') {
params = window.__ytParams;
cacheData = window.__auditCache.yt;
platformIcon = '<img src="assets/yt.svg" style="width:16px;height:16px" />';
} else if (platform === 'tx') {
params = window.__txParams || {};
cacheData = window.__auditCache.tx;
platformIcon = '<img src="assets/icon-tuxi.png" style="width:16px;height:16px;filter:brightness(0) saturate(100%) hue-rotate(220deg)" />';
} else if (platform === 'mt') {
params = window.__mtParams || {};
cacheData = window.__auditCache.mt;
platformIcon = '<svg t="1768977565122" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1625" width="16" height="16"><path d="M0 512a512 512 0 1 0 1024 0A512 512 0 0 0 0 512z" fill="#FFC300" p-id="1626"></path><path d="M431.177143 322.56h-41.179429c-7.460571 22.162286-10.020571 31.085714-10.020571 31.085714H219.721143s-2.413714-8.923429-10.020572-31.085714h-41.106285v31.085714h-49.152v37.156572H276.48v30.72h-149.211429v39.936h149.211429v28.233143h-149.211429v40.009142h149.211429v28.818286H119.442286v39.350857H261.851429s-40.082286 51.346286-144.018286 56.100572v41.910857s112.859429 10.971429 182.125714-79.213714c0 0 47.177143 77.604571 180.297143 79.36V652.434286s-89.380571 2.706286-141.165714-54.637715h141.165714v-39.350857H324.534857v-28.745143h148.260572v-40.009142H324.461714V461.531429h148.260572v-40.009143H324.461714v-30.72h155.794286v-37.083429h-49.152l0.073143-31.085714z m191.561143 303.030857h47.908571c25.892571-50.322286 43.081143-104.594286 50.834286-160.694857h41.691428v101.010286c-0.731429 20.114286-2.925714 40.228571-6.656 59.977143h44.178286a373.028571 373.028571 0 0 0 5.12-59.977143v-100.937143h28.745143v-39.058286h-28.672V393.508571h-42.569143v32.621715H609.28v38.912h67.291429a426.422857 426.422857 0 0 1-53.76 160.402285v0.073143z" fill="#000000" p-id="1627"></path><path d="M542.72 332.8v368.64h310.857143a52.736 52.736 0 0 0 52.662857-52.809143V332.8H542.72z m322.998857 315.830857a12.8 12.8 0 0 1-12.726857 12.873143H582.802286V372.297143h282.843428v276.333714z" fill="#000000" p-id="1628"></path></svg>';
}
const sTime = toEpoch(params.start);
const eTime = toEpoch(params.end);
const cacheData = platform === 'pdd' ? window.__auditCache.pdd : window.__auditCache.yt;
const filteredData = (cacheData || []).filter(r => {
const t = toEpoch(r.ts_cn);
if (t == null) return false;
return (sTime == null || t >= sTime) && (eTime == null || t <= eTime);
});
const platformIcon = platform === 'pdd' ? '<img src="assets/pdd.svg" style="width:16px;height:16px" />' : '<img src="assets/yt.svg" style="width:16px;height:16px" />';
const listHtml = filteredData.slice(0, 100).map(r =>
`<li><span style="display:inline-flex;align-items:center;gap:4px;min-width:180px">${platformIcon}${r.ts_cn||'—'}</span><span class="badge">${r.batch||''}</span><span class="badge">${r.mac||''}</span><span class="badge">${r.note||''}</span></li>`
).join('') || '<li>暂无数据</li>';
@ -1726,10 +1778,9 @@ const Dashboard = (() => {
if (platformSelect) {
platformSelect.onchange = () => {
window.__currentAuditPlatform = platformSelect.value;
// 同步日期选择器
const otherDateEl = platformSelect.value === 'pdd' ? q('audit-date-pdd') : q('audit-date-yt');
if (auditDateEl && otherDateEl) {
auditDateEl.value = otherDateEl.value;
// 清空日期选择器
if (auditDateEl) {
auditDateEl.value = '';
}
updateAuditDisplay();
};
@ -1742,14 +1793,13 @@ const Dashboard = (() => {
const platform = window.__currentAuditPlatform;
if (platform === 'pdd') {
window.__pddParams = dateToRange(d);
const pddDateEl = q('audit-date-pdd');
if (pddDateEl) pddDateEl.value = d;
} else {
} else if (platform === 'yt') {
window.__ytParams = dateToRange(d);
const ytDateEl = q('audit-date-yt');
if (ytDateEl) ytDateEl.value = d;
} else if (platform === 'tx') {
window.__txParams = dateToRange(d);
} else if (platform === 'mt') {
window.__mtParams = dateToRange(d);
}
refreshAuditLists();
updateAuditDisplay();
};
}
@ -1812,7 +1862,7 @@ const Dashboard = (() => {
try {
// 请求全部数据不限制传递AbortController信号
const signal = window.__auditAbortController.signal;
const [pddRes, ytRes, dashRes] = await Promise.all([
const [pddRes, ytRes, txRes, mtRes, dashRes] = await Promise.all([
fetch('/api/audit/pdd', {
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
@ -1829,6 +1879,22 @@ const Dashboard = (() => {
if(e.name === 'AbortError') console.log('[Dashboard] YT请求被取消');
return {list:[]};
}),
fetch('/api/audit/tx', {
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
signal
}).then(r => r.ok ? r.json() : {list:[]}).catch((e)=>{
if(e.name === 'AbortError') console.log('[Dashboard] TX请求被取消');
return {list:[]};
}),
fetch('/api/audit/mt', {
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
signal
}).then(r => r.ok ? r.json() : {list:[]}).catch((e)=>{
if(e.name === 'AbortError') console.log('[Dashboard] MT请求被取消');
return {list:[]};
}),
fetch('/api/dashboard', {
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
@ -1896,10 +1962,12 @@ const Dashboard = (() => {
// 缓存全部数据不再限制30天支持大数据量显示
window.__auditCache.pdd = pddRes.list || [];
window.__auditCache.yt = ytRes.list || [];
window.__auditCache.tx = txRes.list || [];
window.__auditCache.mt = mtRes.list || [];
// 更新趋势图和统计数据
drawTrendChart(window.__auditCache.pdd, window.__auditCache.yt);
updateTrendStats(window.__auditCache.pdd, window.__auditCache.yt);
drawTrendChart(window.__auditCache.pdd, window.__auditCache.yt, window.__auditCache.tx, window.__auditCache.mt);
updateTrendStats(window.__auditCache.pdd, window.__auditCache.yt, window.__auditCache.tx, window.__auditCache.mt);
refreshShipmentPlatformStats(false);
// 更新列表应用筛选只显示前100条
@ -1979,7 +2047,7 @@ const Dashboard = (() => {
window.__auditTimer=setInterval(refreshAll, 10000);
},0);
return `
<div class="dashboard-container" style="display:flex;flex-direction:column;height:100%;overflow:hidden">
<div class="dashboard-container" style="display:flex;flex-direction:column;height:100%;overflow-y:auto;padding-right:8px">
<!-- 四个指标卡片 -->
<div class="dashboard-metrics-4col" style="flex-shrink:0">
${metricsCard('直通良品数', data.fpyCount || 0, 'success')}
@ -1990,7 +2058,7 @@ const Dashboard = (() => {
<!-- 趋势图 + 环形图 -->
<div style="display:flex;gap:12px;margin-top:12px;flex-shrink:0">
<!-- 左侧趋势卡片 -->
<div class="card" style="flex:0 0 72%;padding:0;overflow:hidden;border-radius:16px;background:var(--surface)">
<div class="card" style="flex:0 0 72%;padding:0;overflow:hidden;border-radius:16px;background:var(--surface);min-height:370px">
<div style="display:flex;flex-wrap:wrap;padding:20px">
<!-- 左侧摘要信息 -->
<div style="flex:0 0 160px;padding-right:16px;border-right:1px solid var(--border);display:flex;flex-direction:column;justify-content:center">
@ -2019,8 +2087,10 @@ const Dashboard = (() => {
<div style="display:flex;align-items:center;gap:12px">
<!-- 图例 -->
<div style="display:flex;align-items:center;gap:10px;font-size:11px;color:var(--text-secondary)">
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#10B981"></span></span>
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#3B82F6"></span></span>
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#FF6B81"></span></span>
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#FFB800"></span></span>
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#10B981"></span></span>
</div>
<!-- 时间范围选择 -->
<div id="trend-range-tabs" style="display:flex;background:var(--surface);border-radius:6px;padding:2px;font-size:11px">
@ -2030,18 +2100,26 @@ const Dashboard = (() => {
</div>
</div>
</div>
<div style="height:230px;position:relative">
<div style="height:280px;position:relative">
<canvas id="trend-chart" style="width:100%;height:100%;cursor:crosshair"></canvas>
<div id="chart-tooltip" style="position:absolute;background:rgba(15,22,35,0.95);color:#fff;padding:8px 12px;border-radius:8px;font-size:12px;pointer-events:none;display:none;white-space:nowrap;box-shadow:0 4px 12px rgba(0,0,0,0.3);border:1px solid rgba(255,255,255,0.1)"></div>
</div>
</div>
</div>
<!-- 底部统计栏 -->
<div style="display:grid;grid-template-columns:repeat(4,1fr);border-top:1px solid var(--border);background:var(--surface)">
<div style="display:grid;grid-template-columns:repeat(6,1fr);border-top:1px solid var(--border);background:var(--surface)">
<div style="padding:10px 12px;text-align:center;border-right:1px solid var(--border)">
<div style="font-size:10px;color:var(--text-secondary);text-transform:uppercase;letter-spacing:0.5px;margin-bottom:2px">今日拼多多</div>
<div id="trend-today-pdd" style="font-size:16px;font-weight:600;color:#3B82F6">0</div>
</div>
<div style="padding:10px 12px;text-align:center;border-right:1px solid var(--border)">
<div style="font-size:10px;color:var(--text-secondary);text-transform:uppercase;letter-spacing:0.5px;margin-bottom:2px">今日兔喜</div>
<div id="trend-today-tx" style="font-size:16px;font-weight:600;color:#FF6B81">0</div>
</div>
<div style="padding:10px 12px;text-align:center;border-right:1px solid var(--border)">
<div style="font-size:10px;color:var(--text-secondary);text-transform:uppercase;letter-spacing:0.5px;margin-bottom:2px">今日美团</div>
<div id="trend-today-mt" style="font-size:16px;font-weight:600;color:#FFB800">0</div>
</div>
<div style="padding:10px 12px;text-align:center;border-right:1px solid var(--border)">
<div style="font-size:10px;color:var(--text-secondary);text-transform:uppercase;letter-spacing:0.5px;margin-bottom:2px">今日圆通</div>
<div id="trend-today-yt" style="font-size:16px;font-weight:600;color:#10B981">0</div>
@ -2057,7 +2135,7 @@ const Dashboard = (() => {
</div>
</div>
<!-- 右侧环形图卡片 -->
<div class="card" style="flex:1;padding:20px;border-radius:16px;display:flex;flex-direction:column;background:var(--surface);min-height:290px">
<div class="card" style="flex:1;padding:20px;border-radius:16px;display:flex;flex-direction:column;background:var(--surface);min-height:360px">
<div style="font-weight:600;font-size:14px;margin-bottom:12px">产量占比</div>
<div style="flex:1;display:grid;grid-template-columns:repeat(2,1fr);gap:16px;align-items:center">
<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;min-width:0">
@ -2065,17 +2143,19 @@ const Dashboard = (() => {
<div style="display:flex;align-items:center;justify-content:center;position:relative">
<canvas id="donut-chart" style="width:160px;height:160px"></canvas>
</div>
<div style="display:flex;justify-content:center;gap:24px;margin-top:12px">
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:12px">
<div style="text-align:center">
<div id="donut-pdd-pct" style="font-size:20px;font-weight:700;color:#3B82F6">0%</div>
<div style="display:flex;align-items:center;gap:4px;font-size:11px;color:var(--text-secondary);margin-top:2px">
<span style="width:8px;height:8px;border-radius:50%;background:#3B82F6"></span>
<div style="display:inline-flex;align-items:center;gap:4px;font-size:11px;color:var(--text-secondary);margin-top:2px">
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#3B82F6;flex-shrink:0"></span>
<span>拼多多</span>
</div>
</div>
<div style="text-align:center">
<div id="donut-yt-pct" style="font-size:20px;font-weight:700;color:#10B981">0%</div>
<div style="display:flex;align-items:center;gap:4px;font-size:11px;color:var(--text-secondary);margin-top:2px">
<span style="width:8px;height:8px;border-radius:50%;background:#10B981"></span>
<div style="display:inline-flex;align-items:center;gap:4px;font-size:11px;color:var(--text-secondary);margin-top:2px">
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#10B981;flex-shrink:0"></span>
<span>圆通</span>
</div>
</div>
</div>
@ -2090,15 +2170,17 @@ const Dashboard = (() => {
</div>
</div>
</div>
<div style="margin-top:12px;flex:1;min-height:0;display:flex;gap:12px">
<div style="margin-top:12px;flex:1;min-height:400px;display:flex;gap:12px">
<!-- 审计看板压缩宽度 -->
<div id="audit-card" class="card" style="flex:1;display:flex;flex-direction:column;min-height:0;background:var(--surface);cursor:pointer" onclick="window.Dashboard.showAuditModal()">
<div id="audit-card" class="card" style="flex:1;display:flex;flex-direction:column;min-height:400px;background:var(--surface);cursor:pointer" onclick="window.Dashboard.showAuditModal()">
<div style="font-weight:600;margin-bottom:12px;display:flex;justify-content:space-between;align-items:center;flex-shrink:0;gap:8px">
<span style="display:flex;align-items:center;gap:8px">审计看板 <span style="font-size:11px;color:var(--text-2);font-weight:400">点击查看完整数据</span></span>
<div style="display:flex;gap:8px;align-items:center" onclick="event.stopPropagation()">
<select id="audit-platform-select" style="padding:4px 8px;background:var(--surface);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;outline:none;cursor:pointer" onclick="event.stopPropagation()">
<option value="pdd">拼多多</option>
<option value="yt">圆通</option>
<option value="tx">兔喜</option>
<option value="mt">美团</option>
</select>
<input id="audit-date" type="date" style="padding:4px 8px;background:var(--surface);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;outline:none" onclick="event.stopPropagation()" />
</div>

View File

@ -86,10 +86,10 @@
const list = data.list || [];
const container = document.getElementById('notification-list');
const modalContainer = document.getElementById('notification-modal-list');
if (!container) return;
if (!container && !modalContainer) return;
if (list.length === 0) {
container.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
if (container) container.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
if (modalContainer) modalContainer.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
return;
}
@ -103,27 +103,29 @@
</div>
`).join('');
container.innerHTML = fullHtml;
if (container) container.innerHTML = fullHtml;
if (modalContainer) modalContainer.innerHTML = fullHtml;
// 为每个通知项添加点击事件
container.querySelectorAll('.notification-item').forEach(item => {
item.addEventListener('click', async () => {
const id = item.dataset.id;
if (item.classList.contains('unread')) {
try {
await API.markNotificationRead(id);
item.classList.remove('unread');
// 同步 modal 中对应项
const modalItem = document.querySelector(`#notification-modal-list .notification-item[data-id="${id}"]`);
if (modalItem) modalItem.classList.remove('unread');
await updateUnreadCount();
} catch (e) {
console.error('标记已读失败:', e);
if (container) {
container.querySelectorAll('.notification-item').forEach(item => {
item.addEventListener('click', async () => {
const id = item.dataset.id;
if (item.classList.contains('unread')) {
try {
await API.markNotificationRead(id);
item.classList.remove('unread');
// 同步 modal 中对应项
const modalItem = document.querySelector(`#notification-modal-list .notification-item[data-id="${id}"]`);
if (modalItem) modalItem.classList.remove('unread');
await updateUnreadCount();
} catch (e) {
console.error('标记已读失败:', e);
}
}
}
});
});
});
}
if (modalContainer) {
modalContainer.querySelectorAll('.notification-item').forEach(item => {
@ -178,21 +180,24 @@
return; // 超级管理员和管理员才显示通知铃铛
}
// 显示侧边栏通知卡片
const card = document.getElementById('sidebar-notification-card');
if (!card) {
console.error('[Notifications] 找不到侧边栏通知卡片元素');
// 绑定铃铛按钮点击事件
const bellBtn = document.getElementById('notification-bell-btn');
if (!bellBtn) {
console.error('[Notifications] 找不到铃铛按钮元素');
return;
}
card.style.display = 'block';
console.log('[Notifications] 侧边栏通知卡片已显示');
// 点击卡片标题区域打开大弹窗(列表和按钮区域不触发)
card.addEventListener('click', (e) => {
if (e.target.closest('.sidebar-notification-actions')) return;
if (e.target.closest('.sidebar-notification-list')) return;
// 移除旧的事件监听器
const newBellBtn = bellBtn.cloneNode(true);
bellBtn.parentNode.replaceChild(newBellBtn, bellBtn);
newBellBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
openModal();
});
console.log('[Notifications] 铃铛按钮已绑定');
// 弹窗关闭
const closeBtn = document.getElementById('notification-modal-close');
@ -209,13 +214,13 @@
if (isModalOpen && e.key === 'Escape') closeModal();
});
// 绑定全部标记为已读按钮(移除旧的事件监听器)
const markAllBtn = document.getElementById('mark-all-read');
if (markAllBtn) {
const newMarkAllBtn = markAllBtn.cloneNode(true);
markAllBtn.parentNode.replaceChild(newMarkAllBtn, markAllBtn);
// 绑定弹窗中的全部标记为已读按钮
const modalMarkAllBtn = document.getElementById('modal-mark-all-read');
if (modalMarkAllBtn) {
const newModalMarkAllBtn = modalMarkAllBtn.cloneNode(true);
modalMarkAllBtn.parentNode.replaceChild(newModalMarkAllBtn, modalMarkAllBtn);
newMarkAllBtn.addEventListener('click', async (e) => {
newModalMarkAllBtn.addEventListener('click', async (e) => {
e.preventDefault();
try {
await API.markAllNotificationsRead();
@ -228,13 +233,13 @@
});
}
// 绑定删除已读消息按钮(移除旧的事件监听器)
const deleteBtn = document.getElementById('delete-read');
if (deleteBtn) {
const newDeleteBtn = deleteBtn.cloneNode(true);
deleteBtn.parentNode.replaceChild(newDeleteBtn, deleteBtn);
// 绑定弹窗中的删除已读消息按钮
const modalDeleteBtn = document.getElementById('modal-delete-read');
if (modalDeleteBtn) {
const newModalDeleteBtn = modalDeleteBtn.cloneNode(true);
modalDeleteBtn.parentNode.replaceChild(newModalDeleteBtn, modalDeleteBtn);
newDeleteBtn.addEventListener('click', async (e) => {
newModalDeleteBtn.addEventListener('click', async (e) => {
e.preventDefault();
if (!confirm('确定要删除所有已读消息吗?')) {
return;

View File

@ -191,7 +191,7 @@ const Upload = (() => {
<div style="margin-bottom:16px;display:flex;justify-content:flex-start">
<a href="#/upload/repairs-history" class="btn btn-secondary" style="font-size:12px;padding:6px 10px">📋 查看历史记录</a>
</div>
<div id="repairs-upload-form">
<div id="repairs-upload-form" style="max-height:calc(100vh - 200px);overflow-y:auto;padding-right:8px">
<div class="form-group" style="margin-bottom:16px">
<label style="display:block;font-weight:600;margin-bottom:6px">
设备SN <span style="color:#ef4444">*</span>
@ -253,7 +253,7 @@ const Upload = (() => {
<div id="repair-image-error" style="color:#ef4444;font-size:12px;margin-top:4px;display:none"></div>
</div>
<div class="actions" style="display:flex;gap:12px">
<div class="actions" style="display:flex;gap:12px;position:sticky;bottom:0;background:var(--surface);padding-top:12px;border-top:1px solid var(--border)">
<button class="btn" id="repairs-upload" style="flex:1">
<span id="repairs-upload-text">提交</span>
<span id="repairs-upload-loading" style="display:none">
@ -271,6 +271,10 @@ const Upload = (() => {
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
#repair-image-dropzone:hover { background:rgba(79,140,255,0.12); border-color:var(--primary); }
#repair-image-dropzone.dragover { background:rgba(79,140,255,0.15); border-color:var(--primary); border-style:solid; }
#repairs-upload-form::-webkit-scrollbar { width: 8px; }
#repairs-upload-form::-webkit-scrollbar-track { background: var(--bg); border-radius: 4px; }
#repairs-upload-form::-webkit-scrollbar-thumb { background: rgba(79,140,255,0.3); border-radius: 4px; }
#repairs-upload-form::-webkit-scrollbar-thumb:hover { background: rgba(79,140,255,0.5); }
</style>
</div>
`);

View File

@ -12,7 +12,7 @@ try:
except Exception:
redis = None
_redis_client = None
_audit_cache = {'pdd': {'ts': 0, 'list': []}, 'yt': {'ts': 0, 'list': []}}
_audit_cache = {'pdd': {'ts': 0, 'list': []}, 'yt': {'ts': 0, 'list': []}, 'tx': {'ts': 0, 'list': []}, 'mt': {'ts': 0, 'list': []}}
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DB_PATH = os.path.join(BASE_DIR, 'data.db')
@ -1265,13 +1265,217 @@ def audit_yt():
return jsonify({'list': []})
@app.get('/api/audit/tx')
@require_login
def audit_tx():
start = datetime.utcnow()
try:
q_start = request.args.get('start')
q_end = request.args.get('end')
q_limit = request.args.get('limit')
q_order = request.args.get('order', 'desc')
has_filter = bool(q_start or q_end or q_limit or q_order)
# 缓存优化3秒内不重复查询
if (not has_filter) and ((datetime.utcnow().timestamp() - _audit_cache['tx']['ts']) < 3):
return jsonify({'list': _audit_cache['tx']['list']})
r = get_redis()
# 设置Redis超时为5秒
r.connection_pool.connection_kwargs['socket_timeout'] = 5
items = []
# 支持大数据量默认返回全部数据可通过limit参数限制
max_items = int(q_limit) if q_limit else 50000
for key in ['mac_batch_audit_tx', 'audit:tx', 'tx:audit']:
try:
if r.exists(key):
t = r.type(key)
if t == 'list':
# 获取全部数据或限制数量
total = r.llen(key)
fetch_count = min(total, max_items)
items = r.lrange(key, -fetch_count, -1)
elif t == 'zset':
items = r.zrevrange(key, 0, max_items - 1)
elif t == 'stream':
entries = r.xrevrange(key, max='+', min='-', count=max_items)
items = [json.dumps(v) for _id, v in entries]
else:
v = r.get(key)
items = [v] if v else []
break
except Exception as e:
log('audit_tx_error', f'Redis query error: {str(e)}')
continue
res = [parse_audit_line(x) for x in items]
if q_start or q_end:
def to_epoch(s):
try:
if not s:
return None
if 'T' in s or 'Z' in s or '+' in s:
return datetime.fromisoformat(s.replace('Z','+00:00')).timestamp()
if ' ' in s and ':' in s:
return datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp()
return datetime.strptime(s, '%Y-%m-%d').timestamp()
except Exception:
return None
s_epoch = to_epoch(q_start) if q_start else None
e_epoch = to_epoch(q_end) if q_end else None
tmp = []
for r0 in res:
ts = to_epoch(r0.get('ts_cn'))
if ts is None:
continue
if s_epoch is not None and ts < s_epoch:
continue
if e_epoch is not None and ts > e_epoch:
continue
tmp.append(r0)
res = tmp
try:
def to_key(r):
s = r.get('ts_cn') or ''
try:
if 'T' in s or 'Z' in s or '+' in s:
return datetime.fromisoformat(s.replace('Z','+00:00')).timestamp()
if ' ' in s and ':' in s:
return datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp()
return datetime.strptime(s, '%Y-%m-%d').timestamp()
except Exception:
return 0
res.sort(key=to_key, reverse=(q_order != 'asc'))
except Exception:
res.reverse()
if q_limit:
try:
lim = int(q_limit)
if lim > 0:
res = res[:lim]
except Exception:
pass
if not has_filter:
_audit_cache['tx'] = {'ts': datetime.utcnow().timestamp(), 'list': res}
dur = (datetime.utcnow() - start).total_seconds()
log('audit_tx_cost', f"{dur}s len={len(res)}")
return jsonify({'list': res})
except Exception as e:
log('audit_tx_error', str(e))
return jsonify({'list': []})
@app.get('/api/audit/mt')
@require_login
def audit_mt():
start = datetime.utcnow()
try:
q_start = request.args.get('start')
q_end = request.args.get('end')
q_limit = request.args.get('limit')
q_order = request.args.get('order', 'desc')
has_filter = bool(q_start or q_end or q_limit or q_order)
# 缓存优化3秒内不重复查询
if (not has_filter) and ((datetime.utcnow().timestamp() - _audit_cache['mt']['ts']) < 3):
return jsonify({'list': _audit_cache['mt']['list']})
r = get_redis()
# 设置Redis超时为5秒
r.connection_pool.connection_kwargs['socket_timeout'] = 5
items = []
# 支持大数据量默认返回全部数据可通过limit参数限制
max_items = int(q_limit) if q_limit else 50000
for key in ['mac_batch_audit_mt', 'audit:mt', 'mt:audit']:
try:
if r.exists(key):
t = r.type(key)
if t == 'list':
# 获取全部数据或限制数量
total = r.llen(key)
fetch_count = min(total, max_items)
items = r.lrange(key, -fetch_count, -1)
elif t == 'zset':
items = r.zrevrange(key, 0, max_items - 1)
elif t == 'stream':
entries = r.xrevrange(key, max='+', min='-', count=max_items)
items = [json.dumps(v) for _id, v in entries]
else:
v = r.get(key)
items = [v] if v else []
break
except Exception as e:
log('audit_mt_error', f'Redis query error: {str(e)}')
continue
res = [parse_audit_line(x) for x in items]
if q_start or q_end:
def to_epoch(s):
try:
if not s:
return None
if 'T' in s or 'Z' in s or '+' in s:
return datetime.fromisoformat(s.replace('Z','+00:00')).timestamp()
if ' ' in s and ':' in s:
return datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp()
return datetime.strptime(s, '%Y-%m-%d').timestamp()
except Exception:
return None
s_epoch = to_epoch(q_start) if q_start else None
e_epoch = to_epoch(q_end) if q_end else None
tmp = []
for r0 in res:
ts = to_epoch(r0.get('ts_cn'))
if ts is None:
continue
if s_epoch is not None and ts < s_epoch:
continue
if e_epoch is not None and ts > e_epoch:
continue
tmp.append(r0)
res = tmp
try:
def to_key(r):
s = r.get('ts_cn') or ''
try:
if 'T' in s or 'Z' in s or '+' in s:
return datetime.fromisoformat(s.replace('Z','+00:00')).timestamp()
if ' ' in s and ':' in s:
return datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp()
return datetime.strptime(s, '%Y-%m-%d').timestamp()
except Exception:
return 0
res.sort(key=to_key, reverse=(q_order != 'asc'))
except Exception:
res.reverse()
if q_limit:
try:
lim = int(q_limit)
if lim > 0:
res = res[:lim]
except Exception:
pass
if not has_filter:
_audit_cache['mt'] = {'ts': datetime.utcnow().timestamp(), 'list': res}
dur = (datetime.utcnow() - start).total_seconds()
log('audit_mt_cost', f"{dur}s len={len(res)}")
return jsonify({'list': res})
except Exception as e:
log('audit_mt_error', str(e))
return jsonify({'list': []})
@app.get('/api/audit/diagnose')
@require_login
def audit_diagnose():
try:
r = get_redis()
result = {}
for key in ['mac_batch_audit_pdd', 'mac_batch_audit_yt', 'batch_sn_mapping_pdd', 'batch_sn_mapping_yt']:
for key in ['mac_batch_audit_pdd', 'mac_batch_audit_yt', 'mac_batch_audit_tx', 'mac_batch_audit_mt', 'batch_sn_mapping_pdd', 'batch_sn_mapping_yt']:
try:
t = r.type(key)
if t == 'list':

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 KiB