Browse Source

修复卡顿问题

重写下一页实现
master
Naomi 8 months ago
parent
commit
994af5f616
4 changed files with 41 additions and 6 deletions
  1. BIN
      images/done.png
  2. +24
    -3
      lib/util.js
  3. +6
    -1
      pages/album/album.js
  4. +11
    -2
      pages/album/album.wxml

BIN
images/done.png View File

Before After
Width: 60  |  Height: 60  |  Size: 4.2 KiB

+ 24
- 3
lib/util.js View File

@ -1,12 +1,33 @@
module.exports = {
// 一维数组转二维数组
listToMatrix(list, elementsPerSubArray) {
let matrix = [], i, col, row;
listToMatrix(list, elementsPerSubArray, truncated) {
let matrix = [],
i, col, row;
for (i = 0, row = -1; i < list.length; i += 1) {
col = i % elementsPerSubArray;
row = Math.floor(i / elementsPerSubArray);
if (!matrix[row]) matrix[row] = [0, 0, 0];
if (!matrix[row])
matrix[row] = [0, 0, 0];
matrix[row][col] = list[i];
if (i == list.length - 1) {
if (truncated != 0) {
if (col == 0 || col == 1) {
matrix[row][col + 1] = {
type: 'next'
};
} else if (col == 2) {
matrix[row + 1] = [{
type: 'next'
}, 0, 0];
}
} else if (truncated == 0) {
if (col == 0 || col == 1) {
matrix[row][col + 1] = {
type: 'done'
};
}
}
}
}
return matrix;
},


+ 6
- 1
pages/album/album.js View File

@ -154,6 +154,7 @@ Page({
Prefix: prefix,
Marker: marker,
Delimiter: delimiter,
MaxKeys: 200,
}, function (err, data) {
if (data) {
console.log(data)
@ -163,6 +164,7 @@ Page({
marker: data.NextMarker
})
} else {
that.data.marker = 0
that.setData({
marker: 0
})
@ -181,10 +183,13 @@ Page({
let layoutColumnSize = this.data.layoutColumnSize;
let layoutList = [];
var imageList = [].concat(this.data.albumList);
imageList.unshift({
type: 'add'
});
layoutList = listToMatrix(imageList, layoutColumnSize);
layoutList = listToMatrix(imageList, layoutColumnSize, this.data.marker);
this.setData({
layoutList,
});


+ 11
- 2
pages/album/album.wxml View File

@ -22,11 +22,11 @@
</view>
</block>
<block wx:elif="{{item}}">
<block wx:elif="{{item.type==undefined&&item!=0}}">
<image lazy-load="true" bindtap="enterPreviewMode" bindlongpress="showActions" data-src="{{item}}" class="album-item" src="{{item+'!preview'}}" mode="aspectFill"></image>
</block>
<block wx:elif="{{item===0 && group[cellIndex-1] && marker!=0}}">
<block wx:elif="{{item.type==='next'}}">
<view class="upload-add-outer">
<view class="upload-add" bindtap="nextPage">
<image src="/images/next.gif" mode="aspectFit"></image>
@ -35,6 +35,15 @@
</view>
</block>
<block wx:elif="{{item.type==='done'}}">
<view class="upload-add-outer">
<view class="upload-add">
<image src="/images/done.png" mode="aspectFit"></image>
<text>没有更多图片</text>
</view>
</view>
</block>
<block wx:else>
<view class="album-item empty"></view>
</block>


Loading…
Cancel
Save