大数据展示系统-前端
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.

191 lines
5.8 KiB

2 years ago
2 years ago
  1. <template>
  2. <div id="bookshelf">
  3. <div class="bookshelf-header">
  4. <h2>RFID智慧书架</h2>
  5. <span class="shelf-num">{{ shelfName }}</span>
  6. </div>
  7. <!-- 本架分类 -->
  8. <div class="book-category">
  9. <p>{{ leftShelfMsg }}</p>
  10. <p>{{ rightShelfMsg }}</p>
  11. </div>
  12. <!-- 智慧书架导航 -->
  13. <ul class="book-nav">
  14. <li @click="toSearch">
  15. <img src="~@/assets/images/home/nav1.png" />
  16. <p>图书检索</p>
  17. </li>
  18. <li @click="toPath('/HotBook?bookType=hot')">
  19. <img src="~@/assets/images/home/nav2.png" />
  20. <p>热门图书</p>
  21. </li>
  22. <li @click="toPath('/AuthorRecommend')">
  23. <img src="~@/assets/images/home/nav3.png" />
  24. <p>作者推荐</p>
  25. </li>
  26. <li @click="toPath('/DigitalResource')">
  27. <img src="~@/assets/images/home/nav4.png" />
  28. <p>数字资源</p>
  29. </li>
  30. <li @click="toRoomNav">
  31. <img src="~@/assets/images/home/nav5.png" />
  32. <p>场馆导航</p>
  33. </li>
  34. </ul>
  35. <!-- 本架图书 -->
  36. <div class="book-rack">
  37. <div class="list-top">
  38. <div class="list-top-title">
  39. <svg class="icon" aria-hidden="true">
  40. <use xlink:href="#icon-benjiatushu" />
  41. </svg>
  42. <p>本架图书</p>
  43. </div>
  44. <span class="more" @click="toPath('/CurrentRackBook')">更多<i class="iconfont icon-zuo rotate"></i></span>
  45. </div>
  46. <div class="rack-list">
  47. <BookListItem :list-data.sync="rackList" />
  48. <div class="other-list">
  49. <BookListItem :list-data.sync="otherList" :is-other-book="true" />
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 新书推荐 -->
  54. <div class="book-rack new-recommend">
  55. <div class="list-top">
  56. <div class="list-top-title">
  57. <p>新书推荐</p>
  58. </div>
  59. <span class="more" @click="toPath('/NewBook?bookType=new')">更多<i class="iconfont icon-zuo rotate"></i></span>
  60. </div>
  61. <BookListItem :list-data.sync="newList" :is-new-book="true" />
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import BookListItem from '@/views/module/homeListItem.vue'
  67. import { FetchNewBookRecommend, FetchCoverByISBN, initSmartBookshelf } from '@/api/bookshelf'
  68. export default {
  69. name: 'Home',
  70. components: {
  71. BookListItem
  72. },
  73. data() {
  74. return {
  75. shelfName: '1',
  76. leftShelfMsg: '',
  77. rightShelfMsg: '',
  78. // leftShelfNo: '1201-03-001-A-01',
  79. // rightShelfNo: '1201-03-001-B-01',
  80. leftShelfNo: '',
  81. rightShelfNo: '',
  82. rackList: [], // 本架图书排行第一
  83. otherList: [], // 本架图书排行后两本
  84. newList: [] // 新书推荐
  85. }
  86. },
  87. created() {
  88. this.getNewBookList()
  89. // 本架图书 + 书架借本信息
  90. this.initSmartBookshelf()
  91. },
  92. mounted() {
  93. },
  94. methods: {
  95. toSearch() {
  96. window.location.href = 'https://opac.whlib.org.cn/opac'
  97. },
  98. toPath(path) {
  99. if (path === '/CurrentRackBook') {
  100. const query = { leftShelfNo: this.leftShelfNo, rightShelfNo: this.rightShelfNo }
  101. this.$router.push({ path: path, query: query })
  102. } else {
  103. this.$router.push(path)
  104. }
  105. },
  106. toRoomNav() {
  107. const linkSrc = process.env.VUE_APP_BASE_API
  108. window.location.href = linkSrc + '/anchoring/initVenueNavigation.do?libcode=' + this.libcode
  109. },
  110. // 首页 - 新书推荐
  111. getNewBookList() {
  112. const params = {
  113. libcode: this.libcode,
  114. pageNo: 1,
  115. pageSize: 4
  116. }
  117. FetchNewBookRecommend(params).then(res => {
  118. let data = []
  119. data = res.newbookList
  120. data.forEach(item => {
  121. this.getCoverByISBN(item.isbn.replace(/\-/g, ''), item)
  122. })
  123. }).catch(() => {
  124. this.$message.error('接口错误')
  125. })
  126. },
  127. // 根据isbn获取图书封面
  128. getCoverByISBN(isbn, item) {
  129. const params = {
  130. isbn: isbn
  131. }
  132. console.log(params)
  133. FetchCoverByISBN(params).then((res) => {
  134. // item.cover = window.URL.createObjectURL(res)
  135. if (res) {
  136. item.cover = res
  137. } else {
  138. item.cover = ''
  139. }
  140. this.newList.push(item)
  141. })
  142. },
  143. // 初始化首页书架信息
  144. initSmartBookshelf() {
  145. this.leftShelfNo = this.$route.query.leftShelfNo
  146. this.rightShelfNo = this.$route.query.rightShelfNo
  147. const params = { leftShelfNo: this.leftShelfNo, rightShelfNo: this.rightShelfNo }
  148. // const _this = this
  149. initSmartBookshelf(params).then((res) => {
  150. this.shelfName = res.shelfName
  151. this.leftShelfMsg = res.leftShelf.sortMsg
  152. this.rightShelfMsg = res.rightShelf.sortMsg
  153. Promise.all(this.initBookData(res.bookList.splice(0, 1))).then((res) => {
  154. this.rackList = res
  155. console.log('rackList', this.rackList)
  156. })
  157. Promise.all(this.initBookData(res.bookList.splice(-2))).then((res) => {
  158. this.otherList = res
  159. console.log('otherList', this.otherList)
  160. })
  161. })
  162. },
  163. // 处理数据格式
  164. initBookData(bookList) {
  165. return bookList.map(async(item, index) => {
  166. const newItem = {
  167. cover: item.srcUrl,
  168. ranking: item.bookUID,
  169. nbName: item.bookName,
  170. isOtherBook: index !== 0,
  171. nbAuthor: item.bookAuthor ? item.bookAuthor : '',
  172. isNewBook: false,
  173. num: item.heat ? item.heat : '0',
  174. isbn: item.isbn
  175. }
  176. // const params = {
  177. // isbn: item.isbn
  178. // }
  179. // const res = await FetchCoverByISBN(params)
  180. // newItem.cover = window.URL.createObjectURL(res)
  181. return newItem
  182. })
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. @import "~@/assets/styles/index.scss";
  189. </style>