From 3b097ae8387a198d018227d3002587fd4b1c55fd Mon Sep 17 00:00:00 2001 From: liyuanchao <438964165@qq.com> Date: Wed, 10 Sep 2025 13:42:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/sys/home/home.vue | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/pages/sys/home/home.vue b/pages/sys/home/home.vue index e65aeaf..b3e9370 100644 --- a/pages/sys/home/home.vue +++ b/pages/sys/home/home.vue @@ -154,22 +154,38 @@ import toast from '../../../uview-ui/libs/function/toast'; } }, async getImageUrl() { - // 处理hotList中的图片链接 + // 收集所有需要获取链接的图片ID + const imgIds = []; + const imgIdToIndexMap = []; // 保存图片ID对应的hotList索引 + for (let i = 0; i < this.hotList.length; i++) { const item = this.hotList[i]; if (item.activityImgUrl) { - try { - const imgRes = await this.$u.api.getImageUrl({}, item.activityImgUrl); - if (imgRes.code == 200 && imgRes.data && imgRes.data.length > 0) { - // 将图片ID替换为实际的图片URL - this.$set(this.hotList[i], 'activityImgUrl', imgRes.data[0].url); - } - } catch (error) { - console.error('获取图片链接失败:', error); - } + imgIds.push(item.activityImgUrl); + imgIdToIndexMap.push({ + id: item.activityImgUrl, + index: i + }); + } + } + + // 如果有图片ID需要处理,则调用API一次获取所有图片链接 + if (imgIds.length > 0) { + try { + const imgRes = await this.$u.api.getImageUrl({}, imgIds.join(',')); + if (imgRes.code == 200 && imgRes.data) { + // 将返回的图片URL映射回对应的hotList项 + imgRes.data.forEach(imgItem => { + const mapping = imgIdToIndexMap.find(m => m.id === imgItem.ossId); + if (mapping) { + this.$set(this.hotList[mapping.index], 'activityImgUrl', imgItem.url); + } + }); + } + } catch (error) { + console.error('获取图片链接失败:', error); } } - console.log('t1',this.hotList) }, goNoticeDetail(item){ let params = {}