|
@@ -33,7 +33,8 @@ Page({
|
|
|
},
|
|
|
imageList: [],
|
|
|
image4List: [],
|
|
|
- _locImageList: [],
|
|
|
+ _allImageList: [],
|
|
|
+ _netImageList: [],
|
|
|
selectIndex: 0,
|
|
|
_localImgPicKey: "_localImgPicListKey",
|
|
|
navbarData: {
|
|
@@ -82,18 +83,20 @@ Page({
|
|
|
let _this = this;
|
|
|
deviceWallPaper().then(res => {
|
|
|
let data = res ?? []
|
|
|
+ // 网络的
|
|
|
+ _this.data._netImageList = data;
|
|
|
|
|
|
let localImgList = store.getStore(_this.data._localImgPicKey);
|
|
|
- console.log("壁纸列表", data.length, localImgList, "空");
|
|
|
-
|
|
|
+ console.log("壁纸列表", data.length, "空", localImgList);
|
|
|
+ let allImgs = []
|
|
|
if (localImgList) {
|
|
|
- console.log("壁纸列表2", res.length, localImgList, "空");
|
|
|
- data = localImgList.concat(data)
|
|
|
+ console.log("壁纸列表2", res.length, "空", localImgList, "空");
|
|
|
+ allImgs = localImgList.concat(data)
|
|
|
}
|
|
|
- _this.data._locImageList = data;
|
|
|
+ _this.data._allImageList = allImgs;
|
|
|
_this.setData({
|
|
|
- imageList: _this.data._locImageList,
|
|
|
- image4List: _this.data._locImageList.slice(0, 4),
|
|
|
+ imageList: _this.data._allImageList,
|
|
|
+ image4List: _this.data._allImageList.slice(0, 4),
|
|
|
// topImg: data[0] ?? {}
|
|
|
})
|
|
|
|
|
@@ -102,40 +105,47 @@ Page({
|
|
|
async updateTopImg(topUrl) {
|
|
|
let _this = this;
|
|
|
|
|
|
- // let hasImg = _this.data.imageList.find(function (vForItem) {
|
|
|
- // return vForItem.pic == topUrl;
|
|
|
- // })
|
|
|
- // if (!hasImg) {
|
|
|
let newImg = {
|
|
|
"pic": topUrl, "id": "0"
|
|
|
}
|
|
|
let myImgList = store.getStore(_this.data._localImgPicKey)
|
|
|
myImgList = myImgList ?? []
|
|
|
- let myIndex = myImgList.findIndex(img => img.pic === findImg.pic);
|
|
|
- if (myIndex < 0) {
|
|
|
- myImgList.unshift(newImg)
|
|
|
- }
|
|
|
+ console.log("updateTopImg1", imgList, myImgList)
|
|
|
+
|
|
|
+ // 移除保存的重复图片
|
|
|
+ let myIndex = myImgList.findIndex(img => img.pic === topUrl);
|
|
|
|
|
|
- let imgList = _this.data._locImageList
|
|
|
- console.log("updateTopImg1", imgList)
|
|
|
+
|
|
|
+ let imgList = _this.data._netImageList
|
|
|
+ // 移除网络的重复图片
|
|
|
let findImg = imgList.find(function (img) { return img.pic === topUrl })
|
|
|
console.log("updateTopImg3", findImg)
|
|
|
if (findImg) {
|
|
|
- let index = imgList.findIndex(img => img.pic === findImg.pic);
|
|
|
- imgList.splice(index, 1);
|
|
|
- imgList.unshift(findImg);
|
|
|
+ // 官方不动位置
|
|
|
+ // let index = imgList.findIndex(img => img.pic === findImg.pic);
|
|
|
+ // imgList.splice(index, 1);
|
|
|
+ // imgList.unshift(findImg);
|
|
|
} else {
|
|
|
- imgList.unshift(newImg)
|
|
|
+ if (myIndex < 0) {
|
|
|
+ // 不是官方的壁纸,才添加进缓存
|
|
|
+ myImgList.unshift(newImg)
|
|
|
+ console.log("updateTopImg5", myImgList.length)
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- console.log("updateTopImg2", imgList, findImg)
|
|
|
|
|
|
- if (imgList.length > 10) {
|
|
|
- imgList.pop()
|
|
|
+ if (myImgList.length > 1) {
|
|
|
+ console.log("updateTopImg4", myImgList.length)
|
|
|
+ // 本地图片缓存最多保存1张, 10张
|
|
|
+ myImgList.pop()
|
|
|
}
|
|
|
- _this.data._locImageList = imgList
|
|
|
+
|
|
|
+ console.log("updateTopImg2", imgList, findImg)
|
|
|
+ _this.data._allImageList = myImgList.concat(imgList);
|
|
|
+
|
|
|
_this.setData({
|
|
|
- imageList: _this.data._locImageList,
|
|
|
- image4List: _this.data._locImageList.slice(0, 4),
|
|
|
+ imageList: _this.data._allImageList,
|
|
|
+ image4List: _this.data._allImageList.slice(0, 4),
|
|
|
topImg: newImg
|
|
|
})
|
|
|
store.setStore(_this.data._localImgPicKey, myImgList)
|