Make row size dynamic

pull/37/head
Varun Patil 2022-08-15 04:04:34 +00:00
parent 3c6a5036d4
commit a860208745
1 changed files with 30 additions and 24 deletions

View File

@ -13,8 +13,13 @@
<h1 v-if="item.head" class="head"> <h1 v-if="item.head" class="head">
{{ item.name }} {{ item.name }}
</h1> </h1>
<div v-else class="photo"> <div v-else
<img v-for="img of item.photos" :src="img.src" :key="img.file_id" /> class="photo"
v-bind:style="{ height: rowHeight + 'px' }">
<img v-for="img of item.photos"
:src="img.src" :key="img.file_id"
v-bind:style="{ width: rowHeight + 'px', height: rowHeight + 'px' }"/>
</div> </div>
</RecycleScroller> </RecycleScroller>
</div> </div>
@ -25,11 +30,12 @@ export default {
data() { data() {
return { return {
list: [], list: [],
count: 0, numRows: 0,
nrows: 0, numCols: 5,
ncols: 5,
heads: {}, heads: {},
rowHeight: 100,
currentStart: 0, currentStart: 0,
currentEnd: 0, currentEnd: 0,
} }
@ -43,7 +49,11 @@ export default {
methods: { methods: {
handleResize() { handleResize() {
let height = this.$refs.container.clientHeight; let height = this.$refs.container.clientHeight;
let width = this.$refs.container.clientWidth;
this.$refs.scroller.$el.style.height = (height - 4) + 'px'; this.$refs.scroller.$el.style.height = (height - 4) + 'px';
this.numCols = Math.max(4, Math.floor(width / 150));
this.rowHeight = Math.floor(width / this.numCols) - 4;
}, },
scrollChange(startIndex, endIndex) { scrollChange(startIndex, endIndex) {
@ -95,7 +105,7 @@ export default {
// Add header to list // Add header to list
const head = { const head = {
id: ++this.nrows, id: ++this.numRows,
name: dateStr, name: dateStr,
size: 60, size: 60,
head: true, head: true,
@ -106,14 +116,9 @@ export default {
this.list.push(head); this.list.push(head);
// Add rows // Add rows
const nrows = Math.ceil(day.count / this.ncols); const nrows = Math.ceil(day.count / this.numCols);
for (let i = 0; i < nrows; i++) { for (let i = 0; i < nrows; i++) {
this.list.push({ this.list.push(this.getBlankRow(day.day_id));
id: ++this.nrows,
photos: [],
size: 100,
dayId: day.day_id,
});
} }
} }
}, },
@ -139,15 +144,11 @@ export default {
for (const p of data) { for (const p of data) {
// Check if we ran out of rows // Check if we ran out of rows
if (rowIdx >= this.list.length || this.list[rowIdx].head) { if (rowIdx >= this.list.length || this.list[rowIdx].head) {
this.list.splice(rowIdx, 0, { this.list.splice(rowIdx, 0, this.getBlankRow(dayId));
id: rowIdx,
photos: [],
size: 100,
});
} }
// Go to the next row // Go to the next row
if (this.list[rowIdx].photos.length >= this.ncols) { if (this.list[rowIdx].photos.length >= this.numCols) {
rowIdx++; rowIdx++;
} }
@ -167,6 +168,16 @@ export default {
this.list.splice(rowIdx + 1, spliceCount); this.list.splice(rowIdx + 1, spliceCount);
} }
}, },
// Get a new blank row
getBlankRow(dayId) {
return {
id: ++this.numRows,
photos: [],
size: this.rowHeight,
dayId: dayId,
};
}
}, },
} }
</script> </script>
@ -181,12 +192,7 @@ export default {
width: 100%; width: 100%;
} }
.photo {
height: 100px;
}
.photo img { .photo img {
height: 100px;
width: 100px;
object-fit: cover; object-fit: cover;
padding: 2px; padding: 2px;
} }