From c3eeb0c3bcb4de4ca6dbbc7436c1ed91809f1fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Fri, 31 Oct 2025 14:37:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=93=E8=B4=AD=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=9A=84=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shop/index/index.vue | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/shop/index/index.vue b/packages/shop/index/index.vue index 59be660b..c1d2d3ee 100644 --- a/packages/shop/index/index.vue +++ b/packages/shop/index/index.vue @@ -418,8 +418,30 @@ export default { user_id: uni.getStorageSync("userId"), id: this.secondId, }).then((res) => { - // 深拷贝接口数据,避免引用问题 - const commodityList = JSON.parse(JSON.stringify(res.commodity_list)); + // 过滤掉commodity_goods_info_list为空的数据,并为每个infoItem设置isShow属性 + const filteredList = res.commodity_list.filter(item => { + // 确保item有commodity_info_list属性 + if (item.commodity_info_list && Array.isArray(item.commodity_info_list)) { + // 过滤掉commodity_goods_info_list为空的infoItem + item.commodity_info_list = item.commodity_info_list.filter(infoItem => + infoItem.commodity_goods_info_list && + Array.isArray(infoItem.commodity_goods_info_list) && + infoItem.commodity_goods_info_list.length > 0 + ); + // 只有当过滤后的infoItem列表不为空时,才保留该item + return item.commodity_info_list.length > 0; + } + return false; + }); + + // 为过滤后的数据中的每个infoItem设置isShow属性 + filteredList.forEach((item) => { + item.commodity_info_list.forEach((infoItem) => { + infoItem.isShow = false; + }); + }); + // 深拷贝过滤后的数据,避免引用问题 + const commodityList = JSON.parse(JSON.stringify(filteredList)); commodityList.forEach((tagItem) => { // 重命名外层变量,避免嵌套冲突 tagItem.commodity_info_list.forEach((infoItem) => { // 内层变量重命名 // 初始化isShow为响应式属性