公告列表分页加载
This commit is contained in:
parent
5038bde45e
commit
6050144779
|
|
@ -1,40 +1,87 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view v-for="item in announcementList" :key="item.id" class="item">
|
<view v-for="item in list" :key="item.id" class="item">
|
||||||
<uni-card :extra="item.createTime" :title="item.title" @click="detail(item)"></uni-card>
|
<uni-card :extra="item.createTime" :title="item.title" @click="detail(item)"></uni-card>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 加载更多状态 -->
|
||||||
|
<view v-if="noData && list.length > 0" class="load-more">
|
||||||
|
<text class="no-more-text">没有更多数据了</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { getArticleList } from '@/api/article/article.js'
|
import { getArticleList } from '@/api/article/article.js'
|
||||||
|
import { onUnload, onReachBottom } from '@dcloudio/uni-app'
|
||||||
|
|
||||||
const announcementList = ref([])
|
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
|
||||||
|
|
||||||
// 获取公告列表
|
|
||||||
const fetchAnnouncementList = async () => {
|
|
||||||
try {
|
try {
|
||||||
const res = await getArticleList({
|
loading.value = true
|
||||||
pageNum: '1',
|
let res = await getArticleList(queryParams)
|
||||||
pageSize: '10',
|
|
||||||
})
|
// 确保 res.data 存在且是数组
|
||||||
console.log('文章列表:', res.rows)
|
const newData = res?.rows || []
|
||||||
announcementList.value = 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) {
|
} catch (error) {
|
||||||
console.error('获取公告列表失败:', error)
|
console.error('获取订单列表失败:', error)
|
||||||
|
uni.showToast({
|
||||||
|
title: '获取订单列表失败',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const detail = (item) => {
|
const detail = item => {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/announcementList/announcementDetail?id=${item.id}&title=${encodeURIComponent(item.title)}&content=${encodeURIComponent(item.content)}&createTime=${encodeURIComponent(item.createTime)}`
|
url: `/pages/announcementList/announcementDetail?id=${item.id}&title=${encodeURIComponent(item.title)}&content=${encodeURIComponent(item.content)}&createTime=${encodeURIComponent(item.createTime)}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载时获取数据
|
// 页面加载时获取数据
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchAnnouncementList()
|
getList()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnload(() => {
|
||||||
|
// 清理数据
|
||||||
|
list.value = []
|
||||||
|
noData.value = false
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if (noData.value || loading.value) return
|
||||||
|
queryParams.pageNum++
|
||||||
|
getList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -53,4 +100,14 @@ onMounted(() => {
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
.no-more-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -494,7 +494,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-input {
|
.field-input {
|
||||||
//border: 2rpx solid #d81313;
|
//border: 2rpx solid #d81313;
|
||||||
flex: 3;
|
flex: 3;
|
||||||
height: 80rpx;
|
height: 80rpx;
|
||||||
padding: 0 20rpx;
|
padding: 0 20rpx;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user