From f3a3701397a4ecdef3bf62a0a47c68a830e301f4 Mon Sep 17 00:00:00 2001 From: zhangyan Date: Wed, 17 Jun 2026 09:43:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=AA=E5=AE=8C=E6=88=90=E5=87=80=E8=8F=9C?= =?UTF-8?q?=E5=8D=A1=E7=89=87=EF=BC=8C=E8=BF=9B=E5=BA=A6100%=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 「获取任务」按钮新增随机未完成净菜加工任务(进度0~70%) - 卡片进度=100%时自动隐藏 - 使用唯一ID定位删除,避免索引错位 - 顶部「刷新」按钮保留,用于对已有卡片弹窗确认重量 Co-Authored-By: Claude Opus 4.6 --- .../clean-veg-ratio-scale/01-accept.html | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) 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 e9a6286..d0014ce 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 @@ -360,7 +360,7 @@
- +
@@ -428,7 +428,8 @@ var currentUser = null; var acceptedFoods = []; - var pendingWeightFood = null; // 待确认重量的净菜引用 + var pendingWeightFood = null; + var foodIdCounter = 0; // 唯一ID计数器 // ---- URL 参数 ---- function getUrlParam(name) { @@ -447,22 +448,25 @@ // 初始化净菜列表(带累计已加工重量) acceptedFoods = mockFoods.map(function(f) { - return { name: f.name, size: f.size, shape: f.shape, blade: f.blade, target: f.target, processed: f.processed, icon: f.icon }; + foodIdCounter++; + 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(); })(); - // ---- 渲染净菜卡片列表 ---- + // ---- 渲染净菜卡片列表(隐藏已完成的) ---- function renderFoodCards() { var container = document.getElementById('foodCards'); var html = ''; - acceptedFoods.forEach(function(f, idx) { + // 只渲染未完成的(processed < target) + acceptedFoods.forEach(function(f) { + if (f.processed >= f.target) return; // 已完成则隐藏 var pct = f.target > 0 ? Math.min(100, (f.processed / f.target) * 100) : 0; html += '
' + '
' + '' + f.icon + '' + '' + f.name + '' - + '' + + '' + '
' + '' + f.size + ' · ' + f.shape + ' · ' + f.blade + '' + '
' @@ -477,19 +481,42 @@ + '
'; }); if (html === '') { - html = '
暂无加工净菜,点击右上角「刷新」获取
'; + html = '
暂无加工净菜,点击上方「获取任务」添加
'; } container.innerHTML = html; } // ---- 删除净菜 ---- - function removeFood(idx) { - acceptedFoods.splice(idx, 1); + function removeFood(id) { + for (var i = 0; i < acceptedFoods.length; i++) { + if (acceptedFoods[i].id === id) { acceptedFoods.splice(i, 1); break; } + } renderFoodCards(); showToast('已删除', 1000); } - // ---- 刷新:模拟获取加工任务最新重量 ---- + // ---- 获取任务:新增一个未完成的净菜加工任务 ---- + function handleFetchTask() { + 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) { + showToast('暂无可获取的净菜任务', 1200, 'warn'); + return; + } + 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%进度,确保未完成 + 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(); + showToast('已获取:' + food.name + '(应加工 ' + target.toFixed(1) + '斤)', 1500); + }, 800); + } + + // ---- 刷新:模拟获取加工任务最新重量 ----(顶部刷新按钮) function handleRefresh() { showToast('正在获取加工数据...', 800); setTimeout(function() {