TagPage.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <el-row class="movie-list">
  3. <el-col :md="18">
  4. <el-scrollbar style="width: 100%; height: 80vh;">
  5. <el-row v-for="(item, index) in dataList" :key="index" class="movie-list">
  6. <el-card class="box-card">
  7. <div slot="header" class="clearfix">
  8. <span style="left: 0;margin-bottom: 0px;color: black;">
  9. <router-link style="text-decoration-line: none" target="_blank" :to="`/blog/post/${item.articleId}`">
  10. {{ item.title }}
  11. </router-link>
  12. </span>
  13. </div>
  14. <div class="text item">
  15. <el-row>
  16. <span v-html="item.summary" />
  17. </el-row>
  18. <el-row>
  19. <el-col style="padding: 1px" :md="2" :sm="6" :xs="6">
  20. <span style="left: 0;margin-bottom: 0px;color: black;">
  21. <router-link style="text-decoration-line: none" target="_blank" :to="`/blog/category/post?name=${item.category}`">
  22. <el-tag type="warning">
  23. {{ item.category }}
  24. </el-tag>
  25. </router-link>
  26. </span>
  27. </el-col>
  28. <el-col style="padding: 1px" :md="6" :sm="16" :xs="16">
  29. <span class="el-icon-watch" style="left: 0;margin-bottom: 0px;color: black;">
  30. {{ item.publishAt }}
  31. </span>
  32. </el-col>
  33. </el-row>
  34. </div>
  35. </el-card>
  36. </el-row>
  37. <el-pagination
  38. background
  39. :small="screenWidth <= 768"
  40. layout="prev, pager, next"
  41. :page-size="pageSize"
  42. :current-page="currentPage"
  43. :total="totalSize"
  44. @current-change="handleCurrentChange"
  45. @prev-click="handleCurrentChange"
  46. @next-click="handleCurrentChange"
  47. />
  48. </el-scrollbar>
  49. </el-col>
  50. <el-col :md="6">
  51. <el-row class="movie-list">
  52. <el-card class="box-card">
  53. <div slot="header" class="clearfix">
  54. <el-row>
  55. <span>热门</span>
  56. </el-row>
  57. </div>
  58. <div class="text item">
  59. <el-row />
  60. </div>
  61. </el-card>
  62. </el-row>
  63. </el-col>
  64. </el-row>
  65. </template>
  66. <script>
  67. import { getTagPost } from '@/api/blog'
  68. export default {
  69. name: 'TagPage',
  70. data() {
  71. return {
  72. queryInfo: {
  73. pn: 1,
  74. type: 'tag',
  75. name: ''
  76. },
  77. // 屏幕宽度, 为了控制分页条的大小
  78. screenWidth: document.body.clientWidth,
  79. currentPage: 1,
  80. pageSize: 10,
  81. totalSize: 0,
  82. dataList: []
  83. }
  84. },
  85. created() {
  86. const pageNumber = this.$route.query.pn
  87. if (pageNumber !== undefined && pageNumber !== null) {
  88. this.currentPage = parseInt(pageNumber)
  89. this.queryInfo.pn = parseInt(pageNumber)
  90. }
  91. const name = this.$route.query.name
  92. if (name !== undefined && name !== null) {
  93. this.queryInfo.name = name
  94. }
  95. const path = this.$route.path
  96. const arr = path.split('/')
  97. console.log(arr)
  98. if (arr.length !== 4) {
  99. return
  100. }
  101. if (arr[2] === 'tag') {
  102. this.queryInfo.type = 'tag'
  103. document.title = '包含标签 ' + this.queryInfo.name + ' 的文章'
  104. this.getData()
  105. } else if (arr[2] === 'category') {
  106. this.queryInfo.type = 'category'
  107. document.title = '包含分类 ' + this.queryInfo.name + ' 的文章'
  108. this.getData()
  109. }
  110. },
  111. mounted() {
  112. // 当窗口宽度改变时获取屏幕宽度
  113. window.onresize = () => {
  114. return () => {
  115. window.screenWidth = document.body.clientWidth
  116. this.screenWidth = window.screenWidth
  117. }
  118. }
  119. },
  120. methods: {
  121. handleCurrentChange(currentPage) {
  122. this.queryInfo.pn = currentPage
  123. this.$router.push({
  124. path: '/blog/tag',
  125. query: this.queryInfo
  126. })
  127. this.currentPage = currentPage
  128. this.getData(this.currentPage)
  129. // 回到顶部
  130. scrollTo(0, 0)
  131. },
  132. getData() {
  133. getTagPost(this.queryInfo).then(resp => {
  134. if (resp.code === 0) {
  135. const respData = resp.data
  136. this.dataList = respData.list
  137. this.totalSize = respData.totalSize
  138. } else {
  139. this.$message.error(resp.msg)
  140. }
  141. }).catch(error => {
  142. this.$message.error(error.message)
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. /*处于手机屏幕时*/
  150. @media screen and (max-width: 768px) {
  151. .movie-list {
  152. padding: 5px;
  153. }
  154. .coverImg {
  155. height: 120px !important;
  156. }
  157. }
  158. .movie-list {
  159. padding: 5px;
  160. }
  161. </style>