|
|
<template>
|
|
|
<div class="wf-list">
|
|
|
<div v-for="(i, index) in viewList" :key="index"
|
|
|
<div class="wf-list" :style="{'height': listHeight + 'px'}">
|
|
|
<div
|
|
|
v-for="i in viewList"
|
|
|
:key="`${i._temporary ? '_' : ''}${i.articleId}`"
|
|
|
class="wf-item"
|
|
|
:class="{'wf-item-default': i._default, 'wf-item-temp': i._temporary}"
|
|
|
:style="{width: 100 / cols + '%', left: i.left + '%', top: i.top + 'px'}">
|
|
|
:style="`width: ${100 / cols}%;transform: translate(${i.left}px, ${i.top}px)`">
|
|
|
<div class="wf-item-mid">
|
|
|
<router-link to="/ufo/order/1">
|
|
|
<div class="layer-image" :style="{height: i.coverHeight + 'px'}">
|
|
|
<img v-if="!i._temporary" :src="i[srcKey]" :alt="i.content">
|
|
|
<router-link :to="'/article/' + i.articleId">
|
|
|
<div class="layer-image" :style="{'height': i.coverHeight + 'px'}">
|
|
|
<ImageFormat v-if="!i._temporary" :src="i[srcKey]" :width="coverImageWidth" :height="i.coverHeight"></ImageFormat>
|
|
|
</div>
|
|
|
<div class="description">{{i.content}}</div>
|
|
|
</router-link>
|
|
|
|
|
|
<div class="attribution">
|
|
|
<router-link to="/ufo/order/1" class="auther">
|
|
|
<router-link :to="'/article/' + i.articleId" class="auther">
|
|
|
<span class="avatar">
|
|
|
<img v-if="!i._temporary" :src="i.authorHeadIco">
|
|
|
<WidgetAvatar v-if="!i._temporary" :src="i.authorHeadIco" :width="70" :height="70"></WidgetAvatar>
|
|
|
</span>
|
|
|
<span class="name">{{i.authorName}}</span>
|
|
|
</router-link>
|
|
|
|
|
|
<div class="fav">21321</div>
|
|
|
<div class="fav">
|
|
|
<WidgetFav :articleId="i.articleId" :num="i.praiseCount" :option="favOption"></WidgetFav>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
...
|
...
|
@@ -36,9 +40,15 @@ export default { |
|
|
viewList: [{
|
|
|
_default: true
|
|
|
}],
|
|
|
coverImageWidth: 0,
|
|
|
colWidthPer: 0,
|
|
|
calcIndex: 0,
|
|
|
loadedIndex: 0
|
|
|
loadedIndex: 0,
|
|
|
colsHeight: [],
|
|
|
favOption: {
|
|
|
iconFontSize: 26,
|
|
|
textAlign: 'normal'
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
props: {
|
...
|
...
|
@@ -80,7 +90,7 @@ export default { |
|
|
this.timer = setTimeout(this.resetViewList, 0);
|
|
|
},
|
|
|
list(newList, oldList) {
|
|
|
if (this.viewList.length > newList.length) {
|
|
|
if (oldList.length > newList.length) {
|
|
|
this.reset();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -88,10 +98,12 @@ export default { |
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
// isViewItem() {
|
|
|
// console.log(arguments);
|
|
|
// return true;
|
|
|
// },
|
|
|
listHeight() {
|
|
|
return Math.max.apply(null, this.colsHeight);
|
|
|
},
|
|
|
colWidth() {
|
|
|
return this.$el.offsetWidth / this.cols;
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
clacCoverSize() {
|
...
|
...
|
@@ -100,9 +112,8 @@ export default { |
|
|
for (let i = this.calcIndex; i < this.list.length; i++) {
|
|
|
let item = this.list[i];
|
|
|
|
|
|
item.coverHeight = item.imageHeight / item.imageWidth * this.coverImageWidth;
|
|
|
console.log(item.imageHeight / item.imageWidth * this.coverImageWidth);
|
|
|
console.log(item.imageHeight, item.imageWidth, this.coverImageWidth);
|
|
|
item.coverHeight = Math.floor(item.imageHeight / item.imageWidth * this.coverImageWidth);
|
|
|
|
|
|
nlist.push(assign({_temporary: true}, item));
|
|
|
};
|
|
|
|
...
|
...
|
@@ -130,7 +141,7 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
}
|
|
|
|
|
|
let height = $elem.offsetHeight;
|
|
|
let top, left;
|
|
|
let top, left, leftPer;
|
|
|
let item = this.list[i];
|
|
|
|
|
|
item.height = height;
|
...
|
...
|
@@ -138,19 +149,23 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
if (i < this.cols) {
|
|
|
this.colsHeight[i] = height;
|
|
|
top = 0
|
|
|
left = i * this.colWidthPer
|
|
|
left = i * this.colWidth;
|
|
|
leftPer = i * this.colWidthPer;
|
|
|
} else {
|
|
|
let minHeight = Math.min.apply(null, this.colsHeight);
|
|
|
let minIndex = this.colsHeight.indexOf(minHeight);
|
|
|
|
|
|
top = minHeight;
|
|
|
left = minIndex * this.colWidthPer;
|
|
|
left = minIndex * this.colWidth;
|
|
|
leftPer = minIndex * this.colWidthPer;
|
|
|
|
|
|
this.colsHeight[minIndex] = minHeight + height;
|
|
|
}
|
|
|
|
|
|
item.left = left;
|
|
|
item.leftPer = leftPer;
|
|
|
item.top = top;
|
|
|
item.bottom = top + height;
|
|
|
}
|
|
|
|
|
|
this.loadedIndex = this.list.length;
|
...
|
...
|
@@ -182,6 +197,10 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
this.loadedIndex = 0;
|
|
|
this.calcIndex = 0;
|
|
|
|
|
|
this.viewList = [];
|
|
|
this.lastPos = 0;
|
|
|
this.viewIndex = 0;
|
|
|
|
|
|
this.setImgWidth();
|
|
|
},
|
|
|
resetViewList() {
|
...
|
...
|
@@ -194,10 +213,10 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
let indexArr = [];
|
|
|
|
|
|
if (this.pos < this.lastPos) {
|
|
|
i = this.viewIndex['end'] || 0;
|
|
|
i = Math.min.apply(null, [(this.viewIndex['end'] || 0), this.list.length - 1]);
|
|
|
step = -1;
|
|
|
} else {
|
|
|
i = this.viewIndex['start'] || 0;
|
|
|
i = Math.max.apply(null, [(this.viewIndex['start'] || 0), 0]);
|
|
|
step = 1;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -205,20 +224,26 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
|
|
|
while (loop)
|
|
|
{
|
|
|
let item = this.list[i];
|
|
|
|
|
|
if (!item) {
|
|
|
if (i < 0 || i >= this.list.length) {
|
|
|
loop = false;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (item.top > endPos - this.offsetTop) {
|
|
|
(step > 0) && (loop = false);
|
|
|
} else if (item.top < startPos - this.offsetTop) {
|
|
|
(step < 0) && (loop = false);
|
|
|
} else {
|
|
|
indexArr.push(i);
|
|
|
list.push(item);
|
|
|
let item = this.list[i];
|
|
|
|
|
|
if (item) {
|
|
|
if (item.top > endPos - this.offsetTop) {
|
|
|
if (step > 0) {
|
|
|
loop = false;
|
|
|
}
|
|
|
} else if (item.bottom < startPos - this.offsetTop) {
|
|
|
if (step < 0) {
|
|
|
loop = false;
|
|
|
}
|
|
|
} else {
|
|
|
indexArr.push(i);
|
|
|
list.push(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
i += step;
|
...
|
...
|
@@ -228,7 +253,9 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
return;
|
|
|
}
|
|
|
|
|
|
indexArr = indexArr.sort();
|
|
|
indexArr = indexArr.sort(function(a, b) {
|
|
|
return a - b;
|
|
|
});
|
|
|
|
|
|
let viewIndex = {
|
|
|
start: indexArr[0],
|
...
|
...
|
@@ -253,7 +280,6 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
}
|
|
|
|
|
|
.wf-item {
|
|
|
width: 50%;
|
|
|
padding: 10px;
|
|
|
font-size: 24px;
|
|
|
overflow: hidden;
|
...
|
...
|
@@ -305,6 +331,10 @@ console.log(item.imageHeight, item.imageWidth, this.coverImageWidth); |
|
|
display: inline-block;
|
|
|
vertical-align: middle;
|
|
|
}
|
|
|
|
|
|
.fav {
|
|
|
line-height: 60px;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
.wf-item-default,
|
...
|
...
|
|