mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2025-05-19 01:50:15 +09:00
fix: 修复图库瀑布流bug
This commit is contained in:
parent
ce60c334ec
commit
d4ccc9b7d6
@ -23,24 +23,7 @@
|
|||||||
<block v-else>
|
<block v-else>
|
||||||
<block v-if="galleryConfig.useWaterfall">
|
<block v-if="galleryConfig.useWaterfall">
|
||||||
<!--瀑布流-->
|
<!--瀑布流-->
|
||||||
<tm-flowLayout ref="wafll" style="width: 100%;">
|
<tm-flowLayout-custom ref="wafll" style="width: 100%;" @click="fnOnFlowClick"></tm-flowLayout-custom>
|
||||||
<template v-slot:left="{ hdata }">
|
|
||||||
<tm-translate animation-name="fadeUp">
|
|
||||||
<view class="card round-3 overflow white">
|
|
||||||
<tm-images :previmage="false" :src="hdata.item.spec.cover"
|
|
||||||
@click="fnPreview(hdata.item)"></tm-images>
|
|
||||||
</view>
|
|
||||||
</tm-translate>
|
|
||||||
</template>
|
|
||||||
<template v-slot:right="{ hdata }">
|
|
||||||
<tm-translate animation-name="fadeUp">
|
|
||||||
<view class="card round-3 overflow white">
|
|
||||||
<tm-images :previmage="false" :src="hdata.item.spec.cover"
|
|
||||||
@click="fnPreview(hdata.item)"></tm-images>
|
|
||||||
</view>
|
|
||||||
</tm-translate>
|
|
||||||
</template>
|
|
||||||
</tm-flowLayout>
|
|
||||||
</block>
|
</block>
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<block v-else>
|
<block v-else>
|
||||||
@ -48,7 +31,7 @@
|
|||||||
style="box-sizing: border-box;padding: 6rpx;width: 50%;height: 250rpx;"
|
style="box-sizing: border-box;padding: 6rpx;width: 50%;height: 250rpx;"
|
||||||
animation-name="fadeUp" :wait="calcAniWait(index)">
|
animation-name="fadeUp" :wait="calcAniWait(index)">
|
||||||
<view style="border-radius: 12rpx;overflow: hidden;width: 100%;height: 250rpx;">
|
<view style="border-radius: 12rpx;overflow: hidden;width: 100%;height: 250rpx;">
|
||||||
<image style="width: 100%;height: 100%;" mode="aspectFill" :src="item.spec.cover"
|
<image style="width: 100%;height: 100%;" mode="aspectFill" :src="item.spec.url"
|
||||||
@click="fnPreview(item)"/>
|
@click="fnPreview(item)"/>
|
||||||
</view>
|
</view>
|
||||||
</tm-translate>
|
</tm-translate>
|
||||||
@ -70,10 +53,13 @@ import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
|
|||||||
import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
|
import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
|
||||||
import tmIcons from '@/tm-vuetify/components/tm-icons/tm-icons.vue';
|
import tmIcons from '@/tm-vuetify/components/tm-icons/tm-icons.vue';
|
||||||
import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
|
import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
|
||||||
import tmFlowLayout from '@/tm-vuetify/components/tm-flowLayout/tm-flowLayout.vue';
|
import tmFlowLayoutCustom from '@/tm-vuetify/components/tm-flowLayout-custom/tm-flowLayout-custom.vue';
|
||||||
import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
|
import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
options: {
|
||||||
|
multipleSlots: true
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
tmSkeleton,
|
tmSkeleton,
|
||||||
tmTranslate,
|
tmTranslate,
|
||||||
@ -82,7 +68,7 @@ export default {
|
|||||||
tmEmpty,
|
tmEmpty,
|
||||||
tmIcons,
|
tmIcons,
|
||||||
tmImages,
|
tmImages,
|
||||||
tmFlowLayout,
|
tmFlowLayoutCustom,
|
||||||
tmTabs
|
tmTabs
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -107,7 +93,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
galleryConfig() {
|
galleryConfig() {
|
||||||
return this.$tm.vx.getters().getConfigs?.pageConfig?.galleryConfig;
|
return this.$tm.vx.getters().getConfigs.pageConfig.galleryConfig;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -159,7 +145,7 @@ export default {
|
|||||||
fnGetCategory() {
|
fnGetCategory() {
|
||||||
this.$httpApi.v2.getPhotoGroupList({
|
this.$httpApi.v2.getPhotoGroupList({
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 9999
|
size: 0
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
this.category.list = res.items.map(item => {
|
this.category.list = res.items.map(item => {
|
||||||
return {
|
return {
|
||||||
@ -186,7 +172,7 @@ export default {
|
|||||||
this.loading = 'success';
|
this.loading = 'success';
|
||||||
if (res.items.length !== 0) {
|
if (res.items.length !== 0) {
|
||||||
const _list = res.items.map((item, index) => {
|
const _list = res.items.map((item, index) => {
|
||||||
item.spec.cover = this.$utils.checkImageUrl(item.spec.cover);
|
item.spec.url = this.$utils.checkImageUrl(item.spec.url || item.spec.cover);
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
if (this.isLoadMore) {
|
if (this.isLoadMore) {
|
||||||
@ -196,7 +182,6 @@ export default {
|
|||||||
}
|
}
|
||||||
if (this.galleryConfig.useWaterfall) {
|
if (this.galleryConfig.useWaterfall) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
console.log('_list', _list)
|
|
||||||
this.$refs.wafll.pushData(_list)
|
this.$refs.wafll.pushData(_list)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -215,12 +200,14 @@ export default {
|
|||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
fnOnFlowClick({item}) {
|
||||||
|
this.fnPreview(item)
|
||||||
|
},
|
||||||
// 预览
|
// 预览
|
||||||
fnPreview(data) {
|
fnPreview(data) {
|
||||||
uni.previewImage({
|
uni.previewImage({
|
||||||
current: this.dataList.findIndex(x => x.metadata.name === data.metadata.name),
|
current: this.dataList.findIndex(x => x.metadata.name === data.metadata.name),
|
||||||
urls: this.dataList.map(x => x.spec.cover),
|
urls: this.dataList.map(x => x.spec.url),
|
||||||
indicator: 'number',
|
indicator: 'number',
|
||||||
loop: true
|
loop: true
|
||||||
});
|
});
|
||||||
@ -237,18 +224,13 @@ export default {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-bottom: 24rpx;
|
padding-bottom: 24rpx;
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
|
|
||||||
&.is-balck {
|
|
||||||
background-color: #212121;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 0 24rpx;
|
padding: 24rpx 24rpx 0;
|
||||||
padding-top: 24rpx;
|
|
||||||
gap: 12rpx 0;
|
gap: 12rpx 0;
|
||||||
|
|
||||||
.content-empty {
|
.content-empty {
|
||||||
@ -265,10 +247,6 @@ export default {
|
|||||||
padding: 24rpx;
|
padding: 24rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
|
||||||
box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
|
|
||||||
}
|
|
||||||
|
|
||||||
.load-text {
|
.load-text {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -0,0 +1,219 @@
|
|||||||
|
<template>
|
||||||
|
<view class="tm-flowLayout relative">
|
||||||
|
<view class="tm-flowLayout-hidden absolute fulled">
|
||||||
|
<view v-for="(item, index) in list2" :key="index" style="width: 350rpx;" :class="'tm-flowLayout-hidden-'+index">
|
||||||
|
<tm-images @error="loadimg($event,false,index)" @load="loadimg($event,true,index)" :src="item.spec.url"></tm-images>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="tm-flowLayout-cm flex-between">
|
||||||
|
<view class="tm-flowLayout-left" style="width: 48.6%;">
|
||||||
|
<block v-for="(item, index) in dataList[0]" :key="index">
|
||||||
|
<view @click.stop="onclick(index,0)" class="tm-flowLayout-item mb-20 fulled" :class="['tm-flowLayout-item_'+index]">
|
||||||
|
<tm-translate animation-name="fadeUp">
|
||||||
|
<view class="card round-3 overflow white">
|
||||||
|
<tm-images :previmage="false" :src="item.spec.url"></tm-images>
|
||||||
|
</view>
|
||||||
|
</tm-translate>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
|
<view class="tm-flowLayout-right" style="width: 48.6%;">
|
||||||
|
<block v-for="(item, index) in dataList[1]" :key="index">
|
||||||
|
<view @click.stop="onclick(index,1)" class="tm-flowLayout-item mb-20 fulled" :class="['tm-flowLayout-item_'+index]">
|
||||||
|
<tm-translate animation-name="fadeUp">
|
||||||
|
<view class="card round-3 overflow white">
|
||||||
|
<tm-images :previmage="false" :src="item.spec.url"></tm-images>
|
||||||
|
</view>
|
||||||
|
</tm-translate>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
<view v-if="isLoading" class="flex-shrink fulled">
|
||||||
|
<tm-loadding></tm-loadding>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 瀑布流组件
|
||||||
|
* @property {Function} click 点击项目时触发
|
||||||
|
* @property {Function} load 当前列表加载完成发出的事件。
|
||||||
|
* @property {String} model = [rank|desc] desc下正时排序,所有加载完成再进行显示,rank随机,哪个先加载哪个先排前面。
|
||||||
|
*/
|
||||||
|
import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
|
||||||
|
import tmLoadding from "@/tm-vuetify/components/tm-loadding/tm-loadding.vue"
|
||||||
|
import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
|
||||||
|
import tmTranslate from "@/tm-vuetify/components/tm-translate/tm-translate.vue"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {tmImages, tmLoadding, tmIcons, tmTranslate},
|
||||||
|
name: 'tm-flowLayout',
|
||||||
|
props: {
|
||||||
|
model: {
|
||||||
|
type: String,
|
||||||
|
default: 'rank' //desc下正时排序,所有加载完成再进行显示,rank随机,哪个先加载哪个先排前面。
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list2: [],
|
||||||
|
dataList: [
|
||||||
|
[], []
|
||||||
|
],
|
||||||
|
colHeight: [0, 0],
|
||||||
|
minWidth: 0,
|
||||||
|
isLoading: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
let p = await this.$Querey('.tm-flowLayout-left').catch(e => {
|
||||||
|
});
|
||||||
|
this.minWidth = p[0].width;
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onclick(index, dirIndex) {
|
||||||
|
this.$emit('click',
|
||||||
|
{
|
||||||
|
childrenIndex: index,
|
||||||
|
dirIndex: dirIndex,
|
||||||
|
item: this.dataList[dirIndex][index]
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//修改或者替换列表数据
|
||||||
|
changeItemData(dirIndex, childrenIndex, item) {
|
||||||
|
this.dataList[dirIndex].splice(childrenIndex, 1, item);
|
||||||
|
},
|
||||||
|
//删除一项列表数据
|
||||||
|
delItemData(dirIndex, childrenIndex) {
|
||||||
|
this.colHeight.splice(dirIndex, 1, this.colHeight[dirIndex] - this.dataList[dirIndex][childrenIndex].height)
|
||||||
|
this.dataList[dirIndex].splice(childrenIndex, 1);
|
||||||
|
this.list2.splice(this.dataList[dirIndex][childrenIndex].index, 1);
|
||||||
|
|
||||||
|
this.$nextTick(function () {
|
||||||
|
this.sucessRank();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
//向列表添加数据
|
||||||
|
pushData(list) {
|
||||||
|
console.log('添加图片数据----------',list)
|
||||||
|
|
||||||
|
let prIdx_i = this.list2.length;
|
||||||
|
if (!Array.isArray(list) || typeof list == 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
this.list2.push({
|
||||||
|
index: i + prIdx_i,
|
||||||
|
isLoad: false,
|
||||||
|
image: "",
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
...list[i]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//获取内部列表数据
|
||||||
|
getDataList() {
|
||||||
|
return this.dataList;
|
||||||
|
},
|
||||||
|
async loadimg(event, isLoad, index) {
|
||||||
|
console.log('图片加载事件----------',event)
|
||||||
|
|
||||||
|
this.isLoading = true;
|
||||||
|
let ps = this.list2[index];
|
||||||
|
ps.isLoad = true;
|
||||||
|
if (isLoad == false) {
|
||||||
|
ps.width = this.minWidth;
|
||||||
|
ps.height = this.minWidth;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ps.width = this.minWidth;
|
||||||
|
ps.height = ps.height + event.height;
|
||||||
|
}
|
||||||
|
if (this.list2.length == 0 && this.dataList[0].length == 0 && this.dataList[1].length == 0) {
|
||||||
|
this.isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.list2.splice(index, 1, ps);
|
||||||
|
if (this.model == 'desc') {
|
||||||
|
this.sucessRank();
|
||||||
|
} else if (this.model == 'rank') {
|
||||||
|
let indexCol = this.colHeight[0] <= this.colHeight[1] ? 0 : 1;
|
||||||
|
this.dataList[indexCol].push(this.list2[index]);
|
||||||
|
this.colHeight.splice(indexCol, 1, this.colHeight[indexCol] + this.list2[index].height);
|
||||||
|
if (this.isAllLoading() === false) return;
|
||||||
|
this.isLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isAllLoading() {
|
||||||
|
let isAllload = true;
|
||||||
|
for (let i = 0; i < this.list2.length; i++) {
|
||||||
|
if (this.list2[i].isLoad === false) {
|
||||||
|
isAllload = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isAllload === true) {
|
||||||
|
// 当前列表加载完成发出的事件。
|
||||||
|
this.$emit('load', this.dataList)
|
||||||
|
}
|
||||||
|
return isAllload;
|
||||||
|
},
|
||||||
|
sucessRank() {
|
||||||
|
if (this.isAllLoading() === false) return;
|
||||||
|
this.isLoading = false;
|
||||||
|
for (let i = 0; i < this.list2.length; i++) {
|
||||||
|
// let p = await this.getLeftRightHeight();
|
||||||
|
let index = this.colHeight[0] <= this.colHeight[1] ? 0 : 1;
|
||||||
|
this.dataList[index].push(this.list2[i]);
|
||||||
|
this.colHeight.splice(index, 1, this.colHeight[index] + this.list2[i].height)
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
//清空瀑布流数据 。
|
||||||
|
clear() {
|
||||||
|
this.list2 = [];
|
||||||
|
this.dataList = [[], []];
|
||||||
|
this.isLoading = false;
|
||||||
|
},
|
||||||
|
getLeftRightHeight(index) {
|
||||||
|
let t = this;
|
||||||
|
return new Promise((resolve, rejecvt) => {
|
||||||
|
let q = uni.createSelectorQuery().in(t);
|
||||||
|
q.select(".tm-flowLayout-left").boundingClientRect();
|
||||||
|
q.select(".tm-flowLayout-right").boundingClientRect();
|
||||||
|
q.exec((res) => {
|
||||||
|
resolve([res[0].height, res[1].height])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.tm-flowLayout {
|
||||||
|
.tm-flowLayout-hidden {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
overflow-y: auto;
|
||||||
|
left: -300%;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tm-flowLayout-cm {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
Loading…
Reference in New Issue
Block a user