123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <template>
- <view class="page-news">
- <uni-list ref="list" class="listview" :enableBackToTop="true" :scroll-y="true" @scrolltolower="loadMore()">
- <uni-refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown"
- :display="refreshing ? 'show' : 'hide'">
- <div class="refresh-view">
- <image class="refresh-icon" :src="refreshIcon" :style="{width: (refreshing || pulling) ? 0: '32px'}"
- :class="{'refresh-icon-active': refreshFlag}"></image>
- <uni-load-more v-if="refreshing" class="loading-icon" status="loading"
- :contentText="loadingMoreText"></uni-load-more>
- <text class="loading-text">{{refreshText}}</text>
- </div>
- </uni-refresh>
- <uni-cell v-for="(item, index) in dataList" :key="item.id">
- <news-item :newsItem="item" :type="nid"></news-item>
- </uni-cell>
- <uni-cell>
- <view class="loading-more">
- <text class="loading-more-text">{{loadingText}}</text>
- </view>
- </uni-cell>
- </uni-list>
- </view>
- </template>
- <script>
- import uniList from '@/components/uni-list.vue';
- import uniCell from '@/components/uni-cell.vue';
- import uniRefresh from '@/components/uni-refresh.vue';
- import uniLoadMore from '@/components/uni-load-more.vue';
- import newsItem from './detailPage.nvue';
- import {
- getCheckData
- } from '@/common/api.js'
- export default {
- components: {
- uniList,
- uniCell,
- uniRefresh,
- uniLoadMore,
- newsItem
- },
- props: {
- nid: {
- type: [Number, String],
- default: ''
- },
- },
- data() {
- return {
- searchContent: "",
- dataList: [],
- navigateFlag: false,
- pulling: false,
- refreshing: false,
- refreshFlag: false,
- refreshText: "",
- isLoading: false,
- loadingText: '加载中...',
- isNoData: false,
- pulling: false,
- angle: 0,
- taskId: "",
- runTimes: "",
- loadingMoreText: {
- contentdown: '',
- contentrefresh: '',
- contentnomore: ''
- },
- requestParams: {},
- refreshIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB5QTFRFcHBw3Nzct7e39vb2ycnJioqK7e3tpqam29vb////D8oK7wAAAAp0Uk5T////////////ALLMLM8AAABxSURBVHja7JVBDoAgDASrjqj//7CJBi90iyYeOHTPMwmFZrHjYyyFYYUy1bwUZqtJIYVxhf1a6u0R7iUvWsCcrEtwJHp8MwMdvh2amHduiZD3rpWId9+BgPd7Cc2LIkPyqvlQvKxKBJ//Qwq/CacAAwDUv0a0YuKhzgAAAABJRU5ErkJggg=="
- }
- },
- created() {
- this.pullTimer = null;
- this.requestParams = {
- flag: this.nid,
- currentPage: 1,
- pageSize: 10,
- };
- this.taskId = uni.getStorageSync("xjapptaskId").taskId
- this.runTimes = uni.getStorageSync("xjapptaskId").runTimes
- },
- methods: {
- loadData(refresh) {
- if (this.isLoading) {
- return;
- }
- this.isLoading = true;
- this.isNoData = false;
- getCheckData({
- ...this.requestParams,
- taskId: this.taskId,
- runTimes: this.runTimes,
- pageIndex: this.requestParams.currentPage,
- }, (e) => {
- this.isLoading = false;
- if (refresh) {
- this.refreshing = false;
- this.refreshFlag = false;
- this.refreshText = "已刷新";
- if (this.pullTimer) {
- clearTimeout(this.pullTimer);
- }
- this.pullTimer = setTimeout(() => {
- this.pulling = false;
- }, 1000);
- }
- }).then(result => {
- const data_list = result;
- if (data_list.length < 10) {
- this.loadingText = "没有更多了~"
- this.isNoData = true;
- //#ifdef MP-WEIXIN
- this.isLoading = true
- //#endif
- }
- if (refresh) { //如果是刷新页面,清空数据
- this.dataList = data_list;
- this.requestParams.currentPage = 1;
- } else { //加载更多
- this.dataList = this.dataList.concat(data_list);
- }
- }).catch(e => {
- })
- },
- loadMore(e) {
- if (this.isNoData) {
- return
- }
- ++this.requestParams.currentPage;
- this.loadData();
- },
- clear() {
- this.dataList = [];
- this.loadingText = "加载中..."
- this.requestParams.currentPage = 1;
- },
- goDetail(detail) {
- if (this.nid == 0) {
- uni.navigateTo({
- url: `/pages/webview/work/detail?id=${detail.id}&watched=true`
- })
- } else if (this.nid == 1) {
- uni.navigateTo({
- url: `/pages/webview/work/faultDetail?id=${detail.id}`
- })
- }
- },
- refreshData() {
- if (this.isLoading) {
- return;
- }
- this.pulling = true;
- this.refreshing = true;
- this.refreshText = "正在刷新...";
- this.clear()
- this.loadData(true);
- },
- onrefresh(e) {
- this.isNoData = false
- this.loadingText = "加载中..."
- this.refreshData();
- this.$refs.list.resetLoadmore();
- },
- onpullingdown(e) {
- if (this.refreshing) {
- return;
- }
- this.pulling = false;
- if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
- this.refreshFlag = true;
- this.refreshText = "释放立即刷新";
- } else {
- this.refreshFlag = false;
- this.refreshText = "下拉可以刷新";
- }
- },
- newGuid() {
- let s4 = function() {
- return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
- }
- return (s4() + s4() + "-" + s4() + "-4" + s4().substr(0, 3) + "-" + s4() + "-" + s4() + s4() + s4())
- .toUpperCase();
- }
- }
- }
- </script>
- <style scoped>
- .no-data {
- flex: 1;
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- z-index: 10;
- }
- .page-news {
- flex: 1;
- flex-direction: column;
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- }
- .listview {
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- /* #ifndef APP-NVUE */
- display: flex;
- flex-direction: column;
- /* #endif */
- /* #ifndef MP-ALIPAY */
- flex-direction: column;
- /* #endif */
- }
- .refresh {
- justify-content: center;
- }
- .refresh-view {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- width: 750rpx;
- height: 64px;
- flex-direction: row;
- flex-wrap: nowrap;
- align-items: center;
- justify-content: center;
- }
- .refresh-icon {
- width: 32px;
- height: 32px;
- transition-duration: .5s;
- transition-property: transform;
- transform: rotate(0deg);
- transform-origin: 15px 15px;
- }
- .refresh-icon-active {
- transform: rotate(180deg);
- }
- .loading-icon {
- width: 28px;
- height: 28px;
- margin-right: 5px;
- color: gray;
- }
- .loading-text {
- margin-left: 2px;
- font-size: 16px;
- color: #999999;
- }
- .loading-more {
- align-items: center;
- justify-content: center;
- padding-top: 14px;
- padding-bottom: 14px;
- text-align: center;
- }
- .loading-more-text {
- font-size: 28upx;
- color: #999;
- }
- </style>
|