Преглед на файлове

ADD

信息修改后端对接
RegMs If преди 4 години
родител
ревизия
8a1d7c4aa8

+ 6 - 0
cloudfunctions/updateMessage/config.json

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

+ 71 - 0
cloudfunctions/updateMessage/index.js

@@ -0,0 +1,71 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  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: '只有管理员可以修改',
+      status: 'ERR'
+    }
+  }
+  if (manage_check.data[0].role !== '所有者' && manage_check.data[0].role !== '管理者') {
+    return {
+      errMsg: '没有修改权限',
+      status: 'ERR'
+    }
+  }
+
+  if (event.type === '纳新') {
+    const publisher = await db.collection('publisher')
+      .doc(event.pub_id)
+      .get()
+    event.type = publisher.data.type + '纳新'
+  }
+
+  try {
+    const message = await db.collection('message')
+      .doc(msg_id)
+      .update({
+        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,
+          link: event.link
+        }
+      })
+
+    return {
+      updated: message.updated,
+      status: 'OK'
+    }
+  } catch (err) {
+    return {
+      errMsg: '信息不存在',
+      status: 'ERR'
+    }
+  }
+}

+ 14 - 0
cloudfunctions/updateMessage/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "updateMessage",
+  "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/components/itemCard/itemCard.wxml

@@ -18,7 +18,7 @@
     readonly />
   <imagePicker wx:if="{{!item.poster.length && item.photo.length}}" value="{{item.photo}}" max="1"
     image-width="{{item.photo.length === 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}"
-    image-height="{{item.photo.length === 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}" readonly />
+    image-height="{{item.photo.length === 1 ? 330 : item.photo.length <= 4 ? 330 : 220}}" readonly />
   <view class="bottom-line">
     <view class="tags primary-text-color">
       <text class="tag" wx:for="{{item.tag}}" wx:for-item="tag" wx:key="_id" data-tag="{{tag}}"

+ 1 - 0
miniprogram/components/itemCard/itemCard.wxss

@@ -44,6 +44,7 @@
 }
 
 .time {
+  margin-left: 10rpx;
   font-size: 20rpx;
 }
 

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

@@ -4,7 +4,7 @@
     <view class="card">
       <image wx:if="{{activityInfo.poster.length}}" class="activity-poster" src="{{activityInfo.poster[0]}}"
         mode="aspectFill" />
-      <view>
+      <view style="width: 100%;">
         <view class="profile">
           <view class="avatar-name" bindtap="getPublisherInfo">
             <image class="publisher-avatar" src="{{activityInfo.publisher.avatar}}"></image>

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

@@ -72,7 +72,6 @@
   margin: 10rpx 30rpx;
 }
 
-
 .avatar-name {
   display: flex;
 }
@@ -109,6 +108,7 @@
 }
 
 .time {
+  margin-left: 10rpx;
   font-size: 20rpx;
 }
 
@@ -151,7 +151,7 @@
 }
 
 .activity-poster {
-  height: 400rpx;
+  height: 330rpx;
   width: 700rpx;
   border-radius: 20rpx 20rpx 0rpx 0rpx;
 }

+ 26 - 11
miniprogram/pages/activityPublish/activityPublish.js

@@ -120,17 +120,19 @@ Page({
       title: '上传图片'
     })
     const arr = []
-    if (value.poster.length !== 0) {
+    if (value.poster.length !== 0 && value.poster[0].substr(0, 8) !== 'cloud://') {
       arr.push(wx.cloud.uploadFile({
         cloudPath: `messagePoster/${util.randomString(16)}.jpg`,
         filePath: value.poster[0]
       }))
     }
     for (let i = 0; i < value.photo.length; i++) {
-      arr.push(wx.cloud.uploadFile({
-        cloudPath: `messagePhoto/${util.randomString(16)}.jpg`,
-        filePath: value.photo[i]
-      }))
+      if (value.photo[i].substr(0, 8) !== 'cloud://') {
+        arr.push(wx.cloud.uploadFile({
+          cloudPath: `messagePhoto/${util.randomString(16)}.jpg`,
+          filePath: value.photo[i]
+        }))
+      }
     }
     Promise.all(arr).then(res => {
       wx.hideLoading()
@@ -138,17 +140,30 @@ Page({
         title: '正在发布'
       })
       value.pub_id = this.data.publisherId
-      if (value.poster.length !== 0) {
+      if (value.poster.length !== 0 && value.poster[0].substr(0, 8) !== 'cloud://') {
         value.poster[0] = res[0].fileID
         res.splice(0, 1)
       }
       for (let i = 0; i < value.photo.length; i++) {
-        value.photo[i] = res[i].fileID
+        if (value.photo[i].substr(0, 8) !== 'cloud://') {
+          value.photo[i] = res[0].fileID
+          res.splice(0, 1)
+        }
+      }
+      if (this.data.messageId) {
+        return wx.cloud.callFunction({
+          name: 'updateMessage',
+          data: {
+            msg_id: this.data.messageId,
+            ...util.msgToDb(value)
+          }
+        })
+      } else {
+        return wx.cloud.callFunction({
+          name: 'createMessage',
+          data: util.msgToDb(value)
+        })
       }
-      return wx.cloud.callFunction({
-        name: 'createMessage',
-        data: util.msgToDb(value)
-      })
     }).then(res => {
       wx.hideLoading()
       if (res.result.status !== 'OK') {

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

@@ -183,7 +183,7 @@
 </scroll-view>
 
 <view wx:if="{{currentTab === 4}}" class="con">
-  <view class="con1 primary-text-color">发布成功!</view>
+  <view class="con1 primary-text-color">{{messageId ? '修改' : '发布'}}成功!</view>
   <image class="success-icon" src="../../images/finish.png" mode="aspectFill" />
   <!-- <view class="con2"></view> -->
   <myButton class="button" type="primary" bindtap="returnToPublisher">返回</myButton>