index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="invite">
  3. <div class="head">
  4. <img @click="back" src="@/assets/images/back.png" class="arrow_img" />
  5. <span>{{ $t('lang219') }}</span>
  6. </div>
  7. <van-list v-model="loading" :finished="finished" :finished-text="finishText" @load="onLoad">
  8. <div class="notice" v-for="(item, index) in list" :key="index" @click="navigatorTo('bulletinDetail', item.id)">
  9. <img class="notice_img" :src="item.img_url" alt="" v-if="item.img_url" />
  10. <div class="right">
  11. <span>{{ item.title }}</span>
  12. <span class="time_text">{{ dateFormatFn(item.createtime) }}</span>
  13. </div>
  14. </div>
  15. </van-list>
  16. </div>
  17. </template>
  18. <script>
  19. import { homeApi } from '@/api/index';
  20. import { dateFormat } from '@/utils/formatTool.js';
  21. export default {
  22. data() {
  23. return {
  24. list: [],
  25. page: 0,
  26. loading: false,
  27. finished: false,
  28. total: 1,
  29. finishText: this.$t('lang200'),
  30. };
  31. },
  32. mounted() {
  33. this.onLoad();
  34. window.addEventListener('scroll', this.scrollBottom);
  35. },
  36. destroyed() {
  37. window.removeEventListener('scroll', this.scrollBottom);
  38. },
  39. methods: {
  40. //返回上一页
  41. back() {
  42. this.$router.back();
  43. },
  44. scrollBottom() {
  45. //加载更多
  46. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //变量windowHeight是可视区的高度
  47. var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度
  48. var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; //滚动条到底部的条件
  49. console.log(scrollTop, 'scrollTop');
  50. console.log(windowHeight, 'windowHeight');
  51. console.log(scrollHeight, 'scrollHeight');
  52. if (scrollTop + windowHeight >= scrollHeight && scrollTop > 0) {
  53. //写后台加载数据的函数
  54. // console.log('滚动到底部啦');
  55. if (this.finished) {
  56. this.loading = true; // 关闭加载状态
  57. this.finished = false; // 加载开始
  58. this.finishText = this.$t('lang200');
  59. this.onLoad();
  60. }
  61. } else {
  62. // this.loading = false; // 关闭加载状态
  63. }
  64. },
  65. navigatorTo(name, id) {
  66. this.$router.push({ name, query: { id: id } });
  67. },
  68. dateFormatFn(date) {
  69. return dateFormat(new Date(date * 1000), 'yyyy-MM-dd');
  70. },
  71. getAnnouncement() {
  72. let params = {
  73. page: this.page,
  74. query: {},
  75. };
  76. homeApi.getAnnouncement(params).then(res => {
  77. if (res.code == 200) {
  78. let rows = res.data.rows;
  79. // 如果返回的数组是空或数组长度是0
  80. if (rows == null || rows.length === 0) {
  81. this.loading = false; // 关闭加载状态
  82. this.finished = true; // 加载结束
  83. this.finishText = this.$t('lang202');
  84. if (this.list.length <= 0) {
  85. this.total = 0;
  86. }
  87. return;
  88. }
  89. this.loading = false; // 关闭加载状态
  90. this.finishText = this.$t('lang203');
  91. this.finished = true;
  92. this.total = res.data.total; //数据总条数
  93. this.list = this.list.concat(rows); //合并数组
  94. console.log(this.list);
  95. // 如果合并之后的数组长度大于返回的数据总条数
  96. if (this.list.length >= this.total) {
  97. this.finished = true; // 加载结束
  98. this.finishText = this.$t('lang202');
  99. }
  100. } else {
  101. this.total = 0;
  102. this.loading = false; // 关闭加载状态
  103. this.finished = true; // 加载结束
  104. this.finishText = this.$t('lang202');
  105. }
  106. });
  107. },
  108. onLoad() {
  109. this.page += 1;
  110. this.getAnnouncement();
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="less" scoped>
  116. .invite {
  117. min-height: calc(100vh + 50px);
  118. padding: 66px 16px;
  119. .head {
  120. position: fixed;
  121. top: 0;
  122. width: 100%;
  123. left: 0;
  124. display: flex;
  125. align-items: center;
  126. justify-content: center;
  127. color: rgba(#000, 0.8);
  128. letter-spacing: 1.5px;
  129. font-weight: 550;
  130. background: #fff;
  131. padding: 14px 0;
  132. z-index: 99999;
  133. .arrow_img {
  134. position: absolute;
  135. left: 20px;
  136. width: 10px;
  137. height: 16px;
  138. }
  139. }
  140. .notice {
  141. display: flex;
  142. color: #000;
  143. padding: 16px;
  144. border-radius: 10px;
  145. margin-bottom: 16px;
  146. box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.59);
  147. background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 100%, rgba(255, 255, 255, 0.3) 100%);
  148. &_img {
  149. width: 100px;
  150. height: 68px;
  151. border-radius: 10px;
  152. margin-right: 10px;
  153. }
  154. .right {
  155. display: flex;
  156. flex-direction: column;
  157. justify-content: space-between;
  158. font-size: 14px;
  159. font-weight: 550;
  160. .time_text {
  161. font-weight: normal;
  162. font-size: 13px;
  163. padding-top: 10px;
  164. }
  165. }
  166. }
  167. }
  168. </style>