list.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <Container title="公告列表" :scrollStyle="{ padding: 0 }">
  3. <view ref="loadMoreTrigger" class="notice-page">
  4. <!-- 公告列表 -->
  5. <view class="notice-list" v-if="noticeList !='' && noticeList != null">
  6. <!-- 公告项1 -->
  7. <view class="notice-item" v-for="(item, index) in noticeList" :key="index" @click="handleItemClick(item)">
  8. <navigator class="navigator_item" open-type="navigate" :url="'/pages/notice/detail?id=' + item.id">
  9. <view class="notice-icon">
  10. <image
  11. class="notice-icon-image"
  12. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/8DvVCq6w7CN97Mxdp68vje9WCi8RjKXDC5KwHOOY.png"
  13. mode="aspectFill"
  14. ></image>
  15. </view>
  16. <view class="notice-content" :id="'content-' + index">
  17. <view class="notice-title">{{ item.title }}</view>
  18. <view class="notice-time">{{ formatTimestamp(item.insert_time)}}</view>
  19. </view>
  20. <view class="notice-link">
  21. <image
  22. class="notice-link-image"
  23. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/jYNQJdKYavtqeVoq7bxwYFuF258jFm3sNWVSX1SS.png"
  24. mode="aspectFill"
  25. ></image>
  26. </view>
  27. </navigator>
  28. </view>
  29. </view>
  30. <!-- 加载状态提示 -->
  31. <view class="loading-status">
  32. <text v-if="loading">加载中...</text>
  33. <text v-if="noMore">——已经到底了——</text>
  34. </view>
  35. </view>
  36. </Container>
  37. </template>
  38. <script>
  39. import Container from '../../components/Container/Container.vue';
  40. import CustomerService from '@/components/CustomerService/CustomerService.vue';
  41. export default {
  42. data() {
  43. return {
  44. page: 1,
  45. limit: 10,
  46. noticeLink_top: [],
  47. noticeList: [],
  48. loading: false, // 是否正在加载
  49. noMore: false, // 是否没有更多数据
  50. observer: null
  51. };
  52. },
  53. onReady() {
  54. // this.handleScroll();
  55. },
  56. onLoad() {
  57. this.handleScroll();
  58. },
  59. methods: {
  60. handleScroll() {
  61. // 先销毁之前的观察器
  62. if (this.observer) {
  63. this.observer.disconnect();
  64. this.observer = null;
  65. }
  66. // 创建新的观察器
  67. this.observer = uni.createIntersectionObserver(this);
  68. this.observer.relativeToViewport({
  69. bottom: 50 // 调整为更小的阈值,提高触发灵敏度
  70. }).observe('.loading-status', (res) => {
  71. if (res.intersectionRatio > 0 && !this.loading && !this.noMore) {
  72. this.loading = true; // 添加加载状态
  73. this.notice_system_list().finally(() => {
  74. this.loading = false;
  75. });
  76. this.page++;
  77. }
  78. });
  79. },
  80. formatTimestamp(timestamp) {
  81. if (timestamp) {
  82. timestamp = timestamp * 1000;
  83. }
  84. const date = new Date(timestamp);
  85. const year = date.getFullYear();
  86. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,要 +1
  87. const day = String(date.getDate()).padStart(2, '0');
  88. const hours = String(date.getHours()).padStart(2, '0');
  89. const minutes = String(date.getMinutes()).padStart(2, '0');
  90. const seconds = String(date.getSeconds()).padStart(2, '0');
  91. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  92. },
  93. async notice_system_list() {
  94. this.$http.request('api/question_bank/question_reception/notice/list', { page: this.page, limit: this.limit }).then((callback) => {
  95. if (callback.code == 'success') {
  96. let page = this.page;
  97. if (page == 1) {
  98. this.noticeList = callback.data.data;
  99. } else {
  100. this.noticeList.push(...callback.data.data);
  101. }
  102. if (callback.data.data == '') {
  103. this.noMore = true;
  104. } else {
  105. this.noMore = false;
  106. }
  107. } else {
  108. uni.showToast({
  109. title: callback.msg,
  110. icon: 'none'
  111. });
  112. }
  113. });
  114. },
  115. handleItemClick(item) {
  116. // 处理点击事件
  117. console.log('点击公告:');
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. .notice-page {
  124. background-color: #f5f5f5;
  125. min-height: 100vh;
  126. .notice-list {
  127. background-color: #fff;
  128. border-radius: 12rpx;
  129. overflow: hidden;
  130. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  131. .navigator_item{
  132. display: flex;
  133. width: 100%;
  134. }
  135. .notice-item {
  136. display: flex;
  137. align-items: center;
  138. padding: 24rpx 30rpx;
  139. border-bottom: 1rpx solid #eee;
  140. position: relative;
  141. .notice-icon {
  142. position: absolute;
  143. top: 22rpx;
  144. width: 60rpx;
  145. height: 60rpx;
  146. margin-right: 20rpx;
  147. }
  148. .notice-link {
  149. position: absolute;
  150. right: 0rpx;
  151. width: 50rpx;
  152. height: 50rpx;
  153. margin-right: 20rpx;
  154. top:calc((100% - 50rpx)/2)
  155. }
  156. .notice-link-image,
  157. .notice-icon-image {
  158. width: 50rpx;
  159. height: 50rpx;
  160. }
  161. .notice-content {
  162. flex: 1;
  163. margin-left: 60rpx;
  164. margin-right: 60rpx;
  165. .notice-title {
  166. font-size: 30rpx;
  167. color: #333;
  168. margin-bottom: 10rpx;
  169. line-height: 1.4;
  170. display: -webkit-box;
  171. -webkit-box-orient: vertical;
  172. -webkit-line-clamp: 2;
  173. overflow: hidden;
  174. text-overflow: ellipsis;
  175. }
  176. .notice-time {
  177. font-size: 24rpx;
  178. color: #999;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. .loading-status {
  185. text-align: center;
  186. color: #999;
  187. padding: 120rpx 0rpx;
  188. font-size: 24rpx;
  189. }
  190. </style>