Bladeren bron

ADD

删除提问后端对接
RegMs If 4 jaren geleden
bovenliggende
commit
6cdbbfd5d9

+ 6 - 0
cloudfunctions/createRead/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 54 - 0
cloudfunctions/createRead/index.js

@@ -0,0 +1,54 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+const _ = db.command
+const $ = db.command.aggregate
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  try {
+    await db.collection('message')
+      .doc(event.msg_id)
+      .get()
+  } catch (err) {
+    return {
+      errMsg: '信息不存在',
+      status: 'ERR'
+    }
+  }
+
+  const read_check = await db.collection('read')
+    .aggregate()
+    .match(_.expr($.and([
+      $.eq(['$user_id', OPENID]),
+      $.eq(['$msg_id', event.msg_id]),
+      $.lt([$.subtract([new Date(), '$read_time']), 1000 * 60 * 30])
+    ])))
+    .end()
+  if (read_check.list.length !== 0) {
+    return {
+      errMsg: '30分钟内只算一次阅读量',
+      status: 'ERR'
+    }
+  }
+
+  const read = await db.collection('read')
+    .add({
+      data: {
+        user_id: OPENID,
+        msg_id: event.msg_id || '',
+        read_time: new Date()
+      }
+    })
+
+  return {
+    _id: read._id,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/createRead/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "createRead",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.4.0"
+  }
+}

+ 2 - 9
cloudfunctions/listQuestions/index.js

@@ -19,7 +19,7 @@ exports.main = async (event, context) => {
         answer: _.neq('')
       })
       .sort({
-        rank: 1
+        rank: -1
       })
       .skip(event.page_token)
       .limit(event.page_size)
@@ -40,15 +40,8 @@ exports.main = async (event, context) => {
         as: 'message'
       })
       .unwind('$message')
-      .lookup({
-        from: 'publisher',
-        localField: 'message.pub_id',
-        foreignField: '_id',
-        as: 'message.publisher'
-      })
-      .unwind('$message.publisher')
       .match({
-        'message.publisher._id': event.pub_id
+        'message.pub_id': event.pub_id
       })
       .sort({
         question_time: -1

+ 4 - 1
miniprogram/app.js

@@ -42,6 +42,7 @@ App({
         })
       }).then(res => {
         if (res.result.status !== 'OK') {
+          this.globalData.hasUserInfo = false
           this.globalData.userNotFound = true
           if (this.onUserInfoChange) {
             this.onUserInfoChange()
@@ -50,6 +51,7 @@ App({
         }
         this.globalData.pubInfo = res.result.list
         this.globalData.hasUserInfo = true
+        this.globalData.userNotFound = false
         if (this.onUserInfoChange) {
           this.onUserInfoChange()
         }
@@ -60,9 +62,10 @@ App({
   globalData: {
     userInfo: {},
     pubInfo: [],
+    pubIndex: 0,
     hasUserInfo: false,
     userNotFound: false,
     openId: null,
-    noticeForm: 0
+    notiForm: 0
   }
 })

+ 32 - 27
miniprogram/pages/activity/activity.js

@@ -38,36 +38,35 @@ Page({
   deleteActivity: function () {
     wx.showModal({
       content: "确认删除信息?",
-      confirmColor: "#009195",
-      success: function (res) {
-        if (res.confirm) {
-          wx.showLoading({
-            title: '删除中'
-          })
-          wx.cloud.callFunction({
-            name: 'deleteMessage',
-            data: {
-              msg_id: this.data.messageId
-            }
-          }).then(res => {
-            wx.hideLoading()
-            if (res.result.status !== 'OK') {
-              wx.showToast({
-                title: res.result.errMsg,
-                icon: 'none'
-              })
-              return
-            }
-            wx.navigateBack()
-            const eventChannel = this.getOpenerEventChannel()
-            eventChannel.emit('deleteMessage')
+      confirmColor: "#009195"
+    }).then(res => {
+      if (res.confirm) {
+        wx.showLoading({
+          title: '删除中'
+        })
+        wx.cloud.callFunction({
+          name: 'deleteMessage',
+          data: {
+            msg_id: this.data.messageId
+          }
+        }).then(res => {
+          wx.hideLoading()
+          if (res.result.status !== 'OK') {
             wx.showToast({
-              title: "删除成功",
+              title: res.result.errMsg,
               icon: 'none'
             })
+            return
+          }
+          wx.navigateBack()
+          const eventChannel = this.getOpenerEventChannel()
+          eventChannel.emit('deleteMessage')
+          wx.showToast({
+            title: "删除成功",
+            icon: 'none'
           })
-        }
-      }.bind(this)
+        })
+      }
     })
   },
 
@@ -229,6 +228,12 @@ Page({
         })
         this.processCommonData(res.data)
         this.loadExtraData()
+        wx.cloud.callFunction({
+          name: 'createRead',
+          data: {
+            msg_id: this.data.messageId
+          }
+        })
       })
     }
   },
@@ -272,7 +277,7 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-
+    this.loadExtraData()
   },
 
   /**

+ 1 - 1
miniprogram/pages/activity/activity.wxml

@@ -43,7 +43,7 @@
       <view class="btn primary-background-color" bindtap="editActivity">
         <image class="btn-icon primary-background-color" mode="aspectFit" src="/images/publisher/publish2.png">
         </image>
-        <view class="white-text-color">修改内容</view>
+        <view class="white-text-color">修改</view>
       </view>
     </view>
   </view>

+ 1 - 0
miniprogram/pages/main/main.js

@@ -172,6 +172,7 @@ Page({
       }
     }).then(res => {
       wx.hideNavigationBarLoading()
+      wx.stopPullDownRefresh()
       if (res.result.status !== 'OK') {
         wx.showToast({
           title: res.result.errMsg,

+ 36 - 18
miniprogram/pages/myQuestion/myQuestion.js

@@ -10,24 +10,42 @@ Page({
 
   removeQuestion: function (e) {
     wx.showModal({
-      content: "确认删除?",
-      confirmColor: "#009195",
-      success: function (res) {
-        if (res.confirm) {
-
-          // const db = wx.cloud.database()
-          // db.collection("qaData").doc(e.target.dataset.id).remove({
-          //   success: function () {
-          //     this.onLoad({
-          //       id: this.data.publisherId
-          //     })
-          //     wx.showToast({
-          //       title: "删除成功",
-          //     })
-          //   }.bind(this)
-          // })
-        }
-      }.bind(this)
+      content: "确认删除提问?",
+      confirmColor: "#009195"
+    }).then(res => {
+      if (res.confirm) {
+        wx.showLoading({
+          title: '删除中'
+        })
+        wx.cloud.callFunction({
+          name: 'deleteQuestion',
+          data: {
+            que_id: e.currentTarget.dataset.id
+          }
+        }).then(res => {
+          wx.hideLoading()
+          if (res.result.status !== 'OK') {
+            wx.showToast({
+              title: res.result.errMsg,
+              icon: 'none'
+            })
+            return
+          }
+          for (let i = 0; i < this.data.questions.length; i++) {
+            if (this.data.questions[i]._id === e.currentTarget.dataset.id) {
+              this.data.questions.splice(i, 1)
+              break
+            }
+          }
+          this.setData({
+            questions: this.data.questions
+          })
+          wx.showToast({
+            title: "删除成功",
+            icon: 'none'
+          })
+        })
+      }
     })
   },
 

+ 2 - 2
miniprogram/pages/myQuestion/myQuestion.wxml

@@ -1,7 +1,7 @@
 <!--为我的-我的提问页面-->
 <view wx:if="{{!questions.length}}" class="empty-text primary-text-color">这里空空如也</view>
-<view wx:for="{{questions}}" wx:for-item="item" wx:for-index="index" wx:key="_id">
-  <view wx:if="{{notAnswered && item.answer === '' || answered && item.answer !== ''}}" class="card">
+<view wx:for="{{questions}}" wx:for-item="item" wx:key="_id">
+  <view class="card">
     <view class="title">{{item.message.name}}</view>
     <view class="question">提出的问题:{{item.question}}</view>
     <view class="{{'answer ' + (item.answer ? 'primary' : 'secondary') + '-text-color'}}">{{item.answer ? '收到的回复:' +

+ 3 - 3
miniprogram/pages/publisherPage/publisherPage.js

@@ -18,7 +18,7 @@ Page({
       url: '/pages/publisher/publisher',
     }).then(res => {
       res.eventChannel.emit('loadCommonData', {
-        data: this.data.pubInfo[this.data.pubIndex]
+        data: this.data.pubInfo[this.data.pubIndex].publisher
       })
     })
   },
@@ -66,7 +66,7 @@ Page({
         pubInfo: app.globalData.pubInfo,
         hasPubInfo: true,
         pubName: pubName,
-        pubIndex: 0
+        pubIndex: app.globalData.pubIndex
       })
     } else {
       wx.showToast({
@@ -101,7 +101,7 @@ Page({
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {
-
+    app.globalData.pubIndex = this.data.pubIndex
   },
 
   /**

+ 34 - 42
miniprogram/pages/publisherQuestion/publisherQuestion.js

@@ -56,22 +56,41 @@ Page({
   removeQuestion: function (e) {
     wx.showModal({
       content: "确认删除提问?",
-      confirmColor: "#009195",
-      success: function (res) {
-        if (res.confirm) {
-          const db = wx.cloud.database()
-          db.collection("qaData").doc(e.target.dataset.id).remove({
-            success: function () {
-              this.onLoad({
-                id: this.data.publisherId
-              })
-              wx.showToast({
-                title: "删除成功",
-              })
-            }.bind(this)
+      confirmColor: "#009195"
+    }).then(res => {
+      if (res.confirm) {
+        wx.showLoading({
+          title: '删除中'
+        })
+        wx.cloud.callFunction({
+          name: 'deleteQuestion',
+          data: {
+            que_id: e.currentTarget.dataset.id
+          }
+        }).then(res => {
+          wx.hideLoading()
+          if (res.result.status !== 'OK') {
+            wx.showToast({
+              title: res.result.errMsg,
+              icon: 'none'
+            })
+            return
+          }
+          for (let i = 0; i < this.data.questions.length; i++) {
+            if (this.data.questions[i]._id === e.currentTarget.dataset.id) {
+              this.data.questions.splice(i, 1)
+              break
+            }
+          }
+          this.setData({
+            questions: this.data.questions
+          })
+          wx.showToast({
+            title: "删除成功",
+            icon: 'none'
           })
-        }
-      }.bind(this)
+        })
+      }
     })
   },
 
@@ -103,33 +122,6 @@ Page({
         questions: res.result.list
       })
     })
-
-    // this.setData({
-    //   publisherId: options.id,
-    //   questions: [{
-    //     title: "我是标题",
-    //     question: "我是问题?",
-    //     answer: "我是回答"
-    //   }]
-    // })
-    // const db = wx.cloud.database()
-    // db.collection("qaData").where({
-    //   publisherId: this.data.publisherId,
-    // }).orderBy("questionTime", "desc").get({
-    //   success: async function (res) {
-    //     let arr = []
-    //     for (let i = 0; i < res.data.length; i++) {
-    //       arr.push(db.collection("mainData").doc(res.data[i].activityId).get())
-    //     }
-    //     arr = await Promise.all(arr)
-    //     for (let i = 0; i < res.data.length; i++) {
-    //       res.data[i].title = arr[i].data.title
-    //     }
-    //     this.setData({
-    //       questions: res.data
-    //     })
-    //   }.bind(this)
-    // })
   },
 
   /**

+ 0 - 1
miniprogram/pages/publisherQuestion/publisherQuestion.wxml

@@ -10,7 +10,6 @@
   </view>
 </checkbox-group>
 
-
 <view wx:for="{{questions}}" wx:for-item="item" wx:for-index="index" wx:key="_id">
   <view wx:if="{{notAnswered && item.answer == '' || answered && item.answer != ''}}" class="card">
     <view class="title">{{item.title}}</view>

+ 3 - 3
miniprogram/pages/search/search.wxml

@@ -29,9 +29,9 @@
     <text class="hot-bar-title primary-background-color white-text-color">实时热点</text>
     <view class="hot-bar" wx:for="{{hotBarData}}" wx:key="rank" wx:for-item="bar" wx:for-index="index" wx:key="_id"
       data-activity="{{bar.message}}" bindtap="viewActivity">
-      <view>
-        <text class="primary-text-color" space="nbsp">{{index + 1}}{{' '}}{{' '}}{{' '}}</text><text
-          class="secondary-text-color">{{bar.message.hot_name}}</text>
+      <view class="hot-bar-text">
+        <view class="primary-text-color" style="width: 20rpx; text-align: right;">{{index + 1}}</view>
+        <view class="secondary-text-color" style="margin-left: 30rpx;">{{bar.message.hot_name}}</view>
       </view>
       <image class="more" src="/images/more.png" mode="aspectFill"></image>
     </view>

+ 4 - 6
miniprogram/pages/search/search.wxss

@@ -5,8 +5,6 @@
   height: 80rpx;
   padding-left: 20rpx;
   padding-right: 20rpx;
-  left: 0rpx;
-  right: 0rpx;
 }
 
 .search-inside {
@@ -29,9 +27,7 @@
 .hot-tag-block {
   display: flex;
   flex-direction: column;
-  justify-content: flex-start;
   align-items: flex-start;
-  width: 100%;
   margin-top: 10rpx;
 }
 
@@ -78,18 +74,20 @@
   justify-content: space-between;
 }
 
+.hot-bar-text {
+  display: flex;
+}
+
 .hot-block {
   position: absolute;
   top: 80rpx;
   bottom: 0rpx;
-  width: 100%;
 }
 
 .search-block {
   position: absolute;
   top: 80rpx;
   bottom: 0rpx;
-  width: 100%;
   opacity: 0;
 }
 

+ 8 - 10
miniprogram/pages/setting/setting.js

@@ -5,19 +5,13 @@ Page({
   data: {
     userInfo: null,
     hasUserInfo: false,
-    noticeForm: 0,
-    noticeFormType: ['数字', '红点', '不显示']
-  },
-
-  noticeFormChange: function (e) {
-    app.globalData.noticeForm = e.detail.value
-    this.setData({
-      noticeForm: app.globalData.noticeForm
-    })
+    notiForm: 0,
+    notiFormType: ['数字', '红点', '不显示']
   },
 
   logout: function () {
     app.globalData.hasUserInfo = false
+    app.globalData.userNotFound = true
     wx.navigateBack()
   },
 
@@ -26,7 +20,7 @@ Page({
       this.setData({
         userInfo: app.globalData.userInfo,
         hasUserInfo: true,
-        noticeForm: app.globalData.noticeForm
+        notiForm: app.globalData.notiForm
       })
     } else {
       wx.showToast({
@@ -34,5 +28,9 @@ Page({
         icon: 'none'
       })
     }
+  },
+
+  onUnload: function () {
+    app.globalData.notiForm = this.data.notiForm
   }
 })

+ 2 - 2
miniprogram/pages/setting/setting.wxml

@@ -28,14 +28,14 @@
   <view>{{userInfo._id}}</view>
 </view>
 
-<picker bindchange="noticeFormChange" value="{{noticeForm}}" range="{{noticeFormType}}">
+<picker model:value="{{notiForm}}" range="{{notiFormType}}">
   <view class="block" hover-class="btn-hover">
     <view class="left">
       <image class=" btn-icon" mode="aspectFit" src="/images/user/question.png">
       </image>
       <view>消息通知形式</view>
     </view>
-    <view>{{noticeFormType[noticeForm]}}</view>
+    <view>{{notiFormType[notiForm]}}</view>
   </view>
 </picker>
 

+ 1 - 0
miniprogram/pages/user/user.js

@@ -30,6 +30,7 @@ Page({
           gender: res.userInfo.gender
         }
         app.globalData.hasUserInfo = true
+        app.globalData.userNotFound = false
         if (this.data.hasUserInfo) {
           wx.cloud.callFunction({
             name: 'updateUser',