Article.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div>
  3. <el-row class="movie-list">
  4. <el-col :md="12">
  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;">{{ item.publishAt }}</span>
  9. </div>
  10. <div class="text item">
  11. <el-row>
  12. <el-col :md="4">
  13. <router-link target="_blank" :to="`/news/${item.contentId}`">
  14. <el-image
  15. lazy
  16. fit="cover"
  17. :src="item.coverUrl"
  18. class="coverImg"
  19. />
  20. </router-link>
  21. </el-col>
  22. <el-col :md="20">
  23. <router-link style="text-decoration-line: none" target="_blank" :to="`/news/${item.contentId}`">
  24. <el-row>
  25. <div style="padding: 14px">
  26. <span style="left: 0;margin-bottom: 0px;color: black;">{{ item.title | ellipsis }}</span>
  27. </div>
  28. </el-row>
  29. </router-link>
  30. <el-row>
  31. <div style="padding: 14px">
  32. <span style="left: 0;margin-bottom: 0px;color: black;">{{ item.excerpt }}</span>
  33. </div>
  34. </el-row>
  35. </el-col>
  36. </el-row>
  37. </div>
  38. </el-card>
  39. </el-row>
  40. <el-row>
  41. <div v-if="hasMore" style="display: flex; justify-content: center;">
  42. <el-button link type="plain" icon="el-icon-bottom" @click="loadMore">
  43. 加载更多
  44. </el-button>
  45. </div>
  46. </el-row>
  47. </el-col>
  48. <el-col :md="6">
  49. <el-row class="movie-list">
  50. <el-card class="box-card">
  51. <div slot="header" class="clearfix">
  52. <el-row>
  53. <span>热门</span>
  54. </el-row>
  55. </div>
  56. <div class="text item">
  57. <el-row />
  58. </div>
  59. </el-card>
  60. </el-row>
  61. </el-col>
  62. </el-row>
  63. </div>
  64. </template>
  65. <script>
  66. import { getNewsList } from '@/api/blog'
  67. export default {
  68. name: 'ArticleIndex',
  69. metaInfo: {
  70. meta: [
  71. { name: 'referrer', content: 'no-referrer' }
  72. ]
  73. },
  74. filters: {
  75. ellipsis(value) {
  76. if (!value) return ''
  77. const max = 50
  78. if (value.length > max) {
  79. return value.slice(0, max) + '...'
  80. }
  81. return value
  82. }
  83. },
  84. components: {},
  85. data() {
  86. return {
  87. // 屏幕宽度, 为了控制分页条的大小
  88. screenWidth: document.body.clientWidth,
  89. currentPage: 1,
  90. pageSize: 12,
  91. totalSize: 0,
  92. dataList: [],
  93. hasMore: true
  94. }
  95. },
  96. created() {
  97. document.title = 'News'
  98. this.getArticlesWrapper(this.currentPage)
  99. },
  100. mounted() {
  101. // 当窗口宽度改变时获取屏幕宽度
  102. window.onresize = () => {
  103. return () => {
  104. window.screenWidth = document.body.clientWidth
  105. this.screenWidth = window.screenWidth
  106. }
  107. }
  108. },
  109. methods: {
  110. handleCurrentChange(currentPage) {
  111. this.currentPage = currentPage
  112. this.getArticlesWrapper(this.currentPage)
  113. // 回到顶部
  114. scrollTo(0, 0)
  115. },
  116. getArticlesWrapper(page) {
  117. getNewsList(page).then(resp => {
  118. if (resp.code === 0) {
  119. const respData = resp.data
  120. this.hasMore = respData.hasNext
  121. for (const item of respData.list) {
  122. this.dataList.push(item)
  123. }
  124. }
  125. })
  126. },
  127. loadMore() {
  128. this.currentPage = this.currentPage + 1
  129. this.getArticlesWrapper(this.currentPage)
  130. },
  131. refresh() {
  132. this.$message.info('暂未实现')
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. /*处于手机屏幕时*/
  139. @media screen and (max-width: 768px) {
  140. .movie-list {
  141. padding: 5px;
  142. }
  143. .coverImg {
  144. height: 120px !important;
  145. }
  146. }
  147. .movie-list {
  148. padding: 5px;
  149. }
  150. .coverImg {
  151. width: 100%;
  152. height: 120px;
  153. display: block;
  154. }
  155. .clearfix:before,
  156. .clearfix:after {
  157. display: table;
  158. content: "";
  159. }
  160. .clearfix:after {
  161. clear: both;
  162. }
  163. .not-result {
  164. padding-top: 100px;
  165. padding-bottom: 100px;
  166. text-align: center;
  167. }
  168. </style>