RegMs If преди 4 години
родител
ревизия
490302f9d3
променени са 32 файла, в които са добавени 409 реда и са изтрити 219 реда
  1. 6 0
      cloudfunctions/createFavorite/config.json
  2. 37 0
      cloudfunctions/createFavorite/index.js
  3. 14 0
      cloudfunctions/createFavorite/package.json
  4. 9 4
      cloudfunctions/createMessage/index.js
  5. 11 5
      cloudfunctions/createPublisher/index.js
  6. 6 2
      cloudfunctions/createQuestion/index.js
  7. 8 2
      cloudfunctions/createUser/index.js
  8. 6 0
      cloudfunctions/deleteFavorite/config.json
  9. 24 0
      cloudfunctions/deleteFavorite/index.js
  10. 14 0
      cloudfunctions/deleteFavorite/package.json
  11. 14 2
      cloudfunctions/getMessage/index.js
  12. 8 2
      cloudfunctions/getPublisher/index.js
  13. 8 2
      cloudfunctions/getUser/index.js
  14. 8 2
      cloudfunctions/listMessages/index.js
  15. 18 5
      cloudfunctions/listPublishers/index.js
  16. 8 2
      cloudfunctions/listQuestions/index.js
  17. 8 2
      cloudfunctions/updateUser/index.js
  18. 18 22
      miniprogram/app.js
  19. 1 2
      miniprogram/components/itemActivityComment/itemActivityComment.wxml
  20. 1 7
      miniprogram/components/itemActivityComment/itemActivityComment.wxss
  21. 2 2
      miniprogram/components/itemCard/itemCard.wxml
  22. 103 129
      miniprogram/pages/activity/activity.js
  23. 2 2
      miniprogram/pages/activity/activity.wxml
  24. 19 12
      miniprogram/pages/activityPublish/activityPublish.js
  25. 9 2
      miniprogram/pages/main/main.js
  26. 15 1
      miniprogram/pages/publisher/publisher.js
  27. 7 0
      miniprogram/pages/publisherDetail/publisherDetail.js
  28. 5 5
      miniprogram/pages/publisherLogin/publisherLogin.js
  29. 1 1
      miniprogram/pages/publisherPage/publisherPage.js
  30. 2 2
      miniprogram/pages/publisherPage/publisherPage.wxml
  31. 16 0
      miniprogram/pages/user/user.js
  32. 1 2
      miniprogram/pages/user/user.wxml

+ 6 - 0
cloudfunctions/createFavorite/config.json

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

+ 37 - 0
cloudfunctions/createFavorite/index.js

@@ -0,0 +1,37 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+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 favorite = await db.collection('favorite')
+    .add({
+      data: {
+        user_id: OPENID,
+        msg_id: event.msg_id || '',
+        favorite_time: new Date()
+      }
+    })
+
+  return {
+    _id: favorite._id,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/createFavorite/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "createFavorite",
+  "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"
+  }
+}

+ 9 - 4
cloudfunctions/createMessage/index.js

@@ -18,12 +18,14 @@ exports.main = async (event, context) => {
     .get()
   if (manage_check.data.length === 0) {
     return {
-      errMsg: '只有管理员可以发布'
+      errMsg: '只有管理员可以发布',
+      status: 'ERR'
     }
   }
-  if (manage_check.data[0].role !== '拥有者' && manage_check.data[0].role !== '发布者') {
+  if (manage_check.data[0].role !== '所有者' && manage_check.data[0].role !== '管理者') {
     return {
-      errMsg: '没有发布权限'
+      errMsg: '没有发布权限',
+      status: 'ERR'
     }
   }
 
@@ -55,5 +57,8 @@ exports.main = async (event, context) => {
       }
     })
 
-  return message
+  return {
+    _id: message._id,
+    status: 'OK'
+  }
 }

+ 11 - 5
cloudfunctions/createPublisher/index.js

@@ -17,12 +17,14 @@ exports.main = async (event, context) => {
     .get()
   if (code_check.data.length === 0) {
     return {
-      errMsg: '邀请码不存在'
+      errMsg: '邀请码不存在',
+      status: 'ERR'
     }
   }
   if (code_check.data[0].pub_id !== '') {
     return {
-      errMsg: '邀请码已被使用'
+      errMsg: '邀请码已被使用',
+      status: 'ERR'
     }
   }
 
@@ -33,7 +35,8 @@ exports.main = async (event, context) => {
     .get()
   if (name_check.data.length !== 0) {
     return {
-      errMsg: '名称已存在'
+      errMsg: '名称已存在',
+      status: 'ERR'
     }
   }
 
@@ -70,9 +73,12 @@ exports.main = async (event, context) => {
         pub_id: publisher._id,
         user_id: OPENID,
         title: '',
-        role: '有者'
+        role: '有者'
       }
     })
 
-  return publisher
+  return {
+    _id: publisher._id,
+    status: 'OK'
+  }
 }

+ 6 - 2
cloudfunctions/createQuestion/index.js

@@ -16,7 +16,8 @@ exports.main = async (event, context) => {
       .get()
   } catch (err) {
     return {
-      errMsg: '信息不存在'
+      errMsg: '信息不存在',
+      status: 'ERR'
     }
   }
 
@@ -33,5 +34,8 @@ exports.main = async (event, context) => {
       }
     })
 
-  return question
+  return {
+    _id: question._id,
+    status: 'OK'
+  }
 }

+ 8 - 2
cloudfunctions/createUser/index.js

@@ -11,7 +11,7 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user')
+    const user = await db.collection('user')
       .add({
         data: {
           _id: OPENID,
@@ -23,9 +23,15 @@ exports.main = async (event, context) => {
           notify_form: '数字'
         }
       })
+
+    return {
+      _id: user._id,
+      status: 'OK'
+    }
   } catch (err) {
     return {
-      errMsg: '用户已存在'
+      errMsg: '用户已存在',
+      status: 'ERR'
     }
   }
 }

+ 6 - 0
cloudfunctions/deleteFavorite/config.json

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

+ 24 - 0
cloudfunctions/deleteFavorite/index.js

@@ -0,0 +1,24 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  const favorite = await db.collection('favorite')
+    .where({
+      user_id: OPENID,
+      msg_id: event.msg_id
+    })
+    .remove()
+
+  return {
+    removed: favorite.removed,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/deleteFavorite/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "deleteFavorite",
+  "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"
+  }
+}

+ 14 - 2
cloudfunctions/getMessage/index.js

@@ -24,10 +24,19 @@ exports.main = async (event, context) => {
     .end()
   if (message.list.length !== 1) {
     return {
-      errMsg: '信息不存在'
+      errMsg: '信息不存在',
+      status: 'ERR'
     }
   }
 
+  message.list[0].publisher = message.list[0].publisher[0]
+  message.list[0].favorite = (await db.collection('favorite')
+    .where({
+      user_id: OPENID,
+      msg_id: event.msg_id
+    })
+    .count()).total === 1
+
   await db.collection('read')
     .add({
       data: {
@@ -37,5 +46,8 @@ exports.main = async (event, context) => {
       }
     })
 
-  return message
+  return {
+    data: message.list[0],
+    status: 'OK'
+  }
 }

+ 8 - 2
cloudfunctions/getPublisher/index.js

@@ -11,12 +11,18 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('publisher')
+    const publisher = await db.collection('publisher')
       .doc(event.pub_id)
       .get()
+
+    return {
+      data: publisher.data,
+      status: 'OK'
+    }
   } catch (err) {
     return {
-      errMsg: '社团组织不存在'
+      errMsg: '社团组织不存在',
+      status: 'ERR'
     }
   }
 }

+ 8 - 2
cloudfunctions/getUser/index.js

@@ -11,12 +11,18 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user')
+    const user = await db.collection('user')
       .doc(OPENID)
       .get()
+
+    return {
+      data: user.data,
+      status: 'OK'
+    }
   } catch (err) {
     return {
-      errMsg: '用户不存在'
+      errMsg: '用户不存在',
+      status: 'ERR'
     }
   }
 }

+ 8 - 2
cloudfunctions/listMessages/index.js

@@ -25,7 +25,8 @@ exports.main = async (event, context) => {
 
     return {
       list: messages.list,
-      next_page_token: event.page_token + event.page_size
+      next_page_token: event.page_token + messages.list.length,
+      status: 'OK'
     }
   } else {
     const messages = await db.collection('message')
@@ -43,9 +44,14 @@ exports.main = async (event, context) => {
       })
       .end()
 
+    for (let i = 0; i < messages.list.length; i++) {
+      messages.list[i].publisher = messages.list[i].publisher[0]
+    }
+
     return {
       list: messages.list,
-      next_page_token: event.page_token + event.page_size
+      next_page_token: event.page_token + messages.list.length,
+      status: 'OK'
     }
   }
 }

+ 18 - 5
cloudfunctions/listPublishers/index.js

@@ -11,7 +11,7 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   if (event.user_id) {
-    return await db.collection('manager')
+    const managers = await db.collection('manager')
       .aggregate()
       .match({
         user_id: event.user_id
@@ -23,16 +23,29 @@ exports.main = async (event, context) => {
         localField: 'pub_id',
         foreignField: '_id',
         as: 'publisher'
-      }).end()
+      })
+      .end()
+
+    for (let i = 0; i < managers.list.length; i++) {
+      managers.list[i].publisher = managers.list[i].publisher[0]
+    }
+
+    return {
+      list: managers.list,
+      next_page_token: event.page_token + managers.list.length,
+      status: 'OK'
+    }
   } else {
     const publishers = await db.collection('manager')
+      .aggregate()
       .skip(event.page_token)
       .limit(event.page_size)
-      .get()
+      .end()
 
     return {
-      list: publishers.data,
-      next_page_token: event.page_token + event.page_size
+      list: publishers.list,
+      next_page_token: event.page_token + publishers.list.length,
+      status: 'OK'
     }
   }
 }

+ 8 - 2
cloudfunctions/listQuestions/index.js

@@ -3,6 +3,7 @@ const cloud = require('wx-server-sdk')
 
 cloud.init()
 const db = cloud.database()
+const _ = db.command
 
 // 云函数入口函数
 exports.main = async (event, context) => {
@@ -14,7 +15,8 @@ exports.main = async (event, context) => {
     const questions = await db.collection('question')
       .aggregate()
       .match({
-        msg_id: event.msg_id
+        msg_id: event.msg_id,
+        answer: _.neq('')
       })
       .sort({
         rank: 1
@@ -23,6 +25,10 @@ exports.main = async (event, context) => {
       .limit(event.page_size)
       .end()
 
-    return questions
+    return {
+      list: questions.list,
+      next_page_token: event.page_token + questions.list.length,
+      status: 'OK'
+    }
   }
 }

+ 8 - 2
cloudfunctions/updateUser/index.js

@@ -11,7 +11,7 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user')
+    const user = await db.collection('user')
       .doc(OPENID)
       .update({
         data: {
@@ -20,9 +20,15 @@ exports.main = async (event, context) => {
           gender: event.gender
         }
       })
+
+    return {
+      updated: user.updated,
+      status: 'OK'
+    }
   } catch (err) {
     return {
-      errMsg: '用户不存在'
+      errMsg: '用户不存在',
+      status: 'ERR'
     }
   }
 }

+ 18 - 22
miniprogram/app.js

@@ -28,30 +28,26 @@ App({
       wx.cloud.callFunction({
         name: 'getUser'
       }).then(res => {
-        if (res.result.data !== undefined) {
-          this.globalData.userInfo = res.result.data
-          return wx.cloud.callFunction({
-            name: 'listPublishers',
-            data: {
-              user_id: this.globalData.userInfo._id,
-              page_token: 0,
-              page_size: 25
-            }
-          })
-        } else {
-          return {
-            result: {
-              errMsg: 'please login first'
-            }
-          }
+        if (res.result.status !== 'OK') {
+          return res.result
         }
-      }).then(res => {
-        if (res.result.list !== undefined) {
-          this.globalData.pubInfo = res.result.list
-          this.globalData.hasUserInfo = true
-          if (this.onUserInfoReady) {
-            this.onUserInfoReady()
+        this.globalData.userInfo = res.result.data
+        return wx.cloud.callFunction({
+          name: 'listPublishers',
+          data: {
+            user_id: this.globalData.userInfo._id,
+            page_token: 0,
+            page_size: 25
           }
+        })
+      }).then(res => {
+        if (res.result.status !== 'OK') {
+          return
+        }
+        this.globalData.pubInfo = res.result.list
+        this.globalData.hasUserInfo = true
+        if (this.onUserInfoReady) {
+          this.onUserInfoReady()
         }
       })
     }

+ 1 - 2
miniprogram/components/itemActivityComment/itemActivityComment.wxml

@@ -1,4 +1,3 @@
 <view class="text primary-text-color">{{comment.a_time}}</view>
 <view class="text">Q: {{comment.question}}</view>
-<view class="text">A: {{comment.answer}}</view>
-<view class="line divider-color"></view>
+<view class="text">A: {{comment.answer}}</view>

+ 1 - 7
miniprogram/components/itemActivityComment/itemActivityComment.wxss

@@ -1,10 +1,4 @@
 .text {
   margin-top: 10rpx;
   font-size: 25rpx;
-}
-
-.line {
-  width: 100%;
-  height: 1rpx;
-  margin: 10rpx 0;
-}
+}

+ 2 - 2
miniprogram/components/itemCard/itemCard.wxml

@@ -2,8 +2,8 @@
 <view class="card" bindtap="getActivityInfo">
   <view class="profile">
     <view class="avatar-name" catchtap="getPublisherInfo">
-      <image class="publisher-avatar" src="{{item.publisher[0].avatar}}" mode="aspectFill"></image>
-      <view class="publisher-name">{{item.publisher[0].name}}</view>
+      <image class="publisher-avatar" src="{{item.publisher.avatar}}" mode="aspectFill"></image>
+      <view class="publisher-name">{{item.publisher.name}}</view>
     </view>
     <view class="activity-attribute primary-background-color white-text-color" catchtap="filterMsgType">
       {{item.type[0]}}

+ 103 - 129
miniprogram/pages/activity/activity.js

@@ -9,11 +9,10 @@ Page({
   data: {
     messageId: '',
     activityInfo: {},
+    like: false,
     showEdit: false,
     pageToken: 0,
     activityComment: [],
-    like: -1,
-    likeEnable: true,
     commentText: ''
   },
 
@@ -26,63 +25,90 @@ Page({
   editActivity: function () {
     wx.navigateTo({
       url: '/pages/activityPublish/activityPublish?id=' + this.data.activityInfo.pub_id +
-        '&msg_id=' + this.data.activityInfo._id
+        '&msg_id=' + this.data.messageId
     })
   },
 
   toggleLike: function () {
-    if (!this.data.likeEnable) return
-    this.setData({
-      likeEnable: false
+    wx.showLoading({
+      title: this.data.like ? '取消收藏' : '收藏中'
     })
-    const db = wx.cloud.database()
-    if (this.data.like == 0) {
-      db.collection('likeData').add({
-        data: {
-          type: 'message',
-          id: this.data.activityInfo._id
-        },
-        success: function () {
-          this.setData({
-            like: 1,
-            likeEnable: true
-          })
-          wx.showToast({
-            title: '已收藏',
-          })
-        }.bind(this),
-        fail: function () {
-          wx.showToast({
-            title: '网络错误',
-            icon: 'none'
-          })
-        }
+    wx.cloud.callFunction({
+      name: this.data.like ? 'deleteFavorite' : 'createFavorite',
+      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.showToast({
+        title: this.data.like ? '取消收藏成功' : '收藏成功',
+        icon: 'none'
       })
-    } else {
-      db.collection('likeData').where({
-        type: 'message',
-        id: this.data.activityInfo._id
-      }).remove({
-        success: function () {
-          this.setData({
-            like: 0,
-            likeEnable: true
-          })
-          wx.showToast({
-            title: '已取消收藏',
-          })
-        }.bind(this),
-        fail: function () {
-          wx.showToast({
-            title: '网络错误',
-            icon: 'none'
-          })
-        }
+      this.setData({
+        like: !this.data.like
       })
-    }
+    })
+
+    // if (!this.data.likeEnable) return
+    // this.setData({
+    //   likeEnable: false
+    // })
+    // const db = wx.cloud.database()
+    // if (this.data.like == 0) {
+    //   db.collection('likeData').add({
+    //     data: {
+    //       type: 'message',
+    //       id: this.data.activityInfo._id
+    //     },
+    //     success: function () {
+    //       this.setData({
+    //         like: 1,
+    //         likeEnable: true
+    //       })
+    //       wx.showToast({
+    //         title: '已收藏',
+    //       })
+    //     }.bind(this),
+    //     fail: function () {
+    //       wx.showToast({
+    //         title: '网络错误',
+    //         icon: 'none'
+    //       })
+    //     }
+    //   })
+    // } else {
+    //   db.collection('likeData').where({
+    //     type: 'message',
+    //     id: this.data.activityInfo._id
+    //   }).remove({
+    //     success: function () {
+    //       this.setData({
+    //         like: 0,
+    //         likeEnable: true
+    //       })
+    //       wx.showToast({
+    //         title: '已取消收藏',
+    //       })
+    //     }.bind(this),
+    //     fail: function () {
+    //       wx.showToast({
+    //         title: '网络错误',
+    //         icon: 'none'
+    //       })
+    //     }
+    //   })
+    // }
   },
 
   loadQuestionData: function () {
+    wx.showNavigationBarLoading()
     wx.cloud.callFunction({
       name: 'listQuestions',
       data: {
@@ -91,12 +117,20 @@ Page({
         page_size: 25
       }
     }).then(res => {
+      wx.hideNavigationBarLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
       for (let i = 0; i < res.result.list.length; i++) {
         res.result.list[i].a_time = util.handleDate(res.result.list[i].a_time)
       }
       this.setData({
         activityComment: this.data.activityComment.concat(res.result.list),
-        pageToken: this.data.pageToken + res.result.list.length
+        pageToken: res.result.next_page_token
       })
     })
   },
@@ -114,11 +148,18 @@ Page({
       wx.cloud.callFunction({
         name: 'createQuestion',
         data: {
-          msg_id: this.data.activityInfo._id,
+          msg_id: this.data.messageId,
           question: this.data.commentText
         }
       }).then(res => {
         wx.hideLoading()
+        if (res.result.status !== 'OK') {
+          wx.showToast({
+            title: res.result.errMsg,
+            icon: 'none'
+          })
+          return
+        }
         wx.showToast({
           title: '发送成功,请等待发布者回复',
           icon: 'none'
@@ -127,42 +168,6 @@ Page({
           commentText: ''
         })
       })
-
-      // const db = wx.cloud.database()
-      // db.collection('qaData').where({
-      //   _openid: app.globalData.openId,
-      //   activityId: this.data.activityInfo._id
-      // }).get({
-      //   success: function (res) {
-      //     console.log(res)
-      //     if (res.data.length >= 10) {
-      //       wx.showToast({
-      //         title: '为防止刷屏,每人每消息至多提问10条',
-      //         icon: 'none'
-      //       })
-      //     } else {
-      //       db.collection('qaData').add({
-      //         data: {
-      //           activityId: this.data.activityInfo._id,
-      //           publisherId: this.data.activityInfo.publisherId,
-      //           answer: '',
-      //           answerTime: '',
-      //           question: this.data.commentText,
-      //           questionTime: new Date(),
-      //           rank: ''
-      //         },
-      //         success: function () {
-      //           this.setData({
-      //             commentText: ''
-      //           })
-      //           wx.showToast({
-      //             title: '提问成功'
-      //           })
-      //         }.bind(this)
-      //       })
-      //     }
-      //   }.bind(this)
-      // })
     }
   },
 
@@ -184,58 +189,27 @@ Page({
       }
     }).then(res => {
       wx.hideLoading()
-      res.result.list[0] = util.dbToMsg(res.result.list[0])
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
+      res.result.data = util.dbToMsg(res.result.data)
       let edit = false
       for (let i = 0; i < app.globalData.pubInfo.length; i++) {
-        if (res.result.list[0].pub_id === app.globalData.pubInfo[i].pub_id) {
+        if (res.result.data.pub_id === app.globalData.pubInfo[i].pub_id) {
           edit = true
         }
       }
       this.setData({
-        activityInfo: res.result.list[0],
+        activityInfo: res.result.data,
+        like: res.result.data.favorite,
         showEdit: edit
       })
       this.loadQuestionData()
     })
-
-    // const db = wx.cloud.database()
-    // const _ = db.command
-    // db.collection('mainData').doc(options.id).get({
-    //   success: function (res) {
-    //     res.data.time = util.handleDate(res.data.time)
-    //     this.setData({
-    //       activityInfo: res.data
-    //     })
-    //     wx.hideLoading()
-    //   }.bind(this)
-    // })
-    // db.collection('qaData').where({
-    //   activityId: options.id,
-    //   answer: _.neq('')
-    // }).get({
-    //   success: function (res) {
-    //     for (let i = 0; i < res.data.length; i++) {
-    //       if (res.data[i].answerTime !== '') {
-    //         res.data[i].time = util.handleDate(res.data[i].answerTime)
-    //       } else {
-    //         res.data[i].time = ''
-    //       }
-    //     }
-    //     this.setData({
-    //       activityComment: res.data
-    //     })
-    //   }.bind(this)
-    // })
-    // db.collection('likeData').where({
-    //   type: 'message',
-    //   id: options.id
-    // }).get({
-    //   success: function (res) {
-    //     this.setData({
-    //       like: res.data.length
-    //     })
-    //   }.bind(this)
-    // })
   },
 
   /**

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

@@ -7,8 +7,8 @@
       <view>
         <view class="profile">
           <view class="avatar-name" bindtap="getPublisherInfo">
-            <image class="publisher-avatar" src="{{activityInfo.publisher[0].avatar}}"></image>
-            <view class="publisher-name">{{activityInfo.publisher[0].name}}</view>
+            <image class="publisher-avatar" src="{{activityInfo.publisher.avatar}}"></image>
+            <view class="publisher-name">{{activityInfo.publisher.name}}</view>
           </view>
           <view class="activity-attribute primary-background-color white-text-color">
             {{activityInfo.type}}

+ 19 - 12
miniprogram/pages/activityPublish/activityPublish.js

@@ -152,16 +152,16 @@ Page({
       })
     }).then(res => {
       wx.hideLoading()
-      if (res.result._id !== undefined) {
-        this.setData({
-          currentTab: 4
-        })
-      } else {
+      if (res.result.status !== 'OK') {
         wx.showToast({
           title: res.result.errMsg,
           icon: 'none'
         })
+        return
       }
+      this.setData({
+        currentTab: 4
+      })
     })
   },
 
@@ -187,27 +187,34 @@ Page({
       wx.cloud.callFunction({
         name: 'getMessage',
         data: {
-          msg_id: options.msg_id
+          msg_id: this.data.messageId
         }
       }).then(res => {
         wx.hideLoading()
-        res.result.list[0] = util.dbToMsg(res.result.list[0])
-        const type = res.result.list[0].type[0].substr(res.result.list[0].type[0].length - 2)
+        if (res.result.status !== 'OK') {
+          wx.showToast({
+            title: res.result.errMsg,
+            icon: 'none'
+          })
+          return
+        }
+        res.result.data = util.dbToMsg(res.result.data)
+        const type = res.result.data.type[0].substr(res.result.data.type[0].length - 2)
         for (let i = 0; i < this.data.types1.length; i++) {
-          this.data.types1[i].checked = res.result.list[0].type.indexOf(this.data.types1[i].value) !== -1
+          this.data.types1[i].checked = res.result.data.type.indexOf(this.data.types1[i].value) !== -1
         }
         for (let i = 0; i < this.data.types2.length; i++) {
-          this.data.types2[i].checked = res.result.list[0].tag.indexOf(this.data.types2[i].value) !== -1
+          this.data.types2[i].checked = res.result.data.tag.indexOf(this.data.types2[i].value) !== -1
         }
         for (let i = 0; i < this.data.types3.length; i++) {
-          this.data.types3[i].checked = res.result.list[0].type.indexOf(this.data.types3[i].value) !== -1
+          this.data.types3[i].checked = res.result.data.type.indexOf(this.data.types3[i].value) !== -1
         }
         this.setData({
           types1: this.data.types1,
           types2: this.data.types2,
           types3: this.data.types3,
           currentTab: type === '通知' ? 3 : type === '纳新' ? 2 : 1,
-          activityInfo: res.result.list[0]
+          activityInfo: res.result.data
         })
       })
     }

+ 9 - 2
miniprogram/pages/main/main.js

@@ -154,7 +154,7 @@ Page({
   updateData: function () {
     for (let i = 0; i < this.data.mainDatas.length; i++) {
       this.data.mainDatas[i].show = (this.data.filterItem[1] === '' || this.data.mainDatas[i].type.indexOf(this.data.filterItem[1]) !== -1) &&
-        (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher[0].type) &&
+        (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher.type) &&
         (this.data.filterItem[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
     }
     this.setData({
@@ -172,12 +172,19 @@ Page({
       }
     }).then(res => {
       wx.hideNavigationBarLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
       for (let i = 0; i < res.result.list.length; i++) {
         res.result.list[i] = util.dbToMsg(res.result.list[i])
       }
       this.setData({
         mainDatas: this.data.mainDatas.concat(res.result.list),
-        pageToken: this.data.pageToken + res.result.list.length
+        pageToken: res.result.next_page_token
       })
       this.updateData()
     })

+ 15 - 1
miniprogram/pages/publisher/publisher.js

@@ -31,13 +31,20 @@ Page({
       }
     }).then(res => {
       wx.hideNavigationBarLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
       for (let i = 0; i < res.result.list.length; i++) {
         res.result.list[i] = util.dbToMsg(res.result.list[i])
         res.result.list[i].publisher = [this.data.publisherInfo]
       }
       this.setData({
         mainDatas: this.data.mainDatas.concat(res.result.list),
-        pageToken: this.data.pageToken + res.result.list.length
+        pageToken: res.result.next_page_token
       })
     })
   },
@@ -112,6 +119,13 @@ Page({
       }
     }).then(res => {
       wx.hideLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
       this.setData({
         publisherInfo: res.result.data
       })

+ 7 - 0
miniprogram/pages/publisherDetail/publisherDetail.js

@@ -20,6 +20,13 @@ Page({
       }
     }).then(res => {
       wx.hideLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
       this.setData({
         publisherInfo: res.result.data
       })

+ 5 - 5
miniprogram/pages/publisherLogin/publisherLogin.js

@@ -77,16 +77,16 @@ Page({
       })
     }).then(res => {
       wx.hideLoading()
-      if (res.result._id !== undefined) {
-        this.setData({
-          currentTab: 5
-        })
-      } else {
+      if (res.result.status !== 'OK') {
         wx.showToast({
           title: res.result.errMsg,
           icon: 'none'
         })
+        return
       }
+      this.setData({
+        currentTab: 5
+      })
     })
   },
 

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

@@ -56,7 +56,7 @@ Page({
     if (app.globalData.hasUserInfo) {
       const pubName = []
       for (let i = 0; i < app.globalData.pubInfo.length; i++) {
-        pubName.push(app.globalData.pubInfo[i].publisher[0].name)
+        pubName.push(app.globalData.pubInfo[i].publisher.name)
       }
       this.setData({
         pubInfo: app.globalData.pubInfo,

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

@@ -1,8 +1,8 @@
 <!-- 为发布者个人页面 -->
 <view class="card">
-  <cover-image class="avatar" src="{{hasPubInfo ? pubInfo[pubIndex].publisher[0].avatar : '/images/user/user.png'}}">
+  <cover-image class="avatar" src="{{hasPubInfo ? pubInfo[pubIndex].publisher.avatar : '/images/user/user.png'}}">
   </cover-image>
-  <view wx:if="{{hasPubInfo}}" class="publisher-name">{{pubInfo[pubIndex].publisher[0].name}}</view>
+  <view wx:if="{{hasPubInfo}}" class="publisher-name">{{pubInfo[pubIndex].publisher.name}}</view>
 </view>
 
 <view class="block2" hover-class="btn-hover" bindtap="publisherHome">

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

@@ -34,11 +34,27 @@ Page({
           wx.cloud.callFunction({
             name: 'updateUser',
             data: app.globalData.userInfo
+          }).then(res => {
+            if (res.result.status !== 'OK') {
+              wx.showToast({
+                title: res.result.errMsg,
+                icon: 'none'
+              })
+              return
+            }
           })
         } else {
           wx.cloud.callFunction({
             name: 'createUser',
             data: app.globalData.userInfo
+          }).then(res => {
+            if (res.result.status !== 'OK') {
+              wx.showToast({
+                title: res.result.errMsg,
+                icon: 'none'
+              })
+              return
+            }
           })
         }
         this.setUserInfo()

+ 1 - 2
miniprogram/pages/user/user.wxml

@@ -5,11 +5,10 @@
   <view wx:if="{{hasUserInfo}}" class="nickname primary-text">{{userInfo.name}}</view>
   <view wx:else class="nickname"><button class="block-background-color" size="mini"
       bindtap="getUserProfile">微信登录</button></view>
-  <!-- <view class="location secondary-text">{{pubInfo.length === 0 ? '尚未加入任何社团组织' : pubInfo[0].publisher[0].name}}</view> -->
   <view wx:if="{{hasUserInfo}}">
     <view wx:if="{{pubInfo.length === 0}}" class="pub-name secondary-text">尚未加入任何社团组织</view>
     <view wx:else class="pub-name secondary-text">
-      <view wx:for="{{pubInfo}}" wx:for-item="item" wx:key="pub_id">{{item.publisher[0].name}}</view>
+      <view wx:for="{{pubInfo}}" wx:for-item="item" wx:key="pub_id">{{item.publisher.name}}</view>
     </view>
   </view>
 </view>