Browse Source

社团组织管理

添加社团组织切换功能
RegMs If 4 năm trước cách đây
mục cha
commit
e417796416

+ 6 - 0
cloudfunctions/getPublisher/config.json

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

+ 16 - 0
cloudfunctions/getPublisher/index.js

@@ -0,0 +1,16 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const wxContext = cloud.getWXContext()
+
+  return {
+    event,
+    openid: wxContext.OPENID,
+    appid: wxContext.APPID,
+    unionid: wxContext.UNIONID,
+  }
+}

+ 14 - 0
cloudfunctions/getPublisher/package.json

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

+ 10 - 0
miniprogram/app.js

@@ -68,6 +68,16 @@ App({
       }).then(res => {
         if (res.result.data !== undefined) {
           this.globalData.userInfo = res.result.data
+          return wx.cloud.callFunction({
+            name: 'listPublishers',
+            data: {
+              type: 'manage'
+            }
+          })
+        }
+      }).then(res => {
+        if (res.result.list !== undefined) {
+          this.globalData.pubInfo = res.result.list
           this.globalData.hasUserInfo = true
           if (this.onUserInfoReady) {
             this.onUserInfoReady()

+ 39 - 19
miniprogram/pages/publisherPage/publisherPage.js

@@ -7,31 +7,33 @@ Page({
    * 页面的初始数据
    */
   data: {
-    publisherInfo: null,
-    hasPublisherInfo: false
+    pubInfo: null,
+    hasPubInfo: false,
+    pubName: [],
+    pubIndex: 0
   },
 
   publishInfo: function () {
     wx.navigateTo({
-      url: "/pages/activityPublish/activityPublish?id=" + this.data.publisherInfo._id,
+      url: "/pages/activityPublish/activityPublish?id=" + this.data.pubInfo[this.data.pubIndex].pub_id,
     })
   },
 
   receivedQuestion: function () {
     wx.navigateTo({
-      url: "/pages/receivedQuestion/receivedQuestion?id=" + this.data.publisherInfo._id
+      url: "/pages/receivedQuestion/receivedQuestion?id=" + this.data.pubInfo[this.data.pubIndex].pub_id
     })
   },
 
   publisherInfoChange: function () {
     wx.navigateTo({
-      url: "/pages/publisherInfoChange/publisherInfoChange?id=" + this.data.publisherInfo._id
+      url: "/pages/publisherInfoChange/publisherInfoChange?id=" + this.data.pubInfo[this.data.pubIndex].pub_id
     })
   },
 
   administratorSetting: function () {
     wx.navigateTo({
-      url: "/pages/administratorSetting/administratorSetting?id=" + this.data.publisherInfo._id
+      url: "/pages/administratorSetting/administratorSetting?id=" + this.data.pubInfo[pubIndex].pub_idd
     })
   },
 
@@ -39,19 +41,37 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    wx.showLoading({
-      title: "加载中",
-    })
-    const db = wx.cloud.database()
-    db.collection("publisherInfoData").doc(options.id).get({
-      success: function (res) {
-        this.setData({
-          publisherInfo: res.data,
-          hasPublisherInfo: true
-        })
-        wx.hideLoading()
-      }.bind(this)
-    })
+    // wx.showLoading({
+    //   title: "加载中",
+    // })
+    // const db = wx.cloud.database()
+    // db.collection("publisherInfoData").doc(options.id).get({
+    //   success: function (res) {
+    //     this.setData({
+    //       publisherInfo: res.data,
+    //       hasPublisherInfo: true
+    //     })
+    //     wx.hideLoading()
+    //   }.bind(this)
+    // })
+
+    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)
+      }
+      this.setData({
+        pubInfo: app.globalData.pubInfo,
+        hasPubInfo: true,
+        pubName: pubName,
+        pubIndex: 0
+      })
+    } else {
+      wx.showToast({
+        title: '请先登录',
+        icon: 'none'
+      })
+    }
   },
 
   /**

+ 13 - 4
miniprogram/pages/publisherPage/publisherPage.wxml

@@ -1,7 +1,8 @@
 <!-- 为发布者个人页面 -->
 <view class="card block-background-color">
-  <cover-image class="avatar" src="{{hasPublisherInfo ? publisherInfo.publisherAvatar : '/images/user/user.png'}}"></cover-image>
-  <view wx:if="{{hasPublisherInfo}}" class="publisher-name primary-text">{{publisherInfo.publisherName}}</view>
+  <cover-image class="avatar" src="{{hasPubInfo ? pubInfo[pubIndex].publisher[0].avatar : '/images/user/user.png'}}">
+  </cover-image>
+  <view wx:if="{{hasPubInfo}}" class="publisher-name primary-text">{{pubInfo[pubIndex].publisher[0].name}}</view>
 </view>
 
 <view class="gap"></view>
@@ -40,6 +41,14 @@
 
 <view class="btn block-background-color" hover-class="btn-hover" bindtap="publisherInfoChange">
   <image class="btn-icon" mode="aspectFit" src="/images/user/modify.png"></image>
-  <view class="btn-text primary-text">组织信息修改</view>
+  <view class="btn-text primary-text">社团组织信息修改</view>
   <view class="btn-arrow secondary-text">></view>
-</view>
+</view>
+
+<view class="gap"></view>
+
+<picker class="btn block-background-color" model:value="{{pubIndex}}" range="{{pubName}}">
+  <image class="btn-icon" mode="aspectFit" src="/images/user/setting.png"></image>
+  <view class="btn-text primary-text">切换社团组织</view>
+  <view class="btn-arrow secondary-text">></view>
+</picker>

+ 4 - 18
miniprogram/pages/user/user.js

@@ -20,25 +20,9 @@ Page({
   setUserInfo: function () {
     this.setData({
       userInfo: app.globalData.userInfo,
+      pubInfo: app.globalData.pubInfo,
       hasUserInfo: true
     })
-    wx.cloud.callFunction({
-      name: 'listPublishers',
-      data: {
-        type: 'manage'
-      }
-    }).then(res => {
-      if (res.result.list !== undefined) {
-        this.setData({
-          pubInfo: res.result.list
-        })
-      } else {
-        wx.showToast({
-          title: res.result.errMsg,
-          icon: 'none'
-        })
-      }
-    })
   },
 
   getUserProfile: function () {
@@ -83,7 +67,7 @@ Page({
 
   publisherPage: function () {
     wx.navigateTo({
-      url: "/pages/publisherPage/publisherPage?id=" + this.data.pubInfo[0].pub_id,
+      url: "/pages/publisherPage/publisherPage",
     })
   },
 
@@ -222,7 +206,9 @@ Page({
     if (app.globalData.hasUserInfo) {
       this.setUserInfo()
     } else {
+      wx.showNavigationBarLoading()
       app.onUserInfoReady = () => {
+        wx.hideNavigationBarLoading()
         this.setUserInfo()
       }
     }

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

@@ -5,7 +5,13 @@
   <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].name}}</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>
+  </view>
 </view>
 
 <view class="mid" wx:if="{{hasUserInfo}}">

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

@@ -18,8 +18,9 @@
   margin-bottom: 10rpx;
 }
 
-.location {
+.pub-name {
   font-size: 30rpx;
+  line-height: 50rpx;
 }
 
 .mid {