new-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('new-internet-psychology')
  61. },
  62. {
  63. id: 2,
  64. title: '孝经 (中华经典诵读)',
  65. author: '孔子',
  66. desc: '以孔子与其弟子曾参之间问答的形式,将社会上各种阶层的人士,标示出其实践孝亲的法则与途径,阐述了「孝」的意义。',
  67. cover: getBookImage('new-xiaojing')
  68. },
  69. {
  70. id: 3,
  71. title: '自省',
  72. author: '约翰·班扬',
  73. desc: '讲述了敬虔之人和不敬虔之人截然相反的结局。本书就是他的细细品味,文风一如从前,朴实无华却又字字珠玑。',
  74. cover: getBookImage('new-self-reflection')
  75. },
  76. {
  77. id: 4,
  78. title: '人工智能的未来',
  79. author: '未知',
  80. desc: '探讨人工智能技术的最新发展和未来趋势,分析AI如何改变我们的生活和工作方式。',
  81. cover: getBookImage('new-ai')
  82. },
  83. {
  84. id: 5,
  85. title: '数字时代的阅读',
  86. author: '未知',
  87. desc: '分析数字阅读与传统阅读的差异,探讨如何在数字时代保持深度阅读的能力和习惯。',
  88. cover: getBookImage('new-digital-reading')
  89. },
  90. {
  91. id: 6,
  92. title: '量子物理入门',
  93. author: '未知',
  94. desc: '用通俗易懂的语言介绍量子物理的基本概念,帮助读者理解这个神秘而有趣的科学领域。',
  95. cover: getBookImage('new-quantum')
  96. },
  97. {
  98. id: 7,
  99. title: '全球气候变化',
  100. author: '未知',
  101. desc: '深入分析全球气候变化的成因、影响和应对措施,呼吁全社会关注环境保护。',
  102. cover: getBookImage('new-climate')
  103. },
  104. {
  105. id: 8,
  106. title: '现代艺术史',
  107. author: '未知',
  108. desc: '全面介绍从19世纪末到21世纪初的现代艺术发展历程,包括各种艺术流派和代表作品。',
  109. cover: getBookImage('new-art-history')
  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/blockchain${this.page}/200/300`
  163. },
  164. {
  165. id: 10,
  166. title: '生物多样性保护',
  167. author: '未知',
  168. desc: '探讨生物多样性保护的重要性和方法,呼吁人类共同保护地球上的生命多样性。',
  169. cover: `https://picsum.photos/seed/biodiversity${this.page}/200/300`
  170. },
  171. {
  172. id: 11,
  173. title: '太空探索新纪元',
  174. author: '未知',
  175. desc: '介绍最新的太空探索技术和计划,展望人类探索宇宙的美好未来。',
  176. cover: `https://picsum.photos/seed/space${this.page}/200/300`
  177. },
  178. {
  179. id: 12,
  180. title: '数字化转型指南',
  181. author: '未知',
  182. desc: '为企业提供数字化转型的实用指南,帮助企业在数字时代保持竞争力。',
  183. cover: `https://picsum.photos/seed/digital-transform${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>