itemPage.nvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="page-news">
  3. <uni-list ref="list" class="listview" :Showscrollbar="false" :enableBackToTop="true" :scroll-y="true" @scrolltolower="loadMore()">
  4. <uni-refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown"
  5. :display="refreshing ? 'show' : 'hide'">
  6. <div class="refresh-view">
  7. <image class="refresh-icon" :src="refreshIcon" :style="{width: (refreshing || pulling) ? 0: '32px'}"
  8. :class="{'refresh-icon-active': refreshFlag}"></image>
  9. <uni-load-more v-if="refreshing" class="loading-icon" status="loading"
  10. :contentText="loadingMoreText"></uni-load-more>
  11. <text class="loading-text">{{refreshText}}</text>
  12. </div>
  13. </uni-refresh>
  14. <uni-cell v-for="(item, index) in dataList" :key="item.id">
  15. <news-item :newsItem="item" @click="goDetail(item)"></news-item>
  16. </uni-cell>
  17. <uni-cell>
  18. <view class="loading-more">
  19. <view class="creatView" v-if="isNoData">
  20. <image class="imsa" src="../../../static/nodata.png" mode=""></image>
  21. <text class="c-te">暂无消息</text>
  22. </view>
  23. <text class="loading-more-text">{{loadingText}}</text>
  24. </view>
  25. </uni-cell>
  26. </uni-list>
  27. </view>
  28. </template>
  29. <script>
  30. import uniList from '@/components/uni-list.vue';
  31. import uniCell from '@/components/uni-cell.vue';
  32. import uniRefresh from '@/components/uni-refresh.vue';
  33. import uniLoadMore from '@/components/uni-load-more.vue';
  34. import newsItem from './detailPage.nvue';
  35. import {
  36. getMessageList,
  37. readAll
  38. } from '@/common/api.js'
  39. export default {
  40. components: {
  41. uniList,
  42. uniCell,
  43. uniRefresh,
  44. uniLoadMore,
  45. newsItem
  46. },
  47. props: {
  48. nid: {
  49. type: [Number, String],
  50. default: ''
  51. },
  52. },
  53. data() {
  54. return {
  55. searchContent: "",
  56. dataList: [],
  57. navigateFlag: false,
  58. pulling: false,
  59. refreshing: false,
  60. refreshFlag: false,
  61. refreshText: "",
  62. isLoading: false,
  63. loadingText: '加载中...',
  64. isNoData: false,
  65. pulling: false,
  66. angle: 0,
  67. loadingMoreText: {
  68. contentdown: '',
  69. contentrefresh: '',
  70. contentnomore: ''
  71. },
  72. requestParams: {},
  73. refreshIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB5QTFRFcHBw3Nzct7e39vb2ycnJioqK7e3tpqam29vb////D8oK7wAAAAp0Uk5T////////////ALLMLM8AAABxSURBVHja7JVBDoAgDASrjqj//7CJBi90iyYeOHTPMwmFZrHjYyyFYYUy1bwUZqtJIYVxhf1a6u0R7iUvWsCcrEtwJHp8MwMdvh2amHduiZD3rpWId9+BgPd7Cc2LIkPyqvlQvKxKBJ//Qwq/CacAAwDUv0a0YuKhzgAAAABJRU5ErkJggg=="
  74. }
  75. },
  76. created() {
  77. this.pullTimer = null;
  78. this.requestParams = {
  79. pageIndex: 1,
  80. pageSize: 10,
  81. };
  82. uni.$on("readAll",() =>{
  83. if(this.isNoData) return
  84. readAll({
  85. userId: this.$store.state.Token
  86. }).then(res =>{
  87. this.pulling = true;
  88. this.refreshing = true;
  89. this.refreshText = "正在刷新...";
  90. this.clear()
  91. this.loadData(true);
  92. })
  93. })
  94. },
  95. methods: {
  96. loadData(refresh) {
  97. if (this.isLoading) {
  98. return;
  99. }
  100. this.isLoading = true;
  101. this.isNoData = false;
  102. getMessageList({
  103. ...this.requestParams,
  104. userId: this.$store.state.Token
  105. }, (e) => {
  106. this.isLoading = false;
  107. if (refresh) {
  108. this.refreshing = false;
  109. this.refreshFlag = false;
  110. this.refreshText = "已刷新";
  111. if (this.pullTimer) {
  112. clearTimeout(this.pullTimer);
  113. }
  114. this.pullTimer = setTimeout(() => {
  115. this.pulling = false;
  116. }, 1000);
  117. }
  118. }).then(result => {
  119. let data_list = result;
  120. if (data_list.length < 10) {
  121. this.loadingText = "没有更多了~"
  122. //#ifdef MP-WEIXIN
  123. this.isLoading = true
  124. //#endif
  125. }
  126. if (refresh) { //如果是刷新页面,清空数据
  127. this.dataList = data_list;
  128. this.requestParams.pageIndex = 1;
  129. } else { //加载更多
  130. this.dataList = this.dataList.concat(data_list);
  131. }
  132. if (this.dataList.length == 0) {
  133. this.isNoData = true
  134. this.loadingText = ""
  135. }
  136. }).catch(e => {
  137. })
  138. },
  139. loadMore(e) {
  140. if (this.isNoData) {
  141. return
  142. }
  143. ++this.requestParams.pageIndex;
  144. this.loadData();
  145. },
  146. clear() {
  147. this.dataList = [];
  148. this.loadingText = "加载中..."
  149. this.requestParams.pageIndex = 1;
  150. },
  151. goDetail(detail) {
  152. uni.navigateTo({
  153. url:'/pages/webview/newsDetail'
  154. })
  155. console.log(detail)
  156. uni.setStorageSync("newsDetailxjapp",detail)
  157. // uni.navigateTo({
  158. // url: `/pages/hybrid/index?url=notiveDetail`,
  159. // success: function(res) {
  160. // // 通过eventChannel向被打开页面传送数据
  161. // res.eventChannel.emit('acceptDataFromOpenerPage', {
  162. // value: detail.id
  163. // })
  164. // }
  165. // })
  166. detail.readFlag = 1
  167. },
  168. refreshData() {
  169. if (this.isLoading) {
  170. return;
  171. }
  172. this.pulling = true;
  173. this.refreshing = true;
  174. this.refreshText = "正在刷新...";
  175. this.clear()
  176. this.loadData(true);
  177. },
  178. onrefresh(e) {
  179. this.isNoData = false
  180. this.loadingText = "加载中..."
  181. this.refreshData();
  182. this.$refs.list.resetLoadmore();
  183. },
  184. onpullingdown(e) {
  185. if (this.refreshing) {
  186. return;
  187. }
  188. this.pulling = false;
  189. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  190. this.refreshFlag = true;
  191. this.refreshText = "释放立即刷新";
  192. } else {
  193. this.refreshFlag = false;
  194. this.refreshText = "下拉可以刷新";
  195. }
  196. },
  197. }
  198. }
  199. </script>
  200. <style scoped >
  201. .creatView {
  202. display: flex;
  203. justify-content: center;
  204. align-items: center;
  205. flex-direction: column;
  206. }
  207. .c-te{
  208. color: #0581FD;
  209. padding:30rpx;
  210. font-size: 30rpx;
  211. }
  212. .imsa {
  213. margin-top:260rpx;
  214. width: 387rpx;
  215. height: 200rpx;
  216. }
  217. .no-data {
  218. flex: 1;
  219. position: absolute;
  220. left: 0;
  221. top: 0;
  222. right: 0;
  223. bottom: 0;
  224. z-index: 10;
  225. }
  226. .page-news {
  227. flex: 1;
  228. flex-direction: column;
  229. position: absolute;
  230. left: 0;
  231. top: 0;
  232. right: 0;
  233. bottom: 0;
  234. }
  235. .listview {
  236. position: absolute;
  237. left: 0;
  238. background-color: #F9F9F9;
  239. top: 0;
  240. right: 0;
  241. bottom: 0;
  242. /* #ifndef APP-NVUE */
  243. display: flex;
  244. flex-direction: column;
  245. /* #endif */
  246. /* #ifndef MP-ALIPAY */
  247. flex-direction: column;
  248. /* #endif */
  249. }
  250. .refresh {
  251. justify-content: center;
  252. }
  253. .refresh-view {
  254. /* #ifndef APP-NVUE */
  255. display: flex;
  256. /* #endif */
  257. width: 750rpx;
  258. height: 64px;
  259. flex-direction: row;
  260. flex-wrap: nowrap;
  261. align-items: center;
  262. justify-content: center;
  263. }
  264. .refresh-icon {
  265. width: 32px;
  266. height: 32px;
  267. transition-duration: .5s;
  268. transition-property: transform;
  269. transform: rotate(0deg);
  270. transform-origin: 15px 15px;
  271. }
  272. .refresh-icon-active {
  273. transform: rotate(180deg);
  274. }
  275. .loading-icon {
  276. width: 28px;
  277. height: 28px;
  278. margin-right: 5px;
  279. color: gray;
  280. }
  281. .loading-text {
  282. margin-left: 2px;
  283. font-size: 16px;
  284. color: #999999;
  285. }
  286. .loading-more {
  287. align-items: center;
  288. justify-content: center;
  289. padding-top: 14px;
  290. padding-bottom: 14px;
  291. text-align: center;
  292. }
  293. .loading-more-text {
  294. font-size: 28upx;
  295. color: #999;
  296. }
  297. </style>