【增加】image task 增加滚动分页

This commit is contained in:
cherishsince 2024-06-18 14:31:14 +08:00
parent 990093c0cb
commit 8db7c7d92b

View File

@ -1,12 +1,15 @@
<template>
<el-card class="dr-task" body-class="task-card" shadow="never">
<template #header>绘画任务</template>
<div class="task-image-list" ref="imageTaskRef" @scroll="handleTabsScroll">
<ImageTaskCard
v-for="image in imageList"
:key="image"
:image-detail="image"
@on-btn-click="handlerImageBtnClick"
@on-mj-btn-click="handlerImageMjBtnClick"/>
</div>
</el-card>
<!-- 图片 detail 抽屉 -->
<ImageDetailDrawer
@ -26,6 +29,10 @@ const imageList = ref<ImageDetailVO[]>([]) // image 列表
const imageListInterval = ref<any>() // image
const isShowImageDetail = ref<boolean>(false) // task
const showImageDetailId = ref<number>(0) // task
const imageTaskRef = ref<any>() // ref
const imageTaskLoading = ref<boolean>(false) // loading
const pageNo = ref<number>(1) // page no
const pageSize = ref<number>(20) // page size
/** 抽屉 - close */
const handlerDrawerClose = async () => {
@ -41,8 +48,13 @@ const handlerDrawerOpen = async () => {
* 获取 - image 列表
*/
const getImageList = async () => {
const { list } = await ImageApi.getImageList({pageNo: 1, pageSize: 20})
imageList.value = list
imageTaskLoading.value = true
try {
const { list } = await ImageApi.getImageList({pageNo: pageNo.value, pageSize: pageSize.value})
imageList.value.push.apply(imageList.value, list)
} finally {
imageTaskLoading.value = false
}
}
/** 图片 - btn click */
@ -95,6 +107,18 @@ const downloadImage = async (imageUrl) => {
}
}
const handleTabsScroll = async () => {
if (imageTaskRef.value) {
const { scrollTop, scrollHeight, clientHeight } = imageTaskRef.value;
console.log('scrollTop', scrollTop, clientHeight, scrollHeight)
if (scrollTop + clientHeight >= scrollHeight - 20 && !imageTaskLoading.value) {
console.log('分页')
pageNo.value = pageNo.value + 1
await getImageList();
}
}
}
/** 暴露组件方法 */
defineExpose({getImageList})
@ -118,12 +142,20 @@ onUnmounted(async () => {
<style lang="scss">
.task-card {
margin: 0;
padding: 0;
height: 100%;
}
.task-image-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-content: flex-start;
height: 100%;
overflow: auto;
padding: 20px;
padding-bottom: 300px;
>div {
margin-right: 20px;