Compare commits
No commits in common. "6b2e2d663508d95635d42ec8bc2e80c8c2b5d9e4" and "ae058ccf4fa368c9fa876d1d8cc6cbf343fd72cd" have entirely different histories.
6b2e2d6635
...
ae058ccf4f
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB |
@ -2572,10 +2572,8 @@ 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: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-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-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}
|
||||
@ -2624,7 +2622,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:0;height:100vh;border-radius:0;overflow:hidden;background:#ffffff;border:none;box-shadow:none;display:flex;flex-direction:row}
|
||||
#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 .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}
|
||||
@ -2653,17 +2651,14 @@ 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:flex-end;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:space-between;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:12px 0 0 0;width:100%;z-index:1}
|
||||
#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)}
|
||||
[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}
|
||||
@ -2797,14 +2792,10 @@ 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);gap:12px}
|
||||
.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)}
|
||||
[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);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-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-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}
|
||||
@ -2817,12 +2808,3 @@ 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)}
|
||||
|
||||
@ -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,6 +229,20 @@
|
||||
</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;">
|
||||
@ -246,13 +260,6 @@
|
||||
</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" />
|
||||
@ -293,11 +300,7 @@
|
||||
<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-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>
|
||||
<div class="notification-modal-title">🔔</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>
|
||||
|
||||
@ -173,12 +173,8 @@ 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,
|
||||
|
||||
@ -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;min-height:400px" onclick="AIReport.generateReport()">
|
||||
<div class="card" style="flex:1;display:flex;flex-direction:column;background:var(--surface);cursor:pointer;position:relative;overflow:hidden" 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" />
|
||||
|
||||
@ -67,6 +67,8 @@ 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>
|
||||
|
||||
@ -141,6 +143,8 @@ 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>
|
||||
|
||||
@ -178,7 +182,7 @@ const Dashboard = (() => {
|
||||
|
||||
if (title === '良品 / 不良率') {
|
||||
// 良品率趋势(简化处理,显示固定趋势)
|
||||
return { value: "", color: "#10b981", text: "" };
|
||||
return { value: "+2.4%", color: "#10b981", text: "较昨日" };
|
||||
} else if (title.includes('今日产量')) {
|
||||
// 获取平台特定产量
|
||||
const platform = title.includes('拼多多') ? 'pdd' : 'yt';
|
||||
@ -194,7 +198,7 @@ const Dashboard = (() => {
|
||||
|
||||
// 计算趋势
|
||||
if (yesterdayValue === 0) {
|
||||
return { value: "", color: "#10b981", text: "" };
|
||||
return { value: todayValue > 0 ? "+100%" : "0%", color: "#10b981", text: "较昨日" };
|
||||
}
|
||||
|
||||
const change = ((todayValue - yesterdayValue) / yesterdayValue * 100).toFixed(1);
|
||||
@ -207,9 +211,9 @@ const Dashboard = (() => {
|
||||
}
|
||||
|
||||
return {
|
||||
value: "",
|
||||
value: (isUp ? "+" : "") + change + "%",
|
||||
color: color,
|
||||
text: ""
|
||||
text: "较昨日"
|
||||
};
|
||||
};
|
||||
|
||||
@ -241,6 +245,8 @@ 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>
|
||||
|
||||
@ -470,18 +476,14 @@ const Dashboard = (() => {
|
||||
});
|
||||
|
||||
async function render() {
|
||||
const [dRes,pRes,yRes,tRes,mRes] = await Promise.allSettled([
|
||||
const [dRes,pRes,yRes] = await Promise.allSettled([
|
||||
API.dashboard(),
|
||||
API.auditPddQuiet(),
|
||||
API.auditYtQuiet(),
|
||||
API.auditTxQuiet(),
|
||||
API.auditMtQuiet()
|
||||
API.auditYtQuiet()
|
||||
]);
|
||||
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>';
|
||||
@ -512,8 +514,6 @@ 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, txData, mtData) => {
|
||||
const drawTrendChart = (pddData, ytData) => {
|
||||
const canvas = document.getElementById('trend-chart');
|
||||
if(!canvas) return;
|
||||
const ctx = canvas.getContext('2d');
|
||||
@ -639,15 +639,10 @@ const Dashboard = (() => {
|
||||
|
||||
const pddCounts = countByTime(pddData);
|
||||
const ytCounts = countByTime(ytData);
|
||||
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 maxCount = Math.max(...pddCounts, ...ytCounts, 1);
|
||||
|
||||
// 绘制参数(使用逻辑尺寸而非物理像素)
|
||||
// 根据最大值动态调整左边距,确保Y轴标签不被截断
|
||||
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};
|
||||
@ -659,7 +654,7 @@ const Dashboard = (() => {
|
||||
const effectiveChartHeight = chartHeight - yAxisMargin;
|
||||
|
||||
// 保存图表数据供鼠标事件使用
|
||||
chartData = {timePoints, pddCounts, ytCounts, txCounts, mtCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight};
|
||||
chartData = {timePoints, pddCounts, ytCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight};
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = colors.bg;
|
||||
@ -756,13 +751,9 @@ 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 / platformScale) * effectiveChartHeight
|
||||
y: padding.top + chartHeight - yAxisMargin - (count / maxCount) * effectiveChartHeight
|
||||
}));
|
||||
|
||||
// 1. 绘制填充区域
|
||||
@ -846,10 +837,8 @@ 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时不显示)
|
||||
@ -890,14 +879,12 @@ const Dashboard = (() => {
|
||||
};
|
||||
|
||||
// 初始化缓存数据
|
||||
window.__auditCache = window.__auditCache || {pdd: [], yt: [], tx: [], mt: []};
|
||||
window.__auditCache = window.__auditCache || {pdd: [], yt: []};
|
||||
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, tx.list, mt.list);
|
||||
drawTrendChart(pdd.list, yt.list);
|
||||
|
||||
// 监听主题切换事件,立即重绘图表
|
||||
const themeChangeHandler = () => {
|
||||
@ -908,13 +895,7 @@ const Dashboard = (() => {
|
||||
const ytData = (window.__auditCache && window.__auditCache.yt && window.__auditCache.yt.length > 0)
|
||||
? window.__auditCache.yt
|
||||
: yt.list;
|
||||
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);
|
||||
drawTrendChart(pddData, ytData);
|
||||
};
|
||||
window.addEventListener('themeChanged', themeChangeHandler);
|
||||
|
||||
@ -933,7 +914,7 @@ const Dashboard = (() => {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const mouseX = e.clientX - rect.left;
|
||||
const mouseY = e.clientY - rect.top;
|
||||
const {timePoints, pddCounts, ytCounts, txCounts, mtCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight} = chartData;
|
||||
const {timePoints, pddCounts, ytCounts, maxCount, padding, chartWidth, chartHeight, timeRange, yAxisMargin, effectiveChartHeight} = chartData;
|
||||
|
||||
// 查找最近的数据点
|
||||
let nearestIndex = -1;
|
||||
@ -942,13 +923,9 @@ 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 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);
|
||||
const dist = Math.min(distPdd, distYt);
|
||||
if(dist < minDist){
|
||||
minDist = dist;
|
||||
nearestIndex = i;
|
||||
@ -959,12 +936,10 @@ 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:#FF6B81">兔喜: ${txCount}</div><div style="color:#FFB800">美团: ${mtCount}</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:#10B981">圆通: ${ytCount}</div>`;
|
||||
tooltip.style.display = 'block';
|
||||
|
||||
// 获取提示框宽度以便放在鼠标左侧
|
||||
@ -998,10 +973,8 @@ const Dashboard = (() => {
|
||||
window.__trendTimeRange = tab.dataset.range;
|
||||
const pddData = window.__auditCache?.pdd || pdd.list;
|
||||
const ytData = window.__auditCache?.yt || yt.list;
|
||||
const txData = window.__auditCache?.tx || tx.list;
|
||||
const mtData = window.__auditCache?.mt || mt.list;
|
||||
drawTrendChart(pddData, ytData, txData, mtData);
|
||||
updateTrendStats(pddData, ytData, txData, mtData);
|
||||
drawTrendChart(pddData, ytData);
|
||||
updateTrendStats(pddData, ytData);
|
||||
};
|
||||
});
|
||||
// 初始化active样式
|
||||
@ -1013,7 +986,7 @@ const Dashboard = (() => {
|
||||
}
|
||||
|
||||
// 更新趋势统计数据
|
||||
const updateTrendStats = (pddData, ytData, txData, mtData) => {
|
||||
const updateTrendStats = (pddData, ytData) => {
|
||||
const now = new Date();
|
||||
const today = now.toISOString().split('T')[0];
|
||||
const thisMonth = today.slice(0, 7);
|
||||
@ -1056,8 +1029,6 @@ const Dashboard = (() => {
|
||||
// 保存今日各平台产量
|
||||
history[today].pdd = countTodayUnique(pddData);
|
||||
history[today].yt = countTodayUnique(ytData);
|
||||
history[today].tx = countTodayUnique(txData);
|
||||
history[today].mt = countTodayUnique(mtData);
|
||||
|
||||
// 计算并保存不良数量(假设不良数据在某个字段中)
|
||||
// 这里需要根据实际数据结构调整
|
||||
@ -1086,13 +1057,9 @@ 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 txToday = countTodayUnique(txData);
|
||||
const mtToday = countTodayUnique(mtData);
|
||||
const weekTotal = countWeekUnique(pddData) + countWeekUnique(ytData) + countWeekUnique(txData) + countWeekUnique(mtData);
|
||||
const weekTotal = countWeekUnique(pddData) + countWeekUnique(ytData);
|
||||
|
||||
// 更新DOM
|
||||
const el = (id) => document.getElementById(id);
|
||||
@ -1100,14 +1067,12 @@ 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 + txToday + mtToday > 0){
|
||||
if(pddToday + ytToday > 0){
|
||||
statusEl.textContent = '生产中';
|
||||
statusEl.style.color = '#10b981';
|
||||
} else {
|
||||
@ -1741,33 +1706,16 @@ const Dashboard = (() => {
|
||||
// 更新整合看板显示
|
||||
const updateAuditDisplay = () => {
|
||||
const platform = window.__currentAuditPlatform;
|
||||
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 params = platform === 'pdd' ? window.__pddParams : window.__ytParams;
|
||||
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>';
|
||||
@ -1778,9 +1726,10 @@ const Dashboard = (() => {
|
||||
if (platformSelect) {
|
||||
platformSelect.onchange = () => {
|
||||
window.__currentAuditPlatform = platformSelect.value;
|
||||
// 清空日期选择器
|
||||
if (auditDateEl) {
|
||||
auditDateEl.value = '';
|
||||
// 同步日期选择器
|
||||
const otherDateEl = platformSelect.value === 'pdd' ? q('audit-date-pdd') : q('audit-date-yt');
|
||||
if (auditDateEl && otherDateEl) {
|
||||
auditDateEl.value = otherDateEl.value;
|
||||
}
|
||||
updateAuditDisplay();
|
||||
};
|
||||
@ -1793,13 +1742,14 @@ const Dashboard = (() => {
|
||||
const platform = window.__currentAuditPlatform;
|
||||
if (platform === 'pdd') {
|
||||
window.__pddParams = dateToRange(d);
|
||||
} else if (platform === 'yt') {
|
||||
const pddDateEl = q('audit-date-pdd');
|
||||
if (pddDateEl) pddDateEl.value = d;
|
||||
} else {
|
||||
window.__ytParams = dateToRange(d);
|
||||
} else if (platform === 'tx') {
|
||||
window.__txParams = dateToRange(d);
|
||||
} else if (platform === 'mt') {
|
||||
window.__mtParams = dateToRange(d);
|
||||
const ytDateEl = q('audit-date-yt');
|
||||
if (ytDateEl) ytDateEl.value = d;
|
||||
}
|
||||
refreshAuditLists();
|
||||
updateAuditDisplay();
|
||||
};
|
||||
}
|
||||
@ -1862,7 +1812,7 @@ const Dashboard = (() => {
|
||||
try {
|
||||
// 请求全部数据(不限制),传递AbortController信号
|
||||
const signal = window.__auditAbortController.signal;
|
||||
const [pddRes, ytRes, txRes, mtRes, dashRes] = await Promise.all([
|
||||
const [pddRes, ytRes, dashRes] = await Promise.all([
|
||||
fetch('/api/audit/pdd', {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
@ -1879,22 +1829,6 @@ 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',
|
||||
@ -1962,12 +1896,10 @@ 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, window.__auditCache.tx, window.__auditCache.mt);
|
||||
updateTrendStats(window.__auditCache.pdd, window.__auditCache.yt, window.__auditCache.tx, window.__auditCache.mt);
|
||||
drawTrendChart(window.__auditCache.pdd, window.__auditCache.yt);
|
||||
updateTrendStats(window.__auditCache.pdd, window.__auditCache.yt);
|
||||
refreshShipmentPlatformStats(false);
|
||||
|
||||
// 更新列表(应用筛选,只显示前100条)
|
||||
@ -2047,7 +1979,7 @@ const Dashboard = (() => {
|
||||
window.__auditTimer=setInterval(refreshAll, 10000);
|
||||
},0);
|
||||
return `
|
||||
<div class="dashboard-container" style="display:flex;flex-direction:column;height:100%;overflow-y:auto;padding-right:8px">
|
||||
<div class="dashboard-container" style="display:flex;flex-direction:column;height:100%;overflow:hidden">
|
||||
<!-- 四个指标卡片 -->
|
||||
<div class="dashboard-metrics-4col" style="flex-shrink:0">
|
||||
${metricsCard('直通良品数', data.fpyCount || 0, 'success')}
|
||||
@ -2058,7 +1990,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);min-height:370px">
|
||||
<div class="card" style="flex:0 0 72%;padding:0;overflow:hidden;border-radius:16px;background:var(--surface)">
|
||||
<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">
|
||||
@ -2087,10 +2019,8 @@ 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:#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>
|
||||
<span style="display:flex;align-items:center;gap:3px"><span style="width:6px;height:6px;border-radius:50%;background:#3B82F6"></span>拼多多</span>
|
||||
</div>
|
||||
<!-- 时间范围选择 -->
|
||||
<div id="trend-range-tabs" style="display:flex;background:var(--surface);border-radius:6px;padding:2px;font-size:11px">
|
||||
@ -2100,26 +2030,18 @@ const Dashboard = (() => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="height:280px;position:relative">
|
||||
<div style="height:230px;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(6,1fr);border-top:1px solid var(--border);background:var(--surface)">
|
||||
<div style="display:grid;grid-template-columns:repeat(4,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>
|
||||
@ -2135,7 +2057,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:360px">
|
||||
<div class="card" style="flex:1;padding:20px;border-radius:16px;display:flex;flex-direction:column;background:var(--surface);min-height:290px">
|
||||
<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">
|
||||
@ -2143,19 +2065,17 @@ 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:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:12px">
|
||||
<div style="display:flex;justify-content:center;gap:24px;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: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 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>
|
||||
</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: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 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>
|
||||
</div>
|
||||
</div>
|
||||
@ -2170,17 +2090,15 @@ const Dashboard = (() => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top:12px;flex:1;min-height:400px;display:flex;gap:12px">
|
||||
<div style="margin-top:12px;flex:1;min-height:0;display:flex;gap:12px">
|
||||
<!-- 审计看板(压缩宽度) -->
|
||||
<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 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 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>
|
||||
|
||||
@ -86,10 +86,10 @@
|
||||
const list = data.list || [];
|
||||
const container = document.getElementById('notification-list');
|
||||
const modalContainer = document.getElementById('notification-modal-list');
|
||||
if (!container && !modalContainer) return;
|
||||
if (!container) return;
|
||||
|
||||
if (list.length === 0) {
|
||||
if (container) container.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
|
||||
container.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
|
||||
if (modalContainer) modalContainer.innerHTML = '<div class="notification-empty">暂无消息通知</div>';
|
||||
return;
|
||||
}
|
||||
@ -103,29 +103,27 @@
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
if (container) container.innerHTML = fullHtml;
|
||||
container.innerHTML = fullHtml;
|
||||
if (modalContainer) modalContainer.innerHTML = fullHtml;
|
||||
|
||||
// 为每个通知项添加点击事件
|
||||
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);
|
||||
}
|
||||
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 => {
|
||||
@ -180,24 +178,21 @@
|
||||
return; // 超级管理员和管理员才显示通知铃铛
|
||||
}
|
||||
|
||||
// 绑定铃铛按钮点击事件
|
||||
const bellBtn = document.getElementById('notification-bell-btn');
|
||||
if (!bellBtn) {
|
||||
console.error('[Notifications] 找不到铃铛按钮元素');
|
||||
// 显示侧边栏通知卡片
|
||||
const card = document.getElementById('sidebar-notification-card');
|
||||
if (!card) {
|
||||
console.error('[Notifications] 找不到侧边栏通知卡片元素');
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除旧的事件监听器
|
||||
const newBellBtn = bellBtn.cloneNode(true);
|
||||
bellBtn.parentNode.replaceChild(newBellBtn, bellBtn);
|
||||
|
||||
newBellBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
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;
|
||||
openModal();
|
||||
});
|
||||
|
||||
console.log('[Notifications] 铃铛按钮已绑定');
|
||||
|
||||
// 弹窗关闭
|
||||
const closeBtn = document.getElementById('notification-modal-close');
|
||||
@ -214,13 +209,13 @@
|
||||
if (isModalOpen && e.key === 'Escape') closeModal();
|
||||
});
|
||||
|
||||
// 绑定弹窗中的全部标记为已读按钮
|
||||
const modalMarkAllBtn = document.getElementById('modal-mark-all-read');
|
||||
if (modalMarkAllBtn) {
|
||||
const newModalMarkAllBtn = modalMarkAllBtn.cloneNode(true);
|
||||
modalMarkAllBtn.parentNode.replaceChild(newModalMarkAllBtn, modalMarkAllBtn);
|
||||
// 绑定全部标记为已读按钮(移除旧的事件监听器)
|
||||
const markAllBtn = document.getElementById('mark-all-read');
|
||||
if (markAllBtn) {
|
||||
const newMarkAllBtn = markAllBtn.cloneNode(true);
|
||||
markAllBtn.parentNode.replaceChild(newMarkAllBtn, markAllBtn);
|
||||
|
||||
newModalMarkAllBtn.addEventListener('click', async (e) => {
|
||||
newMarkAllBtn.addEventListener('click', async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await API.markAllNotificationsRead();
|
||||
@ -233,13 +228,13 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 绑定弹窗中的删除已读消息按钮
|
||||
const modalDeleteBtn = document.getElementById('modal-delete-read');
|
||||
if (modalDeleteBtn) {
|
||||
const newModalDeleteBtn = modalDeleteBtn.cloneNode(true);
|
||||
modalDeleteBtn.parentNode.replaceChild(newModalDeleteBtn, modalDeleteBtn);
|
||||
// 绑定删除已读消息按钮(移除旧的事件监听器)
|
||||
const deleteBtn = document.getElementById('delete-read');
|
||||
if (deleteBtn) {
|
||||
const newDeleteBtn = deleteBtn.cloneNode(true);
|
||||
deleteBtn.parentNode.replaceChild(newDeleteBtn, deleteBtn);
|
||||
|
||||
newModalDeleteBtn.addEventListener('click', async (e) => {
|
||||
newDeleteBtn.addEventListener('click', async (e) => {
|
||||
e.preventDefault();
|
||||
if (!confirm('确定要删除所有已读消息吗?')) {
|
||||
return;
|
||||
|
||||
@ -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" style="max-height:calc(100vh - 200px);overflow-y:auto;padding-right:8px">
|
||||
<div id="repairs-upload-form">
|
||||
<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;position:sticky;bottom:0;background:var(--surface);padding-top:12px;border-top:1px solid var(--border)">
|
||||
<div class="actions" style="display:flex;gap:12px">
|
||||
<button class="btn" id="repairs-upload" style="flex:1">
|
||||
<span id="repairs-upload-text">提交</span>
|
||||
<span id="repairs-upload-loading" style="display:none">
|
||||
@ -271,10 +271,6 @@ 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>
|
||||
`);
|
||||
|
||||
208
server/app.py
208
server/app.py
@ -12,7 +12,7 @@ try:
|
||||
except Exception:
|
||||
redis = None
|
||||
_redis_client = None
|
||||
_audit_cache = {'pdd': {'ts': 0, 'list': []}, 'yt': {'ts': 0, 'list': []}, 'tx': {'ts': 0, 'list': []}, 'mt': {'ts': 0, 'list': []}}
|
||||
_audit_cache = {'pdd': {'ts': 0, 'list': []}, 'yt': {'ts': 0, 'list': []}}
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
DB_PATH = os.path.join(BASE_DIR, 'data.db')
|
||||
@ -1265,217 +1265,13 @@ 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', 'mac_batch_audit_tx', 'mac_batch_audit_mt', 'batch_sn_mapping_pdd', 'batch_sn_mapping_yt']:
|
||||
for key in ['mac_batch_audit_pdd', 'mac_batch_audit_yt', 'batch_sn_mapping_pdd', 'batch_sn_mapping_yt']:
|
||||
try:
|
||||
t = r.type(key)
|
||||
if t == 'list':
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 711 KiB |
Loading…
Reference in New Issue
Block a user