baseline: 小军 WMS 二开代码原始快照(含 SynOABusiness.cs Debugger.Break)

This commit is contained in:
Gaussian committed 2026-11-06 18:38:38 +08:00
commit c2b0e7be0d
6522 files changed
+3530643

No files matched your search

+856
View File
@@ -0,0 +1,856 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MES扫码物料追溯看板 - Gaussian</title>
<!-- 公共侧边栏组件 -->
<link rel="stylesheet" href="../common/nav.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI','Microsoft YaHei',sans-serif; background: #f0f2f5; color: #333; }
/* ===== 顶部导航栏 ===== */
.top-bar {
position: fixed; top: 0; left: 0; right: 0; height: 48px;
background: linear-gradient(90deg, #001529 0%, #003a70 100%);
display: flex; align-items: center; padding: 0 24px; z-index: 100;
}
.top-bar .logo { color: #fff; font-size: 16px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }
.top-bar .top-links { display: flex; gap: 4px; height: 100%; margin-left: 40px; }
.top-bar .top-links a {
color: rgba(255,255,255,0.75); text-decoration: none; padding: 0 20px;
display: flex; align-items: center; font-size: 14px; border-radius: 4px 4px 0 0;
transition: all 0.2s;
}
.top-bar .top-links a:hover, .top-bar .top-links a.active { color: #fff; background: rgba(255,255,255,0.15); }
.top-bar .user-info { margin-left: auto; font-size: 13px; color: rgba(255,255,255,0.85); }
/* ===== 页面主体 ===== */
.page-body { padding-top: 48px; }
.header {
background: #fff; padding: 16px 24px; display: flex; justify-content: space-between;
align-items: center; box-shadow: 0 1px 4px rgba(0,0,0,0.05); margin-bottom: 16px;
}
.header h1 { font-size: 20px; font-weight: 600; color: #333; }
.header-right { display: flex; align-items: center; gap: 16px; }
.header-right span { font-size: 13px; color: #999; }
.btn-refresh {
padding: 6px 16px; background: #1890ff; color: #fff; border: none;
border-radius: 4px; font-size: 13px; cursor: pointer; transition: background 0.2s;
}
.btn-refresh:hover { background: #40a9ff; }
.container { padding: 0 24px 24px; }
/* ===== Tab栏 ===== */
.tabs {
display: flex; gap: 4px; background: #fff; padding: 0 24px;
border-radius: 8px 8px 0 0; box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.tab {
padding: 12px 24px; cursor: pointer; font-size: 14px; color: #666;
border-bottom: 2px solid transparent; transition: all 0.2s; white-space: nowrap;
}
.tab:hover { color: #1890ff; }
.tab.active { color: #1890ff; border-bottom-color: #1890ff; font-weight: 500; }
.tab .badge {
display: inline-block; background: #f0f0f0; color: #666; font-size: 12px;
padding: 1px 8px; border-radius: 10px; margin-left: 4px;
}
.tab.active .badge { background: #e6f7ff; color: #1890ff; }
/* ===== 全部机型对比视图 ===== */
.compare-view { padding-top: 16px; }
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; }
.machine-card {
background: #fff; border-radius: 8px; overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.06); transition: box-shadow 0.3s;
}
.machine-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.machine-card-header {
padding: 12px 20px; color: #fff; font-size: 16px; font-weight: 600;
display: flex; justify-content: space-between; align-items: center;
}
.machine-card-header.gss { background: linear-gradient(135deg, #1890ff, #0050b3); }
.machine-card-header.gs50 { background: linear-gradient(135deg, #52c41a, #389e0d); }
.machine-card-header.gs40 { background: linear-gradient(135deg, #fa8c16, #d4380d); }
.machine-card-header.gssw { background: linear-gradient(135deg, #f5222d, #a8071a); }
.machine-card-header .product-count { font-size: 13px; font-weight: 400; opacity: 0.9; }
.machine-card-body { padding: 20px; }
.coverage-ring { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; }
.ring-svg { width: 80px; height: 80px; flex-shrink: 0; }
.ring-info { flex: 1; }
.ring-info .rate { font-size: 28px; font-weight: 700; line-height: 1.2; }
.ring-info .label { font-size: 12px; color: #999; margin-bottom: 2px; }
.ring-info .detail { font-size: 13px; color: #666; }
.status-row { display: flex; gap: 12px; margin-bottom: 16px; }
.status-item {
flex: 1; text-align: center; padding: 8px; border-radius: 6px; background: #fafafa;
}
.status-item .num { font-size: 20px; font-weight: 700; line-height: 1.4; }
.status-item .text { font-size: 12px; color: #999; }
.status-item.completed .num { color: #52c41a; }
.status-item.exception .num { color: #f5222d; }
.status-item.pending .num { color: #bfbfbf; }
.process-bars { display: flex; flex-direction: column; gap: 6px; }
.process-bar-item { font-size: 12px; }
.process-bar-label { display: flex; justify-content: space-between; margin-bottom: 2px; }
.process-bar-label .name { color: #666; }
.process-bar-label .pct { font-weight: 600; }
.process-bar-track { height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden; }
.process-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }
.process-bar-fill.high { background: #52c41a; }
.process-bar-fill.mid { background: #1890ff; }
.process-bar-fill.zero { background: #d9d9d9; }
.machine-card-footer { padding: 8px 20px; border-top: 1px solid #f0f0f0; text-align: right; }
.machine-card-footer a { color: #1890ff; cursor: pointer; font-size: 13px; text-decoration: none; }
.machine-card-footer a:hover { text-decoration: underline; }
/* ===== 单机型深度视图 ===== */
.detail-view { padding-top: 16px; }
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi-card {
background: #fff; border-radius: 8px; padding: 20px; text-align: center;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.kpi-card .value { font-size: 32px; font-weight: 700; line-height: 1.2; }
.kpi-card .label { font-size: 13px; color: #999; margin-top: 4px; }
.kpi-card .sub { font-size: 11px; color: #bbb; margin-top: 2px; }
.kpi-card.blue .value { color: #1890ff; }
.kpi-card.green .value { color: #52c41a; }
.kpi-card.red .value { color: #f5222d; }
.kpi-card.gray .value { color: #bfbfbf; }
.kpi-card.orange .value { color: #fa8c16; }
.kpi-card.purple .value { color: #722ed1; }
/* 图表区 */
.chart-row { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; margin-bottom: 16px; }
.chart-card {
background: #fff; border-radius: 8px; padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.chart-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: #333; }
/* 环形图 */
.donut-container { display: flex; align-items: center; justify-content: center; gap: 20px; }
.donut-svg { width: 160px; height: 160px; }
.donut-legend { font-size: 13px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.donut-legend-item .dot { width: 10px; height: 10px; border-radius: 50%; }
.donut-legend-item .pct { font-weight: 600; margin-left: auto; }
/* 工序条形图 */
.process-bars-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; }
/* 产品明细表 */
.product-table-wrapper {
background: #fff; border-radius: 8px; padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.product-table-wrapper h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.product-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.product-table th { text-align: left; padding: 10px 12px; background: #fafafa; color: #666; font-weight: 500; border-bottom: 2px solid #e8e8e8; white-space: nowrap; }
.product-table td { padding: 10px 12px; border-bottom: 1px solid #f5f5f5; }
.product-table tr:hover { background: #fafafa; }
.progress-bar { display: inline-block; width: 120px; height: 14px; background: #f0f0f0; border-radius: 7px; overflow: hidden; vertical-align: middle; margin-right: 8px; border: 1px solid #e8e8e8; }
.progress-bar-fill { height: 100%; border-radius: 6px; transition: width 0.3s; }
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.status-badge.normal { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.status-badge.abnormal { background: #fff1f0; color: #f5222d; border: 1px solid #ffa39e; }
.status-badge.notstart { background: #fafafa; color: #bfbfbf; border: 1px solid #d9d9d9; }
.btn-detail { color: #1890ff; cursor: pointer; font-size: 13px; }
.btn-detail:hover { text-decoration: underline; }
/* 搜索栏 */
.search-bar { display: flex; gap: 12px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.search-bar input, .search-bar select { padding: 6px 12px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; outline: none; }
.search-bar input:focus, .search-bar select:focus { border-color: #1890ff; }
.btn-search { padding: 6px 16px; background: #1890ff; color: #fff; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; }
.btn-search:hover { background: #40a9ff; }
/* 分页 */
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.pagination button { padding: 4px 10px; border: 1px solid #d9d9d9; background: #fff; border-radius: 4px; font-size: 12px; cursor: pointer; color: #555; }
.pagination button:hover:not(:disabled) { border-color: #1890ff; color: #1890ff; }
.pagination button.active { background: #1890ff; color: #fff; border-color: #1890ff; }
.pagination button:disabled { opacity: 0.5; cursor: default; }
.pagination span { font-size: 12px; color: #999; margin: 0 4px; }
/* 弹窗 */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 8px; width: 800px; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #e8e8e8; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { font-size: 22px; color: #999; cursor: pointer; line-height: 1; }
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; }
.trace-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.trace-table th { text-align: left; padding: 8px 12px; background: #fafafa; color: #666; font-weight: 500; border-bottom: 1px solid #e8e8e8; white-space: nowrap; }
.trace-table td { padding: 8px 12px; border-bottom: 1px solid #f5f5f5; }
.trace-table .scanned { color: #52c41a; }
.trace-table .not-scanned { color: #bfbfbf; }
/* 折线图 */
.trend-card {
background: #fafafa; border: 1px solid #f0f0f0; border-radius: 8px;
padding: 16px; margin-bottom: 20px;
}
.trend-card h4 {
font-size: 14px; font-weight: 600; color: #333;
margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.trend-card h4::before { content: ''; width: 4px; height: 14px; background: #1890ff; border-radius: 2px; }
.trend-chart { position: relative; width: 100%; height: 220px; }
.trend-tooltip {
position: absolute; background: rgba(0,0,0,0.75); color: #fff; padding: 6px 10px;
border-radius: 4px; font-size: 12px; pointer-events: none; display: none;
white-space: nowrap; z-index: 10;
}
.trend-tooltip.show { display: block; }
.chart-legend { display: flex; gap: 20px; margin-top: 8px; font-size: 12px; color: #666; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-item .legend-dot { width: 14px; height: 3px; border-radius: 2px; }
/* 加载中 */
.loading-overlay {
display: none; position: fixed; inset: 0; background: rgba(255,255,255,0.6);
z-index: 999; justify-content: center; align-items: center;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
width: 40px; height: 40px; border: 3px solid #e8e8e8;
border-top-color: #1890ff; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Toast */
.toast {
position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
padding: 10px 24px; border-radius: 4px; font-size: 14px; z-index: 2000;
opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.error { background: #fff1f0; color: #f5222d; border: 1px solid #ffa39e; }
/* 空状态 */
.empty-state { text-align: center; padding: 60px 20px; color: #bbb; font-size: 14px; }
</style>
</head>
<body>
<!-- 侧边栏 -->
<div id="sidebar"></div>
<div class="page-body">
<!-- 标题栏 -->
<div class="header">
<h1>MES 扫码物料追溯看板</h1>
<div class="header-right">
<span id="curTime"></span>
<button class="btn-refresh" onclick="refreshData()">刷新数据</button>
</div>
</div>
<!-- 机型Tab栏 -->
<div class="tabs" id="tabBar"></div>
<div class="container">
<!-- 全部机型对比视图 -->
<div id="compareView" class="compare-view">
<div class="machine-grid" id="machineGrid"></div>
</div>
<!-- 单机型深度视图 -->
<div id="detailView" class="detail-view" style="display:none">
<div class="kpi-row" id="kpiRow"></div>
<div class="chart-row">
<div class="chart-card">
<h3>产品扫码状态分布</h3>
<div class="donut-container" id="donutContainer"></div>
</div>
<div class="chart-card">
<h3>各工序扫码数量</h3>
<div class="process-bars-detail" id="detailProcessBars"></div>
</div>
</div>
<!-- 近一周扫码率趋势 -->
<div class="chart-card" style="margin-bottom:16px">
<h3>近一周每日扫码率</h3>
<div class="trend-chart" id="machineTrendChart"></div>
<div class="chart-legend">
<div class="chart-legend-item"><span class="legend-dot" style="background:#1890ff"></span>每日扫码率(实扫/应扫)</div>
<div class="chart-legend-item"><span class="legend-dot" style="background:#52c41a"></span>基准线 100%</div>
</div>
</div>
<div class="product-table-wrapper">
<h3>产品扫码明细</h3>
<div class="search-bar">
<input type="text" placeholder="搜索车号 / SN..." id="txtSearch">
<select id="selStatus">
<option value="">全部状态</option>
<option value="normal">正常完成</option>
<option value="abnormal">漏扫异常</option>
<option value="notstart">未扫码</option>
</select>
<select id="selLine">
<option value="">全部产线</option>
</select>
<button class="btn-search" onclick="filterProducts()">查询</button>
</div>
<table class="product-table" id="productTable"></table>
<div class="pagination" id="pagination"></div>
</div>
</div>
</div><!-- /container -->
</div><!-- /page-body -->
<!-- 产品扫码详情弹窗 -->
<div class="modal-overlay" id="modalOverlay">
<div class="modal">
<div class="modal-header">
<h3 id="modalTitle">扫码追溯详情</h3>
<span class="modal-close" onclick="closeModal()">&times;</span>
</div>
<div class="modal-body" id="modalBody"></div>
</div>
</div>
<!-- 加载中 -->
<div class="loading-overlay" id="loading">
<div class="loading-spinner"></div>
</div>
<!-- Toast -->
<div class="toast" id="toast"></div>
<script>
/* ===== 全局变量 ===== */
var dashboardData = null; // 全部机型汇总数据
var machineDetail = null; // 当前机型详情数据
var currentMachine = null; // 当前选中的机型key
var filteredProducts = [];
var currentPage = 1;
var pageSize = 10;
/* ===== 工具函数 ===== */
function showLoading() { document.getElementById('loading').classList.add('show'); }
function hideLoading() { document.getElementById('loading').classList.remove('show'); }
function toast(msg) {
var el = document.getElementById('toast');
el.textContent = msg;
el.classList.add('show', 'error');
setTimeout(function() { el.classList.remove('show'); }, 3000);
}
function barClass(barPct) {
if (barPct > 0) return 'mid';
return 'zero';
}
function barColor(scanned) {
return scanned > 0 ? '#1890ff' : '#d9d9d9';
}
function statusBadge(status) {
var map = { normal: '正常完成', abnormal: '漏扫异常', notstart: '未扫码' };
return '<span class="status-badge ' + status + '">' + (map[status] || status) + '</span>';
}
function machineClass(fType) {
var key = (fType || '').toLowerCase();
if (key.indexOf('gssw') >= 0) return 'gssw';
if (key.indexOf('gss') >= 0) return 'gss';
if (key.indexOf('gs50') >= 0) return 'gs50';
if (key.indexOf('gs40') >= 0) return 'gs40';
return 'gss';
}
function machineColor(fType) {
var colors = { gss: '#1890ff', gs50: '#52c41a', gs40: '#fa8c16', gssw: '#f5222d' };
return colors[machineClass(fType)] || '#1890ff';
}
/* ===== API 调用 ===== */
function apiGet(url, callback) {
showLoading();
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function() {
hideLoading();
try {
var r = JSON.parse(xhr.responseText);
if (r.success) { callback(r.data); }
else { toast(r.message || '获取数据失败'); }
} catch(e) { toast('数据解析异常'); }
};
xhr.onerror = function() { hideLoading(); toast('网络请求失败'); };
xhr.send();
}
function loadDashboardData(callback) {
apiGet('../../api/Mes/GetDashboardData', function(data) {
dashboardData = data;
renderTabs();
if (callback) callback();
else renderCompareView();
});
}
/* 默认打开 GSS 机型详情视图 */
function openDefaultMachine() {
if (!dashboardData || !dashboardData.machines || dashboardData.machines.length === 0) {
renderCompareView();
return;
}
// 优先找 GSS(精确匹配),找不到则回退第一个机型
var defaultType = null;
for (var i = 0; i < dashboardData.machines.length; i++) {
if (dashboardData.machines[i].fType === 'GSS') {
defaultType = 'GSS';
break;
}
}
if (!defaultType) defaultType = dashboardData.machines[0].fType;
showDetailView(defaultType);
}
function loadMachineDetail(fType) {
apiGet('../../api/Mes/GetMachineDetail?fType=' + encodeURIComponent(fType), function(data) {
machineDetail = data;
renderDetailView(fType);
});
}
function loadProductDetail(fInterID) {
apiGet('../../api/Mes/GetProductDetail?fInterID=' + encodeURIComponent(fInterID), function(data) {
showProductDetailModal(data);
});
}
/* ===== 渲染Tab栏 ===== */
function renderTabs() {
if (!dashboardData || !dashboardData.machines) return;
var html = '<div class="tab active" onclick="showCompareView()">全部机型 <span class="badge">' + dashboardData.totalCount + '</span></div>';
dashboardData.machines.forEach(function(m) {
html += '<div class="tab" onclick="showDetailView(\'' + m.fType + '\')">' + m.fType + ' <span class="badge">' + m.count + '</span></div>';
});
document.getElementById('tabBar').innerHTML = html;
}
/* ===== 渲染全部机型对比 ===== */
function renderCompareView() {
if (!dashboardData || !dashboardData.machines || dashboardData.machines.length === 0) {
document.getElementById('machineGrid').innerHTML = '<div class="empty-state">暂无扫码数据</div>';
return;
}
var grid = document.getElementById('machineGrid');
var html = '';
dashboardData.machines.forEach(function(m) {
var cls = machineClass(m.fType);
var color = machineColor(m.fType);
var circ = 2 * Math.PI * 32;
var dashLen = (m.coverage / 100) * circ;
html += '<div class="machine-card">'
+ '<div class="machine-card-header ' + cls + '">'
+ '<span>' + m.fType + '</span>'
+ '<span class="product-count">' + m.count + ' 台</span>'
+ '</div>'
+ '<div class="machine-card-body">'
+ '<div class="coverage-ring">'
+ '<svg class="ring-svg" viewBox="0 0 80 80">'
+ '<circle cx="40" cy="40" r="32" fill="none" stroke="#f0f0f0" stroke-width="8"/>'
+ '<circle cx="40" cy="40" r="32" fill="none" stroke="' + color + '" stroke-width="8" stroke-dasharray="' + dashLen.toFixed(1) + ' ' + circ.toFixed(1) + '" stroke-linecap="round" transform="rotate(-90 40 40)"/>'
+ '<text x="40" y="44" text-anchor="middle" font-size="16" font-weight="700" fill="' + color + '">' + m.coverage + '%</text>'
+ '</svg>'
+ '<div class="ring-info">'
+ '<div class="rate" style="color:' + color + '">' + m.coverage + '%</div>'
+ '<div class="label">整体扫码覆盖率</div>'
+ '<div class="detail">正常完成 ' + m.status.normal + ' / 总数 ' + m.count + '</div>'
+ '</div>'
+ '</div>'
+ '<div class="status-row">'
+ '<div class="status-item completed"><div class="num">' + m.status.normal + '</div><div class="text">正常完成</div></div>'
+ '<div class="status-item exception"><div class="num">' + m.status.abnormal + '</div><div class="text">漏扫异常</div></div>'
+ '<div class="status-item pending"><div class="num">' + m.status.notstart + '</div><div class="text">未扫码</div></div>'
+ '</div>'
+ '<div class="process-bars">';
if (m.processes && m.processes.length > 0) {
m.processes.forEach(function(p) {
html += '<div class="process-bar-item">'
+ '<div class="process-bar-label"><span class="name">' + p.name + '</span><span class="pct" style="color:' + barColor(p.scanned) + '">扫码: ' + p.scanned + '</span></div>'
+ '<div class="process-bar-track"><div class="process-bar-fill ' + barClass(p.barPct) + '" style="width:' + p.barPct + '%"></div></div>'
+ '</div>';
});
} else {
html += '<div style="color:#bbb;font-size:12px;padding:8px 0">暂无工序扫码数据</div>';
}
html += '</div></div>'
+ '<div class="machine-card-footer"><a onclick="showDetailView(\'' + m.fType + '\')">查看详情 ></a></div>'
+ '</div>';
});
grid.innerHTML = html;
}
/* ===== 渲染单机型深度视图 ===== */
function renderDetailView(fType) {
var d = machineDetail;
if (!d) return;
currentMachine = fType;
var color = machineColor(fType);
// KPI
var pctC = d.count > 0 ? (d.status.normal / d.count * 100).toFixed(1) : 0;
var pctA = d.count > 0 ? (d.status.abnormal / d.count * 100).toFixed(1) : 0;
var pctN = d.count > 0 ? (d.status.notstart / d.count * 100).toFixed(1) : 0;
document.getElementById('kpiRow').innerHTML = ''
+ '<div class="kpi-card blue"><div class="value">' + d.count + '</div><div class="label">产品总数</div><div class="sub">' + fType + ' 机型</div></div>'
+ '<div class="kpi-card green"><div class="value">' + d.status.normal + '</div><div class="label">正常完成</div><div class="sub">' + pctC + '%</div></div>'
+ '<div class="kpi-card red"><div class="value">' + d.status.abnormal + '</div><div class="label">漏扫异常</div><div class="sub">' + pctA + '%</div></div>'
+ '<div class="kpi-card gray"><div class="value">' + d.status.notstart + '</div><div class="label">未扫码</div><div class="sub">' + pctN + '%</div></div>'
+ '<div class="kpi-card orange"><div class="value">' + d.totalRealityQty + '</div><div class="label">实扫总数</div><div class="sub">应扫 ' + d.totalNeedQty + '</div></div>'
+ '<div class="kpi-card purple"><div class="value">' + d.coverage + '%</div><div class="label">整体覆盖率</div><div class="sub">正常完成/总数</div></div>';
// 环形图
var total = d.count;
var s1 = d.status.normal, s2 = d.status.abnormal, s3 = d.status.notstart;
var circ = 2 * Math.PI * 60;
var d1 = total > 0 ? (s1 / total) * circ : 0;
var d2 = total > 0 ? (s2 / total) * circ : 0;
var donutHtml = '<svg class="donut-svg" viewBox="0 0 160 160">'
+ '<circle cx="80" cy="80" r="60" fill="none" stroke="#f0f0f0" stroke-width="20"/>'
+ '<circle cx="80" cy="80" r="60" fill="none" stroke="#52c41a" stroke-width="20" stroke-dasharray="' + d1.toFixed(1) + ' ' + circ.toFixed(1) + '" transform="rotate(-90 80 80)"/>'
+ '<circle cx="80" cy="80" r="60" fill="none" stroke="#f5222d" stroke-width="20" stroke-dasharray="' + d2.toFixed(1) + ' ' + circ.toFixed(1) + '" stroke-dashoffset="-' + d1.toFixed(1) + '" transform="rotate(-90 80 80)"/>'
+ '<text x="80" y="76" text-anchor="middle" font-size="28" font-weight="700" fill="#333">' + total + '</text>'
+ '<text x="80" y="96" text-anchor="middle" font-size="12" fill="#999">总产量</text>'
+ '</svg>'
+ '<div class="donut-legend">'
+ '<div class="donut-legend-item"><span class="dot" style="background:#52c41a"></span>正常完成 <span class="pct">' + s1 + (total > 0 ? ' (' + (s1/total*100).toFixed(1) + '%)' : '') + '</span></div>'
+ '<div class="donut-legend-item"><span class="dot" style="background:#f5222d"></span>漏扫异常 <span class="pct">' + s2 + (total > 0 ? ' (' + (s2/total*100).toFixed(1) + '%)' : '') + '</span></div>'
+ '<div class="donut-legend-item"><span class="dot" style="background:#f0f0f0;border:1px solid #d9d9d9"></span>未扫码 <span class="pct">' + s3 + (total > 0 ? ' (' + (s3/total*100).toFixed(1) + '%)' : '') + '</span></div>'
+ '</div>';
document.getElementById('donutContainer').innerHTML = donutHtml;
// 工序扫码数量
var procEl = document.getElementById('detailProcessBars');
if (d.processes && d.processes.length > 0) {
var procHtml = '';
d.processes.forEach(function(p) {
procHtml += '<div class="process-bar-item">'
+ '<div class="process-bar-label"><span class="name">' + p.name + '</span><span class="pct" style="color:' + barColor(p.scanned) + '">扫码: ' + p.scanned + '</span></div>'
+ '<div class="process-bar-track"><div class="process-bar-fill ' + barClass(p.barPct) + '" style="width:' + p.barPct + '%"></div></div>'
+ '</div>';
});
procEl.innerHTML = procHtml;
} else {
procEl.innerHTML = '<div class="empty-state" style="padding:20px">暂无工序扫码数据</div>';
}
// 近一周每日扫码量折线图
renderTrendChart('machineTrendChart', d.trend || []);
// 初始化产线筛选
var lines = [];
if (d.products) {
d.products.forEach(function(p) {
if (p.line && lines.indexOf(p.line) < 0) lines.push(p.line);
});
}
lines.sort();
var selLine = document.getElementById('selLine');
selLine.innerHTML = '<option value="">全部产线</option>';
lines.forEach(function(l) { selLine.innerHTML += '<option value="' + l + '">' + l + '</option>'; });
// 产品明细
filteredProducts = (d.products || []).slice();
currentPage = 1;
renderProductTable();
}
/* ===== 产品明细表 ===== */
function renderProductTable() {
var el = document.getElementById('productTable');
var start = (currentPage - 1) * pageSize;
var pageData = filteredProducts.slice(start, start + pageSize);
if (pageData.length === 0) {
el.innerHTML = '<thead><tr><th>车号</th><th>SN</th><th>机型</th><th>应扫</th><th>实扫</th><th>进度</th><th>状态</th><th>缺失工序</th><th>记录时间</th><th>操作</th></tr></thead><tbody><tr><td colspan="10" style="text-align:center;color:#bbb;padding:24px">暂无数据</td></tr></tbody>';
document.getElementById('pagination').innerHTML = '';
return;
}
var html = '<thead><tr><th>车号</th><th>SN</th><th>机型</th><th>应扫</th><th>实扫</th><th>进度</th><th>状态</th><th>缺失工序</th><th>记录时间</th><th>操作</th></tr></thead><tbody>';
pageData.forEach(function(p) {
var pct = p.expected > 0 ? (p.actual / p.expected * 100).toFixed(1) : 0;
var pctNum = parseFloat(pct);
var barBg = pctNum >= 100 ? '#52c41a' : pctNum > 0 ? '#1890ff' : '#bfbfbf';
html += '<tr>'
+ '<td>' + p.carNo + '</td>'
+ '<td>' + p.sn + '</td>'
+ '<td>' + p.fType + '</td>'
+ '<td>' + p.expected + '</td>'
+ '<td>' + p.actual + '</td>'
+ '<td><span class="progress-bar"><span class="progress-bar-fill" style="width:' + Math.min(pct, 100) + '%;background:' + barBg + '"></span></span>' + pct + '%</td>'
+ '<td>' + statusBadge(p.status) + '</td>'
+ '<td>' + (p.missingProcs || '--') + '</td>'
+ '<td>' + p.fDate + '</td>'
+ '<td><span class="btn-detail" onclick="loadProductDetail(\'' + p.fInterID + '\')">详情</span></td>'
+ '</tr>';
});
html += '</tbody>';
el.innerHTML = html;
renderPagination();
}
function renderPagination() {
var total = filteredProducts.length;
var totalPages = Math.ceil(total / pageSize);
var el = document.getElementById('pagination');
if (totalPages <= 1) { el.innerHTML = '<span>共 ' + total + ' 条</span>'; return; }
var html = '<span>共 ' + total + ' 条</span>';
html += '<button onclick="goPage(1)" ' + (currentPage === 1 ? 'disabled' : '') + '>首页</button>';
html += '<button onclick="goPage(' + (currentPage - 1) + ')" ' + (currentPage === 1 ? 'disabled' : '') + '>上一页</button>';
for (var i = 1; i <= totalPages; i++) {
if (i === 1 || i === totalPages || Math.abs(i - currentPage) <= 2) {
html += '<button onclick="goPage(' + i + ')" class="' + (i === currentPage ? 'active' : '') + '">' + i + '</button>';
} else if (Math.abs(i - currentPage) === 3) {
html += '<span>...</span>';
}
}
html += '<button onclick="goPage(' + (currentPage + 1) + ')" ' + (currentPage === totalPages ? 'disabled' : '') + '>下一页</button>';
html += '<button onclick="goPage(' + totalPages + ')" ' + (currentPage === totalPages ? 'disabled' : '') + '>末页</button>';
el.innerHTML = html;
}
function goPage(p) { currentPage = p; renderProductTable(); }
function filterProducts() {
if (!machineDetail || !machineDetail.products) return;
var kw = document.getElementById('txtSearch').value.trim().toLowerCase();
var st = document.getElementById('selStatus').value;
var line = document.getElementById('selLine').value;
filteredProducts = machineDetail.products.filter(function(p) {
var matchKw = !kw || (p.carNo || '').toLowerCase().indexOf(kw) >= 0 || (p.sn || '').toLowerCase().indexOf(kw) >= 0;
var matchSt = !st || p.status === st;
var matchLine = !line || p.line === line;
return matchKw && matchSt && matchLine;
});
currentPage = 1;
renderProductTable();
}
/* ===== 产品扫码详情弹窗 ===== */
function showProductDetailModal(data) {
var html = '<div style="margin-bottom:16px;display:flex;gap:24px;font-size:13px;flex-wrap:wrap;">'
+ '<div><span style="color:#999">车号:</span><b>' + data.carNo + '</b></div>'
+ '<div><span style="color:#999">SN:</span><b>' + data.sn + '</b></div>'
+ '<div><span style="color:#999">机型:</span><b>' + data.fType + '</b></div>'
+ '<div><span style="color:#999">状态:</span>' + statusBadge(data.status) + '</div>'
+ '<div><span style="color:#999">应扫总数:</span><b>' + data.expected + '</b></div>'
+ '<div><span style="color:#999">实扫总数:</span><b>' + data.actual + '</b></div>'
+ '<div><span style="color:#999">记录时间:</span>' + data.fDate + '</div>'
+ '</div>';
if (data.processes && data.processes.length > 0) {
html += '<table class="trace-table"><thead><tr>'
+ '<th>序号</th><th>工序编号</th><th>工序名称</th><th>扫码数量</th><th>扫码状态</th>'
+ '</tr></thead><tbody>';
data.processes.forEach(function(p, idx) {
html += '<tr>'
+ '<td>' + (idx + 1) + '</td>'
+ '<td>' + p.code + '</td>'
+ '<td>' + p.name + '</td>'
+ '<td class="' + (p.scanned ? 'scanned' : 'not-scanned') + '">' + p.qty + '</td>'
+ '<td>' + (p.scanned ? '<span class="status-badge normal">已扫码</span>' : '<span class="status-badge notstart">未扫码</span>') + '</td>'
+ '</tr>';
});
html += '</tbody></table>';
} else {
html += '<div class="empty-state">暂无工序扫码记录</div>';
}
document.getElementById('modalTitle').textContent = '扫码追溯详情 - ' + data.carNo;
document.getElementById('modalBody').innerHTML = html;
document.getElementById('modalOverlay').classList.add('show');
}
function closeModal() { document.getElementById('modalOverlay').classList.remove('show'); }
/* ===== 近一周扫码率折线图(SVG,百分比) ===== */
function renderTrendChart(containerId, trend) {
var el = document.getElementById(containerId);
if (!el || !trend || trend.length === 0) {
if (el) el.innerHTML = '<div class="empty-state" style="padding:30px">暂无近一周扫码数据</div>';
return;
}
var W = el.clientWidth || 700;
var H = 220;
var padL = 44, padR = 16, padT = 16, padB = 36;
var plotW = W - padL - padR;
var plotH = H - padT - padB;
// 取每个点的扫码率(%)
var getVal = function(t) { return t.ratio || 0; };
// Y轴范围:0 ~ 上限(至少100,向上取整到50的倍数)
var maxVal = 100;
trend.forEach(function(t) { var v = getVal(t); if (v > maxVal) maxVal = v; });
maxVal = Math.ceil(maxVal / 50) * 50;
var n = trend.length;
var stepX = n > 1 ? plotW / (n - 1) : 0;
var yFor = function(v) { return padT + plotH - (v / maxVal) * plotH; };
var xFor = function(i) { return padL + i * stepX; };
var html = '<svg width="' + W + '" height="' + H + '" style="display:block">';
// 网格线 + Y轴刻度(5等分)
var yTicks = [0, 0.25, 0.5, 0.75, 1];
yTicks.forEach(function(r) {
var y = yFor(maxVal * r);
html += '<line x1="' + padL + '" y1="' + y + '" x2="' + (W - padR) + '" y2="' + y + '" stroke="#f0f0f0" stroke-width="1"/>';
html += '<text x="' + (padL - 6) + '" y="' + (y + 4) + '" text-anchor="end" font-size="11" fill="#999">' + Math.round(maxVal * r) + '%</text>';
});
// 基准线 100%
if (maxVal >= 100) {
var y100 = yFor(100);
html += '<line x1="' + padL + '" y1="' + y100 + '" x2="' + (W - padR) + '" y2="' + y100 + '" stroke="#52c41a" stroke-width="1" stroke-dasharray="4,4"/>';
}
// X轴标签
trend.forEach(function(t, i) {
var x = xFor(i);
html += '<text x="' + x + '" y="' + (H - padB + 16) + '" text-anchor="middle" font-size="11" fill="#666">' + t.label + '</text>';
});
// 折线路径
var linePath = '', areaPath = 'M ' + padL + ' ' + yFor(0);
trend.forEach(function(t, i) {
var x = xFor(i), y = yFor(getVal(t));
linePath += (i === 0 ? 'M ' : 'L ') + x + ' ' + y + ' ';
areaPath += ' L ' + x + ' ' + y;
});
areaPath += ' L ' + xFor(n - 1) + ' ' + yFor(0) + ' Z';
html += '<path d="' + areaPath + '" fill="rgba(24,144,255,0.10)" stroke="none"/>';
html += '<path d="' + linePath + '" fill="none" stroke="#1890ff" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>';
// 数据点 + tooltip
trend.forEach(function(t, i) {
var x = xFor(i), y = yFor(getVal(t));
html += '<circle cx="' + x + '" cy="' + y + '" r="4" fill="#fff" stroke="#1890ff" stroke-width="2" style="cursor:pointer" data-label="' + t.label + '" data-ratio="' + getVal(t) + '" data-need="' + (t.needQty || 0) + '" data-reality="' + (t.realityQty || 0) + '"/>';
});
html += '</svg>';
html += '<div class="trend-tooltip" id="trendTooltip"></div>';
el.innerHTML = html;
// tooltip 交互
var tooltip = document.getElementById('trendTooltip');
el.querySelectorAll('circle').forEach(function(c) {
c.addEventListener('mousemove', function(e) {
tooltip.innerHTML = '<b>' + c.getAttribute('data-label') + '</b><br>'
+ '实扫 ' + c.getAttribute('data-reality') + ' / 应扫 ' + c.getAttribute('data-need') + '<br>'
+ '扫码率 ' + c.getAttribute('data-ratio') + '%';
tooltip.style.left = (c.getAttribute('cx') - 50) + 'px';
tooltip.style.top = (c.getAttribute('cy') - 34) + 'px';
tooltip.classList.add('show');
});
c.addEventListener('mouseleave', function() { tooltip.classList.remove('show'); });
});
}
/* ===== 视图切换 ===== */
function showCompareView() {
document.querySelectorAll('.tab').forEach(function(t) { t.classList.remove('active'); });
var firstTab = document.querySelector('.tab');
if (firstTab) firstTab.classList.add('active');
document.getElementById('compareView').style.display = '';
document.getElementById('detailView').style.display = 'none';
currentMachine = null;
renderCompareView();
}
function showDetailView(fType) {
document.querySelectorAll('.tab').forEach(function(t) { t.classList.remove('active'); });
var tabs = document.querySelectorAll('.tab');
if (dashboardData) {
for (var i = 0; i < dashboardData.machines.length; i++) {
if (dashboardData.machines[i].fType === fType && tabs[i + 1]) {
tabs[i + 1].classList.add('active');
break;
}
}
}
document.getElementById('compareView').style.display = 'none';
document.getElementById('detailView').style.display = '';
loadMachineDetail(fType);
}
function refreshData() {
if (currentMachine) {
loadMachineDetail(currentMachine);
} else {
loadDashboardData(function() { renderCompareView(); });
}
}
/* ===== 实时时间 ===== */
function updateTime() {
var now = new Date();
var pad = function(n) { return n < 10 ? '0' + n : n; };
document.getElementById('curTime').textContent =
now.getFullYear() + '-' + pad(now.getMonth() + 1) + '-' + pad(now.getDate()) + ' '
+ pad(now.getHours()) + ':' + pad(now.getMinutes()) + ':' + pad(now.getSeconds());
}
/* ===== 页面访问控制:Produce02;导航栏由公共组件提供 ===== */
(function() {
var userData = sessionStorage.getItem('gx_user');
if (!userData) { window.location.href = '../../login.html'; return; }
try {
var user = JSON.parse(userData);
var roles = user.roleNumbers || [];
if (roles.indexOf('Produce02') < 0) {
alert('当前用户无权限访问MES看板');
sessionStorage.removeItem('gx_user');
window.location.href = '../../login.html';
return;
}
} catch(e) {
alert('登录信息异常,请重新登录');
window.location.href = '../../login.html';
return;
}
// 初始化
updateTime();
setInterval(updateTime, 1000);
loadDashboardData(openDefaultMachine);
startAutoRefresh();
})();
/* ===== 定时自动刷新 ===== */
function startAutoRefresh() {
apiGet('../../api/Mes/GetConfig', function(config) {
var seconds = (config && config.autoRefreshSeconds) ? config.autoRefreshSeconds : 600;
if (seconds <= 0) {
console.log('自动刷新已关闭');
return;
}
console.log('看板每 ' + seconds + ' 秒自动刷新一次');
setInterval(function() {
refreshData();
}, seconds * 1000);
});
}
</script>
<!-- 公共侧边栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>