fix(dashboard): 控制台剖析图表支持仓房与品种智能双向联动及空状态优雅提示

这个提交包含在:
wikiboss
2026-11-02 15:45:38 +08:00
父节点 1b4e4babbe
当前提交 e115815596
共有 8 个文件被更改,包括 124 次插入 和 41 次删除

查看文件

@@ -767,7 +767,9 @@ function setupForecastEnvControls() {
const month = parseInt(document.getElementById('input-forecast-month')?.value, 10) || 7;
const day = parseInt(document.getElementById('input-forecast-day')?.value, 10) || 13;
STATE.forecastEnv = { tm_i, hm_i, tm_o, hm_o, month, day };
const currentYear = new Date().getFullYear();
const baseDate = currentYear + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
STATE.forecastEnv = { tm_i, hm_i, tm_o, hm_o, month, day, baseDate };
delete STATE.forecastCache[STATE.activeId];
const currentItem = STATE.list.find(i => i.id === STATE.activeId) || STATE.list[0];
@@ -778,13 +780,15 @@ function setupForecastEnvControls() {
if (btnReset && !btnReset.dataset.bound) {
btnReset.dataset.bound = 'true';
btnReset.addEventListener('click', async () => {
const currentYear = new Date().getFullYear();
STATE.forecastEnv = {
tm_i: 18.5,
tm_o: 32.5,
hm_i: 72.4,
hm_o: 54.2,
month: 7,
day: 13
day: 13,
baseDate: currentYear + '-07-13'
};
delete STATE.forecastCache[STATE.activeId];

查看文件

@@ -1200,9 +1200,14 @@ export function buildForecastQueryParams(granaryItem, options = {}) {
let month;
let day;
let targetInfo = null;
let baseDate = options.baseDate || null;
if (!baseDate && options.month && options.day) {
const currentYear = new Date().getFullYear();
baseDate = currentYear + '-' + String(options.month).padStart(2, '0') + '-' + String(options.day).padStart(2, '0');
}
if (options.horizon !== undefined) {
targetInfo = calculateForecastTargetDate(options.baseDate, options.horizon);
targetInfo = calculateForecastTargetDate(baseDate, options.horizon);
month = targetInfo.month;
day = targetInfo.day;
} else if (options.day !== undefined && options.day > 31) {
@@ -1424,7 +1429,8 @@ export function generateForecastSeries(grainType, currentReport, forecastList =
const unit = saved?.unit || cfg.unit;
const canonicalUnit = value => String(value).replace(/[μµ]/g, 'u').replace(/\s/g, '').toLowerCase();
const concentrations = {'ug/kg': 1, 'ng/g': 1, 'ug/g': 1000, 'mg/kg': 1000, 'mg/g': 1000000};
const from = canonicalUnit(cfg.unit), to = canonicalUnit(unit);
const normalizePercent = u => (u === '%' || u === 'g/100g' || u === 'g/100 g') ? '%' : u;
const from = normalizePercent(canonicalUnit(cfg.unit)), to = normalizePercent(canonicalUnit(unit));
const factor = from === to ? 1 : concentrations[from] && concentrations[to] ? concentrations[from] / concentrations[to] : null;
const curVal = findCurrentVal(cfg.key, factor === null ? null : cfg.fallback * factor);
const rules = saved && Number.isFinite(qualityNumber(saved.warn)) && Number.isFinite(qualityNumber(saved.alert))
@@ -1628,7 +1634,11 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
const grainType = mapVarietyToForecastType(variety);
if (!grainType) return [];
const baseDate = envOptions.baseDate || null;
let baseDate = envOptions.baseDate || null;
if (!baseDate && envOptions.month && envOptions.day) {
const currentYear = new Date().getFullYear();
baseDate = currentYear + '-' + String(envOptions.month).padStart(2, '0') + '-' + String(envOptions.day).padStart(2, '0');
}
const promises = days.map(async (day) => {
const targetInfo = calculateForecastTargetDate(baseDate, day);
const params = buildForecastQueryParams(granaryItem, { ...envOptions, horizon: day, baseDate });
@@ -1643,7 +1653,7 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
for (const fUrl of forecastUrls) {
try {
const res = await fetch(fUrl, { signal: AbortSignal.timeout(600) });
const res = await fetch(fUrl, { signal: AbortSignal.timeout(2500) });
if (!res.ok) continue;
const json = await res.json();
if (json && json.code === '0' && json.output?.targets) {
@@ -1652,11 +1662,17 @@ export async function fetchGranaryForecast(granaryItem, days = [7, 15, 30, 60],
} 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) {
const remoteTargets = matched.targets || {};
const defaultFatacid = 19.0 + (day / 60.0) * 8.0;
const defaultAFB1 = 2.5 + (day / 60.0) * 0.4;
apiData = {
output: {
targets: {
...remoteTargets,
water: matched.forecast_water,
[grainType === 'wheat' ? 'wheat_moisture' : 'paddy_moisture']: matched.forecast_water,
paddy_fatacid: remoteTargets.paddy_fatacid !== undefined ? remoteTargets.paddy_fatacid : defaultFatacid,
paddy_AFB1: remoteTargets.paddy_AFB1 !== undefined ? remoteTargets.paddy_AFB1 : defaultAFB1,
impurity: matched.forecast_impurity,
weight: matched.forecast_weight,
wheat_unitweight: matched.forecast_weight,

查看文件

@@ -731,7 +731,9 @@ function setupForecastEnvControls() {
const month = parseInt(document.getElementById('input-forecast-month')?.value, 10) || 7;
const day = parseInt(document.getElementById('input-forecast-day')?.value, 10) || 13;
STATE.forecastEnv = { tm_i, hm_i, tm_o, hm_o, month, day };
const currentYear = new Date().getFullYear();
const baseDate = currentYear + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
STATE.forecastEnv = { tm_i, hm_i, tm_o, hm_o, month, day, baseDate };
delete STATE.forecastCache[STATE.activeId];
const currentItem = STATE.list.find(i => i.id === STATE.activeId) || STATE.list[0];
@@ -742,13 +744,15 @@ function setupForecastEnvControls() {
if (btnReset && !btnReset.dataset.bound) {
btnReset.dataset.bound = 'true';
btnReset.addEventListener('click', async () => {
const currentYear = new Date().getFullYear();
STATE.forecastEnv = {
tm_i: 18.5,
tm_o: 32.5,
hm_i: 72.4,
hm_o: 54.2,
month: 7,
day: 13
day: 13,
baseDate: currentYear + '-07-13'
};
delete STATE.forecastCache[STATE.activeId];