list.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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" :style="{top: item.isTwoLines ? '67rpx' : '30rpx'}">
  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. this.checkTitleLines();
  59. },
  60. methods: {
  61. checkTitleLines() {
  62. // 使用setTimeout确保DOM已经渲染完成
  63. setTimeout(() => {
  64. this.noticeList.forEach((item, index) => {
  65. const query = uni.createSelectorQuery().in(this);
  66. query.select(`.notice-title`).boundingClientRect(data => {
  67. if (data && data.height > 40) { // 假设单行高度约为40rpx
  68. this.$set(item, 'isTwoLines', true);
  69. } else {
  70. this.$set(item, 'isTwoLines', false);
  71. }
  72. }).exec();
  73. });
  74. }, 300);
  75. },
  76. handleScroll() {
  77. // 先销毁之前的观察器
  78. if (this.observer) {
  79. this.observer.disconnect();
  80. this.observer = null;
  81. }
  82. // 创建新的观察器
  83. this.observer = uni.createIntersectionObserver(this);
  84. this.observer.relativeToViewport({
  85. bottom: 50 // 调整为更小的阈值,提高触发灵敏度
  86. }).observe('.loading-status', (res) => {
  87. if (res.intersectionRatio > 0 && !this.loading && !this.noMore) {
  88. this.loading = true; // 添加加载状态
  89. this.notice_system_list().finally(() => {
  90. this.loading = false;
  91. });
  92. this.page++;
  93. }
  94. });
  95. },
  96. formatTimestamp(timestamp) {
  97. if (timestamp) {
  98. timestamp = timestamp * 1000;
  99. }
  100. const date = new Date(timestamp);
  101. const year = date.getFullYear();
  102. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,要 +1
  103. const day = String(date.getDate()).padStart(2, '0');
  104. const hours = String(date.getHours()).padStart(2, '0');
  105. const minutes = String(date.getMinutes()).padStart(2, '0');
  106. const seconds = String(date.getSeconds()).padStart(2, '0');
  107. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  108. },
  109. async notice_system_list() {
  110. this.$http.request('api/question_bank/question_reception/notice/list', { page: this.page, limit: this.limit }).then((callback) => {
  111. if (callback.code == 'success') {
  112. let page = this.page;
  113. if (page == 1) {
  114. this.noticeList = callback.data.data;
  115. } else {
  116. this.noticeList.push(...callback.data.data);
  117. }
  118. if (callback.data.data == '') {
  119. this.noMore = true;
  120. } else {
  121. this.noMore = false;
  122. }
  123. } else {
  124. uni.showToast({
  125. title: callback.msg,
  126. icon: 'none'
  127. });
  128. }
  129. });
  130. },
  131. handleItemClick(item) {
  132. // 处理点击事件
  133. console.log('点击公告:');
  134. }
  135. }
  136. };
  137. </script>
  138. <style lang="scss">
  139. .notice-page {
  140. background-color: #f5f5f5;
  141. min-height: 100vh;
  142. .notice-list {
  143. background-color: #fff;
  144. border-radius: 12rpx;
  145. overflow: hidden;
  146. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  147. .navigator_item{
  148. display: flex;
  149. width: 100%;
  150. }
  151. .notice-item {
  152. display: flex;
  153. align-items: center;
  154. padding: 24rpx 30rpx;
  155. border-bottom: 1rpx solid #eee;
  156. position: relative;
  157. .notice-icon {
  158. position: absolute;
  159. top: 22rpx;
  160. width: 60rpx;
  161. height: 60rpx;
  162. margin-right: 20rpx;
  163. }
  164. .notice-link {
  165. position: absolute;
  166. right: 0rpx;
  167. width: 50rpx;
  168. height: 50rpx;
  169. margin-right: 20rpx;
  170. }
  171. .notice-link-image,
  172. .notice-icon-image {
  173. width: 50rpx;
  174. height: 50rpx;
  175. }
  176. .notice-content {
  177. flex: 1;
  178. margin-left: 60rpx;
  179. margin-right: 60rpx;
  180. .notice-title {
  181. font-size: 30rpx;
  182. color: #333;
  183. margin-bottom: 10rpx;
  184. line-height: 1.4;
  185. display: -webkit-box;
  186. -webkit-box-orient: vertical;
  187. -webkit-line-clamp: 2;
  188. overflow: hidden;
  189. text-overflow: ellipsis;
  190. }
  191. .notice-time {
  192. font-size: 24rpx;
  193. color: #999;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. .loading-status {
  200. text-align: center;
  201. color: #999;
  202. padding: 120rpx 0rpx;
  203. font-size: 24rpx;
  204. }
  205. </style>