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

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

雪洛's avatar
雪洛 已提交
69 70 71 72
<style>
	.item{
		display: flex;
		flex-direction: column;
DCloud_JSON's avatar
DCloud_JSON 已提交
73 74 75 76
	}
	.article-date {
		color: #C8C7CC;
	}
雪洛's avatar
雪洛 已提交
77
</style>