提交 c9fd15d1 编写于 作者: 芊里

查询文章收藏

上级 58bb0869
......@@ -113,15 +113,36 @@
methods: {
setFavorite(){
if(!this.userInfo)return
db.collection(dbCollectionName).add({
db.collection(dbCollectionName).where({
article_id:this.id,
article_title:this.title,
user_id:this.userInfo._id
}).then((res) => {
})
.get()
.then(res=>{
let value = {
article_id:this.id,
article_title:this.title,
user_id:this.userInfo._id,
update_date:Date.now()
}
if(res.result.data.length == 0){
return db.collection(dbCollectionName).add(value)
} else {
return db.collection(dbCollectionName).where({
article_id:this.id,
user_id:this.userInfo._id
})
.update(value)
}
})
.then(res=>{
console.log(res);
}).catch(err=>{
})
.catch(err=>{
console.log(err);
})
},
loadData(data) {
//如果上一页未传递标题过来(如搜索直达详情),则从新闻详情中读取标题
......
......@@ -4,7 +4,7 @@
"permission": {
"read": "doc.uid == auth.uid",
"create": "auth.uid != null",
"update": false,
"update": "doc.uid == auth.uid",
"delete": "doc.uid == auth.uid"
},
"properties": {
......@@ -34,6 +34,13 @@
"forceDefaultValue": {
"$env": "now"
}
},
"update_date": {
"bsonType": "timestamp",
"description": "更新/修改时间",
"forceDefaultValue": {
"$env": "now"
}
}
}
}
<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="opendb-news-favorite" field="article_id">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="opendb-news-favorite">
<view v-if="error">{{error.message}}</view>
<view v-else-if="data">
<uni-list>
<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item)">
<uni-list-item v-for="(item, index) in data" :key="index" :clickable="true" @click="handleItemClick(item)">
<view slot="body">
<text>{{item.article_title || item.article_id}}</text>
<uni-dateformat :date="item.create_date" format="yyyy-MM-dd hh:mm"
<uni-dateformat class="article-date" :date="item.update_date" format="yyyy-MM-dd hh:mm"
:threshold="[0, 0]" />
</view>
</uni-list-item>
......@@ -65,4 +65,7 @@
</script>
<style>
.article-date{
color: #C8C7CC;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册