news-list.vue 7.9 KB

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