From a11702f72739add7deeee3781eb4d2587ab2f33a Mon Sep 17 00:00:00 2001 From: liuyunqin Date: Mon, 13 Jul 2026 09:48:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E9=A3=9F=E8=B0=B1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weight-management/recipe-record.html | 93 +++++++++++++++++-- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/web-admin/weight-management/recipe-record.html b/web-admin/weight-management/recipe-record.html index 456f563..91a773a 100644 --- a/web-admin/weight-management/recipe-record.html +++ b/web-admin/weight-management/recipe-record.html @@ -116,6 +116,11 @@ tbody tr:hover{background:#F8FBFF;} .food-item__remove{width:28px;height:28px;border:1px solid var(--border);border-radius:var(--radius-sm);background:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;color:var(--text-placeholder);font-size:14px;flex-shrink:0;transition:all .15s;} .food-item__remove:hover{color:var(--danger);border-color:var(--danger);} .food-item:only-child .food-item__remove{display:none;} + +/* 操作列链接按钮 */ +.action-link{cursor:pointer;border:none;background:none;font-size:var(--font-xs);padding:2px 6px;border-radius:2px;transition:all .15s;text-decoration:none;} +.action-link--edit{color:var(--primary);}.action-link--edit:hover{background:var(--primary-light);} +.action-link--danger{color:var(--danger);}.action-link--danger:hover{background:#FFF1F0;} @@ -218,6 +223,7 @@ tbody tr:hover{background:#F8FBFF;} 用餐日期 餐次 餐品名称 + 操作 @@ -326,6 +332,7 @@ var foodMap = { function buildMockData(){ var data = []; var units = ['第四采油厂','采油一厂','采油二厂','采气一厂']; + var idCounter = 0; // 生成近7天的食谱记录 var today = new Date(); for(var d=0;d<7;d++){ @@ -344,6 +351,7 @@ function buildMockData(){ var shuffledFoods = foods.slice().sort(function(){return Math.random()-0.5;}); var foodStr = shuffledFoods.slice(0, foodCount).join('、'); data.push({ + id: ++idCounter, unit: unit, canteen: shuffledCanteens[c], date: dateStr, @@ -361,6 +369,7 @@ var allData = buildMockData(); var filteredData = allData.slice(); var pageSize = 10; var currentPage = 0; +var editingId = null; // 当前编辑的记录ID,null表示新增模式 /* ===== 筛选 ===== */ function applyFilter(){ @@ -405,7 +414,7 @@ function renderTable(){ document.getElementById('tableCount').textContent = '共 ' + filteredData.length + ' 条记录'; document.getElementById('pageNum').textContent = '第 ' + (currentPage + 1) + '/' + totalPages + ' 页'; if(filteredData.length === 0){ - tbody.innerHTML = '暂无匹配数据'; + tbody.innerHTML = '暂无匹配数据'; return; } var html = ''; @@ -416,6 +425,7 @@ function renderTable(){ html += ''+d.date+''; html += ''+d.meal+''; html += ''+esc(d.food)+''; + html += ''; html += ''; }); tbody.innerHTML = html; @@ -432,6 +442,8 @@ function goPage(delta){ /* ===== 新增记录弹窗 ===== */ function openAddDialog(){ + editingId = null; + document.querySelector('#addOverlay .record-dialog__title').textContent = '新增食谱记录'; // 预填日期为今天 var today = new Date(); document.getElementById('addDate').value = today.getFullYear()+'-'+('0'+(today.getMonth()+1)).slice(-2)+'-'+('0'+today.getDate()).slice(-2); @@ -441,6 +453,7 @@ function openAddDialog(){ } function closeAddDialog(){ + editingId = null; document.getElementById('addOverlay').classList.remove('show'); // 清空表单 document.getElementById('addUnit').value = ''; @@ -490,17 +503,85 @@ function submitAdd(){ if(v) foods.push(v); }); if(foods.length === 0){ showToast('请输入至少一个餐品名称'); return; } - // 多个餐品用顿号合并为一条记录 - allData.unshift({unit:unit, canteen:canteen, date:date, meal:meal, food:foods.join('、')}); - closeAddDialog(); - applyFilter(); - showToast('新增记录成功'); + var foodStr = foods.join('、'); + + if(editingId !== null){ + // 编辑模式:更新已有记录 + for(var i=0;i maxId) maxId = d.id; }); + allData.unshift({id: maxId+1, unit:unit, canteen:canteen, date:date, meal:meal, food:foodStr}); + closeAddDialog(); + applyFilter(); + showToast('新增记录成功'); + } } document.getElementById('addOverlay').addEventListener('click',function(e){ if(e.target === this) closeAddDialog(); }); +/* ===== 编辑记录 ===== */ +function editRecord(id){ + // 查找记录 + var record = null; + for(var i=0;i'; + list.appendChild(div); + }); + // 只有一个时隐藏删除按钮 + if(foods.length <= 1){ + var btn = list.querySelector('.food-item__remove'); + if(btn) btn.style.display = 'none'; + } + document.getElementById('addOverlay').classList.add('show'); +} + +/* ===== 删除记录 ===== */ +function deleteRecord(id){ + if(!confirm('确定要删除这条食谱记录吗?删除后不可恢复。')) return; + for(var i=0;i/g,'>');}