diff --git a/other-module/canteen-device/clean-veg-ratio-scale/01-accept.html b/other-module/canteen-device/clean-veg-ratio-scale/01-accept.html index d0014ce..7d06aad 100644 --- a/other-module/canteen-device/clean-veg-ratio-scale/01-accept.html +++ b/other-module/canteen-device/clean-veg-ratio-scale/01-accept.html @@ -452,6 +452,7 @@ return { id: foodIdCounter, name: f.name, size: f.size, shape: f.shape, blade: f.blade, target: f.target, processed: f.processed, icon: f.icon }; }); renderFoodCards(); + startAutoPoll(); })(); // ---- 渲染净菜卡片列表(隐藏已完成的) ---- @@ -495,11 +496,26 @@ showToast('已删除', 1000); } - // ---- 获取任务:新增一个未完成的净菜加工任务 ---- + // ---- 检查是否有未完成任务 ---- + function hasIncomplete() { + for (var i = 0; i < acceptedFoods.length; i++) { + if (acceptedFoods[i].processed < acceptedFoods[i].target) return true; + } + return false; + } + + // ---- 获取任务:仅在全部完成后才拉取新任务 ---- function handleFetchTask() { + if (hasIncomplete()) { + showToast('当前任务未全部完成,等待完成后自动获取', 1500, 'warn'); + return; + } + doFetchTask(); + } + + function doFetchTask() { showToast('正在获取加工任务...', 800); setTimeout(function() { - // 从食材库随机选一个,排除已在列表中未完成的同名净菜 var existingNames = acceptedFoods.filter(function(f) { return f.processed < f.target; }).map(function(f) { return f.name; }); var available = foodDatabase.filter(function(f) { return existingNames.indexOf(f.name) === -1; }); if (available.length === 0) { @@ -508,7 +524,7 @@ } var food = available[Math.floor(Math.random() * available.length)]; var target = parseFloat((Math.random() * 5 + 1.5).toFixed(1)); - var processed = parseFloat((Math.random() * target * 0.7).toFixed(1)); // 0~70%进度,确保未完成 + var processed = parseFloat((Math.random() * target * 0.7).toFixed(1)); foodIdCounter++; acceptedFoods.push({ id: foodIdCounter, name: food.name, size: food.size, shape: food.shape, blade: food.blade, target: target, processed: processed, icon: food.icon }); renderFoodCards(); @@ -516,6 +532,17 @@ }, 800); } + // ---- 自动轮询:每5秒检查,全部完成则自动获取 ---- + var autoPollTimer = null; + function startAutoPoll() { + autoPollTimer = setInterval(function() { + if (acceptedFoods.length === 0 || !hasIncomplete()) { + // 全部完成,自动拉新任务 + doFetchTask(); + } + }, 5000); + } + // ---- 刷新:模拟获取加工任务最新重量 ----(顶部刷新按钮) function handleRefresh() { showToast('正在获取加工数据...', 800);