hot-books.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">热门书籍</text>
  9. <view class="search-btn" @click="goToSearch">
  10. <text class="search-icon">🔍</text>
  11. </view>
  12. </view>
  13. <!-- 书籍列表 -->
  14. <scroll-view class="book-list-container" scroll-y @scrolltolower="loadMore" :lower-threshold="100">
  15. <view
  16. class="book-item"
  17. v-for="(book, index) in bookList"
  18. :key="book.id || index"
  19. @click="goToBookDetail(book)"
  20. >
  21. <image
  22. class="book-cover"
  23. :src="book.cover"
  24. mode="aspectFill"
  25. :lazy-load="true"
  26. @error="handleImageError(index)"
  27. ></image>
  28. <view class="book-info">
  29. <text class="book-title">{{ book.title }}</text>
  30. <text class="book-desc">{{ book.desc }}</text>
  31. <text class="book-author">{{ book.author }}</text>
  32. </view>
  33. </view>
  34. <!-- 加载更多提示 -->
  35. <view class="load-more" v-if="hasMore">
  36. <text class="load-more-text">加载中...</text>
  37. </view>
  38. <view class="load-more" v-else-if="bookList.length > 0">
  39. <text class="load-more-text">没有更多了</text>
  40. </view>
  41. </scroll-view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. // 生成书籍封面图片的函数
  48. const getBookImage = (seed) => {
  49. return `https://picsum.photos/seed/${seed}/200/300`;
  50. };
  51. return {
  52. hasMore: true,
  53. page: 1,
  54. bookList: [
  55. {
  56. id: 1,
  57. title: '互联网心理学',
  58. author: '雷雳',
  59. desc: '当连接万物的互联网遇见无处不在的心理学,我们需要用心理学的方式,重新思考互联网背后的人与社会。',
  60. cover: getBookImage('internet-psychology')
  61. },
  62. {
  63. id: 2,
  64. title: '孝经 (中华经典诵读)',
  65. author: '孔子',
  66. desc: '以孔子与其弟子曾参之间问答的形式,将社会上各种阶层的人士,标示出其实践孝亲的法则与途径,阐述了「孝」的意义。',
  67. cover: getBookImage('xiaojing')
  68. },
  69. {
  70. id: 3,
  71. title: '自省',
  72. author: '约翰·班扬',
  73. desc: '讲述了敬虔之人和不敬虔之人截然相反的结局。本书就是他的细细品味,文风一如从前,朴实无华却又字字珠玑。',
  74. cover: getBookImage('self-reflection')
  75. },
  76. {
  77. id: 4,
  78. title: '思维的艺术',
  79. author: '延斯·森特根',
  80. desc: '一本关于思维方式和哲学思考的经典之作,帮助读者提升逻辑思维和批判性思考能力。',
  81. cover: getBookImage('thinking-art')
  82. },
  83. {
  84. id: 5,
  85. title: '传习录:全译全注',
  86. author: '王阳明',
  87. desc: '王阳明心学的核心著作,记录了其与学生之间的对话,阐述了知行合一的哲学思想。',
  88. cover: getBookImage('chuanxilu')
  89. },
  90. {
  91. id: 6,
  92. title: '社会契约论',
  93. author: '让·雅克·卢梭',
  94. desc: '探讨了政治权力的合法性和人民主权的基本原则,是现代民主理论的重要基石。',
  95. cover: getBookImage('social-contract')
  96. },
  97. {
  98. id: 7,
  99. title: '没有烦恼的世界',
  100. author: '王觉仁',
  101. desc: '通过禅修和正念的实践,帮助读者摆脱内心的烦恼,获得内心的平静与智慧。',
  102. cover: getBookImage('no-worries')
  103. },
  104. {
  105. id: 8,
  106. title: '透过电影看文化',
  107. author: '陈红',
  108. desc: '从电影的角度分析不同文化的特点,探讨电影如何反映和影响社会文化的发展。',
  109. cover: getBookImage('film-culture')
  110. }
  111. ]
  112. }
  113. },
  114. onLoad() {
  115. // 页面加载时加载数据
  116. this.loadBookList();
  117. },
  118. methods: {
  119. goBack() {
  120. uni.navigateBack({
  121. delta: 1
  122. });
  123. },
  124. goToSearch() {
  125. uni.navigateTo({
  126. url: '/pages/search/search'
  127. });
  128. },
  129. goToBookDetail(book) {
  130. if (!book || !book.id) {
  131. uni.showToast({
  132. title: '书籍信息不完整',
  133. icon: 'none'
  134. })
  135. return
  136. }
  137. uni.navigateTo({
  138. url: `/pages/book-detail/book-detail?bookId=${book.id}`
  139. });
  140. },
  141. handleImageError(index) {
  142. // 图片加载失败时使用备用图片
  143. if (this.bookList[index]) {
  144. this.bookList[index].cover = `https://picsum.photos/seed/fallback${index}/200/300`;
  145. }
  146. },
  147. loadBookList() {
  148. // 加载热门书籍列表
  149. // 这里可以调用API获取数据
  150. },
  151. loadMore() {
  152. // 滚动到底部加载更多
  153. if (this.hasMore) {
  154. setTimeout(() => {
  155. // 模拟加载更多数据
  156. const moreBooks = [
  157. {
  158. id: 9,
  159. title: '车尔尼钢琴流畅练习曲',
  160. author: '高新颜',
  161. desc: '经典的钢琴练习曲集,适合中级钢琴学习者,帮助提升演奏技巧和流畅度。',
  162. cover: `https://picsum.photos/seed/czerny${this.page}/200/300`
  163. },
  164. {
  165. id: 10,
  166. title: '古典哲学的趣味',
  167. author: '朱利安·巴吉尼',
  168. desc: '用通俗易懂的方式介绍古典哲学的核心思想,让哲学变得生动有趣。',
  169. cover: `https://picsum.photos/seed/philosophy${this.page}/200/300`
  170. },
  171. {
  172. id: 11,
  173. title: '走向大洋',
  174. author: '未知',
  175. desc: '一部关于海洋探索和人类文明发展的历史著作,展现了人类对未知世界的探索精神。',
  176. cover: `https://picsum.photos/seed/ocean${this.page}/200/300`
  177. },
  178. {
  179. id: 12,
  180. title: '思维的艺术',
  181. author: '延斯·森特根',
  182. desc: '一本关于思维方式和哲学思考的经典之作,帮助读者提升逻辑思维和批判性思考能力。',
  183. cover: `https://picsum.photos/seed/thinking-art2${this.page}/200/300`
  184. }
  185. ];
  186. if (this.page < 3) {
  187. const newBooks = moreBooks.map((book, idx) => ({
  188. ...book,
  189. id: book.id + this.page * 10
  190. }));
  191. this.bookList = [...this.bookList, ...newBooks];
  192. this.page++;
  193. } else {
  194. this.hasMore = false;
  195. }
  196. }, 500);
  197. }
  198. }
  199. }
  200. }
  201. </script>
  202. <style scoped>
  203. .container {
  204. width: 100%;
  205. height: 100vh;
  206. background-color: #FFFFFF;
  207. display: flex;
  208. flex-direction: column;
  209. }
  210. /* 顶部导航栏 */
  211. .header {
  212. display: flex;
  213. align-items: center;
  214. justify-content: space-between;
  215. padding: 20rpx 30rpx;
  216. background-color: #FFFFFF;
  217. border-bottom: 1rpx solid #E5E5E5;
  218. }
  219. .back-btn {
  220. width: 60rpx;
  221. height: 60rpx;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. }
  226. .back-icon {
  227. font-size: 40rpx;
  228. color: #000000;
  229. font-weight: bold;
  230. }
  231. .header-title {
  232. font-size: 36rpx;
  233. font-weight: bold;
  234. color: #000000;
  235. position: absolute;
  236. left: 50%;
  237. transform: translateX(-50%);
  238. }
  239. .search-btn {
  240. width: 60rpx;
  241. height: 60rpx;
  242. display: flex;
  243. align-items: center;
  244. justify-content: center;
  245. }
  246. .search-icon {
  247. font-size: 36rpx;
  248. color: #000000;
  249. }
  250. /* 书籍列表容器 */
  251. .book-list-container {
  252. flex: 1;
  253. width: 100%;
  254. height: 0;
  255. overflow: hidden;
  256. background-color: #FFFFFF;
  257. }
  258. /* 书籍项 */
  259. .book-item {
  260. display: flex;
  261. padding: 30rpx;
  262. border-bottom: 1rpx solid #F0F0F0;
  263. }
  264. .book-item:last-child {
  265. border-bottom: none;
  266. }
  267. /* 书籍封面 */
  268. .book-cover {
  269. width: 160rpx;
  270. height: 220rpx;
  271. border-radius: 8rpx;
  272. margin-right: 24rpx;
  273. flex-shrink: 0;
  274. background-color: #F5F5F5;
  275. }
  276. /* 书籍信息 */
  277. .book-info {
  278. flex: 1;
  279. display: flex;
  280. flex-direction: column;
  281. justify-content: flex-start;
  282. min-width: 0;
  283. }
  284. .book-title {
  285. font-size: 32rpx;
  286. font-weight: bold;
  287. color: #000000;
  288. margin-bottom: 16rpx;
  289. line-height: 1.4;
  290. display: -webkit-box;
  291. -webkit-box-orient: vertical;
  292. -webkit-line-clamp: 2;
  293. overflow: hidden;
  294. text-overflow: ellipsis;
  295. }
  296. .book-desc {
  297. font-size: 28rpx;
  298. color: #666666;
  299. line-height: 1.6;
  300. margin-bottom: 20rpx;
  301. display: -webkit-box;
  302. -webkit-box-orient: vertical;
  303. -webkit-line-clamp: 3;
  304. overflow: hidden;
  305. text-overflow: ellipsis;
  306. }
  307. .book-author {
  308. font-size: 26rpx;
  309. color: #999999;
  310. margin-top: auto;
  311. }
  312. /* 加载更多 */
  313. .load-more {
  314. width: 100%;
  315. height: 80rpx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. margin-top: 20rpx;
  320. margin-bottom: 40rpx;
  321. }
  322. .load-more-text {
  323. font-size: 28rpx;
  324. color: #999999;
  325. }
  326. </style>