chore(screen): 同步更新大屏挂载脚本并与后端API规范对齐

这个提交包含在:
wikiboss
2026-10-15 10:51:48 +08:00
父节点 093b9ec49a
当前提交 dbcd692bae
共有 3 个文件被更改,包括 116 次插入 和 63 次删除

查看文件

@@ -136,11 +136,17 @@ async function fetchGranaryData() {
// 3.1 加载微气候环境工况 // 3.1 加载微气候环境工况
async function fetchEnvData() { async function fetchEnvData() {
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 { try {
const res = await fetch('/api/granary/env?site=center', { cache: 'no-cache' }); const res = await fetch(url, { cache: 'no-cache', signal: AbortSignal.timeout(2000) });
if (!res.ok) return; if (!res.ok) continue;
const json = await res.json(); const json = await res.json();
if (json && json.code === 0 && json.data) { if (json && (json.code === 1 || json.code === 0) && json.data) {
const d = json.data; const d = json.data;
STATE.envData = d; STATE.envData = d;
const inpTmI = document.getElementById('input-forecast-tm-i'); const inpTmI = document.getElementById('input-forecast-tm-i');
@@ -155,9 +161,11 @@ async function fetchEnvData() {
if (pill) { if (pill) {
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`; pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
} }
return;
} }
} catch (e) {} } catch (e) {}
} }
}
// 3.2 渲染全库储粮安全感知与预警走马灯 // 3.2 渲染全库储粮安全感知与预警走马灯
function renderDepotAlerts() { function renderDepotAlerts() {

查看文件

@@ -1438,20 +1438,45 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
if (typeof fetch !== 'undefined') { if (typeof fetch !== 'undefined') {
const query = new URLSearchParams(params).toString(); const query = new URLSearchParams(params).toString();
// 1. 优先尝试本地代理,规避纯静态环境 CORS 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 { try {
const res = await fetch(`/api/forecast?${query}`, { signal: AbortSignal.timeout(1800) }); const res = await fetch(fUrl, { signal: AbortSignal.timeout(600) });
if (res.ok) { if (!res.ok) continue;
const json = await res.json(); const json = await res.json();
if (json && json.code === '0' && json.output?.targets) { if (json && json.code === '0' && json.output?.targets) {
apiData = json; 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
} }
} }
} catch { };
// 本地代理失败,尝试直连在线算法服务 break;
}
}
} catch {}
} }
// 2. 本地代理不可用时,直连公网算法接口 // 2. 后端接口不可用时,直连公网算法接口
if (!apiData) { if (!apiData) {
try { try {
const directUrl = `http://www.probe-cdy-pests.cn:8116/alg/grainquality/forcast?${query}`; const directUrl = `http://www.probe-cdy-pests.cn:8116/alg/grainquality/forcast?${query}`;

查看文件

@@ -89,9 +89,17 @@ function loadGranaryData() {
// 尝试连接后台接口同步最新配置 // 尝试连接后台接口同步最新配置
if (typeof fetch !== 'undefined') { if (typeof fetch !== 'undefined') {
fetch('/api/index/granaryList?site=xishui', { cache: 'no-cache', signal: AbortSignal.timeout(2000) }) const urls = [
.then(res => res.ok ? res.json() : null) '/api/index/granaryList?site=xishui',
.then(json => { '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) { if (json && json.data && Array.isArray(json.data.list) && json.data.list.length > 0) {
STATE.list = normalizeGranaryList(json); STATE.list = normalizeGranaryList(json);
if (json.data.coords) { if (json.data.coords) {
@@ -101,19 +109,29 @@ function loadGranaryData() {
renderHotspots(); renderHotspots();
renderMiniGrid(); renderMiniGrid();
renderDepotAlerts(); renderDepotAlerts();
return;
} }
}) } catch (e) {}
.catch(() => {}); }
})();
} }
} }
// 3.1 加载习水子库微气候环境工况 // 3.1 加载习水子库微气候环境工况
function loadEnvData() { function loadEnvData() {
if (typeof fetch !== 'undefined') { if (typeof fetch !== 'undefined') {
fetch('/api/granary/env?site=xishui', { cache: 'no-cache', signal: AbortSignal.timeout(2000) }) const urls = [
.then(res => res.ok ? res.json() : null) '/api/index/env?site=xishui',
.then(json => { 'https://grain.gynhc.com/api/index/env?site=xishui',
if (json && json.code === 0 && json.data) { '/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; const d = json.data;
STATE.envData = d; STATE.envData = d;
const inpTmI = document.getElementById('input-forecast-tm-i'); const inpTmI = document.getElementById('input-forecast-tm-i');
@@ -129,9 +147,11 @@ function loadEnvData() {
pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`; pill.textContent = `工况: 仓内 ${d.tm_i}℃ / ${d.hm_i}% | 仓外 ${d.tm_o}℃ / ${d.hm_o}%`;
} }
renderDepotAlerts(); renderDepotAlerts();
return;
} }
}) } catch (e) {}
.catch(() => {}); }
})();
} }
} }