book-cover.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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="header-right"></view>
  10. </view>
  11. <!-- 书籍封面 -->
  12. <view class="cover-section">
  13. <image class="book-cover-image" :src="bookInfo.image" mode="aspectFit" :lazy-load="true"></image>
  14. </view>
  15. <!-- 书籍信息 -->
  16. <view class="book-info-section">
  17. <text class="book-title">{{ bookInfo.title }}</text>
  18. <text class="book-author">{{ bookInfo.author }}</text>
  19. </view>
  20. <!-- 开始阅读按钮 -->
  21. <view class="start-reading-section">
  22. <button class="start-reading-btn" @click="startReading">
  23. <text class="btn-text">左滑开始阅读</text>
  24. </button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. bookInfo: {
  33. id: 1,
  34. title: '西游记',
  35. author: '(明) 吴承恩',
  36. image: 'https://picsum.photos/seed/xiyouji/400/600'
  37. }
  38. }
  39. },
  40. onLoad(options) {
  41. // 从路由参数获取书籍信息
  42. if (options.bookId) {
  43. this.bookInfo.id = parseInt(options.bookId)
  44. }
  45. if (options.title) {
  46. this.bookInfo.title = decodeURIComponent(options.title)
  47. }
  48. if (options.image) {
  49. this.bookInfo.image = decodeURIComponent(options.image)
  50. }
  51. if (options.author) {
  52. this.bookInfo.author = decodeURIComponent(options.author)
  53. }
  54. },
  55. methods: {
  56. goBack() {
  57. uni.navigateBack({
  58. delta: 1
  59. })
  60. },
  61. startReading() {
  62. // 开始阅读,跳转到阅读页面
  63. uni.showToast({
  64. title: '开始阅读',
  65. icon: 'success'
  66. })
  67. // 这里可以跳转到阅读页面
  68. // uni.navigateTo({
  69. // url: `/pages/reader/reader?bookId=${this.bookInfo.id}&title=${encodeURIComponent(this.bookInfo.title)}`
  70. // })
  71. // 或者直接开始阅读第一页
  72. setTimeout(() => {
  73. uni.navigateTo({
  74. url: `/pages/reader/reader?bookId=${this.bookInfo.id}&title=${encodeURIComponent(this.bookInfo.title)}&image=${encodeURIComponent(this.bookInfo.image)}&author=${encodeURIComponent(this.bookInfo.author)}`
  75. })
  76. }, 500)
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. .container {
  83. width: 100%;
  84. height: 100vh;
  85. background-color: #FFFFFF;
  86. display: flex;
  87. flex-direction: column;
  88. align-items: center;
  89. justify-content: space-between;
  90. padding: 40rpx 30rpx;
  91. padding-top: calc(30px + 40rpx);
  92. box-sizing: border-box;
  93. box-sizing: border-box;
  94. }
  95. .header {
  96. width: 100%;
  97. display: flex;
  98. align-items: center;
  99. justify-content: space-between;
  100. padding: 20rpx 0;
  101. position: relative;
  102. }
  103. .back-btn {
  104. width: 60rpx;
  105. height: 60rpx;
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. z-index: 10;
  110. cursor: pointer;
  111. -webkit-tap-highlight-color: transparent;
  112. }
  113. .back-icon {
  114. font-size: 40rpx;
  115. color: #333333;
  116. font-weight: bold;
  117. }
  118. .header-title {
  119. position: absolute;
  120. left: 50%;
  121. transform: translateX(-50%);
  122. font-size: 36rpx;
  123. font-weight: bold;
  124. color: #333333;
  125. }
  126. .header-right {
  127. width: 60rpx;
  128. }
  129. .cover-section {
  130. flex: 1;
  131. display: flex;
  132. align-items: center;
  133. justify-content: center;
  134. width: 100%;
  135. padding: 40rpx 0;
  136. }
  137. .book-cover-image {
  138. width: 500rpx;
  139. height: 700rpx;
  140. border-radius: 8rpx;
  141. box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.2);
  142. background-color: #F5F5F5;
  143. }
  144. .book-info-section {
  145. display: flex;
  146. flex-direction: column;
  147. align-items: center;
  148. margin-bottom: 60rpx;
  149. }
  150. .book-title {
  151. font-size: 44rpx;
  152. font-weight: bold;
  153. color: #333333;
  154. margin-bottom: 20rpx;
  155. text-align: center;
  156. }
  157. .book-author {
  158. font-size: 28rpx;
  159. color: #666666;
  160. text-align: center;
  161. }
  162. .start-reading-section {
  163. width: 100%;
  164. padding-bottom: env(safe-area-inset-bottom);
  165. }
  166. .start-reading-btn {
  167. width: 100%;
  168. height: 88rpx;
  169. background-color: #E0E0E0;
  170. color: #333333;
  171. font-size: 32rpx;
  172. border: none;
  173. border-radius: 44rpx;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. .start-reading-btn::after {
  179. border: none;
  180. }
  181. .btn-text {
  182. color: #333333;
  183. }
  184. </style>