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 = {}