read-news-log.vue 1.9 KB
Newer Older
芊里 已提交
1
<template>
2 3 4 5
	<view class="container">
		<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" :where="udbWhere"
			collection="opendb-news-articles" @load="isLoading == false" @error="isLoading == false"
			field="title,_id" :page-size="10">
芊里 已提交
6 7 8 9
			<view v-if="data && data.length">
				<uni-list>
					<uni-list-item v-for="(item, index) in data" :key="index" :clickable="true"
						@click="handleItemClick(item)">
10
						<view slot="body">
11 12
							<text>{{item.title}}</text>
							<uni-dateformat class="article-date" :date="readNewsLog[index].last_time" format="yyyy-MM-dd hh:mm"
芊里 已提交
13 14 15 16
								:threshold="[0, 0]" />
						</view>
					</uni-list-item>
				</uni-list>
17 18 19
			</view>
			<view v-else>
				<uni-load-more v-if="!loading" status="noMore"></uni-load-more>
芊里 已提交
20
			</view>
DCloud_JSON's avatar
DCloud_JSON 已提交
21
			<uni-load-more v-if="data.length>10" :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
芊里 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34
		</unicloud-db>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading: true,
				loadMore: {
					contentdown: '',
					contentrefresh: '',
					contentnomore: '',
35 36 37
				},
				readNewsLog:[],
				udbWhere:''
芊里 已提交
38
			}
39 40 41 42 43 44
		},
		onLoad() {
			this.readNewsLog = uni.getStorageSync('readNewsLog')||[];
			let readNewsLogIds = this.readNewsLog.map(({article_id})=>article_id)
			console.log(typeof readNewsLogIds,readNewsLogIds);
			this.udbWhere = `"_id" in ${JSON.stringify(readNewsLogIds)}`
芊里 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
		},
		onPullDownRefresh() {
			this.refreshData();
		},
		onReachBottom() {
			this.$refs.udb.loadMore()
		},
		methods: {
			refreshData() {
				this.$refs.udb.loadData({
					clear: true
				}, (res) => {
					console.log(res);
					uni.stopPullDownRefresh()
				})
			},
			handleItemClick(item) {
				uni.navigateTo({
63
					url: '/pages/list/detail?id=' + item._id + '&title=' + item.title
芊里 已提交
64 65 66 67 68 69 70 71 72 73
				})
			}
		}
	}
</script>

<style>
	.article-date {
		color: #C8C7CC;
	}
芊里 已提交
74
</style>