notice.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view>
  3. <!--#ifdef APP-PLUS-->
  4. <view class="lz-status_bar">
  5. <view class="lz-top_view"></view>
  6. </view>
  7. <!--#endif-->
  8. <!-- #ifndef MP-WEIXIN -->
  9. <view class="kaoshi-head">
  10. <view class="kaoshi-head-top">
  11. <view class="kaoshi-head-left" @tap="$navigateBack">
  12. <view class="iconfont icon-zuojiantou"></view>
  13. </view>
  14. <view class="kaoshi-head-m">通知公告</view>
  15. </view>
  16. </view>
  17. <!--#endif-->
  18. <mescroll-body height="auto" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  19. :down="downOption" :up="upOption">
  20. <view class="noticelist">
  21. <view class="noticebox" v-for="(item,index) in list" :key="index" @tap="gotoDetail(item)">
  22. <image src="../../static/img/myicon1.png" mode="aspectFit" class="noticeimg"></image>
  23. <view class="noticetext">
  24. <view class="noticetitle">{{item.title}}</view>
  25. <view class="noticetime">{{item.noticetime}}</view>
  26. </view>
  27. <view class="iconfont icon-arrow"></view>
  28. </view>
  29. </view>
  30. </mescroll-body>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. mapState
  36. } from 'vuex';
  37. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
  38. export default {
  39. mixins: [MescrollMixin], // 使用mixin
  40. data() {
  41. return {
  42. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  43. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  44. downOption: {
  45. use: true, // 是否启用下拉刷新; 默认true
  46. auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
  47. native: false // 启用系统自带的下拉组件,默认false;仅mescroll-body生效,mescroll-uni无效(native: true, 则需在pages.json中配置"enablePullDownRefresh":true)
  48. },
  49. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  50. upOption: {
  51. page: {
  52. num: 0,
  53. size: 20 // 每页数据的数量,默认10
  54. },
  55. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  56. empty: {
  57. tip: '暂无相关数据'
  58. }
  59. },
  60. // 列表数据
  61. list: [],
  62. }
  63. },
  64. computed: {
  65. ...mapState(['subject', 'userinfo']),
  66. },
  67. onShow() {
  68. this.canReset && this.mescroll.resetUpScroll() // 自行实现的刷新指定一条数据
  69. this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false
  70. },
  71. onLoad() {
  72. // #ifdef MP-WEIXIN
  73. wx.showShareMenu({
  74. withShareTicket: true,
  75. menus: ["shareAppMessage", "shareTimeline"]
  76. })
  77. // #endif
  78. },
  79. methods: {
  80. async upCallback(page) {
  81. let pageNum = page.num; // 页码, 默认从1开始
  82. let pageSize = page.size; // 页长, 默认每页10条
  83. let res = await this.$myHttp.post({
  84. url: this.$myHttp.urlMap.noticeList,
  85. data: {
  86. subject_id: this.subject.id || this.subList[0].id,
  87. page: pageNum,
  88. limit: pageSize,
  89. cate_id: 1
  90. },
  91. needLogin: false
  92. })
  93. if (res.code == 1) {
  94. // 接口返回的当前页数据列表 (数组)
  95. let curPageData = res.data.data;
  96. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  97. let curPageLen = curPageData.length;
  98. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  99. // let totalPage = data.xxx;
  100. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  101. let totalSize = res.data.total;
  102. this.mescroll.endBySize(curPageLen, totalSize);
  103. if (page.num == 1) this.list = []; //如果是第一页需手动置空列表
  104. this.list = this.list.concat(curPageData); //追加新数据
  105. } else {
  106. this.mescroll.endErr()
  107. }
  108. // 此处仍可以继续写其他接口请求...
  109. // 调用其他方法...
  110. },
  111. gotoDetail(item) {
  112. if (item.url == '') {
  113. uni.navigateTo({
  114. url: '/pages/article/detail?id=' + item.id + '&type=2'
  115. })
  116. } else {
  117. uni.navigateTo({
  118. url: '/pages/webview/webview?url=' + item.url + '&title=' + item.title
  119. })
  120. }
  121. },
  122. }
  123. }
  124. </script>
  125. <style>
  126. page {
  127. background: #f6f6f6;
  128. }
  129. .noticelist {
  130. margin: 0 15px;
  131. }
  132. .noticebox {
  133. display: flex;
  134. justify-content: space-between;
  135. align-items: center;
  136. margin: 15px 0;
  137. padding: 15px;
  138. border-radius: 8px;
  139. background-color: #fff;
  140. box-shadow: 2px 4px 10px rgb(0 0 0 / 8%);
  141. }
  142. .noticeimg {
  143. width: 22px;
  144. height: 22px;
  145. margin-right: 10px;
  146. background: #d7e4fe;
  147. padding: 5px;
  148. border-radius: 24px;
  149. }
  150. .noticetext {
  151. width: calc(100% - 50px);
  152. margin-right: auto;
  153. }
  154. .noticetitle {
  155. width: 100%;
  156. white-space: nowrap;
  157. text-overflow: ellipsis;
  158. overflow: hidden;
  159. margin-bottom: 6px;
  160. color: #333;
  161. }
  162. .noticetime {
  163. color: #999;
  164. font-size: 13px;
  165. }
  166. .icon-arrow {
  167. color: #adadad;
  168. font-size: 15px;
  169. }
  170. </style>