Search.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div id="search-list">
  3. <!--搜索结果面包屑-->
  4. <el-breadcrumb
  5. class="bread"
  6. separator-class="el-icon-arrow-right"
  7. >
  8. <el-breadcrumb-item>
  9. 对 <span class="result">{{ keyword }}</span> 的搜索结果共有<span class="result"> {{ total }} </span>条记录
  10. </el-breadcrumb-item>
  11. </el-breadcrumb>
  12. <el-row>
  13. <el-col :md="6" class="movie-list">
  14. <hot-search :card-prop="cardProp" />
  15. </el-col>
  16. <el-col v-loading="loading" :md="18">
  17. <el-row class="movie-list">
  18. <el-col v-for="(video,index) in dataList" :key="index" :md="6" :sm="8" :xs="12">
  19. <video-card :video="video" />
  20. </el-col>
  21. <!--
  22. 分页按钮:
  23. page-size:每页显示条数
  24. total:总条数
  25. hide-on-single-page: 页数为一时隐藏
  26. -->
  27. <el-col :span="24" class="pagination">
  28. <el-pagination
  29. background
  30. :small="screenWidth <= 768"
  31. hide-on-single-page
  32. layout="prev, pager, next"
  33. :current-page="currentPage"
  34. :page-size="pageSize"
  35. :total="total"
  36. @current-change="handleCurrentChange"
  37. />
  38. </el-col>
  39. </el-row>
  40. </el-col>
  41. </el-row>
  42. <el-row v-if="showEmpty" class="not-result">
  43. <el-col :span="12" :offset="6">
  44. <img src="@/assets/img/icon/not-result.png">
  45. <div>没有结果</div>
  46. </el-col>
  47. </el-row>
  48. </div>
  49. </template>
  50. <script>
  51. import VideoCard from '@/components/card/VideoCard'
  52. import HotSearch from '@/components/card/HotSearch'
  53. import { videoQuery, hotKeyword } from '@/api/search'
  54. export default {
  55. name: 'Search',
  56. components: { VideoCard, HotSearch },
  57. data() {
  58. return {
  59. keyword: null,
  60. currentPage: 1,
  61. total: 0,
  62. length: 0,
  63. pageSize: 12,
  64. dataList: [],
  65. showEmpty: false,
  66. cardProp: {
  67. title: null,
  68. type: null,
  69. dataList: []
  70. },
  71. loading: false
  72. }
  73. },
  74. mounted() {
  75. hotKeyword().then(resp => {
  76. if (resp.code === 0) {
  77. this.cardProp.dataList = resp.data
  78. this.cardProp.title = '热搜排行'
  79. this.cardProp.type = 'hotSearch'
  80. }
  81. })
  82. },
  83. created() {
  84. this.keyword = this.$route.query.keyword
  85. this.currentPage = parseInt(this.$route.query.pageNumber)
  86. this.videoQueryWrapper(this.keyword, this.currentPage)
  87. document.title = '搜索 - ' + this.keyword
  88. },
  89. methods: {
  90. handleCurrentChange(currentPage) {
  91. this.$router.push({
  92. path: '/search',
  93. query: {
  94. keyword: this.keyword,
  95. pageNumber: currentPage
  96. }
  97. })
  98. this.$router.go(0)
  99. },
  100. videoQueryWrapper(keyword, pageNumber) {
  101. this.loading = true
  102. videoQuery(keyword, pageNumber).then(resp => {
  103. if (resp.code === 0) {
  104. this.total = resp.data.totalSize
  105. this.length = resp.data.totalPages
  106. this.dataList = resp.data.list
  107. if (this.total === 0) {
  108. this.showEmpty = true
  109. }
  110. } else {
  111. this.$notify.error({
  112. message: resp.msg,
  113. type: 'warning',
  114. duration: 3000
  115. })
  116. }
  117. }).catch(error => {
  118. this.$notify.error({
  119. message: error.m,
  120. type: 'error',
  121. duration: 3000
  122. })
  123. }).finally(() => {
  124. this.loading = false
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. #search-list {
  132. padding-left: 3px;
  133. padding-right: 3px;
  134. padding-top: 3px;
  135. }
  136. .bread {
  137. font-size: 15px;
  138. }
  139. .movie-list {
  140. padding-top: 15px;
  141. }
  142. .pagination {
  143. text-align: center;
  144. padding: 10px;
  145. }
  146. .result {
  147. color: red;
  148. }
  149. .not-result {
  150. padding-top: 100px;
  151. padding-bottom: 100px;
  152. text-align: center;
  153. }
  154. </style>