图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.1 KiB

2 weeks ago
  1. <template>
  2. <view class="container">
  3. <!-- 图书列表 -->
  4. <view class="list-box">
  5. <book-list-item
  6. v-for="(item, index) in bookList"
  7. :key="index"
  8. :data="item"
  9. :ranking="index + 1"
  10. @click="goToDetail(item)"
  11. />
  12. </view>
  13. <!-- 加载提示 -->
  14. <view class="load-tip" v-if="loading">加载中...</view>
  15. <view class="load-tip" v-if="noMore">没有更多了</view>
  16. </view>
  17. </template>
  18. <script>
  19. import bookListItem from "@/components/book-list-item/book-list-item.vue";
  20. export default {
  21. components: {
  22. bookListItem
  23. },
  24. data() {
  25. return {
  26. bookList: [], // 图书列表
  27. pageNum: 1, // 当前页码
  28. pageSize: 10, // 每页数量
  29. loading: false, // 加载状态
  30. noMore: false // 是否到底
  31. };
  32. },
  33. onLoad() {
  34. this.getList();
  35. },
  36. // 下拉刷新
  37. onPullDownRefresh() {
  38. this.refresh();
  39. },
  40. // 上拉加载
  41. onReachBottom() {
  42. if (!this.loading && !this.noMore) {
  43. this.pageNum++;
  44. this.getList();
  45. }
  46. },
  47. methods: {
  48. // 刷新
  49. refresh() {
  50. this.pageNum = 1;
  51. this.bookList = [];
  52. this.noMore = false;
  53. this.getList();
  54. },
  55. // 获取列表
  56. getList() {
  57. this.loading = true;
  58. // 模拟请求后端接口
  59. setTimeout(() => {
  60. // 模拟数据
  61. const mockData = [
  62. {
  63. imgCover: "https://qiniu.aiyxlib.com/1606124577077",
  64. title: "名侦探柯南",
  65. nickname: "青山刚昌",
  66. publish: "长春出版社"
  67. },
  68. {
  69. imgCover: "https://qiniu.aiyxlib.com/1606124577077",
  70. title: "三体",
  71. nickname: "刘慈欣",
  72. publish: "重庆出版社"
  73. },
  74. {
  75. imgCover: "https://qiniu.aiyxlib.com/1606124577077",
  76. title: "盗墓笔记",
  77. nickname: "南派三叔",
  78. publish: "中国友谊出版公司"
  79. },
  80. {
  81. imgCover: "https://qiniu.aiyxlib.com/1606124577077",
  82. title: "斗罗大陆",
  83. nickname: "唐家三少",
  84. publish: "太白文艺出版社"
  85. },
  86. {
  87. imgCover: "https://qiniu.aiyxlib.com/1606124577077",
  88. title: "斗破苍穹",
  89. nickname: "天蚕土豆",
  90. publish: "湖北少年儿童出版社"
  91. }
  92. ];
  93. let newList = [];
  94. if (this.pageNum === 1) {
  95. newList = mockData;
  96. } else {
  97. // 第2页模拟无数据
  98. this.noMore = true;
  99. }
  100. this.bookList = [...this.bookList, ...newList];
  101. this.loading = false;
  102. uni.stopPullDownRefresh();
  103. }, 800);
  104. },
  105. // 跳详情
  106. goToDetail(item) {
  107. uni.navigateTo({
  108. url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn
  109. });
  110. }
  111. }
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. .container {
  116. padding: 10px;
  117. background-color: #f5f5f5;
  118. min-height: 100vh;
  119. }
  120. .list-box {
  121. display: flex;
  122. flex-direction: column;
  123. gap: 8px;
  124. }
  125. .load-tip {
  126. text-align: center;
  127. padding: 15px;
  128. font-size: 14px;
  129. color: #999;
  130. }
  131. </style>