diff --git a/pages/list/detail.vue b/pages/list/detail.vue index 3005e66b49b681fd677c9534569e6b464edeb05c..840a450df325b3583391763fef317cfcab731375 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 6d92d5d19de9da9564df430a2ed87a668f6ad401..0cb88c407eda3c8c1335f2090fdaac85b2209d05 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 6f5a7b80399a16bcb4108066a131fe5200912eb3..67e4cf688c7f47e1ed973894f7326bcec29e1706 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 @@