itemPage.nvue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="page-news">
  3. <uni-list ref="list" class="listview" :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" :type="nid"></news-item>
  16. </uni-cell>
  17. <uni-cell>
  18. <view class="loading-more">
  19. <text class="loading-more-text">{{loadingText}}</text>
  20. </view>
  21. </uni-cell>
  22. </uni-list>
  23. </view>
  24. </template>
  25. <script>
  26. import uniList from '@/components/uni-list.vue';
  27. import uniCell from '@/components/uni-cell.vue';
  28. import uniRefresh from '@/components/uni-refresh.vue';
  29. import uniLoadMore from '@/components/uni-load-more.vue';
  30. import newsItem from './detailPage.nvue';
  31. import {
  32. getCheckData
  33. } from '@/common/api.js'
  34. export default {
  35. components: {
  36. uniList,
  37. uniCell,
  38. uniRefresh,
  39. uniLoadMore,
  40. newsItem
  41. },
  42. props: {
  43. nid: {
  44. type: [Number, String],
  45. default: ''
  46. },
  47. },
  48. data() {
  49. return {
  50. searchContent: "",
  51. dataList: [],
  52. navigateFlag: false,
  53. pulling: false,
  54. refreshing: false,
  55. refreshFlag: false,
  56. refreshText: "",
  57. isLoading: false,
  58. loadingText: '加载中...',
  59. isNoData: false,
  60. pulling: false,
  61. angle: 0,
  62. taskId: "",
  63. runTimes: "",
  64. loadingMoreText: {
  65. contentdown: '',
  66. contentrefresh: '',
  67. contentnomore: ''
  68. },
  69. requestParams: {},
  70. refreshIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB5QTFRFcHBw3Nzct7e39vb2ycnJioqK7e3tpqam29vb////D8oK7wAAAAp0Uk5T////////////ALLMLM8AAABxSURBVHja7JVBDoAgDASrjqj//7CJBi90iyYeOHTPMwmFZrHjYyyFYYUy1bwUZqtJIYVxhf1a6u0R7iUvWsCcrEtwJHp8MwMdvh2amHduiZD3rpWId9+BgPd7Cc2LIkPyqvlQvKxKBJ//Qwq/CacAAwDUv0a0YuKhzgAAAABJRU5ErkJggg=="
  71. }
  72. },
  73. created() {
  74. this.pullTimer = null;
  75. this.requestParams = {
  76. flag: this.nid,
  77. currentPage: 1,
  78. pageSize: 10,
  79. };
  80. this.taskId = uni.getStorageSync("xjapptaskId").taskId
  81. this.runTimes = uni.getStorageSync("xjapptaskId").runTimes
  82. },
  83. methods: {
  84. loadData(refresh) {
  85. if (this.isLoading) {
  86. return;
  87. }
  88. this.isLoading = true;
  89. this.isNoData = false;
  90. getCheckData({
  91. ...this.requestParams,
  92. taskId: this.taskId,
  93. runTimes: this.runTimes,
  94. pageIndex: this.requestParams.currentPage,
  95. }, (e) => {
  96. this.isLoading = false;
  97. if (refresh) {
  98. this.refreshing = false;
  99. this.refreshFlag = false;
  100. this.refreshText = "已刷新";
  101. if (this.pullTimer) {
  102. clearTimeout(this.pullTimer);
  103. }
  104. this.pullTimer = setTimeout(() => {
  105. this.pulling = false;
  106. }, 1000);
  107. }
  108. }).then(result => {
  109. const data_list = result;
  110. if (data_list.length < 10) {
  111. this.loadingText = "没有更多了~"
  112. this.isNoData = true;
  113. //#ifdef MP-WEIXIN
  114. this.isLoading = true
  115. //#endif
  116. }
  117. if (refresh) { //如果是刷新页面,清空数据
  118. this.dataList = data_list;
  119. this.requestParams.currentPage = 1;
  120. } else { //加载更多
  121. this.dataList = this.dataList.concat(data_list);
  122. }
  123. }).catch(e => {
  124. })
  125. },
  126. loadMore(e) {
  127. if (this.isNoData) {
  128. return
  129. }
  130. ++this.requestParams.currentPage;
  131. this.loadData();
  132. },
  133. clear() {
  134. this.dataList = [];
  135. this.loadingText = "加载中..."
  136. this.requestParams.currentPage = 1;
  137. },
  138. goDetail(detail) {
  139. if (this.nid == 0) {
  140. uni.navigateTo({
  141. url: `/pages/webview/work/detail?id=${detail.id}&watched=true`
  142. })
  143. } else if (this.nid == 1) {
  144. uni.navigateTo({
  145. url: `/pages/webview/work/faultDetail?id=${detail.id}`
  146. })
  147. }
  148. },
  149. refreshData() {
  150. if (this.isLoading) {
  151. return;
  152. }
  153. this.pulling = true;
  154. this.refreshing = true;
  155. this.refreshText = "正在刷新...";
  156. this.clear()
  157. this.loadData(true);
  158. },
  159. onrefresh(e) {
  160. this.isNoData = false
  161. this.loadingText = "加载中..."
  162. this.refreshData();
  163. this.$refs.list.resetLoadmore();
  164. },
  165. onpullingdown(e) {
  166. if (this.refreshing) {
  167. return;
  168. }
  169. this.pulling = false;
  170. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  171. this.refreshFlag = true;
  172. this.refreshText = "释放立即刷新";
  173. } else {
  174. this.refreshFlag = false;
  175. this.refreshText = "下拉可以刷新";
  176. }
  177. },
  178. newGuid() {
  179. let s4 = function() {
  180. return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
  181. }
  182. return (s4() + s4() + "-" + s4() + "-4" + s4().substr(0, 3) + "-" + s4() + "-" + s4() + s4() + s4())
  183. .toUpperCase();
  184. }
  185. }
  186. }
  187. </script>
  188. <style scoped>
  189. .no-data {
  190. flex: 1;
  191. position: absolute;
  192. left: 0;
  193. top: 0;
  194. right: 0;
  195. bottom: 0;
  196. z-index: 10;
  197. }
  198. .page-news {
  199. flex: 1;
  200. flex-direction: column;
  201. position: absolute;
  202. left: 0;
  203. top: 0;
  204. right: 0;
  205. bottom: 0;
  206. }
  207. .listview {
  208. position: absolute;
  209. left: 0;
  210. top: 0;
  211. right: 0;
  212. bottom: 0;
  213. /* #ifndef APP-NVUE */
  214. display: flex;
  215. flex-direction: column;
  216. /* #endif */
  217. /* #ifndef MP-ALIPAY */
  218. flex-direction: column;
  219. /* #endif */
  220. }
  221. .refresh {
  222. justify-content: center;
  223. }
  224. .refresh-view {
  225. /* #ifndef APP-NVUE */
  226. display: flex;
  227. /* #endif */
  228. width: 750rpx;
  229. height: 64px;
  230. flex-direction: row;
  231. flex-wrap: nowrap;
  232. align-items: center;
  233. justify-content: center;
  234. }
  235. .refresh-icon {
  236. width: 32px;
  237. height: 32px;
  238. transition-duration: .5s;
  239. transition-property: transform;
  240. transform: rotate(0deg);
  241. transform-origin: 15px 15px;
  242. }
  243. .refresh-icon-active {
  244. transform: rotate(180deg);
  245. }
  246. .loading-icon {
  247. width: 28px;
  248. height: 28px;
  249. margin-right: 5px;
  250. color: gray;
  251. }
  252. .loading-text {
  253. margin-left: 2px;
  254. font-size: 16px;
  255. color: #999999;
  256. }
  257. .loading-more {
  258. align-items: center;
  259. justify-content: center;
  260. padding-top: 14px;
  261. padding-bottom: 14px;
  262. text-align: center;
  263. }
  264. .loading-more-text {
  265. font-size: 28upx;
  266. color: #999;
  267. }
  268. </style>