提交 c9fd15d1 编写于 作者: 芊里

查询文章收藏

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