国产化查询机
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.

282 lines
7.5 KiB

7 months 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" @click="handleDetails(index)">
  7. <div class="book-list-item">
  8. <div class="book-img">
  9. <img :src="item.imgPath" :onerror="defaultImg">
  10. </div>
  11. <div class="book-info">
  12. <h4 class="title-item">{{ item.name }}</h4>
  13. <p>作者{{ item.author }}</p>
  14. <p>出版社{{ item.publisher }}</p>
  15. <p>出版年份{{ item.publisherdate }}</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. <BookDetails ref="detailDom" />
  32. </div>
  33. </template>
  34. <script>
  35. import { Swiper } from 'vue-awesome-swiper'
  36. import 'swiper/swiper-bundle.css'
  37. // import { FetchNewBookRecommend, FetchCoverByISBN, getBookDetailsByISBN } from '@/api/inquiryMachine'
  38. import { FetchNewBook, FetchMarcByISBN, getBookDetailsByISBN } from '@/api/inquiryMachine'
  39. import BookDetails from './module/bookDetails.vue'
  40. export default {
  41. name: 'NewBookRecommend',
  42. components: {
  43. BookDetails
  44. },
  45. data() {
  46. return {
  47. defaultImg: 'this.src="' + require('@/assets/images/default-img.png') + '"',
  48. coverUrl: null,
  49. rankingList: []
  50. }
  51. },
  52. created() {
  53. this.getNewBook()
  54. },
  55. mounted() {
  56. },
  57. methods: {
  58. initSwiper() {
  59. this.$nextTick(() => {
  60. new Swiper('.swiper-container', {
  61. touchEventsTarget: '.swiper-container',
  62. slidesPerView: 5,
  63. spaceBetween: 20,
  64. centeredSlides: true,
  65. observer: true,
  66. // loop: true,
  67. centeredSlidesBounds: true,
  68. watchSlidesVisibility: true,
  69. navigation: {
  70. nextEl: '.next-btn',
  71. prevEl: '.prev-btn'
  72. }
  73. // on: {
  74. // click: function() {
  75. // alert(this.clickedIndex)
  76. // }
  77. // }
  78. })
  79. })
  80. },
  81. getNewBook() {
  82. console.log('this.$route.query.libcode', this.$route.query.libcode)
  83. const params = {
  84. 'libcode': this.$route.query.libcode,
  85. 'size': 40
  86. }
  87. FetchNewBook(params).then(res => {
  88. // 图片地址格式 http://192.168.99.67:8080/downloadFile/qytsg/ae281b90-b100-4541-9379-3e104854652c.png
  89. // 图片地址格式 http://192.168.99.72:14000/api/fileRelevant/getImg?imgType=2&imgId=c964bcab-ec82-43f0-8653-04d930d7da4a
  90. const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  91. console.log('res.data', res)
  92. this.rankingList = res.map(item => {
  93. if (item.imgPath) {
  94. item.imgPath = linkSrc + '/api/fileRelevant/getImg?imgType=2&imgId=' + item.imgPath
  95. return Promise.resolve(item)
  96. } else {
  97. const params = {
  98. 'sIsbn': item.isbn
  99. }
  100. return FetchMarcByISBN(params).then(response => {
  101. const result = JSON.parse(response.data)[0]
  102. if (result.srcurl) {
  103. item.imgPath = result.srcurl
  104. return item
  105. } else if (result.img) {
  106. item.imgPath = 'data:image/png;base64,' + result.img
  107. return item
  108. } else {
  109. return null
  110. }
  111. })
  112. }
  113. })
  114. Promise.all(this.rankingList).then(results => {
  115. this.rankingList = results.filter(item => item !== null)
  116. this.initSwiper()
  117. })
  118. console.log('this.rankingList', this.rankingList)
  119. })
  120. },
  121. // getBookList() {
  122. // const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  123. // const params = {
  124. // libcode: this.libcode,
  125. // pageNo: 1,
  126. // pageSize: 10
  127. // }
  128. // FetchNewBookRecommend(params).then(res => {
  129. // console.log(res)
  130. // this.rankingList = res.newbookList.map((item, index) => {
  131. // if (item.nbImgPath) {
  132. // item.cover = linkSrc + '/downloadFile' + item.nbImgPath
  133. // } else {
  134. // item.cover = null
  135. // }
  136. // return item
  137. // })
  138. // this.initSwiper()
  139. // }).catch(() => {
  140. // this.$message.error('接口错误')
  141. // })
  142. // },
  143. // getCoverByISBN(isbn, item) {
  144. // const params = {
  145. // isbn: isbn
  146. // }
  147. // FetchCoverByISBN(params).then((res) => {
  148. // // item.cover = window.URL.createObjectURL(res)
  149. // item.cover = res
  150. // this.rankingList.push(item)
  151. // this.initSwiper()
  152. // })
  153. // },
  154. // 详情
  155. handleDetails(index) {
  156. const params = {
  157. isbn: this.rankingList[index].isbn.replace(/\-/g, '')
  158. }
  159. getBookDetailsByISBN(params).then(res => {
  160. const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  161. res.imgPath = linkSrc + '/api/fileRelevant/getImg?imgType=2&imgId=' + res.bookCover
  162. this.$refs.detailDom.bookData = res
  163. this.$refs.detailDom.dialogVisible = true
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss">
  170. @import "~@/assets/styles/index.scss";
  171. .new-main{
  172. position: relative;
  173. padding: 0 50px;
  174. }
  175. .new-book-list{
  176. color: #333;
  177. .book-list-item{
  178. width: 100%;
  179. box-shadow: 0px 0px 20px 1px #D2D2D2;
  180. border-radius: 2px 2px 2px 2px;
  181. }
  182. .book-img{
  183. height: 6.575rem;
  184. display: flex;
  185. align-items: center;
  186. overflow: hidden;
  187. img{
  188. display: block;
  189. width: 100%;
  190. // height: 100%;
  191. }
  192. }
  193. .book-info{
  194. padding: 10px 20px;
  195. h4{
  196. font-weight: normal;
  197. margin-bottom: 20px;
  198. }
  199. p{
  200. margin-bottom: 10px;
  201. }
  202. }
  203. }
  204. .icon{
  205. height: 1.1em;
  206. }
  207. .prev-btn,
  208. .next-btn{
  209. position: absolute;
  210. bottom: 60px;
  211. font-size: 60px;
  212. // color: #71C09E;
  213. z-index: 999;
  214. }
  215. .prev-btn{
  216. left: 100px;
  217. }
  218. .next-btn{
  219. right: 100px;
  220. }
  221. .swiper-container {
  222. width: 100%;
  223. height: 100%;
  224. overflow: hidden;
  225. }
  226. .swiper-slide {
  227. display: -webkit-box;
  228. display: -ms-flexbox;
  229. display: -webkit-flex;
  230. display: flex;
  231. -webkit-box-pack: center;
  232. -ms-flex-pack: center;
  233. -webkit-justify-content: center;
  234. justify-content: center;
  235. -webkit-box-align: center;
  236. -ms-flex-align: center;
  237. -webkit-align-items: center;
  238. align-items: center;
  239. transition: 300ms;
  240. transform: scale(0.84);
  241. .book-info{
  242. line-height: 20px;
  243. font-size: 16px;
  244. h4{
  245. font-size: 20px;
  246. }
  247. }
  248. }
  249. .swiper-slide.swiper-slide-prev,
  250. .swiper-slide.swiper-slide-next {
  251. font-size: 28px;
  252. transform: scale(0.9);
  253. .book-info{
  254. line-height: 28px;
  255. font-size: 22px;
  256. h4{
  257. font-size: 28px;
  258. }
  259. }
  260. }
  261. .swiper-slide-active,.swiper-slide-duplicate-active {
  262. transform: scaleX(1);
  263. .book-info{
  264. line-height: 40px;
  265. font-size: 28px;
  266. h4{
  267. font-size: 40px;
  268. }
  269. }
  270. }
  271. </style>