【增加】image task 增加分页

This commit is contained in:
cherishsince 2024-06-19 10:41:33 +08:00
parent 63f0a2058d
commit bd80a6f34f

View File

@ -1,7 +1,7 @@
<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>
<div class="task-image-list" ref="imageTaskRef" @scroll="handleTabsScroll"> <div class="task-image-list" ref="imageTaskRef">
<ImageTaskCard <ImageTaskCard
v-for="image in imageList" v-for="image in imageList"
:key="image" :key="image"
@ -10,6 +10,13 @@
@on-btn-click="handlerImageBtnClick" @on-btn-click="handlerImageBtnClick"
@on-mj-btn-click="handlerImageMjBtnClick"/> @on-mj-btn-click="handlerImageMjBtnClick"/>
</div> </div>
<div class="task-image-pagination">
<el-pagination background layout="prev, pager, next"
:default-page-size="pageSize"
:total="pageTotal"
@change="handlerPageChange"
/>
</div>
</el-card> </el-card>
<!-- 图片 detail 抽屉 --> <!-- 图片 detail 抽屉 -->
<ImageDetailDrawer <ImageDetailDrawer
@ -34,7 +41,8 @@ const imageTaskRef = ref<any>() // ref
const imageTaskLoadingInstance = ref<any>() // loading const imageTaskLoadingInstance = ref<any>() // loading
const imageTaskLoading = ref<boolean>(false) // loading const imageTaskLoading = ref<boolean>(false) // loading
const pageNo = ref<number>(1) // page no const pageNo = ref<number>(1) // page no
const pageSize = ref<number>(20) // page size const pageSize = ref<number>(10) // page size
const pageTotal = ref<number>(0) // page size
/** 抽屉 - close */ /** 抽屉 - close */
const handlerDrawerClose = async () => { const handlerDrawerClose = async () => {
@ -49,16 +57,20 @@ const handlerDrawerOpen = async () => {
/** /**
* 获取 - image 列表 * 获取 - image 列表
*/ */
const getImageList = async () => { const getImageList = async (apply:boolean = false) => {
imageTaskLoading.value = true imageTaskLoading.value = true
try { try {
imageTaskLoadingInstance.value = ElLoading.service({ imageTaskLoadingInstance.value = ElLoading.service({
target: imageTaskRef.value, target: imageTaskRef.value,
text: '加载中...' text: '加载中...'
}) })
const { list } = await ImageApi.getImageList({pageNo: pageNo.value, pageSize: pageSize.value}) const { list, total } = await ImageApi.getImageList({pageNo: pageNo.value, pageSize: pageSize.value})
// imageList.value.push.apply(imageList.value, list) if (apply) {
imageList.value = [...imageList.value, ...list]
} else {
imageList.value = list imageList.value = list
}
pageTotal.value = total
} finally { } finally {
if (imageTaskLoadingInstance.value) { if (imageTaskLoadingInstance.value) {
imageTaskLoadingInstance.value.close(); imageTaskLoadingInstance.value.close();
@ -118,16 +130,10 @@ const downloadImage = async (imageUrl) => {
} }
} }
const handleTabsScroll = async () => { // page change
// todo top const handlerPageChange = async (page) => {
// if (imageTaskRef.value) { pageNo.value = page
// const { scrollTop, scrollHeight, clientHeight } = imageTaskRef.value; await getImageList(false)
// if (scrollTop + clientHeight >= scrollHeight - 20 && !imageTaskLoading.value) {
// console.log('')
// pageNo.value = pageNo.value + 1
// await getImageList();
// }
// }
} }
/** 暴露组件方法 */ /** 暴露组件方法 */
@ -139,7 +145,7 @@ onMounted(async () => {
await getImageList() await getImageList()
// image // image
imageListInterval.value = setInterval(async () => { imageListInterval.value = setInterval(async () => {
await getImageList() await getImageList(false)
}, 1000 * 20) }, 1000 * 20)
}) })
@ -168,7 +174,7 @@ onUnmounted(async () => {
height: 100%; height: 100%;
overflow: auto; overflow: auto;
padding: 20px; padding: 20px;
padding-bottom: 100px; padding-bottom: 140px;
box-sizing: border-box; /* 确保内边距不会增加高度 */ box-sizing: border-box; /* 确保内边距不会增加高度 */
>div { >div {
@ -179,6 +185,21 @@ onUnmounted(async () => {
//margin-bottom: 100px; //margin-bottom: 100px;
} }
} }
.task-image-pagination {
position: absolute;
bottom: 60px;
height: 50px;
line-height: 90px;
width: 100%;
z-index: 999;
background-color: #ffffff;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
</style> </style>
<style scoped lang="scss"> <style scoped lang="scss">