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.

202 lines
4.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <!-- 新书推荐 -->
  3. <div class="content-main new-main">
  4. <div class="swiper-container">
  5. <div class="swiper-wrapper new-book-list">
  6. <div v-for="(item,index) in rankingList" :key="index" class="swiper-slide">
  7. <div class="book-list-item">
  8. <div class="book-img">
  9. <img :src="item.cover" :onerror="defaultImg">
  10. </div>
  11. <div class="book-info">
  12. <h4 class="title-item">{{ item.nbName }}</h4>
  13. <p>作者{{ item.nbAuthor }}</p>
  14. <p>出版社{{ item.nbPublisher }}</p>
  15. <p>出版年份{{ item.nbPublisherdate }}</p>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="icon iconfont prev-btn">
  21. <svg class="icon svg-icon" aria-hidden="true">
  22. <use xlink:href="#icon-zuohua" />
  23. </svg>
  24. </div>
  25. <div class="icon iconfont next-btn">
  26. <svg class="icon svg-icon" aria-hidden="true">
  27. <use xlink:href="#icon-youhua" />
  28. </svg>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import { Swiper } from 'vue-awesome-swiper'
  35. import 'swiper/swiper-bundle.css'
  36. import { FetchNewBookRecommend, FetchCoverByISBN } from '@/api/inquiryMachine'
  37. export default {
  38. name: 'NewBookRecommend',
  39. data() {
  40. return {
  41. defaultImg: 'this.src="' + require('@/assets/images/default-img.png') + '"',
  42. coverUrl: null,
  43. rankingList: []
  44. }
  45. },
  46. created() {
  47. this.getBookList()
  48. },
  49. mounted() {
  50. },
  51. methods: {
  52. initSwiper() {
  53. this.$nextTick(() => {
  54. new Swiper('.swiper-container', {
  55. touchEventsTarget: '.swiper-container',
  56. slidesPerView: 5,
  57. spaceBetween: 20,
  58. centeredSlides: true,
  59. observer: true,
  60. loop: true,
  61. centeredSlidesBounds: true,
  62. watchSlidesVisibility: true,
  63. navigation: {
  64. nextEl: '.next-btn',
  65. prevEl: '.prev-btn'
  66. }
  67. })
  68. })
  69. },
  70. getBookList() {
  71. FetchNewBookRecommend().then(res => {
  72. console.log(res, 'res')
  73. let data = []
  74. data = res
  75. data.forEach(item => {
  76. this.getCoverByISBN(item.isbn.replace(/\-/g, ''), item)
  77. })
  78. }).catch(() => {
  79. this.$message.error('接口错误')
  80. })
  81. },
  82. getCoverByISBN(isbn, item) {
  83. const params = {
  84. isbn: isbn
  85. }
  86. FetchCoverByISBN(params).then((res) => {
  87. item.cover = window.URL.createObjectURL(res)
  88. this.rankingList.push(item)
  89. this.initSwiper()
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. @import "~@/assets/styles/index.scss";
  97. .new-main{
  98. position: relative;
  99. padding: 0 50px;
  100. }
  101. .new-book-list{
  102. color: #333;
  103. .book-list-item{
  104. width: 100%;
  105. box-shadow: 0px 0px 20px 1px #D2D2D2;
  106. border-radius: 2px 2px 2px 2px;
  107. }
  108. .book-img{
  109. height: 6.575rem;
  110. display: flex;
  111. align-items: center;
  112. overflow: hidden;
  113. img{
  114. display: block;
  115. width: 100%;
  116. // height: 100%;
  117. }
  118. }
  119. .book-info{
  120. padding: 10px 20px;
  121. h4{
  122. font-weight: normal;
  123. margin-bottom: 20px;
  124. }
  125. p{
  126. margin-bottom: 10px;
  127. }
  128. }
  129. }
  130. .prev-btn,
  131. .next-btn{
  132. position: absolute;
  133. bottom: 60px;
  134. font-size: 60px;
  135. color: #71C09E;
  136. z-index: 999;
  137. }
  138. .prev-btn{
  139. left: 100px;
  140. }
  141. .next-btn{
  142. right: 100px;
  143. }
  144. .swiper-container {
  145. width: 100%;
  146. height: 100%;
  147. overflow: hidden;
  148. }
  149. .swiper-slide {
  150. display: -webkit-box;
  151. display: -ms-flexbox;
  152. display: -webkit-flex;
  153. display: flex;
  154. -webkit-box-pack: center;
  155. -ms-flex-pack: center;
  156. -webkit-justify-content: center;
  157. justify-content: center;
  158. -webkit-box-align: center;
  159. -ms-flex-align: center;
  160. -webkit-align-items: center;
  161. align-items: center;
  162. transition: 300ms;
  163. transform: scale(0.84);
  164. .book-info{
  165. line-height: 20px;
  166. font-size: 16px;
  167. h4{
  168. font-size: 20px;
  169. }
  170. }
  171. }
  172. .swiper-slide.swiper-slide-prev,
  173. .swiper-slide.swiper-slide-next {
  174. font-size: 28px;
  175. transform: scale(0.9);
  176. .book-info{
  177. line-height: 28px;
  178. font-size: 22px;
  179. h4{
  180. font-size: 28px;
  181. }
  182. }
  183. }
  184. .swiper-slide-active,.swiper-slide-duplicate-active {
  185. transform: scaleX(1);
  186. .book-info{
  187. line-height: 40px;
  188. font-size: 28px;
  189. h4{
  190. font-size: 40px;
  191. }
  192. }
  193. }
  194. </style>