公告列表采用分页组件

This commit is contained in:
WindowBird 2025-08-26 09:25:40 +08:00
parent 5e09db3d16
commit de2ac5d37c
3 changed files with 91 additions and 119 deletions

View File

@ -65,71 +65,71 @@ export default {
mode: {
type: String,
default: 'loadMore',
validator: value => ['loadMore', 'pager'].includes(value)
validator: value => ['loadMore', 'pager'].includes(value),
},
//
list: {
type: Array,
default: () => []
default: () => [],
},
//
total: {
type: Number,
default: 0
default: 0,
},
//
currentPage: {
type: Number,
default: 1
default: 1,
},
//
pageSize: {
type: Number,
default: 10
default: 10,
},
//
loading: {
type: Boolean,
default: false
default: false,
},
//
noMore: {
type: Boolean,
default: false
default: false,
},
//
loadingText: {
type: String,
default: '正在加载...'
default: '正在加载...',
},
noMoreText: {
type: String,
default: '没有更多数据了'
default: '没有更多数据了',
},
emptyText: {
type: String,
default: '暂无数据'
default: '暂无数据',
},
emptyIcon: {
type: String,
default: '📋'
default: '📋',
},
//
visiblePageCount: {
type: Number,
default: 5
}
default: 5,
},
},
computed: {
@ -155,7 +155,7 @@ export default {
}
return pages
}
},
},
methods: {
@ -171,8 +171,8 @@ export default {
//
reset() {
this.$emit('reset')
}
}
},
},
}
</script>
@ -302,7 +302,11 @@ export default {
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>

View File

@ -4,61 +4,33 @@
<uni-card :extra="item.createTime" :title="item.title" @click="detail(item)"></uni-card>
</view>
<!-- 加载更多状态 -->
<view v-if="noData && list.length > 0" class="load-more">
<text class="no-more-text">没有更多数据了</text>
</view>
<!-- 分页组件 -->
<pagination
:current-page="pagination.currentPage"
:list="list"
:loading="loading"
:mode="'loadMore'"
:no-more="noMore"
:page-size="pagination.pageSize"
:total="pagination.total"
@page-change="handlePageChange"
/>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { onMounted } from 'vue'
import { getArticleList } from '@/api/article/article.js'
import { onUnload, onReachBottom } from '@dcloudio/uni-app'
import { onReachBottom } from '@dcloudio/uni-app'
import { usePagination } from '@/composables/usePagination.js'
const list = ref([])
const noData = ref(false)
const loading = ref(false)
//data
const queryParams = {
pageNum: 1,
pageSize: 6,
}
//
const getList = async () => {
if (loading.value) return
try {
loading.value = true
let res = await getArticleList(queryParams)
// res.data
const newData = res?.rows || []
//
if (queryParams.pageNum === 1) {
list.value = newData
} else {
list.value = [...list.value, ...newData]
}
if (queryParams.pageNum * queryParams.pageSize >= res.total) {
noData.value = true
}
console.log('订单列表:', list.value)
} catch (error) {
console.error('获取订单列表失败:', error)
uni.showToast({
title: '获取订单列表失败',
icon: 'none',
// 使
const { list, loading, noMore, pagination, getList, loadMore } = usePagination({
fetchData: getArticleList,
defaultParams: {},
mode: 'loadMore',
pageSize: 9,
})
} finally {
loading.value = false
}
}
const detail = item => {
uni.navigateTo({
@ -71,18 +43,15 @@ onMounted(() => {
getList()
})
onUnload(() => {
//
list.value = []
noData.value = false
loading.value = false
//
onReachBottom(() => {
loadMore()
})
onReachBottom(() => {
if (noData.value || loading.value) return
queryParams.pageNum++
getList()
})
//
const handlePageChange = page => {
console.log('页码变化:', page)
}
</script>
<style lang="scss" scoped>

View File

@ -73,7 +73,6 @@ import { onMounted } from 'vue'
import { onReachBottom } from '@dcloudio/uni-app'
import { usePagination } from '@/composables/usePagination.js'
import { getMyOrder } from '@/api/order/myOrder.js'
import Pagination from '@/components/pagination/pagination.vue'
// 使
const { list, loading, noMore, pagination, getList, loadMore } = usePagination({