index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="container">
  3. <page-title>公告列表</page-title>
  4. <view class="cards-list">
  5. <view class="card" v-for="(item,index) in announcementList" :key="index">
  6. <card-title :numerator="index + 1" :denominator="total"></card-title>
  7. <!-- 标题 -->
  8. <view class="card-item">
  9. <view class="card-item-announcement">{{item.title || "--"}}</view>
  10. </view>
  11. <!-- 发布时间 -->
  12. <view class="card-item">
  13. <view class="card-item-name">发布时间: {{item.publishDate || "--"}}</view>
  14. </view>
  15. <!-- 按钮 -->
  16. <view class="card-item">
  17. <view class="card-btn fat-btn" @click="goToPage(item.id)">查看详情</view>
  18. </view>
  19. </view>
  20. </view>
  21. <u-back-top :scroll-top="scrollTop"></u-back-top>
  22. </view>
  23. </template>
  24. <script setup>
  25. import {
  26. ref
  27. } from "vue"
  28. import {
  29. onLoad,
  30. onPullDownRefresh,
  31. onReachBottom,
  32. onPageScroll
  33. } from "@dcloudio/uni-app"
  34. import {
  35. getannouncementList,
  36. } from "@/api/home.js"
  37. let scrollTop = ref(0)
  38. let announcementList = ref([])
  39. let total = ref(0)
  40. let pageForm = {
  41. pageNo: 1,
  42. pageSize: 10,
  43. }
  44. // 触底加载flag
  45. let moreListFlag = true
  46. function getList() {
  47. getannouncementList(pageForm).then(res => {
  48. announcementList.value = announcementList.value.concat(res.data.list);
  49. total.value = res.data.totalCount;
  50. if (res.data.total == searchInfo.value.pageNo*searchInfo.value.pageSize-(10 - res.data.list.length)) moreListFlag = false;
  51. })
  52. }
  53. function goToPage(id) {
  54. uni.navigateTo({
  55. url: `/pages/announcement/index?id=${id}`
  56. })
  57. }
  58. onLoad(() => {
  59. getList()
  60. })
  61. onPageScroll((e) => {
  62. scrollTop.value = e.scrollTop
  63. })
  64. onPullDownRefresh(() => {
  65. pageForm.pageNo = 1;
  66. announcementList.value = [];
  67. moreListFlag = true;
  68. try {
  69. getList();
  70. } finally {
  71. uni.stopPullDownRefresh()
  72. }
  73. })
  74. onReachBottom(() => {
  75. if (!moreListFlag) {
  76. return uni.showToast({
  77. title: "已经到底了。",
  78. icon: "none",
  79. duration: 2000
  80. })
  81. }
  82. searchInfo.value.pageNo++;
  83. getList();
  84. })
  85. </script>
  86. <style lang="scss" scoped>
  87. </style>