From 3513222783a61fb9c0b996e26745380889aef7a9 Mon Sep 17 00:00:00 2001 From: lanzhihui <503792708@qq.com> Date: Mon, 25 May 2026 18:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A4=90=E5=8D=95=E6=94=AF=E6=8C=81=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=B0=8F=E6=95=B0=EF=BC=880.5=E5=80=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/appDir/appEditUserMenu.vue | 53 +++++++++++++++++++++++++--- src/views/appDir/appUserMenu.vue | 30 ++++++++++++---- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/views/appDir/appEditUserMenu.vue b/src/views/appDir/appEditUserMenu.vue index 19f84cc..49ae171 100644 --- a/src/views/appDir/appEditUserMenu.vue +++ b/src/views/appDir/appEditUserMenu.vue @@ -60,7 +60,7 @@
- +
@@ -311,14 +311,17 @@ let data = { chat_id: userStore.chatId, prepare_guide: { + // list: formatListForSubmit(readyNutrientList.value), list: readyNutrientList.value, menu: submitTransition(readyNutrientList.value), }, decoration_guide: { + // list: formatListForSubmit(fitmentNutrientList.value), list: fitmentNutrientList.value, menu: submitTransition(fitmentNutrientList.value), }, clean_guide: { + // list: formatListForSubmit(cleanNutrientList.value), list: cleanNutrientList.value, menu: submitTransition(cleanNutrientList.value), }, @@ -346,6 +349,20 @@ }, 100); }; + // 定义一个格式化函数 + const formatListForSubmit = (list) => { + return list.map((item) => { + if (item.config && item.config.length > 0) { + item.config = item.config.map((configItem) => { + // 将 oneNum 转为保留一位小数的字符串,如 "1.0", "0.5" + configItem.oneNum = Number(configItem.oneNum).toFixed(1); + return configItem; + }); + } + return item; + }); + }; + // 检查3种餐单类型是否都设置完成 const troubleshoot = (data) => { let first = true; @@ -510,8 +527,9 @@ }; // 减少营养元素或食物数量 + const minusNutrientChange = (e) => { - if (e.oneNum == 1) { + if (e.oneNum - 1 <= 0) { return; } selectNutrientList.value.forEach((item) => { @@ -519,6 +537,9 @@ item.config.forEach((j) => { if (e.time == j.time) { j.oneNum--; + // if (j.oneNum <= 0) { + // j.oneNum = 0; + // } } }); } @@ -526,12 +547,29 @@ }; // 监听输入的数量改变对应的数据 + // 辅助函数:确保值是 0.5 的倍数 + const toHalfMultiple = (value) => { + const num = parseFloat(value); + if (isNaN(num)) return 0; + // 四舍五入到最近的 0.5 倍数 + return Math.round(num * 2) / 2; + }; + + // 修改后的方法 const changeMenuNum = (e, row) => { + // 将输入值转换为数字并限制为 0.5 的倍数 + let newValue = toHalfMultiple(e); + + // 可选:添加边界限制(不能小于0) + if (newValue < 0) { + newValue = 0; + } + selectNutrientList.value.forEach((item) => { if (item.id == row.id && item.config && item.config.length > 0) { item.config.forEach((j) => { if (row.time == j.time) { - j.oneNum = e * 1; + j.oneNum = newValue; } }); } @@ -693,6 +731,11 @@ i.config = i.config.filter((item, index) => { return arr.indexOf(item.time) == index; }); + // i.config = i.config.map((item, index) => { + // console.log(item, 'item==='); + // item.oneNum = parseFloat(item.oneNum) || 1.0; + // return item; + // }); } }); } @@ -1019,7 +1062,7 @@ } .ui-stepper-box { - width: px2rem(162); + width: px2rem(200); height: px2rem(52); padding: 0 px2rem(20); border-radius: px2rem(30); @@ -1033,7 +1076,7 @@ } .ui-stepper-input-box { - width: px2rem(80); + width: px2rem(100); height: px2rem(52); border-left: px2rem(2) solid #ececec; border-right: px2rem(2) solid #ececec; diff --git a/src/views/appDir/appUserMenu.vue b/src/views/appDir/appUserMenu.vue index 2f9661d..813c0a8 100644 --- a/src/views/appDir/appUserMenu.vue +++ b/src/views/appDir/appUserMenu.vue @@ -28,9 +28,9 @@
- - - + + +
- +
@@ -1635,7 +1635,7 @@ // 减少营养元素或食物数量 const minusNutrientChange = (e) => { - if (e.oneNum == 1) { + if (e.oneNum - 1 <= 0) { return; } selectNutrientList.value.forEach((item) => { @@ -1650,18 +1650,36 @@ }; // 监听输入的数量改变对应的数据 + // 辅助函数:确保值是 0.5 的倍数 + const toHalfMultiple = (value) => { + const num = parseFloat(value); + if (isNaN(num)) return 0; + // 四舍五入到最近的 0.5 倍数 + return Math.round(num * 2) / 2; + }; + + // 修改后的方法 const changeMenuNum = (e, row) => { + // 将输入值转换为数字并限制为 0.5 的倍数 + let newValue = toHalfMultiple(e); + + // 可选:添加边界限制(不能小于0) + if (newValue < 0) { + newValue = 0; + } + selectNutrientList.value.forEach((item) => { if (item.id == row.id && item.config && item.config.length > 0) { item.config.forEach((j) => { if (row.time == j.time) { - j.oneNum = e * 1; + j.oneNum = newValue; } }); } }); // assignment(); }; + const showMenuList = (e) => { let menuList = [ { title: '早餐前', time: 'beforeMorning', config: [] },