瀏覽代碼

更新

连接信息详情和发布者详情后端
RegMs If 4 年之前
父節點
當前提交
0621d0727c

+ 27 - 23
cloudfunctions/createMessage/index.js

@@ -10,10 +10,11 @@ exports.main = async (event, context) => {
     OPENID
   } = cloud.getWXContext()
 
-  const manage_check = await db.collection('manager').where({
-    pub_id: event.pub_id,
-    user_id: OPENID
-  }).get()
+  const manage_check = await db.collection('manager')
+    .where({
+      pub_id: event.pub_id,
+      user_id: OPENID
+    }).get()
   if (manage_check.data.length === 0) {
     return {
       errMsg: '只有管理员可以发布'
@@ -26,28 +27,31 @@ exports.main = async (event, context) => {
   }
 
   if (!event.type) {
-    const publisher = await db.collection('publisher').doc(event.pub_id).get()
+    const publisher = await db.collection('publisher')
+      .doc(event.pub_id)
+      .get()
     event.type = publisher.data.type + '纳新'
   }
 
-  const message = await db.collection('message').add({
-    data: {
-      pub_id: event.pub_id,
-      user_id: OPENID,
-      name: event.name,
-      type: event.type,
-      brief: event.brief,
-      poster: event.poster,
-      photo: event.photo,
-      tag: event.tag,
-      orient: event.orient,
-      time: event.time,
-      place: event.place,
-      contact: event.contact,
-      detail: event.detail,
-      publish_time: new Date()
-    }
-  })
+  const message = await db.collection('message')
+    .add({
+      data: {
+        pub_id: event.pub_id,
+        user_id: OPENID,
+        name: event.name,
+        type: event.type,
+        brief: event.brief,
+        poster: event.poster,
+        photo: event.photo,
+        tag: event.tag,
+        orient: event.orient,
+        time: event.time,
+        place: event.place,
+        contact: event.contact,
+        detail: event.detail,
+        publish_time: new Date()
+      }
+    })
 
   return message
 }

+ 41 - 36
cloudfunctions/createPublisher/index.js

@@ -10,9 +10,10 @@ exports.main = async (event, context) => {
     OPENID
   } = cloud.getWXContext()
 
-  const code_check = await db.collection('invite').where({
-    code: event.code
-  }).get()
+  const code_check = await db.collection('invite')
+    .where({
+      code: event.code
+    }).get()
   if (code_check.data.length === 0) {
     return {
       errMsg: '邀请码不存在'
@@ -24,47 +25,51 @@ exports.main = async (event, context) => {
     }
   }
 
-  const name_check = await db.collection('publisher').where({
-    name: event.name
-  }).get()
+  const name_check = await db.collection('publisher')
+    .where({
+      name: event.name
+    }).get()
   if (name_check.data.length !== 0) {
     return {
       errMsg: '名称已存在'
     }
   }
 
-  const publisher = await db.collection('publisher').add({
-    data: {
-      name: event.name,
-      type: event.type,
-      level: event.level,
-      intro: event.intro,
-      avatar: event.avatar,
-      phone: event.phone,
-      email: event.email,
-      qq: event.qq,
-      wechat: event.wechat,
-      reside_time: new Date()
-    }
-  })
+  const publisher = await db.collection('publisher')
+    .add({
+      data: {
+        name: event.name,
+        type: event.type,
+        level: event.level,
+        intro: event.intro,
+        avatar: event.avatar,
+        phone: event.phone,
+        email: event.email,
+        qq: event.qq,
+        wechat: event.wechat,
+        reside_time: new Date()
+      }
+    })
 
-  await db.collection('invite').where({
-    code: event.code
-  }).update({
-    data: {
-      pub_id: publisher._id,
-      use_time: new Date()
-    }
-  })
+  await db.collection('invite')
+    .where({
+      code: event.code
+    }).update({
+      data: {
+        pub_id: publisher._id,
+        use_time: new Date()
+      }
+    })
 
-  await db.collection('manager').add({
-    data: {
-      pub_id: publisher._id,
-      user_id: OPENID,
-      title: '',
-      role: '拥有者'
-    }
-  })
+  await db.collection('manager')
+    .add({
+      data: {
+        pub_id: publisher._id,
+        user_id: OPENID,
+        title: '',
+        role: '拥有者'
+      }
+    })
 
   return publisher
 }

+ 12 - 8
cloudfunctions/createUser/index.js

@@ -11,14 +11,18 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user').add({
-      data: {
-        _id: OPENID,
-        name: event.name,
-        avatar: event.avatar,
-        gender: event.gender
-      }
-    })
+    return await db.collection('user')
+      .add({
+        data: {
+          _id: OPENID,
+          name: event.name,
+          avatar: event.avatar,
+          gender: event.gender ? '男' : '女',
+          university: '浙江大学',
+          theme: '默认',
+          notify_form: '数字'
+        }
+      })
   } catch (err) {
     return {
       errMsg: 'user exists'

+ 6 - 0
cloudfunctions/getMessage/config.json

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

+ 45 - 0
cloudfunctions/getMessage/index.js

@@ -0,0 +1,45 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  let {
+    OPENID
+  } = cloud.getWXContext()
+
+  try {
+    const message = await db.collection('message')
+      .aggregate()
+      .match({
+        _id: event.msg_id
+      })
+      .lookup({
+        from: 'publisher',
+        localField: 'pub_id',
+        foreignField: '_id',
+        as: 'publisher'
+      })
+      .end()
+    if (message.list.length !== 1) {
+      throw 'error'
+    }
+
+    await db.collection('read')
+      .add({
+        data: {
+          user_id: OPENID,
+          msg_id: event.msg_id,
+          read_time: new Date()
+        }
+      })
+
+    return message
+  } catch (err) {
+    return {
+      errMsg: 'no such message'
+    }
+  }
+}

+ 14 - 0
cloudfunctions/getMessage/package.json

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

+ 12 - 6
cloudfunctions/getPublisher/index.js

@@ -2,15 +2,21 @@
 const cloud = require('wx-server-sdk')
 
 cloud.init()
+const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  const wxContext = cloud.getWXContext()
+  let {
+    OPENID
+  } = cloud.getWXContext()
 
-  return {
-    event,
-    openid: wxContext.OPENID,
-    appid: wxContext.APPID,
-    unionid: wxContext.UNIONID,
+  try {
+    return await db.collection('publisher')
+      .doc(event.pub_id)
+      .get()
+  } catch (err) {
+    return {
+      errMsg: 'no such publisher'
+    }
   }
 }

+ 3 - 1
cloudfunctions/getUser/index.js

@@ -11,7 +11,9 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user').doc(OPENID).get()
+    return await db.collection('user')
+      .doc(OPENID)
+      .get()
   } catch (err) {
     return {
       errMsg: 'no such user'

+ 41 - 1
cloudfunctions/listMessages/index.js

@@ -2,10 +2,50 @@
 const cloud = require('wx-server-sdk')
 
 cloud.init()
-
 const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
+  let {
+    OPENID
+  } = cloud.getWXContext()
+
+  if (event.pub_id) {
+    const messages = await db.collection('message')
+      .aggregate()
+      .match({
+        pub_id: event.pub_id
+      })
+      .sort({
+        publish_time: -1
+      })
+      .skip(event.page_token)
+      .limit(event.page_size)
+      .end()
+
+    return {
+      list: messages.list,
+      next_page_token: event.page_token + event.page_size
+    }
+  } else {
+    const messages = await db.collection('message')
+      .aggregate()
+      .sort({
+        publish_time: -1
+      })
+      .skip(event.page_token)
+      .limit(event.page_size)
+      .lookup({
+        from: 'publisher',
+        localField: 'pub_id',
+        foreignField: '_id',
+        as: 'publisher'
+      })
+      .end()
 
+    return {
+      list: messages.list,
+      next_page_token: event.page_token + event.page_size
+    }
+  }
 }

+ 24 - 9
cloudfunctions/listPublishers/index.js

@@ -10,14 +10,29 @@ exports.main = async (event, context) => {
     OPENID
   } = cloud.getWXContext()
 
-  if (event.type === 'manage') {
-    return await db.collection('manager').aggregate().match({
-      user_id: OPENID
-    }).lookup({
-      from: 'publisher',
-      localField: 'pub_id',
-      foreignField: '_id',
-      as: 'publisher'
-    }).end()
+  if (event.user_id) {
+    return await db.collection('manager')
+      .aggregate()
+      .match({
+        user_id: event.user_id
+      })
+      .skip(event.page_token)
+      .limit(event.page_size)
+      .lookup({
+        from: 'publisher',
+        localField: 'pub_id',
+        foreignField: '_id',
+        as: 'publisher'
+      }).end()
+  } else {
+    const publishers = await db.collection('manager')
+      .skip(event.page_token)
+      .limit(event.page_size)
+      .get()
+
+    return {
+      list: publishers.data,
+      next_page_token: event.page_token + event.page_size
+    }
   }
 }

+ 9 - 7
cloudfunctions/updateUser/index.js

@@ -11,13 +11,15 @@ exports.main = async (event, context) => {
   } = cloud.getWXContext()
 
   try {
-    return await db.collection('user').doc(OPENID).update({
-      data: {
-        name: event.name,
-        avatar: event.avatar,
-        gender: event.gender
-      }
-    })
+    return await db.collection('user')
+      .doc(OPENID)
+      .update({
+        data: {
+          name: event.name,
+          avatar: event.avatar,
+          gender: event.gender
+        }
+      })
   } catch (err) {
     return {
       errMsg: 'no such user'

+ 9 - 1
miniprogram/app.js

@@ -33,9 +33,17 @@ App({
           return wx.cloud.callFunction({
             name: 'listPublishers',
             data: {
-              type: 'manage'
+              user_id: this.globalData.userInfo._id,
+              page_token: 0,
+              page_size: 25
             }
           })
+        } else {
+          return {
+            result: {
+              errMsg: 'please login first'
+            }
+          }
         }
       }).then(res => {
         if (res.result.list !== undefined) {

+ 13 - 5
miniprogram/components/itemCard/itemCard.js

@@ -1,7 +1,9 @@
 // components/itemCard.js
+const util = require('../../utils/util.js')
+
 Component({
   options: {
-    styleIsolation: "apply-shared"
+    styleIsolation: 'apply-shared'
   },
 
   /**
@@ -24,19 +26,25 @@ Component({
   methods: {
     getPublisherInfo: function () {
       wx.navigateTo({
-        url: "/pages/publisher/publisher?id=" + this.properties.item.publisherId
+        url: '/pages/publisher/publisher?id=' + this.data.item.pub_id
       })
     },
 
     getActivityInfo: function () {
       wx.navigateTo({
-        url: "/pages/activity/activity?id=" + this.properties.item._id
+        url: '/pages/activity/activity?id=' + this.data.item._id
       })
     },
 
     filterMsgType: function (e) {
-      this.triggerEvent("filtermsgtype", {
-        attr: this.properties.item.attribute[0]
+      this.triggerEvent('filtermsgtype', {
+        type: this.data.item.type
+      })
+    },
+
+    filterTag: function (e) {
+      this.triggerEvent('filtertag', {
+        tag: e.currentTarget.dataset.tag
       })
     }
   }

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

@@ -2,27 +2,27 @@
 <view class="card" bindtap="getActivityInfo">
   <view class="profile">
     <view class="avatar-name" catchtap="getPublisherInfo">
-      <image class="publisher-avatar" src="{{item.publisherAvatar}}" mode="aspectFill"></image>
-      <view class="publisher-name">{{item.publisherName}}</view>
+      <image class="publisher-avatar" src="{{item.publisher[0].avatar}}" mode="aspectFill"></image>
+      <view class="publisher-name">{{item.publisher[0].name}}</view>
     </view>
     <view class="activity-attribute primary-background-color white-text-color" catchtap="filterMsgType">
-      {{item.attribute[0]}}
+      {{item.type}}
     </view>
   </view>
   <view class="title-time">
-    <view class="title">{{item.title}}</view>
-    <view class="time primary-text-color">{{item.time}}</view>
+    <view class="title">{{item.name}}</view>
+    <view class="time primary-text-color">{{item.publish_time}}</view>
   </view>
-  <view class="sub-title">{{item.subTitle}}</view>
-  <imagePicker wx:if="{{item.poster != ''}}" images="{{[item.poster]}}" max="1" image-width="700" image-height="350"
+  <view class="sub-title">{{item.brief}}</view>
+  <imagePicker wx:if="{{item.poster !== ''}}" value="{{[item.poster]}}" max="1" image-width="696" image-height="330"
     readonly />
-  <imagePicker wx:if="{{item.poster == '' && item.photo.length != 0}}" value="{{item.photo}}" max="1"
+  <imagePicker wx:if="{{item.poster === '' && item.photo.length !== 0}}" value="{{item.photo}}" max="1"
     image-width="{{item.photo.length == 1 ? 696 : item.photo.length <= 4 ? 330 : 220}}"
     image-height="{{item.photo.length == 1 ? 696 : item.photo.length <= 4 ? 330 : 220}}" readonly />
   <view class="bottom-line">
     <view class="tags primary-text-color">
-      <text style="font-size: 25rpx; margin: 0rpx 30rpx;" wx:for="{{item.tag}}" wx:for-item="tag"
-        wx:key="_id">{{tag}}</text>
+      <text style="font-size: 25rpx; margin: 0rpx 30rpx;" wx:for="{{item.tag}}" wx:for-item="tag" wx:key="_id"
+        data-tag="{{tag}}" catchtap="filterTag">{{tag}}</text>
     </view>
     <view class="to-detail">
       <text class="primary-text-color" style="font-size: 20rpx;">查看详情</text>

+ 53 - 50
miniprogram/pages/activity/activity.js

@@ -24,19 +24,7 @@ Page({
 
   getPublisherInfo: function () {
     wx.navigateTo({
-      url: "/pages/publisher/publisher?id=" + this.properties.item.publisherId
-    })
-  },
-
-  getActivityInfo: function () {
-    wx.navigateTo({
-      url: "/pages/activity/activity?id=" + this.properties.item._id
-    })
-  },
-
-  filterMsgType: function (e) {
-    this.triggerEvent("filtermsgtype", {
-      attr: this.properties.item.attribute[0]
+      url: "/pages/publisher/publisher?id=" + this.data.activityInfo.pub_id
     })
   },
 
@@ -144,44 +132,59 @@ Page({
     wx.showLoading({
       title: "加载中",
     })
-    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)
+    wx.cloud.callFunction({
+      name: 'getMessage',
+      data: {
+        msg_id: options.id
+      }
+    }).then(res => {
+      wx.hideLoading()
+      res.result.list[0].photo = res.result.list[0].photo.split(',')
+      res.result.list[0].tag = res.result.list[0].tag.split(',')
+      res.result.list[0].publish_time = util.handleDate(res.result.list[0].publish_time)
+      this.setData({
+        activityInfo: res.result.list[0]
+      })
     })
+
+    // 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)
+    // })
   },
 
   /**

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

@@ -1,40 +1,40 @@
 <!--为首页-信息详情页面-->
 <view class="page">
   <view class="card">
-    <image wx:if="{{activityInfo.poster != ''}}" class="activity-poster" src="{{activityInfo.poster}}"
+    <image wx:if="{{activityInfo.poster !== ''}}" class="activity-poster" src="{{activityInfo.poster}}"
       mode="aspectFill" />
     <view>
       <view class="profile">
         <view class="avatar-name" catchtap="getPublisherInfo">
-          <image class="publisher-avatar" src="{{activityInfo.publisherAvatar}}"></image>
-          <view class="publisher-name">{{activityInfo.publisherName}}</view>
+          <image class="publisher-avatar" src="{{activityInfo.publisher[0].avatar}}"></image>
+          <view class="publisher-name">{{activityInfo.publisher[0].name}}</view>
         </view>
         <view class="activity-attribute primary-background-color white-text-color" catchtap="filterMsgType">
-          {{activityInfo.attribute[0]}}
+          {{activityInfo.type}}
         </view>
       </view>
       <view class="title-time">
-        <view class="title">{{activityInfo.title}}</view>
-        <view class="time primary-text-color">{{activityInfo.time}}</view>
+        <view class="title">{{activityInfo.name}}</view>
+        <view class="time primary-text-color">{{activityInfo.publish_time}}</view>
       </view>
 
       <view wx:if="{{activityInfo.details != ''}}" class="text">
-        <text>{{activityInfo.details}}</text>
+        <text>{{activityInfo.detail}}</text>
       </view>
 
       <view class="line primary-background-color"></view>
 
-      <view wx:if="{{activityInfo.activityTime != ''}}" class="text">时间:{{activityInfo.activityTime}}</view>
+      <view wx:if="{{activityInfo.activityTime != ''}}" class="text">时间:{{activityInfo.time}}</view>
 
       <view wx:if="{{activityInfo.place != ''}}" class="text">地点:{{activityInfo.place}}</view>
 
-      <view class="text">活动提供:</view>
+      <view class="text">活动提供:<text wx:for="{{activityInfo.tag}}" wx:for-item="tag" wx:key="tag">{{tag}} </text></view>
 
-      <view class="text">面向对象:</view>
+      <view class="text">面向对象:{{activityInfo.orient}}</view>
 
-      <view class="text">联系方式:</view>
+      <view class="text">联系方式:{{activityInfo.contact}}</view>
 
-      <view class="text">报名链接:</view>
+      <view class="text">报名链接:{{activityInfo.link}}</view>
 
       <imagePicker wx:if="{{activityInfo.photo.length != 0}}" value="{{activityInfo.photo}}" max="1"
         image-width="{{activityInfo.photo.length == 1 ? 696 : activityInfo.photo.length <= 4 ? 330 : 220}}"

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

@@ -37,7 +37,7 @@
     </view>
     <view class="block">
       <view class="cate" style="align-self: flex-start;">活动封图</view>
-      <imagePicker name="poster" max="1" image-width="450" image-height="270" />
+      <imagePicker name="poster" max="1" image-width="450" image-height="215" />
     </view>
     <view class="block" style="margin-bottom: 20rpx;">
       <view class="cate" style="align-self: flex-start;">活动图片</view>
@@ -92,7 +92,7 @@
     </view>
     <view class="block">
       <view class="cate" style="align-self: flex-start;">纳新封图</view>
-      <imagePicker name="poster" max="1" image-width="450" image-height="270" />
+      <imagePicker name="poster" max="1" image-width="450" image-height="215" />
     </view>
     <view class="block" style="margin-bottom: 20rpx;">
       <view class="cate" style="align-self: flex-start;">纳新图片</view>
@@ -147,7 +147,7 @@
     </view>
     <view class="block">
       <view class="cate" style="align-self: flex-start;">通知封图</view>
-      <imagePicker name="poster" max="1" image-width="450" image-height="270" />
+      <imagePicker name="poster" max="1" image-width="450" image-height="215" />
     </view>
     <view class="block" style="margin-bottom: 20rpx;">
       <view class="cate" style="align-self: flex-start;">通知图片</view>

+ 111 - 83
miniprogram/pages/main/main.js

@@ -6,51 +6,60 @@ Page({
    * 页面的初始数据
    */
   data: {
+    pageToken: 0,
     mainDatas: [],
     toggleEnable: true,
     filterList: 0,
-    filterItem: ["", "", "", ""],
+    filterItem: ['', '', '', ''],
     filterName: [{},
       {
-        title: "信息类型",
+        title: '信息类型',
         children: [{
-            title: "通知",
+            title: '通知',
             children: [{
-                title: "生活通知",
-                children: ["水电通知", "缴费通知", "假期通知", "后勤通知", "图书馆通知"]
+                title: '生活通知',
+                children: ['水电通知', '缴费通知', '假期通知', '后勤通知', '图书馆通知']
               },
               {
-                title: "学业通知",
-                children: ["选课通知", "竞赛通知", "考试通知"]
+                title: '学业通知',
+                children: ['选课通知', '竞赛通知', '考试通知']
               },
               {
-                title: "其他通知",
-                children: ["其他通知"]
+                title: '其他通知',
+                children: ['其他通知']
               }
             ]
           },
           {
-            title: "活动",
-            children: ["志愿活动", "文艺活动", "体育活动", "学术活动", "素质拓展", "精品课程", "其他活动"]
+            title: '活动',
+            children: ['志愿活动', '文艺活动', '体育活动', '学术活动', '素质拓展', '精品课程', '其他活动']
           },
           {
-            title: "纳新",
-            children: ["社团纳新", "组织纳新"]
+            title: '纳新',
+            children: ['社团纳新', '组织纳新']
           }
         ]
       },
       {
-        title: "发布来源",
-        children: ["我关注的", "社团", "组织", "权服侠", "学校部门"]
+        title: '发布来源',
+        children: ['我关注的', '社团', '组织', '权服侠', '学校部门']
       },
       {
-        title: "我的需求",
-        children: ["二课分", "三课分", "四课分", "勤工助学", "志愿者小时数", "综素/活动纪实"]
+        title: '我的需求',
+        children: ['二课分', '三课分', '四课分', '勤工助学', '志愿者小时数', '综素/活动纪实']
       }
-    ],
-    activity: null,
-    inform: null,
-    recruit: null
+    ]
+  },
+
+  updateData: function () {
+    for (let i = 0; i < this.data.mainDatas.length; i++) {
+      this.data.mainDatas[i].show = (this.data.filterItem[1] === '' || this.data.filterItem[1] === this.data.mainDatas[i].type) &&
+        (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher[0].type) &&
+        (this.data.filterItem[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
+    }
+    this.setData({
+      mainDatas: this.data.mainDatas
+    })
   },
 
   showList: function (id) {
@@ -58,14 +67,14 @@ Page({
     this.setData({
       filterList: id
     })
-    this.animate("#arrow" + id, [{
+    this.animate('#arrow' + id, [{
         rotate: 0
       },
       {
         rotate: 180
       },
     ], 150)
-    this.animate("#list" + id, [{
+    this.animate('#list' + id, [{
         opacity: 0
       },
       {
@@ -81,14 +90,14 @@ Page({
 
   hideList: function (id) {
     this.data.toggleEnable = false
-    this.animate("#arrow" + id, [{
+    this.animate('#arrow' + id, [{
         rotate: 180
       },
       {
         rotate: 360
       },
     ], 150)
-    this.animate("#list" + id, [{
+    this.animate('#list' + id, [{
         opacity: 1
       },
       {
@@ -108,16 +117,16 @@ Page({
 
   toggleFilterList: function (e) {
     if (!this.data.toggleEnable) return
-    var list = e.currentTarget.dataset.filterList
-    if (this.data.filterList == list) {
-      if (this.data.filterList != 0) {
+    const list = e.currentTarget.dataset.filterList
+    if (this.data.filterList === list) {
+      if (this.data.filterList !== 0) {
         this.hideList(this.data.filterList)
       }
     } else {
-      if (this.data.filterList != 0) {
+      if (this.data.filterList !== 0) {
         this.hideList(this.data.filterList)
       }
-      if (list != 0) {
+      if (list !== 0) {
         this.showList(list)
       }
     }
@@ -125,61 +134,94 @@ Page({
 
   toggleFilterItem: function (e) {
     if (!this.data.toggleEnable) return
-    if (this.data.filterList != 0 && this.data.filterList == e.currentTarget.dataset.filterList) {
+    if (this.data.filterList !== 0 && this.data.filterList === e.currentTarget.dataset.filterList) {
       var item = e.currentTarget.dataset.filterItem
       var arr = this.data.filterItem
-      arr[this.data.filterList] = arr[this.data.filterList] == item ? "" : item;
+      arr[this.data.filterList] = arr[this.data.filterList] === item ? '' : item;
       this.setData({
         filterItem: arr
       })
+      this.updateData()
       this.hideList(this.data.filterList)
     }
   },
 
   filterMsgType: function (e) {
-    var arr = this.data.filterItem
-    arr[1] = e.detail.attr
+    this.data.filterItem[1] = e.detail.type
     this.setData({
-      filterItem: arr
+      filterItem: this.data.filterItem
     })
+    this.updateData()
   },
 
-  processData: function (start, arr) {
-    const db = wx.cloud.database()
-    for (let i = start; i < arr.length; i++) {
-      arr[i].time = util.handleDate(arr[i].time)
-      db.collection("publisherInfoData").where({
-        publisherName: arr[i].publisherName
-      }).get({
-        success: function (res) {
-          arr[i].publisherAttribute = res.data[0].publisherAttribute
-          if (i == 0) {
-            arr[i].tag = ['紫金港', '管控', '保卫处']
-          } else if (i == 1) {
-            arr[i].tag = ['玉泉', '停电']
-          } else if (i == 2) {
-            arr[i].tag = ['公益', '画展']
-          }
-          this.setData({
-            mainDatas: arr
-          })
-          wx.hideNavigationBarLoading()
-        }.bind(this)
+  filterTag: function (e) {
+    this.data.filterItem[3] = e.detail.tag
+    this.setData({
+      filterItem: this.data.filterItem
+    })
+    this.updateData()
+  },
+
+  // processData: function (start, arr) {
+  //   const db = wx.cloud.database()
+  //   for (let i = start; i < arr.length; i++) {
+  //     arr[i].time = util.handleDate(arr[i].time)
+  //     db.collection('publisherInfoData').where({
+  //       publisherName: arr[i].publisherName
+  //     }).get({
+  //       success: function (res) {
+  //         arr[i].publisherAttribute = res.data[0].publisherAttribute
+  //         if (i == 0) {
+  //           arr[i].tag = ['紫金港', '管控', '保卫处']
+  //         } else if (i == 1) {
+  //           arr[i].tag = ['玉泉', '停电']
+  //         } else if (i == 2) {
+  //           arr[i].tag = ['公益', '画展']
+  //         }
+  //         this.setData({
+  //           mainDatas: arr
+  //         })
+  //         wx.hideNavigationBarLoading()
+  //       }.bind(this)
+  //     })
+  //   }
+  // },
+
+  loadMessageData: function () {
+    wx.showNavigationBarLoading()
+    wx.cloud.callFunction({
+      name: 'listMessages',
+      data: {
+        page_token: this.data.pageToken,
+        page_size: 25
+      }
+    }).then(res => {
+      wx.hideNavigationBarLoading()
+      for (let i = 0; i < res.result.list.length; i++) {
+        res.result.list[i].photo = res.result.list[i].photo.split(',')
+        res.result.list[i].tag = res.result.list[i].tag.split(',')
+        res.result.list[i].publish_time = util.handleDate(res.result.list[i].publish_time)
+      }
+      this.setData({
+        mainDatas: this.data.mainDatas.concat(res.result.list),
+        pageToken: this.data.pageToken + res.result.list.length
       })
-    }
+      this.updateData()
+    })
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    wx.showNavigationBarLoading()
-    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()
+
+    // const db = wx.cloud.database()
+    // db.collection('mainData').orderBy('time', 'desc').limit(20).get({
+    //   success: function (res) {
+    //     this.processData(0, res.data)
+    //   }.bind(this)
+    // })
   },
 
   /**
@@ -214,32 +256,18 @@ Page({
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
-    wx.showNavigationBarLoading()
-    const db = wx.cloud.database()
-    db.collection("mainData").orderBy("time", "desc").limit(20).get({
-      success: function (res) {
-        this.processData(0, res.data)
-        wx.stopPullDownRefresh()
-      }.bind(this)
+    this.setData({
+      mainDatas: [],
+      pageToken: 0
     })
+    this.loadMessageData()
   },
 
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    wx.showNavigationBarLoading()
-    const db = wx.cloud.database()
-    db.collection("mainData").orderBy("time", "desc").skip(this.data.mainDatas.length).limit(20).get({
-      success: function (res) {
-        if (res.data.length == 0) {
-          wx.hideNavigationBarLoading()
-          return
-        }
-        res.data = this.data.mainDatas.concat(res.data)
-        this.processData(this.data.mainDatas.length, res.data)
-      }.bind(this)
-    })
+    this.loadMessageData()
   },
 
   /**

+ 4 - 6
miniprogram/pages/main/main.wxml

@@ -37,23 +37,21 @@
     <view class="filter-list"></view>
     <view wx:if="{{filterList == 2}}" class="filter-list" id="list2">
       <view class="filter-list-item secondary-text-color" wx:for="{{filterName[2].children}}" wx:for-item="title"
-        wx:key="*this" data-filter-list="2" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
+        wx:key="title" data-filter-list="2" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
           wx:if="{{filterItem[2] == title}}">✔</view>
       </view>
     </view>
     <view class="filter-list"></view>
     <view wx:if="{{filterList == 3}}" class="filter-list" id="list3">
       <view class="filter-list-item secondary-text-color" wx:for="{{filterName[3].children}}" wx:for-item="title"
-        wx:key="*this" data-filter-list="3" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
+        wx:key="title" data-filter-list="3" data-filter-item="{{title}}" bindtap="toggleFilterItem">{{title}}<view
           wx:if="{{filterItem[3] == title}}">✔</view>
       </view>
     </view>
   </view>
   <view style="margin-top: 60rpx;">
-    <view wx:for="{{mainDatas}}" wx:for-item="item" wx:for-index="index" wx:key="_id">
-      <itemCard
-        wx:if="{{(filterItem[1] == '' || filterItem[1] == item.attribute[0]) && (filterItem[2] == '' || filterItem[2] == item.publisherAttribute[0]) && (filterItem[3] == '' || filterItem[3] == item.supply[0])}}"
-        item="{{item}}" bindfiltermsgtype="filterMsgType" />
+    <view wx:for="{{mainDatas}}" wx:for-item="item" wx:key="_id">
+      <itemCard wx:if="{{item.show}}" item="{{item}}" bindfiltermsgtype="filterMsgType" bindfiltertag="filterTag" />
     </view>
   </view>
 </view>

+ 61 - 34
miniprogram/pages/publisher/publisher.js

@@ -6,7 +6,8 @@ Page({
    * 页面的初始数据
    */
   data: {
-    publisherInfo: [],
+    publisherInfo: {},
+    pageToken: 0,
     mainDatas: [],
     like: -1,
     likeEnable: true
@@ -14,18 +15,31 @@ Page({
 
   detail: function () {
     wx.navigateTo({
-      url: '/pages/publisherDetail/publisherDetail',
+      url: '/pages/publisherDetail/publisherDetail?id=' + this.data.publisherInfo._id,
     })
   },
 
-  processData: function (start, arr) {
-    for (let i = start; i < arr.length; i++) {
-      arr[i].time = util.handleDate(arr[i].time)
-    }
-    this.setData({
-      mainDatas: arr
+  loadMessageData: function () {
+    wx.showNavigationBarLoading()
+    wx.cloud.callFunction({
+      name: 'listMessages',
+      data: {
+        pub_id: this.data.publisherInfo.pub_id,
+        page_token: this.data.pageToken,
+        page_size: 25
+      }
+    }).then(res => {
+      wx.hideNavigationBarLoading()
+      for (let i = 0; i < res.result.list.length; i++) {
+        res.result.list[i].photo = res.result.list[i].photo.split(',')
+        res.result.list[i].tag = res.result.list[i].tag.split(',')
+        res.result.list[i].publish_time = util.handleDate(res.result.list[i].publish_time)
+      }
+      this.setData({
+        mainDatas: this.data.mainDatas.concat(res.result.list),
+        pageToken: this.data.pageToken + res.result.list.length
+      })
     })
-    wx.hideLoading()
   },
 
   toggleLike: function () {
@@ -87,31 +101,44 @@ Page({
     wx.showLoading({
       title: "加载中"
     })
-    const db = wx.cloud.database()
-    db.collection("publisherInfoData").doc(options.id).get({
-      success: function (res) {
-        this.setData({
-          publisherInfo: res.data
-        })
-        db.collection("mainData").where({
-          publisherName: this.data.publisherInfo.publisherName
-        }).orderBy("time", "desc").limit(20).get({
-          success: function (res) {
-            this.processData(0, res.data)
-          }.bind(this)
-        })
-      }.bind(this)
-    })
-    db.collection("likeData").where({
-      type: "publisher",
-      id: options.id
-    }).get({
-      success: function (res) {
-        this.setData({
-          like: res.data.length
-        })
-      }.bind(this)
+    wx.cloud.callFunction({
+      name: 'getPublisher',
+      data: {
+        pub_id: options.id
+      }
+    }).then(res => {
+      wx.hideLoading()
+      this.setData({
+        publisherInfo: res.result.data
+      })
+      this.loadMessageData()
     })
+
+    // const db = wx.cloud.database()
+    // db.collection("publisherInfoData").doc(options.id).get({
+    //   success: function (res) {
+    //     this.setData({
+    //       publisherInfo: res.data
+    //     })
+    //     db.collection("mainData").where({
+    //       publisherName: this.data.publisherInfo.publisherName
+    //     }).orderBy("time", "desc").limit(20).get({
+    //       success: function (res) {
+    //         this.processData(0, res.data)
+    //       }.bind(this)
+    //     })
+    //   }.bind(this)
+    // })
+    // db.collection("likeData").where({
+    //   type: "publisher",
+    //   id: options.id
+    // }).get({
+    //   success: function (res) {
+    //     this.setData({
+    //       like: res.data.length
+    //     })
+    //   }.bind(this)
+    // })
   },
 
   /**
@@ -153,7 +180,7 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-
+    this.loadMessageData()
   },
 
   /**

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

@@ -2,8 +2,8 @@
 <view class="top">
   <view class="brief-info">
     <view class="brief-info-left">
-      <image class="publisher-avatar" src="{{publisherInfo.publisherAvatar}}" mode="aspectFill" />
-      <text class="publisher-name">{{publisherInfo.publisherName}}</text>
+      <image class="publisher-avatar" src="{{publisherInfo.avatar}}" mode="aspectFill" />
+      <text class="publisher-name">{{publisherInfo.name}}</text>
     </view>
     <image wx:if="{{like != -1}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
       bindtap="toggleLike" />
@@ -12,7 +12,7 @@
 
   <view class="detailed-info">
     <view class="publisher-intro secondary-text-color"><text
-        class="primary-text-color">简介:</text>{{publisherInfo.publisherIntro}}</view>
+        class="primary-text-color">简介:</text>{{publisherInfo.intro}}</view>
     <view class="check">
       <text class="check-text primary-text-color" bindtap="detail">查看详情</text>
       <image class="arrow" src="/images/hollow_arrow.png" mode="aspectFill"></image>

+ 20 - 2
miniprogram/pages/publisherDetail/publisherDetail.js

@@ -3,8 +3,7 @@ const util = require('../../utils/util.js')
 Page({
 
   data: {
-    publisherInfo: [],
-    mainDatas: [],
+    publisherInfo: {},
   },
 
   // processData: function (start, arr) {
@@ -48,4 +47,23 @@ Page({
   //   })
   // },
 
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    wx.showLoading({
+      title: "加载中"
+    })
+    wx.cloud.callFunction({
+      name: 'getPublisher',
+      data: {
+        pub_id: options.id
+      }
+    }).then(res => {
+      wx.hideLoading()
+      this.setData({
+        publisherInfo: res.result.data
+      })
+    })
+  }
 })

+ 6 - 6
miniprogram/pages/publisherDetail/publisherDetail.wxml

@@ -2,25 +2,25 @@
 <view class="sub-text secondary-text-color">组织详情</view>
 <view class="block">
   <view class="cate">组织类型</view>
-  <view class="input">组织组织组织</view>
+  <view class="input">{{publisherInfo.type}}</view>
 </view>
 <view class="block2">
   <view class="cate">组织简介</view>
-  <text class="input">这里可以换行吗\n我也不知道哎</text>
+  <text class="input">{{publisherInfo.intro}}</text>
 </view>
 <view class="block">
   <view class="cate">联系电话</view>
-  <view class="input">18237189857</view>
+  <view class="input">{{publisherInfo.phone}}</view>
 </view>
 <view class="block">
   <view class="cate">邮箱地址</view>
-  <view class="input">23041084912@qq.com</view>
+  <view class="input">{{publisherInfo.email}}</view>
 </view>
 <view class="block">
   <view class="cate">官方QQ</view>
-  <view class="input">124071590</view>
+  <view class="input">{{publisherInfo.qq}}</view>
 </view>
 <view class="block">
   <view class="cate">公众号</view>
-  <view class="input">hiahiahiahi</view>
+  <view class="input">{{publisherInfo.wechat}}</view>
 </view>

+ 18 - 19
miniprogram/utils/util.js

@@ -16,31 +16,30 @@ const formatNumber = n => {
 
 // 计算时间差
 const handleDate = date => {
-  var now = new Date().getTime()
-  var diffValue = now - date.getTime()
+  const diffValue = new Date().getTime() - new Date(date).getTime()
   if (diffValue < 0) {
-    console.log("时间不同步")
-    return "刚刚"
+    console.log('时间不同步')
+    return '刚刚'
   }
-  var result = ""
-  var minute = 1000 * 60
-  var hour = minute * 60
-  var day = hour * 24
-  var minC = diffValue / minute
-  var hourC = diffValue / hour
-  var dayC = diffValue / day
-  if (parseInt(dayC) > 30) {
-    result += date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate()
+  const minute = 1000 * 60
+  const hour = minute * 60
+  const day = hour * 24
+  const minC = diffValue / minute
+  const hourC = diffValue / hour
+  const dayC = diffValue / day
+  let result = ''
+  if (parseInt(dayC) > 3) {
+    result = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()
   } else if (parseInt(dayC) > 1) {
-    result += parseInt(dayC) + "天前"
+    result = parseInt(dayC) + '天前'
   } else if (parseInt(dayC) == 1) {
-    result += "昨天"
+    result = '昨天'
   } else if (hourC >= 1) {
-    result += parseInt(hourC) + "小时前"
-  } else if (minC >= 5) {
-    result += parseInt(minC) + "分钟前"
+    result = parseInt(hourC) + '小时前'
+  } else if (minC >= 3) {
+    result = parseInt(minC) + '分钟前'
   } else {
-    result += "刚刚"
+    result = '刚刚'
   }
   return result
 }