itemPage.nvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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.dataList.map((item) =>{
  88. item.readFlag = 1
  89. })
  90. console.log(res)
  91. })
  92. })
  93. },
  94. methods: {
  95. loadData(refresh) {
  96. if (this.isLoading) {
  97. return;
  98. }
  99. this.isLoading = true;
  100. this.isNoData = false;
  101. getMessageList({
  102. ...this.requestParams,
  103. userId: this.$store.state.Token
  104. }, (e) => {
  105. this.isLoading = false;
  106. if (refresh) {
  107. this.refreshing = false;
  108. this.refreshFlag = false;
  109. this.refreshText = "已刷新";
  110. if (this.pullTimer) {
  111. clearTimeout(this.pullTimer);
  112. }
  113. this.pullTimer = setTimeout(() => {
  114. this.pulling = false;
  115. }, 1000);
  116. }
  117. }).then(result => {
  118. let data_list = result;
  119. if (data_list.length < 10) {
  120. this.loadingText = "没有更多了~"
  121. //#ifdef MP-WEIXIN
  122. this.isLoading = true
  123. //#endif
  124. }
  125. if (refresh) { //如果是刷新页面,清空数据
  126. this.dataList = data_list;
  127. this.requestParams.pageIndex = 1;
  128. } else { //加载更多
  129. this.dataList = this.dataList.concat(data_list);
  130. }
  131. if (this.dataList.length == 0) {
  132. this.isNoData = true
  133. this.loadingText = ""
  134. }
  135. }).catch(e => {
  136. })
  137. },
  138. loadMore(e) {
  139. if (this.isNoData) {
  140. return
  141. }
  142. ++this.requestParams.pageIndex;
  143. this.loadData();
  144. },
  145. clear() {
  146. this.dataList = [];
  147. this.loadingText = "加载中..."
  148. this.requestParams.pageIndex = 1;
  149. },
  150. goDetail(detail) {
  151. uni.navigateTo({
  152. url:'/pages/webview/newsDetail'
  153. })
  154. console.log(detail)
  155. uni.setStorageSync("newsDetailxjapp",detail)
  156. // uni.navigateTo({
  157. // url: `/pages/hybrid/index?url=notiveDetail`,
  158. // success: function(res) {
  159. // // 通过eventChannel向被打开页面传送数据
  160. // res.eventChannel.emit('acceptDataFromOpenerPage', {
  161. // value: detail.id
  162. // })
  163. // }
  164. // })
  165. detail.readFlag = 1
  166. },
  167. refreshData() {
  168. if (this.isLoading) {
  169. return;
  170. }
  171. this.pulling = true;
  172. this.refreshing = true;
  173. this.refreshText = "正在刷新...";
  174. this.clear()
  175. this.loadData(true);
  176. },
  177. onrefresh(e) {
  178. this.isNoData = false
  179. this.loadingText = "加载中..."
  180. this.refreshData();
  181. this.$refs.list.resetLoadmore();
  182. },
  183. onpullingdown(e) {
  184. if (this.refreshing) {
  185. return;
  186. }
  187. this.pulling = false;
  188. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  189. this.refreshFlag = true;
  190. this.refreshText = "释放立即刷新";
  191. } else {
  192. this.refreshFlag = false;
  193. this.refreshText = "下拉可以刷新";
  194. }
  195. },
  196. }
  197. }
  198. </script>
  199. <style scoped >
  200. .creatView {
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. flex-direction: column;
  205. }
  206. .c-te{
  207. color: #0581FD;
  208. padding:30rpx;
  209. font-size: 30rpx;
  210. }
  211. .imsa {
  212. margin-top:260rpx;
  213. width: 387rpx;
  214. height: 200rpx;
  215. }
  216. .no-data {
  217. flex: 1;
  218. position: absolute;
  219. left: 0;
  220. top: 0;
  221. right: 0;
  222. bottom: 0;
  223. z-index: 10;
  224. }
  225. .page-news {
  226. flex: 1;
  227. flex-direction: column;
  228. position: absolute;
  229. left: 0;
  230. top: 0;
  231. right: 0;
  232. bottom: 0;
  233. }
  234. .listview {
  235. position: absolute;
  236. left: 0;
  237. background-color: #F9F9F9;
  238. top: 0;
  239. right: 0;
  240. bottom: 0;
  241. /* #ifndef APP-NVUE */
  242. display: flex;
  243. flex-direction: column;
  244. /* #endif */
  245. /* #ifndef MP-ALIPAY */
  246. flex-direction: column;
  247. /* #endif */
  248. }
  249. .refresh {
  250. justify-content: center;
  251. }
  252. .refresh-view {
  253. /* #ifndef APP-NVUE */
  254. display: flex;
  255. /* #endif */
  256. width: 750rpx;
  257. height: 64px;
  258. flex-direction: row;
  259. flex-wrap: nowrap;
  260. align-items: center;
  261. justify-content: center;
  262. }
  263. .refresh-icon {
  264. width: 32px;
  265. height: 32px;
  266. transition-duration: .5s;
  267. transition-property: transform;
  268. transform: rotate(0deg);
  269. transform-origin: 15px 15px;
  270. }
  271. .refresh-icon-active {
  272. transform: rotate(180deg);
  273. }
  274. .loading-icon {
  275. width: 28px;
  276. height: 28px;
  277. margin-right: 5px;
  278. color: gray;
  279. }
  280. .loading-text {
  281. margin-left: 2px;
  282. font-size: 16px;
  283. color: #999999;
  284. }
  285. .loading-more {
  286. align-items: center;
  287. justify-content: center;
  288. padding-top: 14px;
  289. padding-bottom: 14px;
  290. text-align: center;
  291. }
  292. .loading-more-text {
  293. font-size: 28upx;
  294. color: #999;
  295. }
  296. </style>