Search.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 class="movie-list">
  13. <el-col :md="18">
  14. <el-col v-for="(video,index) in dataList" :key="index" :md="6" :sm="8" :xs="12">
  15. <video-card :video="video" />
  16. </el-col>
  17. <!--
  18. 分页按钮:
  19. page-size:每页显示条数
  20. total:总条数
  21. hide-on-single-page: 页数为一时隐藏
  22. -->
  23. <el-col :span="24" class="pagination">
  24. <el-pagination
  25. background
  26. hide-on-single-page
  27. layout="prev, pager, next"
  28. :current-page="currentPage"
  29. :page-size="pageSize"
  30. :total="total"
  31. @current-change="handleCurrentChange"
  32. />
  33. </el-col>
  34. </el-col>
  35. <el-col :md="6">
  36. <hot-search />
  37. </el-col>
  38. </el-row>
  39. <el-row v-if="showEmpty" class="not-result">
  40. <el-col :span="12" :offset="6">
  41. <img src="@/assets/img/icon/not-result.png">
  42. <div>没有结果</div>
  43. </el-col>
  44. </el-row>
  45. </div>
  46. </template>
  47. <script>
  48. import VideoCard from '@/components/card/VideoCard'
  49. import HotSearch from '@/components/card/HotSearch'
  50. import { videoQuery } from '@/api/search'
  51. export default {
  52. name: 'Search',
  53. components: { VideoCard, HotSearch },
  54. data() {
  55. return {
  56. keyword: null,
  57. currentPage: 1,
  58. total: 0,
  59. length: 0,
  60. pageSize: 12,
  61. dataList: [],
  62. showEmpty: true
  63. }
  64. },
  65. created() {
  66. this.keyword = this.$route.query.keyword
  67. this.currentPage = parseInt(this.$route.query.pageNumber)
  68. this.videoQueryWrapper(this.keyword, this.currentPage)
  69. document.title = '搜索 - ' + this.keyword
  70. },
  71. methods: {
  72. handleCurrentChange(currentPage) {
  73. this.$router.push({
  74. path: '/search',
  75. query: {
  76. keyword: this.keyword,
  77. pageNumber: currentPage
  78. }
  79. })
  80. },
  81. videoQueryWrapper(keyword, pageNumber) {
  82. videoQuery(keyword, pageNumber)
  83. .then(res => {
  84. if (res.code === 0) {
  85. const resData = res.data
  86. this.total = resData.totalSize
  87. this.length = resData.totalPages
  88. this.dataList = resData.list
  89. if (this.total !== 0) {
  90. this.showEmpty = false
  91. }
  92. } else {
  93. console.error(res.msg)
  94. }
  95. }).catch(error => {
  96. console.error(error.message)
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. #search-list {
  104. padding-left: 6%;
  105. padding-right: 6%;
  106. padding-top: 30px;
  107. }
  108. .bread {
  109. font-size: 15px;
  110. }
  111. .movie-list {
  112. padding-top: 15px;
  113. }
  114. .pagination {
  115. text-align: center;
  116. padding: 10px;
  117. }
  118. .result {
  119. color: red;
  120. }
  121. .not-result {
  122. padding-top: 100px;
  123. padding-bottom: 100px;
  124. text-align: center;
  125. }
  126. </style>