chore(screen): 同步更新大屏挂载脚本并与后端API规范对齐
这个提交包含在:
@@ -136,27 +136,35 @@ async function fetchGranaryData() {
|
||||
|
||||
// 3.1 加载微气候环境工况
|
||||
async function fetchEnvData() {
|
||||
try {
|
||||
const res = await fetch('/api/granary/env?site=center', { cache: 'no-cache' });
|
||||
if (!res.ok) return;
|
||||
const json = await res.json();
|
||||
if (json && json.code === 0 && json.data) {
|
||||
const d = json.data;
|
||||
STATE.envData = d;
|
||||
const inpTmI = document.getElementById('input-forecast-tm-i');
|
||||
const inpTmO = document.getElementById('input-forecast-tm-o');
|
||||
const inpHmI = document.getElementById('input-forecast-hm-i');
|
||||
const inpHmO = document.getElementById('input-forecast-hm-o');
|
||||
if (inpTmI && d.tm_i !== undefined) inpTmI.value = d.tm_i;
|
||||
if (inpTmO && d.tm_o !== undefined) inpTmO.value = d.tm_o;
|
||||
if (inpHmI && d.hm_i !== undefined) inpHmI.value = d.hm_i;
|
||||
if (inpHmO && d.hm_o !== undefined) inpHmO.value = d.hm_o;
|
||||
const pill = document.getElementById('forecast-trend-env-pill');
|
||||
if (pill) {
|
||||
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
|
||||
const endpoints = [
|
||||
'/api/index/env?site=center',
|
||||
'https://grain.gynhc.com/api/index/env?site=center',
|
||||
'/api/granary/env?site=center'
|
||||
];
|
||||
for (const url of endpoints) {
|
||||
try {
|
||||
const res = await fetch(url, { cache: 'no-cache', signal: AbortSignal.timeout(2000) });
|
||||
if (!res.ok) continue;
|
||||
const json = await res.json();
|
||||
if (json && (json.code === 1 || json.code === 0) && json.data) {
|
||||
const d = json.data;
|
||||
STATE.envData = d;
|
||||
const inpTmI = document.getElementById('input-forecast-tm-i');
|
||||
const inpTmO = document.getElementById('input-forecast-tm-o');
|
||||
const inpHmI = document.getElementById('input-forecast-hm-i');
|
||||
const inpHmO = document.getElementById('input-forecast-hm-o');
|
||||
if (inpTmI && d.tm_i !== undefined) inpTmI.value = d.tm_i;
|
||||
if (inpTmO && d.tm_o !== undefined) inpTmO.value = d.tm_o;
|
||||
if (inpHmI && d.hm_i !== undefined) inpHmI.value = d.hm_i;
|
||||
if (inpHmO && d.hm_o !== undefined) inpHmO.value = d.hm_o;
|
||||
const pill = document.getElementById('forecast-trend-env-pill');
|
||||
if (pill) {
|
||||
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
// 3.2 渲染全库储粮安全感知与预警走马灯
|
||||
|
||||
@@ -1438,20 +1438,45 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
|
||||
|
||||
if (typeof fetch !== 'undefined') {
|
||||
const query = new URLSearchParams(params).toString();
|
||||
// 1. 优先尝试本地代理,规避纯静态环境 CORS
|
||||
try {
|
||||
const res = await fetch(`/api/forecast?${query}`, { signal: AbortSignal.timeout(1800) });
|
||||
if (res.ok) {
|
||||
const isBrowser = typeof window !== 'undefined';
|
||||
const forecastUrls = isBrowser
|
||||
? [`/api/index/forecast?${query}`, `/api/forecast?${query}`, `https://grain.gynhc.com/api/index/forecast?${query}`]
|
||||
: [`https://grain.gynhc.com/api/index/forecast?${query}`];
|
||||
|
||||
for (const fUrl of forecastUrls) {
|
||||
try {
|
||||
const res = await fetch(fUrl, { signal: AbortSignal.timeout(600) });
|
||||
if (!res.ok) continue;
|
||||
const json = await res.json();
|
||||
if (json && json.code === '0' && json.output?.targets) {
|
||||
apiData = json;
|
||||
break;
|
||||
} else if (json && json.code === 1 && json.data && Array.isArray(json.data.list)) {
|
||||
const matched = json.data.list.find(i => i.day === day);
|
||||
if (matched) {
|
||||
apiData = {
|
||||
output: {
|
||||
targets: {
|
||||
water: matched.forecast_water,
|
||||
wheat_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,
|
||||
wheat_unsoundkernels: matched.forecast_imperfect,
|
||||
taste: matched.forecast_taste,
|
||||
wheat_tasteevaluation: matched.forecast_taste
|
||||
}
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 本地代理失败,尝试直连在线算法服务
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// 2. 本地代理不可用时,直连公网算法接口
|
||||
// 2. 后端接口不可用时,直连公网算法接口
|
||||
if (!apiData) {
|
||||
try {
|
||||
const directUrl = `http://www.probe-cdy-pests.cn:8116/alg/grainquality/forcast?${query}`;
|
||||
|
||||
@@ -89,49 +89,69 @@ function loadGranaryData() {
|
||||
|
||||
// 尝试连接后台接口同步最新配置
|
||||
if (typeof fetch !== 'undefined') {
|
||||
fetch('/api/index/granaryList?site=xishui', { cache: 'no-cache', signal: AbortSignal.timeout(2000) })
|
||||
.then(res => res.ok ? res.json() : null)
|
||||
.then(json => {
|
||||
if (json && json.data && Array.isArray(json.data.list) && json.data.list.length > 0) {
|
||||
STATE.list = normalizeGranaryList(json);
|
||||
if (json.data.coords) {
|
||||
STATE.customCoords = json.data.coords;
|
||||
const urls = [
|
||||
'/api/index/granaryList?site=xishui',
|
||||
'https://grain.gynhc.com/api/index/granaryList?site=xishui',
|
||||
'/api/granary/list?site=xishui'
|
||||
];
|
||||
(async () => {
|
||||
for (const u of urls) {
|
||||
try {
|
||||
const res = await fetch(u, { cache: 'no-cache', signal: AbortSignal.timeout(2000) });
|
||||
if (!res.ok) continue;
|
||||
const json = await res.json();
|
||||
if (json && json.data && Array.isArray(json.data.list) && json.data.list.length > 0) {
|
||||
STATE.list = normalizeGranaryList(json);
|
||||
if (json.data.coords) {
|
||||
STATE.customCoords = json.data.coords;
|
||||
}
|
||||
renderKPIs();
|
||||
renderHotspots();
|
||||
renderMiniGrid();
|
||||
renderDepotAlerts();
|
||||
return;
|
||||
}
|
||||
renderKPIs();
|
||||
renderHotspots();
|
||||
renderMiniGrid();
|
||||
renderDepotAlerts();
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
} catch (e) {}
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
// 3.1 加载习水子库微气候环境工况
|
||||
function loadEnvData() {
|
||||
if (typeof fetch !== 'undefined') {
|
||||
fetch('/api/granary/env?site=xishui', { cache: 'no-cache', signal: AbortSignal.timeout(2000) })
|
||||
.then(res => res.ok ? res.json() : null)
|
||||
.then(json => {
|
||||
if (json && json.code === 0 && json.data) {
|
||||
const d = json.data;
|
||||
STATE.envData = d;
|
||||
const inpTmI = document.getElementById('input-forecast-tm-i');
|
||||
const inpTmO = document.getElementById('input-forecast-tm-o');
|
||||
const inpHmI = document.getElementById('input-forecast-hm-i');
|
||||
const inpHmO = document.getElementById('input-forecast-hm-o');
|
||||
if (inpTmI && d.tm_i !== undefined) inpTmI.value = d.tm_i;
|
||||
if (inpTmO && d.tm_o !== undefined) inpTmO.value = d.tm_o;
|
||||
if (inpHmI && d.hm_i !== undefined) inpHmI.value = d.hm_i;
|
||||
if (inpHmO && d.hm_o !== undefined) inpHmO.value = d.hm_o;
|
||||
const pill = document.getElementById('forecast-trend-env-pill');
|
||||
if (pill) {
|
||||
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
|
||||
const urls = [
|
||||
'/api/index/env?site=xishui',
|
||||
'https://grain.gynhc.com/api/index/env?site=xishui',
|
||||
'/api/granary/env?site=xishui'
|
||||
];
|
||||
(async () => {
|
||||
for (const u of urls) {
|
||||
try {
|
||||
const res = await fetch(u, { cache: 'no-cache', signal: AbortSignal.timeout(2000) });
|
||||
if (!res.ok) continue;
|
||||
const json = await res.json();
|
||||
if (json && (json.code === 1 || json.code === 0) && json.data) {
|
||||
const d = json.data;
|
||||
STATE.envData = d;
|
||||
const inpTmI = document.getElementById('input-forecast-tm-i');
|
||||
const inpTmO = document.getElementById('input-forecast-tm-o');
|
||||
const inpHmI = document.getElementById('input-forecast-hm-i');
|
||||
const inpHmO = document.getElementById('input-forecast-hm-o');
|
||||
if (inpTmI && d.tm_i !== undefined) inpTmI.value = d.tm_i;
|
||||
if (inpTmO && d.tm_o !== undefined) inpTmO.value = d.tm_o;
|
||||
if (inpHmI && d.hm_i !== undefined) inpHmI.value = d.hm_i;
|
||||
if (inpHmO && d.hm_o !== undefined) inpHmO.value = d.hm_o;
|
||||
const pill = document.getElementById('forecast-trend-env-pill');
|
||||
if (pill) {
|
||||
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
|
||||
}
|
||||
renderDepotAlerts();
|
||||
return;
|
||||
}
|
||||
renderDepotAlerts();
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
} catch (e) {}
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户