提交 a377db11 编写于 作者: H hdx

long-list: TODO add loading

上级 8743372d
<template> <template>
<list-view ref="listView" class="list" :rebound="false" :scroll-y="true" :custom-nested-scroll="true" <list-view ref="listView" class="list" :rebound="false" :scroll-y="true" :custom-nested-scroll="true"
@scrolltolower="loadData(null)"> @scrolltolower="loadData(null)">
<!-- TODO 暂时这样写才能保证 loading 在 list 底部 --> <list-item class="list-item" v-for="(item, _) in dataList" :key="item.plugin_id">
<template v-for="(item, index) in dataList" :key="index">
<list-item class="list-item">
<view class="list-item-icon"> <view class="list-item-icon">
<image class="list-item-icon-image" :src="item.plugin_img_link"></image> <image class="list-item-icon-image" :src="item.plugin_img_link"></image>
</view> </view>
...@@ -14,7 +12,7 @@ ...@@ -14,7 +12,7 @@
<view class="description"> <view class="description">
<text class="description-text">{{item.plugin_intro}}</text> <text class="description-text">{{item.plugin_intro}}</text>
</view> </view>
<text class="font-star icon-star">{{convertToStarUnicode(item.score)}}</text> <text class="icon-star">{{convertToStarUnicode(item.score)}}</text>
<view class="tag-list"> <view class="tag-list">
<text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2}}</text> <text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2}}</text>
</view> </view>
...@@ -24,12 +22,11 @@ ...@@ -24,12 +22,11 @@
<text class="author">{{item.author_name}}</text> <text class="author">{{item.author_name}}</text>
</view> </view>
</view> </view>
<!-- TODO 暂时这样写才能保证 loading 在 list 底部 -->
<view v-if="item.plugin_id==-1" class="loading">
<text class="loading-text">{{loadingText}}</text>
</view>
</list-item> </list-item>
<!-- TODO 暂时注释,否者在清空数据时引发异常 -->
<!-- <list-item v-if="index==dataList.length-1" key="loading">
<text class="loading">{{loadingText}}</text>
</list-item> -->
</template>
</list-view> </list-view>
</template> </template>
...@@ -87,21 +84,32 @@ ...@@ -87,21 +84,32 @@
}, },
}, },
created() { created() {
// TODO 后续通过css加载本地路径 this.insertLoadingData()
uni.loadFontFace({
global: false,
family: 'UtsIconsFontFamily',
source: '/static/fonts/icon-star.ttf'
})
if (this.preload) { if (this.preload) {
this.loadData(null) this.loadData(null)
} }
}, },
methods: { methods: {
// TODO 目前 list-item 不支持注释节点
// 暂时在数据末尾插入一条空数据用于显示 loading
insertLoadingData() {
const loadingData = {
plugin_id: -1,
plugin_img_link: '',
plugin_name: '',
plugin_intro: '',
score: 0,
tags: [],
update_date: '',
author_name: '',
} as ListItem
this.dataList.push(loadingData)
},
refreshData(loadComplete : (() => void) | null) { refreshData(loadComplete : (() => void) | null) {
this.dataList.length = 0 this.dataList.length = 0
this.$currentPage = 1 this.$currentPage = 1
this.insertLoadingData()
this.loadData(loadComplete) this.loadData(loadComplete)
}, },
loadData(loadComplete : (() => void) | null) { loadData(loadComplete : (() => void) | null) {
...@@ -123,7 +131,9 @@ ...@@ -123,7 +131,9 @@
return return
} }
this.dataList.push(...responseData.data) // TODO
this.dataList.splice(this.dataList.length - 1, 0, ...responseData.data)
// this.dataList.push(...responseData.data)
if (responseData.data.length == 0) { if (responseData.data.length == 0) {
this.isEnded = true this.isEnded = true
...@@ -164,12 +174,11 @@ ...@@ -164,12 +174,11 @@
</script> </script>
<style> <style>
.font-star { /* TODO 暂时写到了页面 long-list */
font-family: "UtsIconsFontFamily" !important; /* @font-face {
/* src: url('~@/static/fonts/icon-star.ttf') format('truetype'); */ font-family: "UtsStarIcons";
font-size: 16px; src: url('@/static/fonts/icon-star.ttf');
font-style: normal; } */
}
.list { .list {
flex: 1; flex: 1;
...@@ -196,10 +205,6 @@ ...@@ -196,10 +205,6 @@
margin-left: 15px; margin-left: 15px;
} }
.description {
/* line-height: 14px; */
}
.description-text { .description-text {
font-size: 13px; font-size: 13px;
color: #666; color: #666;
...@@ -207,6 +212,9 @@ ...@@ -207,6 +212,9 @@
} }
.icon-star { .icon-star {
font-family: "UtsStarIcons";
font-size: 16px;
font-style: normal;
color: #ffca3e; color: #ffca3e;
letter-spacing: 3px; letter-spacing: 3px;
} }
...@@ -247,9 +255,18 @@ ...@@ -247,9 +255,18 @@
} }
.loading { .loading {
padding: 20px; position: absolute;
text-align: center; left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: #f8f8f8; background-color: #f8f8f8;
margin-bottom: 1px; margin-bottom: 1px;
justify-content: center;
}
.loading-text {
padding: 20px;
text-align: center;
} }
</style> </style>
\ No newline at end of file
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
const deltaY = event.deltaY const deltaY = event.deltaY
const scrollTop = this.$pageScrollView!.scrollTop const scrollTop = this.$pageScrollView!.scrollTop
/// 优先处理父容器滚动,父容器不能滚动时滚动子 /// 优先处理父容器滚动,父容器不能滚动时滚动子
// 向上滚动 // 向上滚动
if (deltaY > 0) { if (deltaY > 0) {
// 如果父容器 header scrollTop < offsetHeight,先滚动父容器 // 如果父容器 header scrollTop < offsetHeight,先滚动父容器
...@@ -220,6 +220,12 @@ ...@@ -220,6 +220,12 @@
</script> </script>
<style> <style>
/* TODO 应该写在 long-list-page */
@font-face {
font-family: "UtsStarIcons";
src: url('@/static/fonts/icon-star.ttf');
}
.flex-row { .flex-row {
flex-direction: row; flex-direction: row;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册