feat: 完善仓库建筑绑定、质检预警规则与大屏展示
这个提交包含在:
@@ -346,7 +346,7 @@ html, body {
|
||||
display: inline-flex;
|
||||
gap: 16px;
|
||||
white-space: nowrap;
|
||||
animation: marquee-scroll 45s linear infinite;
|
||||
animation: marquee-scroll var(--marquee-duration, 90s) linear infinite;
|
||||
}
|
||||
|
||||
.alert-marquee-track:hover {
|
||||
@@ -1189,12 +1189,12 @@ html, body {
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
margin: 6px 0 8px 0;
|
||||
background: linear-gradient(135deg, rgba(6, 14, 32, 0.52) 0%, rgba(3, 8, 20, 0.45) 100%);
|
||||
background: linear-gradient(135deg, rgba(12, 26, 44, 0.97) 0%, rgba(8, 19, 33, 0.98) 100%);
|
||||
border: 1px solid rgba(56, 189, 248, 0.25);
|
||||
border-top: 1.5px solid rgba(56, 189, 248, 0.65);
|
||||
border-radius: 8px;
|
||||
backdrop-filter: blur(20px) saturate(160%);
|
||||
-webkit-backdrop-filter: blur(20px) saturate(160%);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 35px rgba(56, 189, 248, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
||||
padding: 12px 18px;
|
||||
display: flex;
|
||||
@@ -1462,7 +1462,7 @@ html, body {
|
||||
|
||||
.forecast-charts-row {
|
||||
display: grid;
|
||||
grid-template-columns: 58% 42%;
|
||||
grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
@@ -2150,3 +2150,22 @@ html, body {
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forecast analysis: quiet surfaces, legible hierarchy and independent scales. */
|
||||
.forecast-charts-row > .center-chart-card { min-width: 0; }
|
||||
.forecast-charts-row .center-chart-card-title-bar { flex-wrap: wrap; align-items: flex-start; gap: 4px; margin-bottom: 8px; }
|
||||
.forecast-charts-row .center-chart-card-title { color: #e3edf7; font-size: 13px; margin-bottom: 0; letter-spacing: .2px; }
|
||||
.forecast-charts-row .center-chart-card:last-child { padding-left: 18px; border-left-color: rgba(148, 173, 200, .13); }
|
||||
.forecast-chart-note { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; color: #8ba4bd; font-size: 10px; line-height: 1.7; padding: 0 0 12px; }
|
||||
.threshold-key { color: #dfb883; }
|
||||
.forecast-env-pill { color: #9eb5cb; border-color: #314459; background: #132438; font-size: 9px; }
|
||||
.forecast-env-bar { border-color: #2a4058; box-shadow: none; padding: 8px 10px; flex-wrap: wrap; }
|
||||
.forecast-env-items { flex-wrap: wrap; gap: 7px; }
|
||||
.forecast-env-label { color: #c2d2e3; }
|
||||
.forecast-env-label .env-pulse-icon, .chart-pulse-dot { animation: none; box-shadow: none; }
|
||||
.center-chart-board .center-chart-title { color: #dcebf8; }
|
||||
.center-chart-tabs { border-color: #30465e; border-radius: 6px; background: #0b192b; }
|
||||
.center-chart-tab { padding: 6px 12px; }
|
||||
.center-chart-tab#tab-chart-forecast.active { background: #193e58; color: #93e4f6; box-shadow: none; border-color: #306079; }
|
||||
.center-chart-board button:focus-visible { outline: 2px solid #91d9f5; outline-offset: 3px; }
|
||||
@media (prefers-reduced-motion: reduce) { .center-chart-board { animation: none; } }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>中储粮(遵义)智慧粮仓综合监测中心</title>
|
||||
<link rel="stylesheet" href="./css/style.css">
|
||||
<link rel="stylesheet" href="./css/style.css?v=20261028_chart3">
|
||||
<!-- ECharts 可视化库 (CDN) -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
|
||||
</head>
|
||||
@@ -298,7 +298,7 @@
|
||||
<div class="forecast-env-bar">
|
||||
<div class="forecast-env-label">
|
||||
<span class="env-pulse-icon"></span>
|
||||
<span>推演环境工况 (API输入):</span>
|
||||
<span>推演环境设置</span>
|
||||
</div>
|
||||
<div class="forecast-env-items">
|
||||
<div class="forecast-env-group">
|
||||
@@ -340,9 +340,10 @@
|
||||
<!-- 左侧:多周期未来质量演变趋势折线图 (含国家警戒线) -->
|
||||
<div class="center-chart-card">
|
||||
<div class="center-chart-card-title-bar">
|
||||
<div class="center-chart-card-title" id="forecast-trend-title">粮食质量指标多周期演变趋势推演 (未来 7~60天走势与国家警戒线)</div>
|
||||
<div class="center-chart-card-title" id="forecast-trend-title">多周期趋势</div>
|
||||
<div class="forecast-env-pill" id="forecast-trend-env-pill">工况: 仓内 18.5℃ / 72.4% · 仓外 32.5℃ / 54.2%</div>
|
||||
</div>
|
||||
<div class="forecast-chart-note"><span>各指标独立刻度 · 保留原始单位</span><span>● 实测起点 ┈ 预测趋势 <span class="threshold-key">┄ 警戒参考</span></span></div>
|
||||
<div id="chart-forecast-trend" class="center-chart-canvas"></div>
|
||||
</div>
|
||||
<!-- 右侧:现状实测 vs 预测推演偏离对比柱状图 -->
|
||||
@@ -350,6 +351,7 @@
|
||||
<div class="center-chart-card-title-bar">
|
||||
<div class="center-chart-card-title" id="forecast-compare-title">现状实测值 vs 预测终值偏离对比与风险评估</div>
|
||||
</div>
|
||||
<div class="forecast-chart-note">同一指标内对比柱长 · 悬停查看变化量</div>
|
||||
<div id="chart-forecast-compare" class="center-chart-canvas"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -403,7 +405,7 @@
|
||||
<span>数据接口: <strong>https://grain.gynhc.com/api/index/granaryList</strong> (数据同步正常)</span>
|
||||
</div>
|
||||
<div class="footer-item">
|
||||
<span>全库仓罐总数: <strong>20 座/栋</strong></span>
|
||||
<span>全库仓罐总数: <strong id="depot-total-count">20 座/栋</strong></span>
|
||||
</div>
|
||||
<div class="footer-item">
|
||||
<span>电视遥控/键盘: <strong>[方向键 ← / →] 切换仓房</strong> | <strong>[V键] 切换鸟瞰图</strong> | <strong>[空格键] 全屏控制</strong></span>
|
||||
@@ -415,6 +417,6 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script type="module" src="./js/app.js?v=20260916_v3"></script>
|
||||
<script type="module" src="./js/app.js?v=20261028_chart3"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -17,8 +17,11 @@ import {
|
||||
getAerialModeConfig,
|
||||
getNextAerialMode,
|
||||
CENTER_HOTSPOT_COORDS,
|
||||
generateDepotAlerts
|
||||
} from './grain_monitor_core.js';
|
||||
CENTER_EXTRA_POSITIONS,
|
||||
resolveHotspotCoord,
|
||||
generateDepotAlerts,
|
||||
syncAlertMarqueeSpeed
|
||||
} from './grain_monitor_core.js?v=20261028_chart3';
|
||||
|
||||
// 全局状态
|
||||
const STATE = {
|
||||
@@ -96,28 +99,7 @@ async function fetchGranaryData() {
|
||||
if (!res.ok) continue;
|
||||
const json = await res.json();
|
||||
if (json && json.data && Array.isArray(json.data.list) && json.data.list.length > 0) {
|
||||
let list = json.data.list;
|
||||
// 业务规范对齐:若线上外部API尚未同步最新规划 (缺少44号仓),自动执行“新增的是43,后面的仓库递增”
|
||||
if (!list.some(item => item.name && item.name.includes('44号'))) {
|
||||
list = list.map(item => {
|
||||
if (item.name === '43号仓房' || (item.id === 46 && item.name.includes('43'))) {
|
||||
return {
|
||||
...item,
|
||||
name: '44号仓房',
|
||||
num: 44,
|
||||
content: item.content ? { ...item.content, code: '44', warehouseType: '高大平房仓' } : item.content
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
if (!list.some(item => item.id === 51 || item.name === '43号仓房')) {
|
||||
const default43 = DEFAULT_GRANARY_DATA?.data?.list?.find(i => i.id === 51);
|
||||
if (default43) {
|
||||
list.push(default43);
|
||||
}
|
||||
}
|
||||
}
|
||||
const list = json.data.list;
|
||||
STATE.list = normalizeGranaryList({ ...json, data: { ...json.data, list } });
|
||||
if (json.data && json.data.coords) {
|
||||
STATE.customCoords = json.data.coords;
|
||||
@@ -172,6 +154,9 @@ function renderDepotAlerts() {
|
||||
const marqueeTrack = document.getElementById('alert-marquee-track');
|
||||
if (!marqueeTrack) return;
|
||||
const alerts = generateDepotAlerts(STATE.list, STATE.envData);
|
||||
const signature = alerts.map(a => `${a.id}|${a.text}`).join('\n');
|
||||
if (marqueeTrack.dataset.alertSignature === signature && marqueeTrack.childElementCount > 0) return;
|
||||
marqueeTrack.dataset.alertSignature = signature;
|
||||
marqueeTrack.innerHTML = '';
|
||||
const displayAlerts = alerts.length > 0 ? (alerts.length === 1 ? alerts : alerts.concat(alerts)) : [];
|
||||
displayAlerts.forEach(alert => {
|
||||
@@ -192,6 +177,7 @@ function renderDepotAlerts() {
|
||||
}
|
||||
marqueeTrack.appendChild(pill);
|
||||
});
|
||||
requestAnimationFrame(() => syncAlertMarqueeSpeed(marqueeTrack));
|
||||
}
|
||||
|
||||
// 4. 渲染顶部 KPIs
|
||||
@@ -204,6 +190,16 @@ function renderKPIs() {
|
||||
document.getElementById('kpi-utilization').textContent = `${s.utilizationRate}%`;
|
||||
document.getElementById('kpi-warehouse-count').textContent = `${s.warehouseCount} 栋`;
|
||||
document.getElementById('kpi-oil-count').textContent = `${s.oilTankCount} 座`;
|
||||
const filterLabels = {
|
||||
all: `全部 (${STATE.list.length})`,
|
||||
warehouse: `平房仓群 (${s.warehouseCount})`,
|
||||
oilTank: `储油罐区 (${s.oilTankCount})`
|
||||
};
|
||||
document.querySelectorAll('.filter-btn[data-filter]').forEach(button => {
|
||||
button.textContent = filterLabels[button.dataset.filter];
|
||||
});
|
||||
const totalCount = document.getElementById('depot-total-count');
|
||||
if (totalCount) totalCount.textContent = `${STATE.list.length} 座/栋`;
|
||||
}
|
||||
|
||||
// 5. 渲染 3D 鸟瞰图全景热点图钉 (20 个仓房/油罐全量覆盖,像素级对准与错层防重叠)
|
||||
@@ -211,12 +207,10 @@ function renderHotspots() {
|
||||
const container = document.getElementById('aerial-hotspots');
|
||||
if (!container) return;
|
||||
|
||||
const hotspotCoords = STATE.customCoords ? { ...CENTER_HOTSPOT_COORDS, ...STATE.customCoords } : CENTER_HOTSPOT_COORDS;
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
STATE.list.forEach(item => {
|
||||
const rawCoord = hotspotCoords[item.id] || hotspotCoords[item.num] || hotspotCoords[item.name];
|
||||
const rawCoord = resolveHotspotCoord(item, STATE.customCoords, CENTER_HOTSPOT_COORDS);
|
||||
if (!rawCoord) return;
|
||||
|
||||
const coord = {
|
||||
@@ -241,7 +235,7 @@ function renderHotspots() {
|
||||
pin.style.left = `${coord.x}%`;
|
||||
pin.style.top = `${coord.y}%`;
|
||||
|
||||
const shortName = item.name.replace('号仓房', '号仓').replace('号油罐', '号罐');
|
||||
const shortName = `${item.num}号${isOil ? '罐' : '仓'}`;
|
||||
|
||||
let stemHtml = '';
|
||||
if (hasStem) {
|
||||
@@ -259,8 +253,8 @@ function renderHotspots() {
|
||||
|
||||
pin.innerHTML = `
|
||||
<div class="bubble-inner">
|
||||
<span class="bubble-name">${shortName}</span>
|
||||
<span class="bubble-tag">${item.grainName}</span>
|
||||
<span class="bubble-name"></span>
|
||||
<span class="bubble-tag"></span>
|
||||
</div>
|
||||
<div class="bubble-arrow"></div>
|
||||
${stemHtml}
|
||||
@@ -271,8 +265,25 @@ function renderHotspots() {
|
||||
selectGranary(item.id, true);
|
||||
};
|
||||
|
||||
pin.querySelector('.bubble-name').textContent = shortName;
|
||||
pin.querySelector('.bubble-tag').textContent = item.grainName;
|
||||
container.appendChild(pin);
|
||||
});
|
||||
|
||||
// 未建台账的位置只显示待编号,不参与库存统计或质量预测。
|
||||
if (STATE.filterType !== 'oilTank') {
|
||||
Object.entries(CENTER_EXTRA_POSITIONS).forEach(([position, coord]) => {
|
||||
if (STATE.list.some(item => item.screenPosition === position)) return;
|
||||
const pin = document.createElement('div');
|
||||
pin.className = 'hotspot-pin wheat pending-warehouse';
|
||||
pin.style.left = `${coord.x}%`;
|
||||
pin.style.top = `${coord.y}%`;
|
||||
pin.style.cursor = 'default';
|
||||
pin.title = '请在后台粮仓管理添加仓库,选择对应的大屏建筑位置并填写仓号';
|
||||
pin.innerHTML = '<div class="bubble-inner"><span class="bubble-name">待编号</span></div><div class="bubble-arrow"></div>';
|
||||
container.appendChild(pin);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 渲染底部仓房/油罐快捷导航条 (纯净 20 仓罐双排点阵)
|
||||
@@ -293,8 +304,10 @@ function renderMiniGrid() {
|
||||
const typeClass = isOil ? 'oil' : (item.grainName === '稻谷' ? 'paddy' : 'wheat');
|
||||
const isActive = item.id === STATE.activeId;
|
||||
btn.className = `mini-btn ${typeClass} ${isActive ? 'active' : ''}`;
|
||||
const shortName = item.name.replace('号仓房', '号仓').replace('号油罐', '号罐');
|
||||
btn.innerHTML = `<span class="btn-name">${shortName}</span><span class="btn-grain">${item.grainName}</span>`;
|
||||
const shortName = `${item.num}号${isOil ? '罐' : '仓'}`;
|
||||
btn.innerHTML = '<span class="btn-name"></span><span class="btn-grain"></span>';
|
||||
btn.querySelector('.btn-name').textContent = shortName;
|
||||
btn.querySelector('.btn-grain').textContent = item.grainName;
|
||||
btn.title = `${item.name} (${item.grainName}) - 实存 ${item.storageNum} 吨`;
|
||||
btn.onclick = () => selectGranary(item.id, true);
|
||||
container.appendChild(btn);
|
||||
@@ -633,7 +646,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
|
||||
setupForecastEnvControls();
|
||||
|
||||
const currentReport = getGranaryQualityReport(grainName, currentItem.rawContent || currentItem.content || {});
|
||||
const currentReport = getGranaryQualityReport(grainName, currentItem.rawContent || currentItem.content || {}, currentItem.qualityTest);
|
||||
|
||||
// 1. 0 毫秒即时秒出基础图表 (杜绝任何白屏与残亮点)
|
||||
const baselineList = [
|
||||
@@ -673,6 +686,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const initialFuture30 = initialSeries.metrics.map(m => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
unit: m.unit,
|
||||
predictedValue: m.values[3] !== undefined ? m.values[3] : m.values[m.values.length - 1]
|
||||
}));
|
||||
const initialCompareOption = buildForecastCompareChartOption(grainType, currentReport?.items || [], initialFuture30);
|
||||
@@ -698,7 +712,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const series = generateForecastSeries(grainType, currentReport, forecastList, STATE.forecastEnv);
|
||||
|
||||
if (trendTitleEl) {
|
||||
trendTitleEl.textContent = `${currentItem.name} (${grainName}) 质量指标多周期演变推演 (当前实测与未来 7~60天)`;
|
||||
trendTitleEl.textContent = `${currentItem.name} (${grainName}) 多周期趋势`;
|
||||
}
|
||||
const trendOption = buildForecastTrendChartOption(series);
|
||||
if (trendOption) {
|
||||
@@ -708,11 +722,12 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const future30Targets = series.metrics.map(m => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
unit: m.unit,
|
||||
predictedValue: m.values[3] !== undefined ? m.values[3] : m.values[m.values.length - 1]
|
||||
}));
|
||||
|
||||
if (compareTitleEl) {
|
||||
compareTitleEl.textContent = `${currentItem.name} 现状实测 vs 未来30天预测终值偏离评估`;
|
||||
compareTitleEl.textContent = `${currentItem.name} 未来30天 · 变化对比`;
|
||||
}
|
||||
const compareOption = buildForecastCompareChartOption(grainType, currentReport?.items || [], future30Targets);
|
||||
if (compareOption) {
|
||||
|
||||
@@ -205,6 +205,34 @@ export function aggregateWarehouseData(warehouseList) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台 json_encode 未保留中文,反斜杠又在入库时被吃掉,字段会变成 u9ad8u5927 这种串。
|
||||
* 只还原落在汉字区的码位,避免误伤普通编号。
|
||||
* @param {string} value
|
||||
*/
|
||||
export function decodeLooseUnicodeString(value) {
|
||||
if (typeof value !== 'string' || !value.includes('u')) return value;
|
||||
return value.replace(/\\?u([0-9a-fA-F]{4})/g, (match, hex) => {
|
||||
const code = parseInt(hex, 16);
|
||||
const isCjk = (code >= 0x3400 && code <= 0x9FFF)
|
||||
|| (code >= 0xF900 && code <= 0xFAFF)
|
||||
|| (code >= 0x3000 && code <= 0x303F)
|
||||
|| (code >= 0xFF00 && code <= 0xFFEF);
|
||||
return isCjk ? String.fromCharCode(code) : match;
|
||||
});
|
||||
}
|
||||
|
||||
function decodeLooseUnicodeDeep(input) {
|
||||
if (typeof input === 'string') return decodeLooseUnicodeString(input);
|
||||
if (Array.isArray(input)) return input.map(decodeLooseUnicodeDeep);
|
||||
if (input && typeof input === 'object') {
|
||||
const out = {};
|
||||
for (const [key, val] of Object.entries(input)) out[key] = decodeLooseUnicodeDeep(val);
|
||||
return out;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准化 API 返回的 granaryList 列表
|
||||
* @param {Object} apiData 接口返回数据 { code, msg, data: { list: [...] } }
|
||||
@@ -213,14 +241,14 @@ export function normalizeGranaryList(apiData) {
|
||||
const rawList = apiData?.data?.list || apiData?.list || (Array.isArray(apiData) ? apiData : []);
|
||||
|
||||
return rawList.map(item => {
|
||||
const content = decodeLooseUnicodeDeep(item.content || {});
|
||||
const isOilTank = item.granary_type === 1 || item.name.includes('油罐');
|
||||
const isSilo = item.granary_type === 3 ||
|
||||
item.name.includes('浅圆') ||
|
||||
item.name.includes('筒仓') ||
|
||||
item.content?.warehouseType?.includes('浅圆') ||
|
||||
item.content?.warehouseType?.includes('筒仓');
|
||||
content.warehouseType?.includes('浅圆') ||
|
||||
content.warehouseType?.includes('筒仓');
|
||||
const grainTypeCategory = isOilTank ? 'oilTank' : (isSilo ? 'silo' : 'warehouse');
|
||||
const content = item.content || {};
|
||||
|
||||
const capacityNum = Number(content.capacity || content.tankCapacity || 0);
|
||||
const storageNum = Number(content.storageNum || 0);
|
||||
@@ -230,6 +258,8 @@ export function normalizeGranaryList(apiData) {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
num: item.num,
|
||||
screenPosition: content.screenPosition || '',
|
||||
screenCoord: item.screen_coord || null,
|
||||
storage: item.storage || '遵义直属库有限公司中心库区',
|
||||
granaryType: item.granary_type,
|
||||
isOilTank,
|
||||
@@ -239,6 +269,7 @@ export function normalizeGranaryList(apiData) {
|
||||
storageNum,
|
||||
utilization: capacityNum > 0 ? Number(((storageNum / capacityNum) * 100).toFixed(1)) : 0,
|
||||
rawContent: content,
|
||||
qualityTest: decodeLooseUnicodeDeep(item.quality_test || null),
|
||||
createTime: item.create_time
|
||||
};
|
||||
});
|
||||
@@ -329,10 +360,11 @@ export function evaluateQualityStatus(item) {
|
||||
|
||||
if (item.type === 'qualitative') {
|
||||
const val = String(item.value || '');
|
||||
const isOk = val.includes('正常') || val.includes('达标') || val.includes('宜存') ||
|
||||
const negative = /不合格|未达标|不达标|不宜存|不符合|异常|不具有|未有|有异味/.test(val.replace(/无异味/g, ''));
|
||||
const isOk = !negative && (val.includes('正常') || val.includes('达标') || val.includes('宜存') ||
|
||||
val.includes('符合') || val.includes('合格') || val.includes('透明') ||
|
||||
val.includes('变浅') || val.includes('棕') || val.includes('固有') ||
|
||||
val.includes('无析出物') || val.includes('无异味') || val.includes('未检出');
|
||||
val.includes('无析出物') || val.includes('无异味') || val.includes('未检出'));
|
||||
return isOk
|
||||
? { status: 'normal', statusText: '健康达标', badgeText: '达标', color: '#10b981' }
|
||||
: { status: 'danger', statusText: '超标异常', badgeText: '异常', color: '#ef4444' };
|
||||
@@ -370,7 +402,7 @@ export function evaluateQualityStatus(item) {
|
||||
* @param {string} grainTypeOrName 品种名称或类型
|
||||
* @param {Object} overrides 仓房特有指标覆盖 (如 { water: '12.8%' })
|
||||
*/
|
||||
export function getGranaryQualityReport(grainTypeOrName = '小麦', overrides = {}) {
|
||||
export function getGranaryQualityReport(grainTypeOrName = '小麦', overrides = {}, qualityTest = null) {
|
||||
const str = String(grainTypeOrName || '').toLowerCase();
|
||||
let key = 'wheat';
|
||||
if (str.includes('油') || str.includes('oil') || str.includes('rapeseed')) {
|
||||
@@ -386,9 +418,36 @@ export function getGranaryQualityReport(grainTypeOrName = '小麦', overrides =
|
||||
let warnCount = 0;
|
||||
let normalCount = 0;
|
||||
|
||||
const items = benchmark.items.map(baseItem => {
|
||||
// A saved test is the source of truth for values, thresholds and direction.
|
||||
const savedParams = qualityTest?.testing_params || [];
|
||||
const cleanName = name => String(name).replace(/[((].*?[))]/g, '').replace(/[、,,\s]/g, '');
|
||||
const aliases = {
|
||||
'杂质': 'impurity', '杂质总量': 'impurity', '谷外糙米': 'milledGrainOutside',
|
||||
'谷外碾米': 'milledGrainOutside', '互混': 'mixRate', '互混率': 'mixRate',
|
||||
'色泽气味质量指标': 'qualityOdor', '色泽气味储存指标': 'storageOdor',
|
||||
'铅': 'pb', '镉': 'cd', '总汞': 'hg', '总砷': 'as', '无机砷': 'as'
|
||||
};
|
||||
const sourceItems = savedParams.length ? savedParams.map((param, index) => {
|
||||
let itemKey = aliases[cleanName(param.name)];
|
||||
if (String(param.name).includes('色泽') && String(param.name).includes('气味')) {
|
||||
itemKey = String(param.name).includes('储存') ? 'storageOdor' : 'qualityOdor';
|
||||
}
|
||||
const base = benchmark.items.find(it => it.key === itemKey
|
||||
|| cleanName(it.name) === cleanName(param.name) || cleanName(it.shortName) === cleanName(param.name));
|
||||
const numeric = [param.warning, param.alert].every(v => v !== null && v !== undefined
|
||||
&& String(v).trim() !== '' && Number.isFinite(Number(v)));
|
||||
return {
|
||||
...(base || { key: `saved-${param.num || index}`, category: 'physical' }),
|
||||
name: param.name, shortName: base?.shortName || param.name,
|
||||
value: param.val, unit: param.unit || '', warn: param.warning, alert: param.alert,
|
||||
direction: param.direction === 'upper' || param.direction === 'lower' ? param.direction
|
||||
: (numeric && Number(param.warning) > Number(param.alert) ? 'lower' : 'upper'),
|
||||
type: numeric ? undefined : 'qualitative', savedRule: numeric
|
||||
};
|
||||
}) : benchmark.items;
|
||||
const items = sourceItems.map(baseItem => {
|
||||
const item = { ...baseItem };
|
||||
if (overrides[item.key] !== undefined && overrides[item.key] !== null) {
|
||||
if (!savedParams.length && overrides[item.key] !== undefined && overrides[item.key] !== null) {
|
||||
const cleanVal = String(overrides[item.key]).replace(/[^0-9.]/g, '');
|
||||
if (cleanVal) item.value = cleanVal;
|
||||
}
|
||||
@@ -410,8 +469,8 @@ export function getGranaryQualityReport(grainTypeOrName = '小麦', overrides =
|
||||
return {
|
||||
variety: benchmark.variety,
|
||||
varietyKey: key,
|
||||
inspectDate: benchmark.inspectDate,
|
||||
inspectStage: benchmark.inspectStage,
|
||||
inspectDate: qualityTest?.test_date ? String(qualityTest.test_date).replace(/^(\d{4})(\d{2})$/, '$1-$2') : benchmark.inspectDate,
|
||||
inspectStage: qualityTest ? ({ 1: '春季检测', 2: '秋季检测', 3: '满仓验收' }[qualityTest.season] || '最新检测') : benchmark.inspectStage,
|
||||
items,
|
||||
summary: {
|
||||
totalCount: items.length,
|
||||
@@ -428,6 +487,12 @@ export function getGranaryQualityReport(grainTypeOrName = '小麦', overrides =
|
||||
* @param {Object} qualityReport getGranaryQualityReport 返回的对象
|
||||
* @param {string} filterCategory 'all' | 'physical' | 'storage' | 'safety'
|
||||
*/
|
||||
function escapeQualityText(value) {
|
||||
return String(value ?? '').replace(/[&<>"']/g, char => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||
}[char]));
|
||||
}
|
||||
|
||||
export function buildQualityHtml(qualityReport, filterCategory = 'all') {
|
||||
if (!qualityReport || !qualityReport.items) return '';
|
||||
|
||||
@@ -453,14 +518,14 @@ export function buildQualityHtml(qualityReport, filterCategory = 'all') {
|
||||
const displayName = it.shortName || it.name;
|
||||
|
||||
return `
|
||||
<div class="quality-card ${cardClass}" title="${it.name}: ${displayVal} (预警:${it.warn ?? '-'} 警戒:${it.alert ?? '-'} [${it.statusText}])">
|
||||
<div class="quality-card ${cardClass}" title="${escapeQualityText(it.name)}: ${escapeQualityText(displayVal)} (预警:${escapeQualityText(it.warn ?? '-')} 警戒:${escapeQualityText(it.alert ?? '-')} [${it.statusText}])">
|
||||
<div class="quality-card-header">
|
||||
<span class="quality-card-name" title="${it.name}">${displayName}</span>
|
||||
<span class="quality-card-name" title="${escapeQualityText(it.name)}">${escapeQualityText(displayName)}</span>
|
||||
<span class="quality-badge status-${it.status}">${it.badgeText}</span>
|
||||
</div>
|
||||
<div class="quality-card-body">
|
||||
<span class="quality-card-value ${valClass}">${it.status === 'danger' ? '⚠️ ' : ''}${displayVal}</span>
|
||||
<span class="quality-card-thresh">${threshDesc}</span>
|
||||
<span class="quality-card-value ${valClass}">${it.status === 'danger' ? '⚠️ ' : ''}${escapeQualityText(displayVal)}</span>
|
||||
<span class="quality-card-thresh">${escapeQualityText(threshDesc)}</span>
|
||||
</div>
|
||||
</div>
|
||||
`.trim();
|
||||
@@ -618,6 +683,11 @@ export function computeStripMetric(it, varietyKey = 'wheat') {
|
||||
limitDesc = it.value === '未检出' ? `限量达标 · 未检出` : `监测达标`;
|
||||
}
|
||||
|
||||
if (it.savedRule) {
|
||||
const lower = it.direction === 'lower';
|
||||
limitDesc = `${it.status === 'danger' ? '警告' : it.status === 'warn' ? '预警' : '正常'} | ${lower ? '越大越好(低值预警)' : '越小越好(高值预警)'} · 预警${lower ? '<' : '>'}${it.warn} · 警告${lower ? '<' : '>'}${it.alert}${it.unit || ''}`;
|
||||
}
|
||||
|
||||
return {
|
||||
...it,
|
||||
gaugePercent,
|
||||
@@ -655,7 +725,7 @@ export function buildQualityHudHtml(qualityReport, filterCategory = 'all') {
|
||||
|
||||
// 统计各分类数量
|
||||
const totalCount = allItems.length;
|
||||
const coreCount = coreKeys.length;
|
||||
const coreCount = allItems.filter(it => coreKeys.includes(it.key)).length;
|
||||
const physicalCount = allItems.filter(it => it.category === 'physical' || it.category === 'storage').length;
|
||||
const safetyCount = allItems.filter(it => it.category === 'safety').length;
|
||||
|
||||
@@ -670,15 +740,15 @@ export function buildQualityHudHtml(qualityReport, filterCategory = 'all') {
|
||||
const unitStr = item.unit ? `${item.unit}` : '';
|
||||
|
||||
return `
|
||||
<div class="quality-strip-card ${cardClass}" data-key="${item.key}" data-category="${item.category}" title="${item.name}: ${item.value}${unitStr} (${item.limitDesc})">
|
||||
<div class="quality-strip-card ${cardClass}" data-key="${item.key}" data-category="${item.category}" title="${escapeQualityText(item.name)}: ${escapeQualityText(item.value)}${escapeQualityText(unitStr)} (${escapeQualityText(item.limitDesc)})">
|
||||
<div class="strip-card-header">
|
||||
<div class="strip-card-title-group">
|
||||
<span class="strip-card-title">${displayName}</span>
|
||||
<span class="strip-card-title">${escapeQualityText(displayName)}</span>
|
||||
<span class="quality-badge status-${item.status}">${item.badgeText}</span>
|
||||
</div>
|
||||
<div class="strip-card-val-group">
|
||||
<span class="strip-main-val ${valClass}">${alertPrefix}${item.value}</span>
|
||||
<span class="strip-unit">${unitStr}</span>
|
||||
<span class="strip-main-val ${valClass}">${alertPrefix}${escapeQualityText(item.value)}</span>
|
||||
<span class="strip-unit">${escapeQualityText(unitStr)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="strip-card-gauge-box">
|
||||
@@ -687,7 +757,7 @@ export function buildQualityHudHtml(qualityReport, filterCategory = 'all') {
|
||||
</div>
|
||||
</div>
|
||||
<div class="strip-card-footer">
|
||||
<span class="strip-limit-desc">${item.limitDesc}</span>
|
||||
<span class="strip-limit-desc">${escapeQualityText(item.limitDesc)}</span>
|
||||
</div>
|
||||
</div>
|
||||
`.trim();
|
||||
@@ -722,7 +792,7 @@ export function formatGranaryParams(normalizedItem) {
|
||||
const c = normalizedItem.rawContent || {};
|
||||
const isOil = normalizedItem.isOilTank;
|
||||
const grainVariety = normalizedItem.grainName || c.varieties || (isOil ? '菜籽油' : '小麦');
|
||||
const qualityReport = getGranaryQualityReport(grainVariety, c);
|
||||
const qualityReport = getGranaryQualityReport(grainVariety, c, normalizedItem.qualityTest);
|
||||
|
||||
const natureMap = {
|
||||
'ZC': '中央储备粮 (ZC)',
|
||||
@@ -1171,7 +1241,7 @@ export function generateForecastSeries(grainType, currentReport, forecastList =
|
||||
const curVal = findCurrentVal(cfg.key, cfg.fallback);
|
||||
const futureVals = forecastList.map(f => {
|
||||
const tVal = f.targets ? f.targets[cfg.targetKey] : undefined;
|
||||
return tVal !== undefined ? Number(Number(tVal).toFixed(2)) : curVal;
|
||||
return tVal !== undefined && tVal !== null && tVal !== '' && Number.isFinite(Number(tVal)) ? Number(Number(tVal).toFixed(2)) : null;
|
||||
});
|
||||
return {
|
||||
key: cfg.key,
|
||||
@@ -1179,6 +1249,7 @@ export function generateForecastSeries(grainType, currentReport, forecastList =
|
||||
unit: cfg.unit,
|
||||
alert: cfg.alert,
|
||||
warn: cfg.warn,
|
||||
direction: cfg.key === 'glutenWater' ? 'lower' : 'upper',
|
||||
values: [curVal, ...futureVals]
|
||||
};
|
||||
});
|
||||
@@ -1191,238 +1262,151 @@ export function generateForecastSeries(grainType, currentReport, forecastList =
|
||||
};
|
||||
}
|
||||
|
||||
/** OKLCH (L: 0~1, C: 色度, H: 角度) 转换为 sRGB 十六进制颜色。 */
|
||||
export function OklchtoHex(L, C, H) {
|
||||
const hr = (H * Math.PI) / 180;
|
||||
const a = C * Math.cos(hr);
|
||||
const b = C * Math.sin(hr);
|
||||
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
||||
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
||||
const s = (L - 0.0894841775 * a - 1.2914855480 * b) ** 3;
|
||||
const toHex = value => {
|
||||
const x = Math.max(0, Math.min(1, value));
|
||||
const gamma = x >= 0.0031308
|
||||
? 1.055 * Math.pow(x, 1 / 2.4) - 0.055
|
||||
: 12.92 * x;
|
||||
return Math.round(gamma * 255).toString(16).padStart(2, '0');
|
||||
};
|
||||
const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
|
||||
const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
|
||||
const blue = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s;
|
||||
return `#${toHex(r)}${toHex(g)}${toHex(blue)}`;
|
||||
}
|
||||
|
||||
/** 黄金角分布配色;传入起始色相可复用同一套颜色。 */
|
||||
export function distinctColorsOKLCH(count, startHue = Math.random() * 360) {
|
||||
const out = [];
|
||||
let h = startHue;
|
||||
for (let i = 0; i < count; i++) {
|
||||
h = (h + 137.508) % 360;
|
||||
out.push(OklchtoHex(0.72, 0.15 + (i % 4) * 0.02, h));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// 同一页面会先绘制基线再接收算法数据,按指标缓存配色,避免重绘或切仓时跳色。
|
||||
const forecastPaletteHue = Math.random() * 360;
|
||||
const forecastMetricColors = new Map();
|
||||
|
||||
/**
|
||||
* 粮食质量未来趋势 ECharts 配置生成
|
||||
* @param {Object} forecastSeries generateForecastSeries 返回的对象
|
||||
*/
|
||||
const forecastNumber = value => value !== null && value !== undefined && value !== '' && Number.isFinite(parseFloat(value)) ? parseFloat(value) : null;
|
||||
const forecastText = value => forecastNumber(value) === null ? '暂无数据' : Number(Number(value).toFixed(2)).toString();
|
||||
const forecastEscape = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
const forecastTooltip = {
|
||||
trigger: 'axis', confine: true, backgroundColor: '#101f32', borderColor: '#31465d',
|
||||
padding: [12, 16], textStyle: { color: '#e6edf5', fontSize: 12 },
|
||||
extraCssText: 'border-radius:10px;box-shadow:0 12px 32px #0006;line-height:1.7;'
|
||||
};
|
||||
|
||||
export function buildForecastTrendChartOption(forecastSeries) {
|
||||
if (!forecastSeries || !forecastSeries.timeline) return null;
|
||||
if (!forecastSeries?.timeline || !forecastSeries.metrics?.length) return null;
|
||||
const { timeline, metrics, env } = forecastSeries;
|
||||
const envInfo = env || { tm_i: 18.5, tm_o: 32.5, hm_i: 72.4, hm_o: 54.2 };
|
||||
const colors = ['#38bdf8', '#10b981', '#f59e0b', '#ec4899', '#8b5cf6'];
|
||||
|
||||
const colors = distinctColorsOKLCH(forecastMetricColors.size + metrics.length, forecastPaletteHue);
|
||||
const row = 100 / metrics.length;
|
||||
const titles = [], grids = [], xAxes = [], yAxes = [];
|
||||
const series = metrics.map((m, idx) => {
|
||||
const c = colors[idx % colors.length];
|
||||
const s = {
|
||||
name: m.name,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'circle',
|
||||
symbolSize: 6,
|
||||
itemStyle: { color: c },
|
||||
lineStyle: { width: 2.5, color: c },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0, y: 0, x2: 0, y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: c + '40' },
|
||||
{ offset: 1, color: c + '05' }
|
||||
]
|
||||
}
|
||||
},
|
||||
data: m.values
|
||||
};
|
||||
|
||||
if (m.alert !== undefined) {
|
||||
s.markLine = {
|
||||
symbol: ['none', 'none'],
|
||||
silent: true,
|
||||
data: [
|
||||
{
|
||||
yAxis: m.alert,
|
||||
name: `${m.name}警戒线`,
|
||||
lineStyle: { color: '#ef4444', type: 'dashed', width: 1.5 },
|
||||
label: {
|
||||
formatter: `${m.name}警戒: {c}`,
|
||||
position: 'insideEndTop',
|
||||
color: '#f87171',
|
||||
fontSize: 10,
|
||||
fontWeight: 600,
|
||||
backgroundColor: 'rgba(15, 23, 42, 0.75)',
|
||||
borderColor: 'rgba(239, 68, 68, 0.4)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 3,
|
||||
padding: [2, 4]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
return s;
|
||||
const key = m.key || m.name;
|
||||
if (!forecastMetricColors.has(key)) forecastMetricColors.set(key, colors[forecastMetricColors.size]);
|
||||
const c = forecastMetricColors.get(key);
|
||||
const current = forecastText(m.values[0]);
|
||||
const last = forecastText(m.values[m.values.length - 1]);
|
||||
const threshold = m.alert === undefined ? '' : `\n警戒 ${m.direction === 'lower' ? '≥' : '≤'} ${m.alert} ${m.unit || ''}`;
|
||||
titles.push({ text: m.name, subtext: `${current} → ${last} ${m.unit || ''}${threshold}`, left: 8, top: `${idx * row + 1}%`,
|
||||
textStyle: {color: '#e2eaf4', fontSize: 12, fontWeight: 600},
|
||||
subtextStyle: {color: c, fontSize: 12, lineHeight: 16}, itemGap: 5 });
|
||||
grids.push({ left: 154, right: 36, top: `${idx * row + 3}%`, height: `${row - 9}%`, containLabel: true });
|
||||
xAxes.push({ type: 'category', gridIndex: idx, data: timeline, boundaryGap: false,
|
||||
axisTick: {show: false}, axisLine: {show: false},
|
||||
axisLabel: {color: '#8ea3ba', fontSize: 10, hideOverlap: true, formatter: v => v.replace('天预测', '天')},
|
||||
axisPointer: {lineStyle: {color: '#7893ac', type: 'dashed'}} });
|
||||
yAxes.push({ type: 'value', gridIndex: idx, splitNumber: 2,
|
||||
scale: true, axisLabel: {color: '#7188a1', fontSize: 10},
|
||||
splitLine: {lineStyle: {color: 'rgba(148,173,200,0.10)', type: 'dashed'}} });
|
||||
const result = { name: m.name, type: 'line', xAxisIndex: idx, yAxisIndex: idx,
|
||||
smooth: false, connectNulls: false, symbol: 'circle', symbolSize: 6,
|
||||
itemStyle: {color: c, borderColor: '#0c1929', borderWidth: 2},
|
||||
lineStyle: {width: 2, color: c, type: 'dotted'},
|
||||
emphasis: {focus: 'series', scale: 1.5},
|
||||
areaStyle: {color: {type: 'linear', x: 0, y: 0, x2: 0, y2: 1,
|
||||
colorStops: [{offset: 0, color: c + '16'}, {offset: 1, color: c + '00'}]}},
|
||||
data: m.values };
|
||||
if (m.alert !== undefined) result.markLine = {symbol: ['none', 'none'], silent: true, data: [{
|
||||
yAxis: m.alert, name: `${m.name}警戒线`,
|
||||
lineStyle: {color: '#c89e68', type: 'dashed', width: 1, opacity: 0.65},
|
||||
label: {formatter: `警戒 {c}${m.unit || ''}`, position: 'insideEndTop', color: '#dfb883', fontSize: 9,
|
||||
backgroundColor: '#122031', padding: [2, 4], borderRadius: 3}
|
||||
}]};
|
||||
return result;
|
||||
});
|
||||
|
||||
return {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: 'rgba(11, 22, 44, 0.94)',
|
||||
borderColor: 'rgba(56, 189, 248, 0.4)',
|
||||
textStyle: { color: '#f8fafc', fontSize: 11 },
|
||||
formatter: (params) => {
|
||||
if (!Array.isArray(params) || params.length === 0) return '';
|
||||
const axisValue = params[0].axisValue || params[0].name || '';
|
||||
let html = `<div style="font-weight:700;margin-bottom:6px;color:#38bdf8;">${axisValue}</div>`;
|
||||
params.forEach(p => {
|
||||
const valStr = p.value !== undefined ? p.value : '-';
|
||||
html += `<div style="display:flex;justify-content:space-between;gap:16px;margin:3px 0;">
|
||||
<span>${p.marker} ${p.seriesName}</span>
|
||||
<strong style="color:#f8fafc;">${valStr}</strong>
|
||||
</div>`;
|
||||
});
|
||||
const isFuture = axisValue.includes('预测') || (params[0].dataIndex !== undefined && params[0].dataIndex > 0) || !axisValue.includes('现状');
|
||||
const condTitle = isFuture ? '⚙️ 算法推演工况条件:' : '🌡️ 当前环境监测工况:';
|
||||
html += `<div style="margin-top:6px;padding-top:5px;border-top:1px dashed rgba(56,189,248,0.25);font-size:10px;color:#94a3b8;line-height:1.4;">
|
||||
<div style="color:#cbd5e1;margin-bottom:2px;">${condTitle}</div>
|
||||
<div>仓内环境: <span style="color:#38bdf8;font-weight:600;">${envInfo.tm_i}℃</span> / <span style="color:#38bdf8;font-weight:600;">${envInfo.hm_i}%</span></div>
|
||||
<div>仓外气象: <span style="color:#10b981;font-weight:600;">${envInfo.tm_o}℃</span> / <span style="color:#10b981;font-weight:600;">${envInfo.hm_o}%</span></div>
|
||||
</div>`;
|
||||
return html;
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
top: '0%',
|
||||
right: '2%',
|
||||
itemGap: 12,
|
||||
textStyle: { color: '#cbd5e1', fontSize: 11 }
|
||||
},
|
||||
grid: {
|
||||
top: '15%',
|
||||
left: '4%',
|
||||
right: '6%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: timeline,
|
||||
axisLabel: { color: '#94a3b8', fontSize: 10.5 },
|
||||
axisLine: { lineStyle: { color: 'rgba(56, 189, 248, 0.2)' } }
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLabel: { color: '#94a3b8', fontSize: 10 },
|
||||
splitLine: { lineStyle: { color: 'rgba(56, 189, 248, 0.08)' } }
|
||||
},
|
||||
series
|
||||
};
|
||||
return { animationDuration: 350, title: titles, grid: grids, xAxis: xAxes, yAxis: yAxes,
|
||||
aria: {enabled: true, description: '各指标使用独立刻度。圆点为实测与预测值,点状虚线为预测趋势,金色虚线为警戒参考。'},
|
||||
axisPointer: {link: [{xAxisIndex: 'all'}]},
|
||||
tooltip: {...forecastTooltip, formatter: params => {
|
||||
if (!Array.isArray(params) || !params.length) return '';
|
||||
const heading = params[0].axisValue || params[0].name || '';
|
||||
let html = `<div style="font-weight:600;margin-bottom:8px">${forecastEscape(heading)}</div>`;
|
||||
params.forEach(p => {
|
||||
const m = metrics[p.seriesIndex] || metrics.find(m => m.name === p.seriesName);
|
||||
html += `<div style="display:flex;justify-content:space-between;gap:24px"><span>${p.marker || ''} ${forecastEscape(p.seriesName)}</span><b>${forecastText(p.value)} <small>${forecastEscape(m?.unit)}</small></b></div>`;
|
||||
});
|
||||
html += `<div style="margin-top:10px;padding-top:8px;border-top:1px solid #304157;color:#8ea3ba;font-size:11px">仓内 ${forecastEscape(envInfo.tm_i)}℃ / ${forecastEscape(envInfo.hm_i)}% · 仓外 ${forecastEscape(envInfo.tm_o)}℃ / ${forecastEscape(envInfo.hm_o)}%</div>`;
|
||||
return html;
|
||||
}}, series };
|
||||
}
|
||||
|
||||
/**
|
||||
* 现状实测 vs 预测推演偏离对比 ECharts 配置生成 (高质感防截断水平对比条形图)
|
||||
* @param {string} grainType 粮种类型
|
||||
* @param {Array<Object>} currentItems 当前化验指标列表
|
||||
* @param {Array<Object>} futureTargets 未来预测指标列表
|
||||
*/
|
||||
/** 每行按自身最大值设定比例,原始数值与单位始终直接标注,禁止跨指标比较柱长。 */
|
||||
export function buildForecastCompareChartOption(grainType, currentItems = [], futureTargets = []) {
|
||||
const names = futureTargets.map(f => f.name);
|
||||
const currentValues = futureTargets.map(f => {
|
||||
const rows = futureTargets.map(f => {
|
||||
const cur = currentItems.find(c => c.key === f.key || c.name === f.name);
|
||||
const num = cur ? parseFloat(cur.value || cur.predictedValue) : 0;
|
||||
return isNaN(num) ? 0 : num;
|
||||
const current = forecastNumber(cur?.value ?? cur?.predictedValue);
|
||||
const future = forecastNumber(f.predictedValue);
|
||||
const unit = f.unit || cur?.unit || '';
|
||||
const scale = Math.max(current ?? 0, future ?? 0, 0.01);
|
||||
const delta = current !== null && future !== null ? Number((future - current).toFixed(2)) : null;
|
||||
return {...f, current, future, unit, scale, delta};
|
||||
});
|
||||
const forecastValues = futureTargets.map(f => Number(f.predictedValue || 0));
|
||||
|
||||
return {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: { type: 'shadow' },
|
||||
backgroundColor: 'rgba(11, 22, 44, 0.94)',
|
||||
borderColor: 'rgba(56, 189, 248, 0.4)',
|
||||
textStyle: { color: '#f8fafc', fontSize: 11 },
|
||||
formatter: (params) => {
|
||||
if (!Array.isArray(params) || params.length === 0) return '';
|
||||
const name = params[0].name || '';
|
||||
const p0 = params[0];
|
||||
const p1 = params[1] || {};
|
||||
const val0 = Number(p0.value || 0);
|
||||
const val1 = Number(p1.value || 0);
|
||||
const delta = Number((val1 - val0).toFixed(2));
|
||||
const deltaText = delta >= 0 ? `+${delta}` : `${delta}`;
|
||||
const deltaColor = delta > 0 ? '#f59e0b' : '#38bdf8';
|
||||
return `<div style="font-weight:700;margin-bottom:6px;color:#38bdf8;">${name}</div>
|
||||
<div style="display:flex;justify-content:space-between;gap:16px;margin:2px 0;">
|
||||
<span>${p0.marker} ${p0.seriesName}</span>
|
||||
<strong style="color:#f8fafc;">${val0}</strong>
|
||||
</div>
|
||||
<div style="display:flex;justify-content:space-between;gap:16px;margin:2px 0;">
|
||||
<span>${p1.marker} ${p1.seriesName}</span>
|
||||
<strong style="color:#6ee7b7;">${val1}</strong>
|
||||
</div>
|
||||
<div style="margin-top:5px;padding-top:4px;border-top:1px dashed rgba(56,189,248,0.25);font-size:10px;color:#94a3b8;">
|
||||
未来演变偏离差: <strong style="color:${deltaColor};">${deltaText}</strong>
|
||||
</div>`;
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
top: '0%',
|
||||
right: '2%',
|
||||
textStyle: { color: '#cbd5e1', fontSize: 10.5 },
|
||||
data: ['现状实测', '未来预测']
|
||||
},
|
||||
grid: {
|
||||
top: '15%',
|
||||
left: '4%',
|
||||
right: '12%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
yAxis: {
|
||||
type: 'category',
|
||||
inverse: true,
|
||||
data: names,
|
||||
axisLabel: {
|
||||
color: '#cbd5e1',
|
||||
fontSize: 10.5,
|
||||
fontWeight: 500,
|
||||
formatter: (v) => v.length > 9 ? v.substring(0, 8) + '…' : v
|
||||
},
|
||||
axisTick: { show: false },
|
||||
axisLine: { lineStyle: { color: 'rgba(56, 189, 248, 0.2)' } }
|
||||
},
|
||||
xAxis: {
|
||||
type: 'value',
|
||||
axisLabel: { color: '#94a3b8', fontSize: 10 },
|
||||
splitLine: { lineStyle: { color: 'rgba(56, 189, 248, 0.08)' } }
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '现状实测',
|
||||
type: 'bar',
|
||||
barWidth: 10,
|
||||
barGap: '35%',
|
||||
itemStyle: {
|
||||
borderRadius: [0, 4, 4, 0],
|
||||
color: '#38bdf8'
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
position: 'right',
|
||||
color: '#93c5fd',
|
||||
fontSize: 10,
|
||||
fontWeight: 600,
|
||||
formatter: '{c}'
|
||||
},
|
||||
data: currentValues
|
||||
},
|
||||
{
|
||||
name: '未来预测',
|
||||
type: 'bar',
|
||||
barWidth: 10,
|
||||
itemStyle: {
|
||||
borderRadius: [0, 4, 4, 0],
|
||||
color: '#10b981'
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
position: 'right',
|
||||
color: '#6ee7b7',
|
||||
fontSize: 10,
|
||||
fontWeight: 600,
|
||||
formatter: '{c}'
|
||||
},
|
||||
data: forecastValues
|
||||
}
|
||||
]
|
||||
const datum = (r, value) => ({value: value === null ? null : value / r.scale * 100, rawValue: value, unit: r.unit});
|
||||
return { animationDuration: 350,
|
||||
aria: {enabled: true, description: '每个指标独立对比当前实测与未来预测,柱长仅可在同一指标内比较。'},
|
||||
tooltip: {...forecastTooltip, axisPointer: {type: 'shadow', shadowStyle: {color: '#94adc808'}}, formatter: params => {
|
||||
if (!Array.isArray(params) || !params.length) return '';
|
||||
const r = rows[params[0].dataIndex];
|
||||
if (!r) return '';
|
||||
const change = r.delta === null ? '暂无预测' : `${r.delta > 0 ? '+' : ''}${r.delta} ${r.unit}`;
|
||||
return `<b>${forecastEscape(r.name)}</b><div>现状实测:${forecastText(r.current)} ${forecastEscape(r.unit)}</div><div>未来预测:${forecastText(r.future)} ${forecastEscape(r.unit)}</div><div style="border-top:1px solid #304157;margin-top:8px;padding-top:8px;color:#b9c9da">变化量:${forecastEscape(change)}</div>`;
|
||||
}},
|
||||
legend: {top: 10, left: 12, itemWidth: 12, itemHeight: 7, itemGap: 22,
|
||||
textStyle: {color: '#a6bbcf', fontSize: 11}, data: ['现状实测', '未来预测']},
|
||||
grid: {top: 54, left: 128, right: 120, bottom: 32},
|
||||
yAxis: {type: 'category', inverse: true, data: rows.map(r => r.name),
|
||||
axisTick: {show: false}, axisLine: {show: false},
|
||||
axisLabel: {color: '#d2dfed', fontSize: 11, lineHeight: 17, width: 112, overflow: 'break',
|
||||
formatter: (v, i) => `${v.match(/.{1,8}/g)?.join('\n') || v}\n{unit|${rows[i].unit}}`, rich: {unit: {color: '#7089a2', fontSize: 10}}}},
|
||||
xAxis: {type: 'value', max: 100, show: false},
|
||||
series: [{name: '现状实测', type: 'bar', barWidth: 9, barGap: '65%',
|
||||
itemStyle: {color: '#547797', borderRadius: 3},
|
||||
label: {show: true, position: 'right', distance: 8, color: '#afc3d8', fontSize: 11,
|
||||
formatter: p => `${forecastText(p.data.rawValue)} ${p.data.unit}`},
|
||||
data: rows.map(r => datum(r, r.current))},
|
||||
{name: '未来预测', type: 'bar', barWidth: 9,
|
||||
itemStyle: {color: '#59d9ce', borderRadius: 3},
|
||||
label: {show: true, position: 'right', distance: 8, color: '#83e9df', fontSize: 11, fontWeight: 600,
|
||||
formatter: p => `${forecastText(p.data.rawValue)} ${p.data.unit}`},
|
||||
data: rows.map(r => datum(r, r.future))}]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1464,9 +1448,8 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
|
||||
output: {
|
||||
targets: {
|
||||
water: matched.forecast_water,
|
||||
wheat_moisture: matched.forecast_water,
|
||||
[grainType === 'wheat' ? 'wheat_moisture' : 'paddy_moisture']: matched.forecast_water,
|
||||
impurity: matched.forecast_impurity,
|
||||
wheat_GWAC: matched.forecast_impurity,
|
||||
weight: matched.forecast_weight,
|
||||
wheat_unitweight: matched.forecast_weight,
|
||||
imperfect: matched.forecast_imperfect,
|
||||
@@ -1544,6 +1527,32 @@ export const DEFAULT_GRANARY_DATA = {"code":1,"msg":"获取成功","time":"17872
|
||||
* 中心库 3D 鸟瞰实景 (assets/aerial_view2.jpg 3840x2143) 像素级建筑物热点精准锚定与错层避让
|
||||
* 覆盖 13 栋粮食平房仓 (屋脊几何中心) + 7 座立式储油罐 (高低错层 0 重叠 + 激光引线指向罐顶)
|
||||
*/
|
||||
/**
|
||||
* 后台坐标按仓号发布,内置坐标按数据库 id 发布。两者不能合并成一张表,
|
||||
* 否则 id 与另一座仓的仓号相同时,编号会标到错误的建筑上。
|
||||
* @param {Object} item
|
||||
* @param {Object|null} customCoords 后台坐标,键为仓号
|
||||
* @param {Object} builtinCoords 内置坐标,键为 id
|
||||
*/
|
||||
export function resolveHotspotCoord(item, customCoords, builtinCoords) {
|
||||
if (!item) return null;
|
||||
if (item.screenCoord) return item.screenCoord;
|
||||
if (CENTER_EXTRA_POSITIONS[item.screenPosition]) return CENTER_EXTRA_POSITIONS[item.screenPosition];
|
||||
const custom = customCoords || null;
|
||||
const builtin = builtinCoords || {};
|
||||
if (custom && item.num !== undefined && item.num !== null && custom[item.num]) {
|
||||
return custom[item.num];
|
||||
}
|
||||
if (custom && item.name && custom[item.name]) return custom[item.name];
|
||||
return builtin[item.id] || builtin[item.num] || (item.name && builtin[item.name]) || null;
|
||||
}
|
||||
|
||||
// 建筑位置与可编辑仓号分开保存,改号后仍指向同一栋建筑。
|
||||
export const CENTER_EXTRA_POSITIONS = {
|
||||
center_upper_left: { x: 46.8, y: 28.4 },
|
||||
center_lower_right: { x: 58.8, y: 34.1 }
|
||||
};
|
||||
|
||||
export const CENTER_HOTSPOT_COORDS = {
|
||||
// 7 座立式储油罐 (左侧储油罐群 · 像素级真实罐顶中心锚定 + 全员配备发光激光引线立体错层 0 重叠)
|
||||
43: { x: 4.8, y: 12.8, stemX: 2.8, stemY: 20.3 }, // 14号油罐 (最左立式大罐 · 2500吨 · 气泡右移避开左侧侧边栏遮挡,激光引线斜向直达罐顶正中心)
|
||||
@@ -2042,7 +2051,7 @@ export function generateDepotAlerts(normalizedList = [], envData = null) {
|
||||
// 2. 遍历各仓房质检报告
|
||||
(normalizedList || []).forEach(item => {
|
||||
const vName = item.grainName || (item.rawContent && item.rawContent.varieties) || (item.isOilTank ? '菜籽油' : '小麦');
|
||||
const report = getGranaryQualityReport(vName, item.rawContent || {});
|
||||
const report = getGranaryQualityReport(vName, item.rawContent || {}, item.qualityTest || null);
|
||||
if (!report || !report.items) return;
|
||||
|
||||
report.items.forEach(it => {
|
||||
@@ -2087,6 +2096,17 @@ export function generateDepotAlerts(normalizedList = [], envData = null) {
|
||||
return alerts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按轨道宽度设定走马灯时长,保持约 32px/s,避免告警变多后固定时长滚得过快。
|
||||
* @param {HTMLElement} track
|
||||
*/
|
||||
export function syncAlertMarqueeSpeed(track) {
|
||||
if (!track) return;
|
||||
const distance = track.scrollWidth / 2;
|
||||
const seconds = Math.max(60, Math.round((distance || 0) / 32));
|
||||
track.style.setProperty('--marquee-duration', `${seconds}s`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成粮油质检化验单 CSV 模板 (带 UTF-8 BOM,Excel 打开无乱码)
|
||||
* @param {string} varietyKey 'wheat' | 'oil' | 'paddy'
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
DESIGN_THEME,
|
||||
XISHUI_GRANARY_DATA,
|
||||
XISHUI_HOTSPOT_COORDS,
|
||||
resolveHotspotCoord,
|
||||
buildQualityHtml,
|
||||
buildQualityHudHtml,
|
||||
mapVarietyToForecastType,
|
||||
@@ -14,8 +15,9 @@ import {
|
||||
buildForecastCompareChartOption,
|
||||
fetchGranaryForecast,
|
||||
getGranaryQualityReport,
|
||||
generateDepotAlerts
|
||||
} from './grain_monitor_core.js';
|
||||
generateDepotAlerts,
|
||||
syncAlertMarqueeSpeed
|
||||
} from './grain_monitor_core.js?v=20261028_chart3';
|
||||
|
||||
// 全局状态
|
||||
const STATE = {
|
||||
@@ -108,6 +110,7 @@ function loadGranaryData() {
|
||||
renderKPIs();
|
||||
renderHotspots();
|
||||
renderMiniGrid();
|
||||
renderDetailPanels();
|
||||
renderDepotAlerts();
|
||||
return;
|
||||
}
|
||||
@@ -160,6 +163,9 @@ function renderDepotAlerts() {
|
||||
const marqueeTrack = document.getElementById('alert-marquee-track');
|
||||
if (!marqueeTrack) return;
|
||||
const alerts = generateDepotAlerts(STATE.list, STATE.envData);
|
||||
const signature = alerts.map(a => `${a.id}|${a.text}`).join('\n');
|
||||
if (marqueeTrack.dataset.alertSignature === signature && marqueeTrack.childElementCount > 0) return;
|
||||
marqueeTrack.dataset.alertSignature = signature;
|
||||
marqueeTrack.innerHTML = '';
|
||||
const displayAlerts = alerts.length > 0 ? (alerts.length === 1 ? alerts : alerts.concat(alerts)) : [];
|
||||
displayAlerts.forEach(alert => {
|
||||
@@ -180,6 +186,7 @@ function renderDepotAlerts() {
|
||||
}
|
||||
marqueeTrack.appendChild(pill);
|
||||
});
|
||||
requestAnimationFrame(() => syncAlertMarqueeSpeed(marqueeTrack));
|
||||
}
|
||||
|
||||
// 4. 渲染顶部关键 KPIs
|
||||
@@ -199,12 +206,10 @@ function renderHotspots() {
|
||||
const container = document.getElementById('aerial-hotspots');
|
||||
if (!container) return;
|
||||
|
||||
const hotspotCoords = STATE.customCoords ? { ...XISHUI_HOTSPOT_COORDS, ...STATE.customCoords } : XISHUI_HOTSPOT_COORDS;
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
STATE.list.forEach(item => {
|
||||
const rawCoord = hotspotCoords[item.id] || hotspotCoords[item.num] || hotspotCoords[item.name];
|
||||
const rawCoord = resolveHotspotCoord(item, STATE.customCoords, XISHUI_HOTSPOT_COORDS);
|
||||
if (!rawCoord) return;
|
||||
|
||||
const coord = {
|
||||
@@ -602,7 +607,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
|
||||
setupForecastEnvControls();
|
||||
|
||||
const currentReport = getGranaryQualityReport(grainName, currentItem.rawContent || currentItem.content || {});
|
||||
const currentReport = getGranaryQualityReport(grainName, currentItem.rawContent || currentItem.content || {}, currentItem.qualityTest);
|
||||
|
||||
// 1. 0 毫秒即时秒出基础图表 (杜绝任何白屏与残亮点)
|
||||
const baselineList = [
|
||||
@@ -642,6 +647,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const initialFuture30 = initialSeries.metrics.map(m => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
unit: m.unit,
|
||||
predictedValue: m.values[3] !== undefined ? m.values[3] : m.values[m.values.length - 1]
|
||||
}));
|
||||
const initialCompareOption = buildForecastCompareChartOption(grainType, currentReport?.items || [], initialFuture30);
|
||||
@@ -667,7 +673,7 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const series = generateForecastSeries(grainType, currentReport, forecastList, STATE.forecastEnv);
|
||||
|
||||
if (trendTitleEl) {
|
||||
trendTitleEl.textContent = `${currentItem.name} (${grainName}) 质量指标多周期演变推演 (当前实测与未来 7~60天)`;
|
||||
trendTitleEl.textContent = `${currentItem.name} (${grainName}) 多周期趋势`;
|
||||
}
|
||||
const trendOption = buildForecastTrendChartOption(series);
|
||||
if (trendOption) {
|
||||
@@ -677,11 +683,12 @@ async function initOrUpdateForecastCharts(granaryItem) {
|
||||
const future30Targets = series.metrics.map(m => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
unit: m.unit,
|
||||
predictedValue: m.values[3] !== undefined ? m.values[3] : m.values[m.values.length - 1]
|
||||
}));
|
||||
|
||||
if (compareTitleEl) {
|
||||
compareTitleEl.textContent = `${currentItem.name} 现状实测 vs 未来30天预测终值偏离评估`;
|
||||
compareTitleEl.textContent = `${currentItem.name} 未来30天 · 变化对比`;
|
||||
}
|
||||
const compareOption = buildForecastCompareChartOption(grainType, currentReport?.items || [], future30Targets);
|
||||
if (compareOption) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>中储粮(习水)智慧粮仓综合监测中心</title>
|
||||
<link rel="stylesheet" href="./css/style.css">
|
||||
<link rel="stylesheet" href="./css/style.css?v=20261028_chart3">
|
||||
<!-- ECharts 可视化库 (CDN) -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
|
||||
</head>
|
||||
@@ -283,7 +283,7 @@
|
||||
<div class="forecast-env-bar">
|
||||
<div class="forecast-env-label">
|
||||
<span class="env-pulse-icon"></span>
|
||||
<span>推演环境工况 (API输入):</span>
|
||||
<span>推演环境设置</span>
|
||||
</div>
|
||||
<div class="forecast-env-items">
|
||||
<div class="forecast-env-group">
|
||||
@@ -325,9 +325,10 @@
|
||||
<!-- 左侧:多周期未来质量演变趋势折线图 (含国家警戒线) -->
|
||||
<div class="center-chart-card">
|
||||
<div class="center-chart-card-title-bar">
|
||||
<div class="center-chart-card-title" id="forecast-trend-title">粮食质量指标多周期演变趋势推演 (未来 7~60天走势与国家警戒线)</div>
|
||||
<div class="center-chart-card-title" id="forecast-trend-title">多周期趋势</div>
|
||||
<div class="forecast-env-pill" id="forecast-trend-env-pill">工况: 仓内 18.5℃ / 72.4% · 仓外 32.5℃ / 54.2%</div>
|
||||
</div>
|
||||
<div class="forecast-chart-note"><span>各指标独立刻度 · 保留原始单位</span><span>● 实测起点 ┈ 预测趋势 <span class="threshold-key">┄ 警戒参考</span></span></div>
|
||||
<div id="chart-forecast-trend" class="center-chart-canvas"></div>
|
||||
</div>
|
||||
<!-- 右侧:现状实测 vs 预测推演偏离对比柱状图 -->
|
||||
@@ -335,6 +336,7 @@
|
||||
<div class="center-chart-card-title-bar">
|
||||
<div class="center-chart-card-title" id="forecast-compare-title">现状实测值 vs 预测终值偏离对比与风险评估</div>
|
||||
</div>
|
||||
<div class="forecast-chart-note">同一指标内对比柱长 · 悬停查看变化量</div>
|
||||
<div id="chart-forecast-compare" class="center-chart-canvas"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -400,6 +402,6 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script type="module" src="./js/xishui_app.js?v=20260916_v3"></script>
|
||||
<script type="module" src="./js/xishui_app.js?v=20261028_chart3"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
在新工单中引用
屏蔽一个用户