HomeLease/pages/announcementList/announcementList.vue

90 lines
2.0 KiB
Vue
Raw Normal View History

<template>
<view class="container">
2025-08-25 17:56:17 +08:00
<view v-for="item in list" :key="item.id" class="item">
<uni-card :extra="item.createTime" :title="item.title" @click="detail(item)"></uni-card>
</view>
2025-08-25 17:56:17 +08:00
2025-08-26 09:25:40 +08:00
<!-- 分页组件 -->
<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>
2025-08-26 09:25:40 +08:00
import { onMounted } from 'vue'
import { getArticleList } from '@/api/article/article.js'
2025-08-26 09:25:40 +08:00
import { onReachBottom } from '@dcloudio/uni-app'
import { usePagination } from '@/composables/usePagination.js'
2025-08-26 09:38:47 +08:00
import Pagination from '@/components/pagination/pagination.vue'
2025-08-26 09:25:40 +08:00
// 使用分页组合式函数
const { list, loading, noMore, pagination, getList, loadMore } = usePagination({
fetchData: getArticleList,
defaultParams: {},
mode: 'loadMore',
pageSize: 15,
2025-08-26 09:25:40 +08:00
})
2025-08-25 17:56:17 +08:00
const detail = item => {
uni.navigateTo({
url: `/pages/announcementList/announcementDetail?id=${item.id}&title=${encodeURIComponent(item.title)}&content=${encodeURIComponent(item.content)}&createTime=${encodeURIComponent(item.createTime)}`,
})
}
// 页面加载时获取数据
onMounted(() => {
2025-08-25 17:56:17 +08:00
getList()
})
2025-08-26 09:25:40 +08:00
// 上拉加载更多
2025-08-25 17:56:17 +08:00
onReachBottom(() => {
console.log('触发上拉加载更多,当前状态:', {
loading: loading.value,
noMore: noMore.value,
2025-08-26 09:38:47 +08:00
listLength: list.value.length,
total: pagination.value.total,
2025-08-26 09:38:47 +08:00
})
2025-08-26 09:25:40 +08:00
loadMore()
})
2025-08-26 09:25:40 +08:00
// 处理页码变化
const handlePageChange = page => {
console.log('页码变化:', page)
}
</script>
<style lang="scss" scoped>
.container {
overflow: hidden;
padding: 20rpx;
}
.item {
margin-bottom: 20rpx;
}
.uni-body {
font-size: 28rpx;
line-height: 1.6;
color: #666;
}
2025-08-25 17:56:17 +08:00
.load-more {
margin-top: 20rpx;
text-align: center;
.no-more-text {
font-size: 24rpx;
color: #999;
}
}
</style>