From da48954ee1471ccd79797835794ef9bcd0ea78fa Mon Sep 17 00:00:00 2001 From: linju-json Date: Fri, 30 Apr 2021 20:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E7=AB=A0=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E8=AE=B0=E5=BD=95=E7=9A=84=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=E4=B8=BAread-news-log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 2 +- pages/list/detail.vue | 51 ++-- .../ucenter/read-news-log/read-news-log.vue | 14 +- pages/ucenter/ucenter.vue | 2 +- .../cloudfunctions/user-center/index.js | 3 +- .../database/read-news-log.schema.json | 35 +++ .../changelog.md | 0 .../js_sdk/validator/opendb-news-favorite.js | 0 .../package.json | 0 .../readme.md | 0 .../js_sdk/validator/uni-id-users.js | 73 ------ uni_modules/uni-id-users/package.json | 91 ------- .../uni-id-users/pages/uni-id-users/edit.vue | 234 ------------------ 13 files changed, 68 insertions(+), 437 deletions(-) rename uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue => pages/ucenter/read-news-log/read-news-log.vue (66%) create mode 100644 uniCloud-aliyun/database/read-news-log.schema.json rename uni_modules/{uni-news-favorite => read-news-log}/changelog.md (100%) rename uni_modules/{uni-news-favorite => read-news-log}/js_sdk/validator/opendb-news-favorite.js (100%) rename uni_modules/{uni-news-favorite => read-news-log}/package.json (100%) rename uni_modules/{uni-news-favorite => read-news-log}/readme.md (100%) delete mode 100644 uni_modules/uni-id-users/js_sdk/validator/uni-id-users.js delete mode 100644 uni_modules/uni-id-users/package.json delete mode 100644 uni_modules/uni-id-users/pages/uni-id-users/edit.vue diff --git a/pages.json b/pages.json index 8e043c89..9b612706 100644 --- a/pages.json +++ b/pages.json @@ -180,7 +180,7 @@ }, { - "path": "uni_modules/uni-news-favorite/pages/uni-news-favorite/list", + "path": "pages/ucenter/read-news-log/read-news-log", "style": { "navigationBarTitleText": "阅读记录", "enablePullDownRefresh": false diff --git a/pages/list/detail.vue b/pages/list/detail.vue index 1502ca01..c9d97174 100644 --- a/pages/list/detail.vue +++ b/pages/list/detail.vue @@ -50,7 +50,7 @@ import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js'; const db = uniCloud.database(); - const newsFavoriteTable = db.collection('opendb-news-favorite') + const readNewsLog = db.collection('read-news-log') import { mapGetters } from 'vuex'; @@ -114,35 +114,26 @@ }, methods: { setFavorite() { - if (!this.hasLogin) return - newsFavoriteTable.where({ - article_id: this.id, - user_id: this.userInfo._id - }) - .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 newsFavoriteTable.add(value) - } else { - return newsFavoriteTable.where({ - article_id: this.id, - user_id: this.userInfo._id - }) - .update(value) - } - }) - .then(res => { - // console.log(res); - }) - .catch(err => { - console.log(err); - }) + if (!this.hasLogin){ + return console.log('未登陆用户'); + } + let article_id = this.id, + last_time = Date.now(); + console.log({article_id,last_time}); + readNewsLog.where(`"article_id" == "${article_id}" && "user_id"==$env.uid`) + .update({last_time}) + .then(({result:{updated}}) => { + console.log('updated',updated); + if (!updated) { + readNewsLog.add({article_id}).then(e=>{ + console.log(e); + }).catch(err => { + console.log(err); + }) + } + }).catch(err => { + console.log(err); + }) }, loadData(data) { //如果上一页未传递标题过来(如搜索直达详情),则从新闻详情中读取标题 diff --git a/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue b/pages/ucenter/read-news-log/read-news-log.vue similarity index 66% rename from uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue rename to pages/ucenter/read-news-log/read-news-log.vue index b4b6f2cb..63dd6d31 100644 --- a/uni_modules/uni-news-favorite/pages/uni-news-favorite/list.vue +++ b/pages/ucenter/read-news-log/read-news-log.vue @@ -1,18 +1,22 @@