Bladeren bron

ADD

组织关注后端对接
RegMs If 4 jaren geleden
bovenliggende
commit
d2749faf38

+ 6 - 0
cloudfunctions/createFollow/config.json

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

+ 37 - 0
cloudfunctions/createFollow/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('publisher')
+      .doc(event.pub_id)
+      .get()
+  } catch (err) {
+    return {
+      errMsg: '社团组织不存在',
+      status: 'ERR'
+    }
+  }
+
+  const follow = await db.collection('follow')
+    .add({
+      data: {
+        user_id: OPENID,
+        pub_id: event.pub_id || '',
+        follow_time: new Date()
+      }
+    })
+
+  return {
+    _id: follow._id,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/createFollow/package.json

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

+ 6 - 0
cloudfunctions/deleteFollow/config.json

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

+ 24 - 0
cloudfunctions/deleteFollow/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 follow = await db.collection('follow')
+    .where({
+      user_id: OPENID,
+      pub_id: event.pub_id
+    })
+    .remove()
+
+  return {
+    removed: follow.removed,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/deleteFollow/package.json

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

+ 6 - 0
cloudfunctions/getFollow/config.json

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

+ 24 - 0
cloudfunctions/getFollow/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 follow = await db.collection('follow')
+    .where({
+      user_id: OPENID,
+      pub_id: event.pub_id
+    })
+    .count()
+
+  return {
+    total: follow.total,
+    status: 'OK'
+  }
+}

+ 14 - 0
cloudfunctions/getFollow/package.json

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

+ 1 - 1
miniprogram/app.js

@@ -37,7 +37,7 @@ App({
           data: {
             user_id: this.globalData.userInfo._id,
             page_token: 0,
-            page_size: 25
+            page_size: 20
           }
         })
       }).then(res => {

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

@@ -34,7 +34,7 @@
     </view>
     <view class="activity-detail">
       <rich-text class="detail-text">
-        想法诞生的来源,第一是目前学校各种组织社团发布信息的渠道不一,在qq空间发说说、在微信公众平台发推文、在朵朵校友圈发软广、在钉钉群发通知、qq邮箱发邮件、在文广等地宣传等等。很多时候,你完全不能知道所有的活动、通知、纳新招募,往往在感兴趣的活动过去了以后才惊觉还有这样的活动。
+        想法诞生的来源,第一是目前学校各种社团组织发布信息的渠道不一,在qq空间发说说、在微信公众平台发推文、在朵朵校友圈发软广、在钉钉群发通知、qq邮箱发邮件、在文广等地宣传等等。很多时候,你完全不能知道所有的活动、通知、纳新招募,往往在感兴趣的活动过去了以后才惊觉还有这样的活动。
       </rich-text>
     </view>
     <view class="activity-detail">

+ 3 - 5
miniprogram/pages/activity/activity.js

@@ -115,16 +115,14 @@ Page({
   },
 
   loadExtraData: function () {
-    wx.showLoading({
-      title: '加载中'
-    })
+    wx.showNavigationBarLoading()
     const arr = []
     arr.push(wx.cloud.callFunction({
       name: 'listQuestions',
       data: {
         msg_id: this.data.messageId,
         page_token: this.data.pageToken,
-        page_size: 25
+        page_size: 20
       }
     }))
     arr.push(wx.cloud.callFunction({
@@ -134,7 +132,7 @@ Page({
       }
     }))
     Promise.all(arr).then(res => {
-      wx.hideLoading()
+      wx.hideNavigationBarLoading()
       if (res[0].result.status !== 'OK' || res[1].result.status !== 'OK') {
         wx.showToast({
           title: res[0].result.errMsg || res[1].result.errMsg,

+ 2 - 1
miniprogram/pages/activity/activity.wxss

@@ -122,7 +122,8 @@
   padding-right: 20rpx;
   position: fixed;
   bottom: 0rpx;
-  width: 100%;
+  left: 0rpx;
+  right: 0rpx;
 }
 
 .comment-inside {

+ 7 - 17
miniprogram/pages/main/main.js

@@ -162,13 +162,13 @@ Page({
     })
   },
 
-  loadMessageData: function () {
+  loadMessageData: function (refresh) {
     wx.showNavigationBarLoading()
     wx.cloud.callFunction({
       name: 'listMessages',
       data: {
-        page_token: this.data.pageToken,
-        page_size: 25
+        page_token: refresh ? 0 : this.data.pageToken,
+        page_size: 20
       }
     }).then(res => {
       wx.hideNavigationBarLoading()
@@ -183,7 +183,7 @@ Page({
         res.result.list[i] = util.dbToMsg(res.result.list[i])
       }
       this.setData({
-        mainDatas: this.data.mainDatas.concat(res.result.list),
+        mainDatas: refresh ? res.result.list : this.data.mainDatas.concat(res.result.list),
         pageToken: res.result.next_page_token
       })
       this.updateData()
@@ -194,14 +194,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    this.loadMessageData()
-
-    // const db = wx.cloud.database()
-    // db.collection('mainData').orderBy('time', 'desc').limit(20).get({
-    //   success: function (res) {
-    //     this.processData(0, res.data)
-    //   }.bind(this)
-    // })
+    this.loadMessageData(true)
   },
 
   /**
@@ -236,17 +229,14 @@ Page({
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
-    this.setData({
-      pageToken: 0
-    })
-    this.loadMessageData()
+    this.loadMessageData(true)
   },
 
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    this.loadMessageData()
+    this.loadMessageData(false)
   },
 
   /**

+ 50 - 63
miniprogram/pages/publisher/publisher.js

@@ -8,10 +8,10 @@ Page({
   data: {
     publisherId: '',
     publisherInfo: {},
-    pageToken: 0,
-    mainDatas: [],
     like: false,
-    likeEnable: true
+    likeDisabled: true,
+    pageToken: 0,
+    mainDatas: []
   },
 
   detail: function () {
@@ -25,86 +25,73 @@ Page({
   },
 
   loadExtraData: function () {
-    wx.showLoading({
-      title: '加载中'
-    })
-    wx.cloud.callFunction({
+    wx.showNavigationBarLoading()
+    const arr = []
+    arr.push(wx.cloud.callFunction({
       name: 'listMessages',
       data: {
         pub_id: this.data.publisherId,
         page_token: this.data.pageToken,
-        page_size: 25
+        page_size: 20
       }
-    }).then(res => {
-      wx.hideLoading()
-      if (res.result.status !== 'OK') {
+    }))
+    arr.push(wx.cloud.callFunction({
+      name: 'getFollow',
+      data: {
+        pub_id: this.data.publisherId
+      }
+    }))
+    Promise.all(arr).then(res => {
+      wx.hideNavigationBarLoading()
+      if (res[0].result.status !== 'OK' || res[1].result.status !== 'OK') {
         wx.showToast({
-          title: res.result.errMsg,
+          title: res[0].result.errMsg || res[1].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
+      for (let i = 0; i < res[0].result.list.length; i++) {
+        res[0].result.list[i] = util.dbToMsg(res[0].result.list[i])
+        res[0].result.list[i].publisher = this.data.publisherInfo
       }
       this.setData({
-        mainDatas: this.data.mainDatas.concat(res.result.list),
-        pageToken: res.result.next_page_token
+        mainDatas: this.data.mainDatas.concat(res[0].result.list),
+        pageToken: res[0].result.next_page_token,
+        like: res[1].result.total === 1,
+        likeDisabled: false
       })
     })
   },
 
   toggleLike: function () {
-    if (!this.data.likeEnable) return
-    this.setData({
-      likeEnable: false
+    if (this.data.likeDisabled) {
+      return
+    }
+    wx.showLoading({
+      title: this.data.like ? '取消关注' : '关注中'
     })
-    const db = wx.cloud.database()
-    if (this.data.like == 0) {
-      db.collection("likeData").add({
-        data: {
-          type: "publisher",
-          id: this.data.publisherInfo._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 ? 'deleteFollow' : 'createFollow',
+      data: {
+        pub_id: this.data.publisherId
+      }
+    }).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: "publisher",
-        id: this.data.publisherInfo._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
       })
-    }
+    })
   },
 
   /**

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

@@ -124,7 +124,7 @@ Page({
       data: {
         keyword: this.data.searchText,
         page_token: 0,
-        page_size: 25
+        page_size: 20
       }
     }).then(res => {
       wx.hideLoading()