图书馆小程序
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.

245 lines
7.8 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
  1. <template>
  2. <view class="collection-page">
  3. <view class="tab-box">
  4. <view class="tab-item" :class="activeTab === 1 ? 'active' : ''" @click="switchTab(1)"> 图书 </view>
  5. <view class="tab-item" :class="activeTab === 2 ? 'active' : ''" @click="switchTab(2)"> 活动 </view>
  6. </view>
  7. <!-- 内容区域 -->
  8. <view class="content-box">
  9. <!-- 图书收藏 -->
  10. <view v-if="activeTab === 1" class="tab-content">
  11. <view class="empty" v-if="bookCollectList.length === 0">
  12. <uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons>
  13. <text style="margin-top: 20px;">暂无收藏的图书~</text>
  14. </view>
  15. <view class="recommendation-list" v-else>
  16. <view
  17. class="book-item"
  18. v-for="(item, index) in bookCollectList"
  19. @click="goToBookDetail(item)"
  20. :key="index"
  21. >
  22. <image class="book-cover" :src="item.cover"></image>
  23. <view class="book-title">{{ item.title }}</view>
  24. </view>
  25. </view>
  26. <uni-load-more status="loading" v-if="isLoading"></uni-load-more>
  27. <view class="no-more" v-if="noMore && bookCollectList.length > 0">
  28. 没有更多数据了
  29. </view>
  30. </view>
  31. <!-- 活动收藏 -->
  32. <view v-if="activeTab === 2" class="tab-content">
  33. <view class="empty" v-if="activityCollectList.length === 0">
  34. <uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons>
  35. <text style="margin-top: 20px;">暂无收藏的活动~</text>
  36. </view>
  37. <view class="activity-list" v-else>
  38. <view
  39. class="activity-item"
  40. v-for="(item, index) in activityCollectList"
  41. @click="toActivityDetail(item)"
  42. :key="index"
  43. >
  44. <image class="activity-img" :src="item.imgUrl"></image>
  45. <view class="activity-info">
  46. <view class="activity-info-left">
  47. <text class="title">{{ item.title }}</text>
  48. <view class="time">
  49. <uni-icons class="time-icon" type="time" size="15"></uni-icons>
  50. <text>{{ item.time }}</text>
  51. </view>
  52. </view>
  53. <button
  54. class="activity-btn"
  55. :class="item.status === 0 ? 'disabled-btn' : ''"
  56. type="primary"
  57. :disabled="item.status === 0"
  58. >
  59. {{ item.status === 1 ? '立即参加' : '活动结束' }}
  60. </button>
  61. </view>
  62. </view>
  63. </view>
  64. <uni-load-more status="loading" v-if="isLoading"></uni-load-more>
  65. <view class="no-more" v-if="noMore && activityCollectList.length > 0">
  66. 没有更多数据了
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. activeTab: 1,
  77. isLoading: false,
  78. noMore: false,
  79. pageNum: 1,
  80. pageSize: 5,
  81. bookCollectList: [
  82. // { isbn: '9787544741110', title: '人工智能基础——数学知识', cover: 'https://qiniu.aiyxlib.com/1606124577077' },
  83. // { isbn: '9787539938032', title: 'Vim 8文本处理实战', cover: 'https://qiniu.aiyxlib.com/1606178450151' },
  84. // { isbn: '9787536692930', title: 'Oracle从入门到精通', cover: 'https://qiniu.aiyxlib.com/1606123986028' }
  85. ],
  86. allActivityList: [
  87. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '读书分享会', time: "2025-11-03 ~2025-11-09", status: 1 },
  88. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '作者见面会', time: "2025-11-03 ~2025-11-09", status: 0 },
  89. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '新书签售会', time: "2025-11-05 ~2025-11-10", status: 1 },
  90. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '文学讲座', time: "2025-11-06 ~2025-11-12", status: 1 },
  91. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '亲子阅读日', time: "2025-11-07 ~2025-11-13", status: 1 },
  92. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '书法展览', time: "2025-11-08 ~2025-11-14", status: 1 },
  93. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '诗词大会', time: "2025-11-09 ~2025-11-15", status: 0 },
  94. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '绘本故事', time: "2025-11-10 ~2025-11-16", status: 1 },
  95. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '读书打卡', time: "2025-11-11 ~2025-11-17", status: 1 },
  96. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '作家访谈', time: "2025-11-12 ~2025-11-18", status: 1 },
  97. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '文化沙龙', time: "2025-11-13 ~2025-11-19", status: 1 },
  98. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '手工创作', time: "2025-11-14 ~2025-11-20", status: 0 },
  99. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '经典诵读', time: "2025-11-15 ~2025-11-21", status: 1 },
  100. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '图书交换', time: "2025-11-16 ~2025-11-22", status: 1 },
  101. // { imgUrl: "https://qiniu.aiyxlib.com/1605060269830", title: '阅读竞赛', time: "2025-11-17 ~2025-11-23", status: 1 },
  102. ],
  103. activityCollectList: [],
  104. }
  105. },
  106. onLoad() {
  107. this.initActivityList() // 只初始化一次活动列表
  108. },
  109. onPullDownRefresh() {
  110. this.refreshData()
  111. },
  112. onReachBottom() {
  113. if (this.noMore || this.isLoading) return
  114. this.loadMore() // 这里只调用“追加”,不刷新
  115. },
  116. methods: {
  117. switchTab(tab) {
  118. this.activeTab = tab
  119. // 切Tab不重置活动列表,避免闪屏
  120. },
  121. // 初始化第一页(进入页面/下拉刷新用)
  122. initActivityList() {
  123. this.pageNum = 1
  124. this.noMore = false
  125. this.activityCollectList = this.allActivityList.slice(0, this.pageSize)
  126. this.noMore = this.allActivityList.length <= this.pageSize
  127. },
  128. refreshData() {
  129. this.isLoading = true
  130. setTimeout(() => {
  131. // 图书重置
  132. this.bookCollectList = [
  133. { isbn: '9787544741110', title: '人工智能基础——数学知识', cover: 'https://qiniu.aiyxlib.com/1606124577077' },
  134. { isbn: '9787539938032', title: 'Vim 8文本处理实战', cover: 'https://qiniu.aiyxlib.com/1606178450151' },
  135. { isbn: '9787536692930', title: 'Oracle从入门到精通', cover: 'https://qiniu.aiyxlib.com/1606123986028' }
  136. ]
  137. // 活动回到第一页
  138. this.initActivityList()
  139. this.isLoading = false
  140. uni.stopPullDownRefresh()
  141. }, 500)
  142. },
  143. // 上拉加载
  144. loadMore() {
  145. this.isLoading = true
  146. this.pageNum++
  147. setTimeout(() => {
  148. const start = (this.pageNum - 1) * this.pageSize
  149. const end = this.pageNum * this.pageSize
  150. const newArr = this.allActivityList.slice(start, end)
  151. if (newArr.length) {
  152. this.activityCollectList = [...this.activityCollectList, ...newArr]
  153. }
  154. this.noMore = this.allActivityList.length <= end
  155. this.isLoading = false
  156. }, 500)
  157. },
  158. goToBookDetail(item) {
  159. uni.navigateTo({ url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn })
  160. },
  161. toActivityDetail(item) {
  162. uni.navigateTo({ url: "/subpkg/pages/activity-detail/activity-detail?title=" + item.title })
  163. },
  164. },
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .collection-page {
  169. background-color: #f7f8fa;
  170. min-height: 100vh;
  171. }
  172. .tab-box {
  173. display: flex;
  174. background-color: #fff;
  175. margin-bottom: 10px;
  176. position: sticky;
  177. top: 0;
  178. z-index: 99;
  179. }
  180. .tab-item {
  181. flex: 1;
  182. text-align: center;
  183. padding: 10px 0;
  184. font-size: 15px;
  185. color: #333;
  186. position: relative;
  187. }
  188. .tab-item.active {
  189. color: #01a4fe;
  190. font-weight: bold;
  191. }
  192. .tab-item.active::after {
  193. content: '';
  194. position: absolute;
  195. width: 25px;
  196. height: 2px;
  197. background-color: #01a4fe;
  198. bottom: 0;
  199. left: 50%;
  200. transform: translateX(-50%);
  201. border-radius: 2px;
  202. }
  203. .content-box {
  204. padding: 0 10px;
  205. }
  206. .tab-content {
  207. padding-top: 10px;
  208. }
  209. .empty {
  210. text-align: center;
  211. padding: 60px 0;
  212. color: #999;
  213. font-size: 14px;
  214. }
  215. .no-more {
  216. text-align: center;
  217. padding: 20px 0;
  218. color: #999;
  219. font-size: 13px;
  220. }
  221. .recommendation-list{
  222. flex-wrap: wrap;
  223. .book-item {
  224. margin-bottom: 16px;
  225. }
  226. }
  227. </style>