index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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" v-if="auth != 1">
  10. <view class="kaoshi-head-top">
  11. <view class="kaoshi-head-left"></view>
  12. <view class="kaoshi-head-m">新闻资讯</view>
  13. <view class="kaoshi-head-right"></view>
  14. </view>
  15. </view>
  16. <!--#endif-->
  17. <mescroll-body height="auto" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  18. :down="downOption" :up="upOption">
  19. <view class="news-content" v-if="auth != 1">
  20. <view class="news-list" v-for="(item,index) in list" :key="index" @tap="gotoDetail(item)">
  21. <view class="news-flex">
  22. <image :src="item.image == '' ? '../../static/img/pic.jpg' : item.image" class="news-list-img">
  23. </image>
  24. <view class="news-list-r">
  25. <view class="news-list-title">{{item.title}}</view>
  26. <view class="news-list-time">{{item.noticetime}}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </mescroll-body>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. mapState
  37. } from 'vuex';
  38. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
  39. export default {
  40. mixins: [MescrollMixin], // 使用mixin
  41. data() {
  42. return {
  43. // #ifdef MP
  44. auth: 1,
  45. // #endif
  46. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  47. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  48. downOption: {
  49. use: true, // 是否启用下拉刷新; 默认true
  50. auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
  51. native: false // 启用系统自带的下拉组件,默认false;仅mescroll-body生效,mescroll-uni无效(native: true, 则需在pages.json中配置"enablePullDownRefresh":true)
  52. },
  53. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  54. upOption: {
  55. page: {
  56. num: 0,
  57. size: 20 // 每页数据的数量,默认10
  58. },
  59. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  60. empty: {
  61. tip: '暂无相关数据'
  62. }
  63. },
  64. // 列表数据
  65. list: [],
  66. }
  67. },
  68. onShow() {
  69. this.canReset && this.mescroll.resetUpScroll() // 自行实现的刷新指定一条数据
  70. this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false
  71. },
  72. computed: {
  73. ...mapState(['subject', 'userinfo']),
  74. },
  75. onLoad() {
  76. // #ifdef MP-WEIXIN
  77. this.getSh()
  78. wx.showShareMenu({
  79. withShareTicket: true,
  80. menus: ["shareAppMessage", "shareTimeline"]
  81. })
  82. // #endif
  83. },
  84. methods: {
  85. async getSh() {
  86. let res = await this.$myHttp.get({
  87. url: this.$myHttp.urlMap.sh,
  88. data: {},
  89. needLogin: false,
  90. })
  91. if (res.code == 1) {
  92. // this.navList = res.data.data
  93. console.log(res)
  94. this.auth = res.data.auth
  95. // #ifdef MP
  96. if(this.auth == 1) {
  97. uni.setNavigationBarTitle({
  98. title: ''
  99. })
  100. }
  101. // #endif
  102. // #ifdef H5
  103. this.auth = 0
  104. // #endif
  105. }
  106. },
  107. gotoDetail(item) {
  108. if (item.url == '') {
  109. uni.navigateTo({
  110. url: '/pages/article/detail?id=' + item.id + '&type=1'
  111. })
  112. } else {
  113. uni.navigateTo({
  114. url: '/pages/webview/webview?url=' + item.url + '&title=' + item.title
  115. })
  116. }
  117. },
  118. /*上拉加载的回调*/
  119. async upCallback(page) {
  120. let pageNum = page.num; // 页码, 默认从1开始
  121. let pageSize = page.size; // 页长, 默认每页10条
  122. let res = await this.$myHttp.post({
  123. url: this.$myHttp.urlMap.noticeList,
  124. data: {
  125. // type:this.current_id,
  126. subject_id: this.subject.id || this.subList[0].id,
  127. page: pageNum,
  128. limit: pageSize,
  129. cate_id: 2
  130. },
  131. needLogin: false
  132. })
  133. if (res.code == 1) {
  134. // 接口返回的当前页数据列表 (数组)
  135. let curPageData = res.data.data;
  136. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  137. let curPageLen = curPageData.length;
  138. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  139. // let totalPage = data.xxx;
  140. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  141. let totalSize = res.data.total;
  142. this.mescroll.endBySize(curPageLen, totalSize);
  143. if (page.num == 1) this.list = []; //如果是第一页需手动置空列表
  144. this.list = this.list.concat(curPageData); //追加新数据
  145. } else {
  146. this.mescroll.endErr()
  147. }
  148. // 此处仍可以继续写其他接口请求...
  149. // 调用其他方法...
  150. },
  151. }
  152. }
  153. </script>
  154. <style>
  155. page {
  156. background-color: #f6f6f6;
  157. }
  158. .news-content {
  159. width: 98%;
  160. margin: 0 auto 25px;
  161. }
  162. .news-title {
  163. display: flex;
  164. align-items: center;
  165. margin: 15px 0 13px;
  166. font-size: 18px;
  167. font-weight: bold;
  168. justify-content: space-between;
  169. }
  170. .news-title .iconfont {
  171. font-size: 15px;
  172. margin-left: 8px;
  173. color: #bbb;
  174. }
  175. .news-flex {
  176. display: flex;
  177. align-items: flex-start;
  178. }
  179. .news-list-img {
  180. width: 66px;
  181. height: 66px;
  182. border: solid 1px #f1f1f1;
  183. border-radius: 6px;
  184. }
  185. .news-list-r {
  186. margin-left: 10px;
  187. flex: 1;
  188. height: 66px;
  189. display: flex;
  190. flex-direction: column;
  191. justify-content: space-between;
  192. }
  193. .news-list-title {
  194. font-size: 16px;
  195. line-height: 21px;
  196. padding-top: 4px;
  197. text-overflow: ellipsis;
  198. display: -webkit-box;
  199. -webkit-line-clamp: 2;
  200. -webkit-box-orient: vertical;
  201. display: -moz-box;
  202. -moz-line-clamp: 2;
  203. -moz-box-orient: vertical;
  204. overflow-wrap: break-word;
  205. word-break: break-all;
  206. white-space: normal;
  207. overflow: hidden;
  208. }
  209. .news-list-time {
  210. display: flex;
  211. flex-direction: column;
  212. align-items: flex-start;
  213. color: #999;
  214. font-size: 13px;
  215. }
  216. .news-list-flex {
  217. display: flex;
  218. align-items: center;
  219. margin-top: 3px;
  220. }
  221. .swiper {
  222. height: 160px !important;
  223. }
  224. .news-list {
  225. background: #fff;
  226. padding: 11px 13px;
  227. margin: 14px 8px;
  228. border-radius: 10px;
  229. box-shadow: 2px 4px 10px rgb(0 0 0 / 8%);
  230. }
  231. .news-content .news-list:last-child {
  232. margin-bottom: 0;
  233. border-bottom: none
  234. }
  235. </style>