Explorar o código

ADD

答疑区对接
RegMs If %!s(int64=4) %!d(string=hai) anos
pai
achega
78f0cb65c4

+ 2 - 1
cloudfunctions/createMessage/index.js

@@ -14,7 +14,8 @@ exports.main = async (event, context) => {
     .where({
       pub_id: event.pub_id,
       user_id: OPENID
-    }).get()
+    })
+    .get()
   if (manage_check.data.length === 0) {
     return {
       errMsg: '只有管理员可以发布'

+ 6 - 3
cloudfunctions/createPublisher/index.js

@@ -13,7 +13,8 @@ exports.main = async (event, context) => {
   const code_check = await db.collection('invite')
     .where({
       code: event.code
-    }).get()
+    })
+    .get()
   if (code_check.data.length === 0) {
     return {
       errMsg: '邀请码不存在'
@@ -28,7 +29,8 @@ exports.main = async (event, context) => {
   const name_check = await db.collection('publisher')
     .where({
       name: event.name
-    }).get()
+    })
+    .get()
   if (name_check.data.length !== 0) {
     return {
       errMsg: '名称已存在'
@@ -54,7 +56,8 @@ exports.main = async (event, context) => {
   await db.collection('invite')
     .where({
       code: event.code
-    }).update({
+    })
+    .update({
       data: {
         pub_id: publisher._id,
         use_time: new Date()

+ 6 - 0
cloudfunctions/listQuestions/config.json

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

+ 28 - 0
cloudfunctions/listQuestions/index.js

@@ -0,0 +1,28 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  if (event.msg_id) {
+    const questions = await db.collection('question')
+      .aggregate()
+      .match({
+        msg_id: event.msg_id
+      })
+      .sort({
+        rank: 1
+      })
+      .skip(event.page_token)
+      .limit(event.page_size)
+      .end()
+
+    return questions
+  }
+}

+ 14 - 0
cloudfunctions/listQuestions/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "listQuestions",
+  "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 - 3
miniprogram/components/itemActivityComment/itemActivityComment.js

@@ -7,8 +7,7 @@ Component({
    * 组件的属性列表
    */
   properties: {
-    comment: Object,
-    time: String
+    comment: Object
   },
 
   /**
@@ -24,4 +23,4 @@ Component({
   methods: {
 
   }
-})
+})

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

@@ -1,4 +1,4 @@
-<view class="text primary-text-color">{{time}}</view>
+<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>

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

@@ -7,8 +7,10 @@ Page({
    * 页面的初始数据
    */
   data: {
+    messageId: '',
     activityInfo: {},
     showEdit: false,
+    pageToken: 0,
     activityComment: [],
     like: -1,
     likeEnable: true,
@@ -80,6 +82,25 @@ Page({
     }
   },
 
+  loadQuestionData: function () {
+    wx.cloud.callFunction({
+      name: 'listQuestions',
+      data: {
+        msg_id: this.data.messageId,
+        page_token: this.data.pageToken,
+        page_size: 25
+      }
+    }).then(res => {
+      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
+      })
+    })
+  },
+
   comment: function () {
     if (this.data.commentText.length < 5) {
       wx.showToast({
@@ -149,13 +170,17 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    this.setData({
+      messageId: options.id
+    })
+
     wx.showLoading({
       title: '加载中'
     })
     wx.cloud.callFunction({
       name: 'getMessage',
       data: {
-        msg_id: options.id
+        msg_id: this.data.messageId
       }
     }).then(res => {
       wx.hideLoading()
@@ -170,6 +195,7 @@ Page({
         activityInfo: res.result.list[0],
         showEdit: edit
       })
+      this.loadQuestionData()
     })
 
     // const db = wx.cloud.database()

+ 5 - 6
miniprogram/pages/activity/activity.wxml

@@ -27,11 +27,11 @@
 
         <view wx:if="{{activityInfo.time}}" class="text">时间:{{activityInfo.time}}</view>
         <view wx:if="{{activityInfo.place}}" class="text">地点:{{activityInfo.place}}</view>
-        <view wx:if="{{activityInfo.tag[0]}}" class="text">活动提供:<text wx:for="{{activityInfo.tag}}" wx:for-item="tag"
-            wx:key="tag">{{tag}} </text></view>
+        <view wx:if="{{activityInfo.tag.length}}" class="text">活动提供:<text wx:for="{{activityInfo.tag}}"
+            wx:for-item="tag" wx:key="tag">{{tag}} </text></view>
         <view wx:if="{{activityInfo.orient}}" class="text">面向对象:{{activityInfo.orient}}</view>
         <view wx:if="{{activityInfo.contact}}" class="text">联系方式:{{activityInfo.contact}}</view>
-        <view wx:if="{{activityInfo.orient}}" class="text">链接:{{activityInfo.link}}</view>
+        <view wx:if="{{activityInfo.link}}" class="text">链接:{{activityInfo.link}}</view>
 
         <imagePicker wx:if="{{activityInfo.photo.length}}" value="{{activityInfo.photo}}" max="1"
           image-width="{{activityInfo.photo.length === 1 ? 698 : activityInfo.photo.length <= 4 ? 330 : 220}}"
@@ -47,10 +47,9 @@
 
     <view class="message-block">
       <view class="title2">{{activityComment.length == 0 ? "暂无问答" : "答疑区:"}}</view>
-      <image wx:if="{{like != -1}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
-        catchtap="toggleLike" />
+      <image class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png" catchtap="toggleLike" />
       <view class="card1" wx:for="{{activityComment}}" wx:for-item="item" wx:key="_id">
-        <itemActivityComment comment="{{item}}" time="{{item.time}}" />
+        <itemActivityComment comment="{{item}}" />
       </view>
     </view>
   </scroll-view>

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

@@ -6,6 +6,10 @@ Page({
    * 页面的初始数据
    */
   data: {
+    publisherId: '',
+    messageId: '',
+    activityInfo: {},
+    currentTab: 0,
     winWidth: 0,
     winHeight: 0,
     types1: [{
@@ -76,11 +80,7 @@ Page({
     }, {
       value: '其他通知',
       checked: false
-    }],
-    publisherId: '',
-    messageId: '',
-    currentTab: 0,
-    activityInfo: {}
+    }]
   },
 
   switch1: function (e) {

+ 10 - 35
miniprogram/pages/main/main.js

@@ -51,17 +51,6 @@ 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[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
-    }
-    this.setData({
-      mainDatas: this.data.mainDatas
-    })
-  },
-
   showList: function (id) {
     this.data.toggleEnable = false
     this.setData({
@@ -162,30 +151,16 @@ Page({
     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)
-  //     })
-  //   }
-  // },
+  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[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
+    }
+    this.setData({
+      mainDatas: this.data.mainDatas
+    })
+  },
 
   loadMessageData: function () {
     wx.showNavigationBarLoading()

+ 10 - 3
miniprogram/pages/publisher/publisher.js

@@ -6,6 +6,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    publisherId: '',
     publisherInfo: {},
     pageToken: 0,
     mainDatas: [],
@@ -15,7 +16,7 @@ Page({
 
   detail: function () {
     wx.navigateTo({
-      url: '/pages/publisherDetail/publisherDetail?id=' + this.data.publisherInfo._id,
+      url: '/pages/publisherDetail/publisherDetail?id=' + this.data.publisherId,
     })
   },
 
@@ -24,7 +25,7 @@ Page({
     wx.cloud.callFunction({
       name: 'listMessages',
       data: {
-        pub_id: this.data.publisherInfo._id,
+        pub_id: this.data.publisherId,
         page_token: this.data.pageToken,
         page_size: 25
       }
@@ -97,13 +98,17 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    this.setData({
+      publisherId: options.id
+    })
+
     wx.showLoading({
       title: "加载中"
     })
     wx.cloud.callFunction({
       name: 'getPublisher',
       data: {
-        pub_id: options.id
+        pub_id: this.data.publisherId
       }
     }).then(res => {
       wx.hideLoading()
@@ -113,6 +118,8 @@ Page({
       this.loadMessageData()
     })
 
+
+
     // const db = wx.cloud.database()
     // db.collection("publisherInfoData").doc(options.id).get({
     //   success: function (res) {