提交 ff31beac 编写于 作者: H hdx

long-list: 增加 loading

上级 237456bc
<template> <template>
<list-view class="list" ref="listView" @scroll="onScroll" @scrolltolower="loadData"> <list-view class="list" ref="listView" @scrolltolower="loadData">
<list-item class="list-item" v-for="(item, index) in dataList" :key="index"> <template v-for="(item, index) in dataList" :key="index">
<view class="list-item-icon"> <list-item class="list-item">
<image class="list-item-icon-image" :src="item.plugin_img_link"></image> <view class="list-item-icon">
</view> <image class="list-item-icon-image" :src="item.plugin_img_link"></image>
<view class="list-item-fill">
<view class="flex-row">
<text class="title">{{item.plugin_name}}</text>
</view> </view>
<view class="description"> <view class="list-item-fill">
<text class="description-text">{{item.plugin_intro}}</text> <view class="flex-row">
<text class="title">{{item.plugin_name}}</text>
</view>
<view class="description">
<text class="description-text">{{item.plugin_intro}}</text>
</view>
<text class="icon-star star">{{convertToStarUnicode(item.score)}}</text>
<view class="tag-list">
<text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2}}</text>
</view>
<view class="flex-row update-date">
<text class="update-date-text">更新日期</text>
<text class="update-date-value">{{item.update_date}}</text>
<text class="author">{{item.author_name}}</text>
</view>
</view> </view>
<text class="icon-star star">{{convertToStarUnicode(item.score)}}</text> </list-item>
<view class="tag-list"> <!-- TODO 暂时这样写才能保证 loading 在 list 底部 -->
<text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2}}</text> <list-item key="loading" v-if="index==dataList.length-1">
</view> <text class="loading">{{loadingText}}</text>
<view class="flex-row update-date"> </list-item>
<text class="update-date-text">更新日期</text> </template>
<text class="update-date-value">{{item.update_date}}</text>
<text class="author">{{item.author_name}}</text>
</view>
</view>
</list-item>
</list-view> </list-view>
</template> </template>
...@@ -57,9 +63,23 @@ ...@@ -57,9 +63,23 @@
loading: false, loading: false,
dataList: [] as ListItem[], dataList: [] as ListItem[],
isEnded: false, isEnded: false,
loadingError: '',
$currentPage: 0 $currentPage: 0
} }
}, },
computed: {
loadingText() : string {
if (this.loading) {
return "加载中..."
} else if (this.isEnded) {
return "没有更多了"
} else if (this.loadingError.length > 0) {
return this.loadingError
} else {
return ""
}
}
},
mounted() { mounted() {
uni.loadFontFace({ uni.loadFontFace({
global: false, global: false,
...@@ -105,7 +125,7 @@ ...@@ -105,7 +125,7 @@
} }
}, },
fail: (err) => { fail: (err) => {
console.log(err) this.loadingError = err.errMsg
}, },
complete: () => { complete: () => {
this.loading = false this.loading = false
...@@ -128,10 +148,6 @@ ...@@ -128,10 +148,6 @@
if (nullStarCount > 0) { result += null_code.repeat(nullStarCount) } if (nullStarCount > 0) { result += null_code.repeat(nullStarCount) }
return result return result
},
onScroll(e : ScrollEvent) {
// TODO e.detail.deltaY 值不正确
this.$emit('pageScroll', e.detail.deltaY)
} }
} }
} }
...@@ -215,4 +231,10 @@ ...@@ -215,4 +231,10 @@
color: #008000; color: #008000;
margin-left: auto; margin-left: auto;
} }
.loading {
padding: 20px;
text-align: center;
background-color: #f8f8f8;
}
</style> </style>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<view class="swiper-tabs-item" v-for="(item, index) in swiperList" :id="'swipertab' + index" ref="swipertab" <view class="swiper-tabs-item" v-for="(item, index) in swiperList" :id="'swipertab' + index" ref="swipertab"
:key="index" @click="onTabClick(index)"> :key="index" @click="onTabClick(index)">
<text class="swiper-tabs-item-text" <text class="swiper-tabs-item-text"
:class="swiperIndex==index ? 'uni-tab-item-title-active' : ''">{{item.name}}</text> :class="swiperIndex==index ? 'swiper-tabs-item-text-active' : ''">{{item.name}}</text>
</view> </view>
</view> </view>
<view class="swiper-tabs-indicator"> <view class="swiper-tabs-indicator">
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange" <swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange"
@transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish"> @transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish">
<swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index"> <swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index">
<long-page ref="longPage" :type="item.type" @pageScroll="onSwiperItemPageScroll"></long-page> <long-page ref="longPage" :type="item.type"></long-page>
</swiper-item> </swiper-item>
</swiper> </swiper>
</view> </view>
...@@ -120,17 +120,9 @@ ...@@ -120,17 +120,9 @@
//console.log(this.$lastSwiperIndex, moveToIndex, offsetX, this.$swiperWidth, percentage); //console.log(this.$lastSwiperIndex, moveToIndex, offsetX, this.$swiperWidth, percentage);
}, },
onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) { onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
this.$lastSwiperIndex = e.detail.current;
// console.log("onSwiperAnimationfinish", e.detail.current); // console.log("onSwiperAnimationfinish", e.detail.current);
// this.setSwiperIndex(e.detail.current, true); this.$lastSwiperIndex = e.detail.current
}, this.setSwiperIndex(e.detail.current, true)
onSwiperItemPageScroll(dy : number) {
let top = this.pageScrollTop + dy
if (top > this.$headerHeight) { top = this.$headerHeight }
if (top < 0) { top = 0 }
this.pageScrollTop = top
}, },
queryTabItemsSize() { queryTabItemsSize() {
this.$swiperTabsRect.length = 0; this.$swiperTabsRect.length = 0;
...@@ -186,7 +178,8 @@ ...@@ -186,7 +178,8 @@
} }
.swiper-list { .swiper-list {
height: 100%; flex: 1;
/* height: 100%; */
} }
.swiper-tabs { .swiper-tabs {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册