From b865f6f560ce54462720c860cb2af6bda251c436 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=82=93=E5=B9=B3=E8=89=BA?= <52643018@qq.com>
Date: Fri, 19 Nov 2021 20:51:42 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=20?=
=?UTF-8?q?=E5=8F=91=E7=8E=B0=E5=A5=BD=E4=BA=A7=E5=93=81=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E4=BB=B7=E6=A0=BCtab=E6=9C=AA=E6=BF=80=E6=B4=BB=E4=BD=86?=
=?UTF-8?q?=E9=AB=98=E4=BA=AE=E6=98=BE=E7=A4=BA=E7=9A=84BUG=20=E3=80=90?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=91=20=E5=8F=91=E7=8E=B0=E5=A5=BD?=
=?UTF-8?q?=E4=BA=A7=E5=93=81=E9=A1=B5=E9=9D=A2market=E5=8A=A0=E8=BD=BD?=
=?UTF-8?q?=E8=BF=87=E4=B9=85(=E6=AF=8F=E6=AC=A1download=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98)=E7=9A=84BUG?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/shopmap/index.vue | 89 +++++++++++++++++++++++++----------------
1 file changed, 54 insertions(+), 35 deletions(-)
diff --git a/pages/shopmap/index.vue b/pages/shopmap/index.vue
index d778c6f..82a3cbc 100644
--- a/pages/shopmap/index.vue
+++ b/pages/shopmap/index.vue
@@ -22,8 +22,8 @@
-
-
+
+
@@ -150,7 +150,8 @@
isPage: true,
pageSize: 20,
sort: 0,
- address: ''
+ address: '',
+ downloadImages: [] // 已下载过的图片缓存
}
},
onLoad() {
@@ -301,7 +302,6 @@
},
tabChange(index){
this.current = index;
- console.log('重复只想')
this.getActivityList()
},
// 滑块下标值变化
@@ -310,7 +310,6 @@
if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
},
changeSort(sort) {
- console.log('排序')
this.sort != this.sort
this.getActivityList()
},
@@ -351,8 +350,7 @@
tab_item.loadingText = '没有更多数据啦~';
}
this.tab_list[this.current].isRefresher = false;
- console.log(this.tab_list[this.current].isRefresher )
- console.log(this.tab_list[this.current])
+
if(tab_item.page == 1){
tab_item.list = res.data.data;
}else{
@@ -369,45 +367,66 @@
createMarkers(res_list){
let markers_self = [];
let p_list = []; // 异步队列
+ let downloadImages = JSON.parse(JSON.stringify(this.downloadImages)); // 已下载过的图片缓存
uni.showLoading({
title: '加载地图信息中'
})
res_list.map(item => {
let itemP = new Promise((resolve, reject) => {
- uni.downloadFile({
- url: item.picture,
- complete: result => {
- let tempFilePath = "";
- if (result.statusCode === 200) {
- tempFilePath = result.tempFilePath;
- }
- let obj = {
- id: item.id,
- name: item.title,
- address: item.address,
- latitude: Number(item.latitude),
- longitude: Number(item.longitude),
- iconPath: tempFilePath,
- width: 30,
- height: 30,
- callout: {
- content: item.title,
- fontSize: 14,
- textAlign: 'center',
- bgColor: "#fff",
- borderRadius: 14,
- padding: 4,
- display: "ALWAYS"
+ let tempFilePath = ""; // 图片临时路径地址
+ let obj = {
+ id: item.id,
+ name: item.title,
+ address: item.address,
+ latitude: Number(item.latitude),
+ longitude: Number(item.longitude),
+ // iconPath: tempFilePath,
+ width: 30,
+ height: 30,
+ callout: {
+ content: item.title,
+ fontSize: 14,
+ textAlign: 'center',
+ bgColor: "#fff",
+ borderRadius: 14,
+ padding: 4,
+ display: "ALWAYS"
+ }
+ };
+
+ let image = downloadImages.filter(function(f_item, f_index, f_arr){
+ return f_item.id == item.id;
+ });
+
+ if(image.length > 0){
+ // 找到缓存匹配项
+ tempFilePath = image[0].url;
+ obj.iconPath = image[0].url;
+ markers_self.push(obj);
+ resolve();
+ }else{
+ // 未放入缓存,将执行download
+ uni.downloadFile({
+ url: item.picture,
+ complete: result => {
+ if (result.statusCode === 200) {
+ tempFilePath = result.tempFilePath;
}
+ obj.iconPath = tempFilePath;
+ markers_self.push(obj);
+ downloadImages.push({
+ id: item.id,
+ url: tempFilePath
+ });
+ resolve();
}
- markers_self.push(obj);
- resolve();
- }
- })
+ })
+ }
});
p_list.push(itemP);
});
Promise.all(p_list).then(res => {
+ this.downloadImages = JSON.parse(JSON.stringify(downloadImages));
this.markers_list = markers_self;
uni.hideLoading();
})