From c9fd15d145a663abc53faba1c569cd18cf04f092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=8A=E9=87=8C?= <1227971437@qq.com> Date: Thu, 22 Apr 2021 14:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=96=87=E7=AB=A0=E6=94=B6?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/list/detail.vue | 29 ++++++++++++++++--- .../database/opendb-news-favorite.schema.json | 9 +++++- .../pages/uni-news-favorite/list.vue | 9 ++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/pages/list/detail.vue b/pages/list/detail.vue index 3005e66..840a450 100644 --- a/pages/list/detail.vue +++ b/pages/list/detail.vue @@ -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) { //如果上一页未传递标题过来(如搜索直达详情),则从新闻详情中读取标题 diff --git a/uniCloud-aliyun/database/opendb-news-favorite.schema.json b/uniCloud-aliyun/database/opendb-news-favorite.schema.json index 6d92d5d..0cb88c4 100644 --- a/uniCloud-aliyun/database/opendb-news-favorite.schema.json +++ b/uniCloud-aliyun/database/opendb-news-favorite.schema.json @@ -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" + } } } } diff --git a/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue b/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue index 6f5a7b8..67e4cf6 100644 --- a/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue +++ b/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue @@ -1,13 +1,13 @@