外卖餐具智能推荐

问题1

javascript 复制代码
// 智能推荐餐具数量
        const recommendedCount = computed(() => {
            // TODO :目标 1 待补充代码 Start
            // 初始化空数组
            let category = []
            // 初始化推荐餐具数为0
            let count = 0
            // 遍历当前已选中的菜品数组
            cartItems.value.forEach(item => {
                // 用for循环使每一份菜品都单独存入数组
                for (let i = 0; i < item.count; i++) {
                    category.push(item.category)
                }
            })
            // 用if语句判断菜品全是主食或全是热菜,则按照主食或热菜的数量赋值给推荐餐具数
            if ((category.includes('主食') && !category.includes('热菜')) || (!category.includes('主食') && category.includes('热菜'))) {
                count = category.length
            } else {
                // 若既有主食又有热菜
                // 则通过比较两者数量,数量较多的一者,赋值给推荐餐具数
                if (category.filter(item => item === '主食').length > category.filter(item => item === '热菜').length) {
                    count = category.filter(item => item === '主食').length
                } else if (category.filter(item => item === '主食').length < category.filter(item => item === '热菜').length) {
                    count = category.filter(item => item === '热菜').length
                }
            }
            // 输出推荐餐具数
            return count
            // TODO :目标 1 待补充代码 End
        });

问题2

javascript 复制代码
// 选择餐具模式
        const selectUtensilsMode = (mode) => {
            // TODO :目标 2 待补充代码 Start
            // 根据题目意思将选择模式赋值给utensilsMode
            utensilsMode.value = mode
            // 判断mode为auto或custom
            if (mode === 'auto') {
                // mode为auto时,
                // 给utensilsMode新赋值auto
                // 将 utensilsCount 设置为 recommendedCount
                utensilsMode.value = 'auto'
                utensilsCount.value = recommendedCount.value
            } else if (mode === 'custom') {
                // mode为custom时
                // 给utensilsMode新赋值custom
                // 将 utensilsCount 设置为 customUtensilsCount
                utensilsMode.value = 'custom'
                utensilsCount.value = customUtensilsCount.value
            }
            // TODO :目标 2 待补充代码 End
        };


// 选择具体餐具数量
        const selectUtensilsCount = (count) => {
            // TODO :目标 2 待补充代码 Start
            // 判断推荐餐具数为1、2、3时
            // 给 utensilsMode新赋值manual
            // 更新utensilsCount.value
            if (count === 1 || count === 2 || count === 3) {
                utensilsMode.value = 'manual'
                utensilsCount.value = count
            }
            // TODO :目标 2 待补充代码 End
        };


 <!-- TODO :目标 2 待补充代码 Start -->
                     <el-input-number v-model="utensilsCount" max=4 min=1></el-input-number>
<!-- TODO :目标 2 待补充代码 End -->
相关推荐
刘某的Cloud1 分钟前
Galera Cluster mariadb 生产环境常见问题排查与运维指南
linux·运维·数据库·mariadb·集群高可用
生戎马 平安京策5 分钟前
只学一点点:我的技术学习策略
前端·javascript·react.js
70asunflower15 分钟前
Linux 性能排查分析完全教程
linux·运维
大鹏说大话19 分钟前
HTML5 地理定位 Geolocation:获取用户位置的“红线”与最佳实践
前端·html·html5
Csvn40 分钟前
content-visibility: auto —— 让浏览器跳过离屏渲染的性能黑科技
前端
小鹰信息技术服务部40 分钟前
Edge安装包MicrosoftEdgeSetup.exe无法运行,点击没反应
前端·edge
webkubor1 小时前
一次前端生产白屏复盘:旧 HTML、Hash 资源和 MIME type text/html
前端·前端工程化
咩咩啃树皮2 小时前
第63篇【终极整合巨作】从零手写原生中后台管理系统|整合62篇全部前端知识点|从头到尾完整架构+全功能逻辑
前端·架构
dok122 小时前
Johannes 《Linux内核模块与设备驱动开发:编写Linux驱动程序》 (11)kmalloc 动态内存分配和struct file中的私有数据
linux·驱动开发·算法
IT小盘2 小时前
17-构建Prompt测试集-提示词优化不再凭感觉
服务器·windows·prompt