【增加】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> <template>
<el-card class="dr-task" body-class="task-card" shadow="never"> <el-card class="dr-task" body-class="task-card" shadow="never">
<template #header>绘画任务</template> <template #header>绘画任务</template>
<ImageTaskCard <div class="task-image-list" ref="imageTaskRef" @scroll="handleTabsScroll">
v-for="image in imageList" <ImageTaskCard
:key="image" v-for="image in imageList"
:image-detail="image" :key="image"
@on-btn-click="handlerImageBtnClick" :image-detail="image"
@on-mj-btn-click="handlerImageMjBtnClick"/>
@on-btn-click="handlerImageBtnClick"
@on-mj-btn-click="handlerImageMjBtnClick"/>
</div>
</el-card> </el-card>
<!-- 图片 detail 抽屉 --> <!-- 图片 detail 抽屉 -->
<ImageDetailDrawer <ImageDetailDrawer
@ -26,6 +29,10 @@ const imageList = ref<ImageDetailVO[]>([]) // image 列表
const imageListInterval = ref<any>() // image const imageListInterval = ref<any>() // image
const isShowImageDetail = ref<boolean>(false) // task const isShowImageDetail = ref<boolean>(false) // task
const showImageDetailId = ref<number>(0) // 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 */ /** 抽屉 - close */
const handlerDrawerClose = async () => { const handlerDrawerClose = async () => {
@ -41,8 +48,13 @@ const handlerDrawerOpen = async () => {
* 获取 - image 列表 * 获取 - image 列表
*/ */
const getImageList = async () => { const getImageList = async () => {
const { list } = await ImageApi.getImageList({pageNo: 1, pageSize: 20}) imageTaskLoading.value = true
imageList.value = list 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 */ /** 图片 - 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}) defineExpose({getImageList})
@ -118,12 +142,20 @@ onUnmounted(async () => {
<style lang="scss"> <style lang="scss">
.task-card { .task-card {
margin: 0;
padding: 0;
height: 100%;
}
.task-image-list {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
align-content: flex-start; align-content: flex-start;
height: 100%; height: 100%;
overflow: auto; overflow: auto;
padding: 20px;
padding-bottom: 300px;
>div { >div {
margin-right: 20px; margin-right: 20px;