itemPage.nvue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="page-news">
  3. <uni-list ref="list" class="listview" :Showscrollbar="true" :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 id="loading-more" 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. getReadNum
  39. } from '@/common/api.js'
  40. export default {
  41. components: {
  42. uniList,
  43. uniCell,
  44. uniRefresh,
  45. uniLoadMore,
  46. newsItem
  47. },
  48. props: {
  49. nid: {
  50. type: [Number, String],
  51. default: ''
  52. },
  53. },
  54. data() {
  55. return {
  56. searchContent: "",
  57. dataList: [],
  58. navigateFlag: false,
  59. pulling: false,
  60. refreshing: false,
  61. refreshFlag: false,
  62. refreshText: "",
  63. isLoading: false,
  64. loadingText: '加载中...',
  65. isNoData: false,
  66. pulling: false,
  67. angle: 0,
  68. loadingMoreText: {
  69. contentdown: '',
  70. contentrefresh: '',
  71. contentnomore: ''
  72. },
  73. requestParams: {},
  74. refreshIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB5QTFRFcHBw3Nzct7e39vb2ycnJioqK7e3tpqam29vb////D8oK7wAAAAp0Uk5T////////////ALLMLM8AAABxSURBVHja7JVBDoAgDASrjqj//7CJBi90iyYeOHTPMwmFZrHjYyyFYYUy1bwUZqtJIYVxhf1a6u0R7iUvWsCcrEtwJHp8MwMdvh2amHduiZD3rpWId9+BgPd7Cc2LIkPyqvlQvKxKBJ//Qwq/CacAAwDUv0a0YuKhzgAAAABJRU5ErkJggg=="
  75. }
  76. },
  77. onShow() {
  78. this.loadData(true);
  79. },
  80. created() {
  81. var that = this;
  82. /* setInterval(function(){
  83. if(uni.getStorageSync("getRealNews")==1){
  84. console.log("+++++++++实时告警请求--------------")
  85. that.requestParams.pageIndex = 1;
  86. that.loadData(true);
  87. }
  88. },5000) */
  89. this.pullTimer = null;
  90. this.requestParams = {
  91. pageIndex: 1,
  92. pageSize: 10,
  93. };
  94. uni.$on("readAll",() =>{
  95. if(this.isNoData) return
  96. readAll({
  97. userId: this.$store.state.Token
  98. }).then(res =>{
  99. this.pulling = true;
  100. this.refreshing = true;
  101. this.refreshText = "正在刷新...";
  102. this.clear()
  103. this.loadData(true);
  104. })
  105. })
  106. },
  107. onPageScroll(e){ //根据距离顶部距离是否显示回到顶部按钮
  108. console.log(111111111111)
  109. if(e.scrollTop>600){ //当距离大于600时显示回到顶部按钮
  110. this.topState = true
  111. }else{ //当距离小于600时显示回到顶部按钮
  112. console.log(111111111111)
  113. this.topState = false
  114. }
  115. },
  116. methods: {
  117. loadData(refresh) {
  118. if (this.isLoading) {
  119. return;
  120. }
  121. this.isLoading = true;
  122. this.isNoData = false;
  123. getReadNum({
  124. userId: this.$store.state.Token
  125. }).then(res => {
  126. if(res==0){
  127. uni.hideTabBarRedDot({ //隐藏红点
  128. index: 2
  129. })
  130. }else{
  131. uni.showTabBarRedDot({ //显示红点
  132. index: 2
  133. })
  134. }
  135. }).catch(e => {
  136. console.log(e)
  137. })
  138. getMessageList({
  139. ...this.requestParams,
  140. userId: this.$store.state.Token
  141. }, (e) => {
  142. this.isLoading = false;
  143. if (refresh) {
  144. this.refreshing = false;
  145. this.refreshFlag = false;
  146. this.refreshText = "已刷新";
  147. if (this.pullTimer) {
  148. clearTimeout(this.pullTimer);
  149. }
  150. this.pullTimer = setTimeout(() => {
  151. this.pulling = false;
  152. }, 500);
  153. }
  154. }).then(result => {
  155. let data_list = result;
  156. if (data_list.length < 10) {
  157. this.loadingText = "没有更多了~"
  158. //#ifdef MP-WEIXIN
  159. this.isLoading = true
  160. //#endif
  161. }
  162. if (refresh) { //如果是刷新页面,清空数据
  163. this.dataList = data_list;
  164. this.requestParams.pageIndex = 1;
  165. } else { //加载更多
  166. this.dataList = this.dataList.concat(data_list);
  167. }
  168. if (this.dataList.length == 0) {
  169. this.isNoData = true
  170. this.loadingText = ""
  171. }
  172. }).catch(e => {
  173. })
  174. },
  175. loadMore(e) {
  176. if (this.isNoData) {
  177. return
  178. }
  179. ++this.requestParams.pageIndex;
  180. this.loadData();
  181. let info = uni.createSelectorQuery().select("#loading-more");
  182.     info.boundingClientRect(function(data) { //data - 各种参数
  183. console.log(data.top)
  184.    }).exec() 
  185. },
  186. clear() {
  187. this.dataList = [];
  188. this.loadingText = "加载中..."
  189. this.requestParams.pageIndex = 1;
  190. },
  191. goDetail(detail) {
  192. var that = this
  193. uni.navigateTo({
  194. url:'/pages/webview/newsDetail'
  195. })
  196. console.log(detail)
  197. uni.setStorageSync("newsDetailxjapp",detail)
  198. // uni.navigateTo({
  199. // url: `/pages/hybrid/index?url=notiveDetail`,
  200. // success: function(res) {
  201. // // 通过eventChannel向被打开页面传送数据
  202. // res.eventChannel.emit('acceptDataFromOpenerPage', {
  203. // value: detail.id
  204. // })
  205. // }
  206. // })
  207. detail.readFlag = 1
  208. getReadNum({
  209. userId: that.$store.state.Token
  210. }).then(res => {
  211. if(res==0){
  212. uni.hideTabBarRedDot({ //隐藏红点
  213. index: 2
  214. })
  215. }else{
  216. uni.showTabBarRedDot({ //显示红点
  217. index: 2
  218. })
  219. }
  220. }).catch(e => {
  221. console.log(e)
  222. })
  223. },
  224. refreshData() {
  225. if (this.isLoading) {
  226. return;
  227. }
  228. this.pulling = true;
  229. this.refreshing = true;
  230. this.refreshText = "正在刷新...";
  231. this.clear()
  232. this.loadData(true);
  233. },
  234. onrefresh(e) {
  235. this.isNoData = false
  236. this.loadingText = "加载中..."
  237. this.refreshData();
  238. this.$refs.list.resetLoadmore();
  239. },
  240. onpullingdown(e) {
  241. if (this.refreshing) {
  242. return;
  243. }
  244. this.pulling = false;
  245. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  246. this.refreshFlag = true;
  247. this.refreshText = "释放立即刷新";
  248. } else {
  249. this.refreshFlag = false;
  250. this.refreshText = "下拉可以刷新";
  251. }
  252. },
  253. }
  254. }
  255. </script>
  256. <style scoped >
  257. .creatView {
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. flex-direction: column;
  262. }
  263. .c-te{
  264. color: #0581FD;
  265. padding:30rpx;
  266. font-size: 30rpx;
  267. }
  268. .imsa {
  269. margin-top:260rpx;
  270. width: 387rpx;
  271. height: 200rpx;
  272. }
  273. .no-data {
  274. flex: 1;
  275. position: absolute;
  276. left: 0;
  277. top: 0;
  278. right: 0;
  279. bottom: 0;
  280. z-index: 10;
  281. }
  282. .page-news {
  283. flex: 1;
  284. flex-direction: column;
  285. position: absolute;
  286. left: 0;
  287. top: 0;
  288. right: 0;
  289. bottom: 0;
  290. }
  291. .listview {
  292. position: absolute;
  293. left: 0;
  294. background-color: #F9F9F9;
  295. top: 0;
  296. right: 0;
  297. bottom: 0;
  298. /* #ifndef APP-NVUE */
  299. display: flex;
  300. flex-direction: column;
  301. /* #endif */
  302. /* #ifndef MP-ALIPAY */
  303. flex-direction: column;
  304. /* #endif */
  305. }
  306. .refresh {
  307. justify-content: center;
  308. }
  309. .refresh-view {
  310. /* #ifndef APP-NVUE */
  311. display: flex;
  312. /* #endif */
  313. width: 750rpx;
  314. height: 64px;
  315. flex-direction: row;
  316. flex-wrap: nowrap;
  317. align-items: center;
  318. justify-content: center;
  319. }
  320. .refresh-icon {
  321. width: 32px;
  322. height: 32px;
  323. transition-duration: .5s;
  324. transition-property: transform;
  325. transform: rotate(0deg);
  326. transform-origin: 15px 15px;
  327. }
  328. .refresh-icon-active {
  329. transform: rotate(180deg);
  330. }
  331. .loading-icon {
  332. width: 28px;
  333. height: 28px;
  334. margin-right: 5px;
  335. color: gray;
  336. }
  337. .loading-text {
  338. margin-left: 2px;
  339. font-size: 16px;
  340. color: #999999;
  341. }
  342. .loading-more {
  343. align-items: center;
  344. justify-content: center;
  345. padding-top: 14px;
  346. padding-bottom: 14px;
  347. text-align: center;
  348. }
  349. .loading-more-text {
  350. font-size: 28upx;
  351. color: #999;
  352. }
  353. </style>