my-news-list.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!-- 在这个文件对每个tab对应的列表进行渲染 -->
  2. <template>
  3. <view class="content">
  4. <!-- 这里设置了z-paging加载时禁止自动调用reload方法,自行控制何时reload(懒加载)-->
  5. <z-paging
  6. ref="paging"
  7. v-model="dataList"
  8. @query="queryList"
  9. use-page-scroll
  10. :hide-empty-view="hideEmptyView"
  11. :refresher-enabled="false"
  12. @contentHeightChanged="contentHeightChanged"
  13. :loading-full-fixed="true"
  14. :auto="false"
  15. :auto-clean-list-when-reload="false"
  16. >
  17. <!-- 如果希望其他view跟着页面滚动,可以放在z-paging标签内 -->
  18. <view class="item" v-for="(item, index) in dataList" :key="index" @click="toDetail(item.id)">
  19. <view class="itemTitle">
  20. {{ formatTitle(item.title) }}
  21. <text v-if="item.title.length > 90" class="allContent">全文</text>
  22. </view>
  23. <view class="resources" v-if="item.clueInfoList.length <= 1">
  24. <view
  25. class="resourcesItem resourcesItemOne"
  26. v-for="items in item.clueInfoList"
  27. :key="items.id"
  28. >
  29. <image v-if="items.type == '1'" class="logo" :src="items.localUrl"></image>
  30. <image v-if="items.type == '2'" class="logo" src="../../static/image/video.png"></image>
  31. <image v-if="items.type == '3'" class="logo" src="../../static/image/music.png"></image>
  32. <image
  33. v-if="items.type == 2 || items.type == 3"
  34. src="../../static/image/playBtn.png"
  35. class="playBtn"
  36. ></image>
  37. </view>
  38. </view>
  39. <view class="resources" v-else>
  40. <view
  41. class="resourcesItem resourcesItems"
  42. v-for="items in item.clueInfoList"
  43. :key="items.id"
  44. >
  45. <image v-if="items.type == '1'" class="logo" :src="items.localUrl"></image>
  46. <image v-if="items.type == '2'" class="logo" src="../../static/image/video.png"></image>
  47. <image v-if="items.type == '3'" class="logo" src="../../static/image/music.png"></image>
  48. <image
  49. v-if="items.type == 2 || items.type == 3"
  50. src="../../static/image/playBtn.png"
  51. class="playBtn"
  52. ></image>
  53. </view>
  54. <view
  55. class="resourcesItem resourcesItems"
  56. v-if="item.clueInfoList.length % 3 == 2"
  57. ></view>
  58. </view>
  59. <view class="bottomBox">
  60. <view class="timeBox">{{ item.modifyTime }}</view>
  61. </view>
  62. <view class="seat"></view>
  63. </view>
  64. </z-paging>
  65. </view>
  66. </template>
  67. <script>
  68. import { findPage } from '../../network/api.js';
  69. export default {
  70. data() {
  71. return {
  72. //v-model绑定的这个变量不要在分页请求结束中自己赋值!!!
  73. dataList: [],
  74. height: 0,
  75. hideEmptyView: true,
  76. completeFunc: null
  77. };
  78. },
  79. props: {
  80. //当前组件的index,也就是当前组件是swiper中的第几个
  81. tabIndex: {
  82. type: Number,
  83. default: function() {
  84. return 0;
  85. }
  86. },
  87. //当前swiper切换到第几个index
  88. currentIndex: {
  89. type: Number,
  90. default: function() {
  91. return 0;
  92. }
  93. },
  94. phone: {
  95. type: String,
  96. default: function() {
  97. return '';
  98. }
  99. }
  100. },
  101. watch: {
  102. currentIndex: {
  103. handler(newVal) {
  104. if (newVal === this.tabIndex) {
  105. //懒加载,当滑动到当前的item时,才去加载
  106. setTimeout(() => {
  107. this.$refs.paging.reload();
  108. }, 100);
  109. }
  110. },
  111. immediate: true
  112. }
  113. },
  114. methods: {
  115. toDetail(id) {
  116. uni.navigateTo({
  117. url: `../../pages/newsDetail/newsDetail?id=${id}`
  118. });
  119. },
  120. formatTitle(title) {
  121. return title.length > 105 ? title.substring(0, 104) + '...' : title;
  122. },
  123. queryList(pageNo, pageSize) {
  124. //组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
  125. //这里的pageNo和pageSize会自动计算好,直接传给服务器即可
  126. //模拟请求服务器获取分页数据,请替换成自己的网络请求
  127. let statusType = [1, 0];
  128. const params = {
  129. pageNumber: pageNo,
  130. pageSize: pageSize,
  131. ascription: 1,
  132. status: statusType[this.tabIndex],
  133. phone: this.phone
  134. };
  135. findPage(params).then(
  136. res => {
  137. if (res.data.state == 200) {
  138. let data = res.data.data.pageRecords.map(item => {
  139. item.clueInfoList = item.clueInfoList.filter(i => {
  140. return i.type !== 0;
  141. });
  142. return item;
  143. });
  144. console.log(data);
  145. this.$refs.paging.complete(data);
  146. } else {
  147. this.$refs.paging.complete([]);
  148. }
  149. this.hideEmptyView = false;
  150. //请求结束,调用父组件的下拉刷新结束回调函数,使得父组件中的z-paging下拉刷新结束
  151. if (this.completeFunc) {
  152. this.completeFunc();
  153. }
  154. },
  155. error => {
  156. this.$refs.paging.complete(false);
  157. if (this.completeFunc) {
  158. this.completeFunc();
  159. }
  160. }
  161. );
  162. },
  163. //页面通知当前子组件刷新列表
  164. reload(completeFunc) {
  165. //先把父组件下拉刷新的回调函数存起来
  166. this.completeFunc = completeFunc;
  167. //调用z-paging的reload方法
  168. this.$refs.paging.reload();
  169. },
  170. //当列表高度改变时,通知页面的swiper同步更改高度
  171. contentHeightChanged(height) {
  172. const finalHeight = this.dataList.length ? height : 0;
  173. this.$emit('heightChanged', finalHeight);
  174. },
  175. //页面通知当前子组件加载更多数据
  176. doLoadMore() {
  177. this.$refs.paging.doLoadMore();
  178. },
  179. //页面通知当前子组件清除数据
  180. clear() {
  181. this.$refs.paging.clear();
  182. this.hideEmptyView = true;
  183. }
  184. }
  185. };
  186. </script>
  187. <style scoped lang="scss">
  188. /* 注意,1、父节点需要固定高度,z-paging的height:100%才会生效 */
  189. /* 注意,2、请确保z-paging与同级的其他view的总高度不得超过屏幕宽度,以避免超出屏幕高度时页面的滚动与z-paging内部的滚动冲突 */
  190. .content {
  191. height: 100%;
  192. }
  193. .item {
  194. .seat {
  195. height: 8px;
  196. width: 100%;
  197. background-color: #f7f7f9;
  198. }
  199. position: relative;
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: space-between;
  203. padding: 0rpx 30rpx;
  204. margin-top: 16px;
  205. .itemTitle {
  206. font-size: 14px;
  207. position: relative;
  208. .allContent {
  209. position: absolute;
  210. bottom: 0;
  211. right: 0;
  212. color: #2468f2;
  213. z-index: 10;
  214. background-color: #ffffff;
  215. }
  216. }
  217. .resources {
  218. display: flex;
  219. flex-wrap: wrap;
  220. margin-top: 8px;
  221. justify-content: space-between;
  222. .resourcesItem {
  223. border-radius: 5px;
  224. overflow: hidden;
  225. position: relative;
  226. margin-bottom: 5px;
  227. .logo {
  228. width: 100%;
  229. height: 100%;
  230. }
  231. .playBtn {
  232. width: 26rpx;
  233. height: 26rpx;
  234. position: absolute;
  235. left: 50%;
  236. top: 50%;
  237. transform: translate(-50%, -50%);
  238. }
  239. }
  240. .resourcesItemOne {
  241. width: 686rpx;
  242. height: 386rpx;
  243. }
  244. .resourcesItems {
  245. width: 218rpx;
  246. height: 218rpx;
  247. }
  248. }
  249. .bottomBox {
  250. margin: 16px 0;
  251. display: flex;
  252. align-items: center;
  253. font-size: 12px;
  254. color: #5c5f66;
  255. }
  256. }
  257. .item-detail {
  258. padding: 5rpx 15rpx;
  259. border-radius: 10rpx;
  260. font-size: 28rpx;
  261. color: white;
  262. background-color: #007aff;
  263. }
  264. .item-line {
  265. position: absolute;
  266. bottom: 0rpx;
  267. left: 0rpx;
  268. height: 1px;
  269. width: 100%;
  270. background-color: #eeeeee;
  271. }
  272. </style>