提交 9d21f4c5 编写于 作者: H hdx

long-list: 改为网络数据

上级 b9db0cd5
<template> <template>
<list-view class="list" @loadmore="loadData"> <list-view class="list" @scrolltolower="loadData">
<list-item class="list-item" v-for="(item, index) in dataList" :key="index"> <list-item class="list-item" v-for="(item, index) in dataList" :key="index">
<view class="list-item-icon"> <view class="list-item-icon">
<image class="list-item-icon-image" :src="item.image"></image> <image class="list-item-icon-image" :src="item.img"></image>
<text class="list-item-icon-index">{{item.index}}</text>
</view> </view>
<view class="list-item-fill"> <view class="list-item-fill">
<view class="flex-row"> <view class="flex-row">
<text class="title">{{item.title}}</text> <text class="title">{{item.name}}</text>
</view> </view>
<view class="description"> <view class="description">
<text class="description-text">{{item.description}}</text> <text class="description-text">{{item.intro}}</text>
</view> </view>
<view class="tag-list"> <!-- <view class="tag-list">
<text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2.name}}</text> <text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2.name}}</text>
</view> </view> -->
<!-- <uts-rate></uts-rate> --> <!-- <uts-rate></uts-rate> -->
<view class="flex-row update-date"> <view class="flex-row update-date">
<text class="update-date-text">更新日期</text> <text class="update-date-text">更新日期</text>
<text class="update-date-value">{{item.updateDate}}</text> <!-- <text class="update-date-value">{{item.updateDate}}</text> -->
<text class="author">Dcloud</text> <!-- <text class="author">Dcloud</text> -->
</view> </view>
</view> </view>
</list-item> </list-item>
...@@ -27,78 +26,73 @@ ...@@ -27,78 +26,73 @@
</template> </template>
<script> <script>
// 测试数据 - 标题 // TODO 临时地址
const TEST_DATA_TITLE_LIST = [ const SERVER_URL = "https://test-ext.dcloud.net.cn/plugin/plugin-list"
'升级中心 uni-upgrade-center', const PAGE_SIZE = 10; // 最大值 10
'schema2code',
'uni-sec-check',
'uni-starter',
'uni-admin 基础框架',
'有奖猜歌游戏',
'看图App模板',
'网赚游戏管理后台',
'云端一体搜索模板',
]
// 测试数据 - 标签
const TEST_DATA_TAG_LIST = [
'uni-ai-chat',
'gpt',
'chatgpt',
'openai',
]
type TagItem = {
index : string,
name : string
}
// TODO 暂不支持tag,更新日期等属性
type ListItem = { type ListItem = {
index : string, id : number,
image : string, img : string,
title : string, name : string,
description : string, intro : string,
tags : Array<TagItem>, // tags : Array<String>,
updateDate : string, // updateDate : string,
} }
export default { export default {
data() { data() {
return { return {
dataList: [] as ListItem[] loading: false,
dataList: [] as ListItem[],
isEnded: false,
$currentPage: 0
} }
}, },
onLoad() { onLoad() {
this.loadData() this.loadData()
}, },
methods: { methods: {
// 滚动到页面底部时调用
loadData() { loadData() {
let index = this.dataList.length if (this.loading || this.isEnded) {
return
}
// 生成 20 条测试数据, 随机标题、标签 this.loading = true;
const updateDate = new Date().toISOString().split('T')[0]
for (let i = 0; i < 20; i++) { uni.request({
// 标签 url: SERVER_URL,
let tags : TagItem[] = [] data: {
for (let j = 0; j < 3; j++) { page: this.$currentPage,
tags.push({ pageSize: PAGE_SIZE
index: i + '_' + j, },
name: TEST_DATA_TAG_LIST[parseInt((Math.random() * (TEST_DATA_TAG_LIST.length - 1)) + '')], success: (res) => {
} as TagItem) const responseData = res.data as UTSJSONObject
if (responseData['data'] == null) {
return;
} }
const responseDataList = responseData['data'] as UTSJSONObject[]
for (const item in responseDataList) {
this.dataList.push({ this.dataList.push({
index: index.toString(), id: item["id"] as number,
image: '/static/uni.png', img: 'https:' + item["img"] as string,
title: TEST_DATA_TITLE_LIST[parseInt((Math.random() * (TEST_DATA_TITLE_LIST.length - 1)) + '')], name: item["name"] as string,
description: '描述', intro: item["intro"] as string,
tags: tags,
updateDate
} as ListItem) } as ListItem)
}
this.isEnded = responseDataList.length <= 0;
index++ this.$currentPage++
},
fail: (err) => {
console.log(err);
},
complete: () => {
this.loading = false;
} }
})
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册