Bladeren bron

Merge refs/remotes/origin/master into refs/heads/master

Chicolor 4 jaren geleden
bovenliggende
commit
9eadcfdc2d

+ 6 - 0
cloudfunctions/getUser/config.json

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

+ 16 - 0
cloudfunctions/getUser/index.js

@@ -0,0 +1,16 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  let {
+    OPENID
+  } = cloud.getWXContext()
+
+  return db.collection('user').where({
+    _id: OPENID
+  }).get()
+}

+ 14 - 0
cloudfunctions/getUser/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "getCurrentUser",
+  "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/updateUser/config.json

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

+ 35 - 0
cloudfunctions/updateUser/index.js

@@ -0,0 +1,35 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  let {
+    OPENID
+  } = cloud.getWXContext()
+
+  db.collection('user').where({
+    _id: OPENID
+  }).get().then(res => {
+    if (res.data.length) {
+      db.collection('user').doc(OPENID).update({
+        data: {
+          name: event.name,
+          avatar: event.avatar,
+          gender: event.gender
+        }
+      })
+    } else {
+      db.collection('user').add({
+        data: {
+          _id: OPENID,
+          name: event.name,
+          avatar: event.avatar,
+          gender: event.gender
+        }
+      })
+    }
+  })
+}

+ 14 - 0
cloudfunctions/updateUser/package.json

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

+ 53 - 48
miniprogram/app.js

@@ -6,50 +6,50 @@ App({
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
 
-    // 登录
-    wx.login({
-      success: res => {
-        // 发送 res.code 到后台换取 openId, sessionKey, unionId
-      }
-    })
-    // 获取用户信息
-    wx.getSetting({
-      success: res => {
-        if (res.authSetting['scope.userInfo']) {
-          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
-          wx.getUserInfo({
-            success: res => {
-              // 可以将 res 发送给后台解码出 unionId
-              this.globalData.userInfo = res.userInfo
-              console.log(this.globalData.userInfo)
-              const db = wx.cloud.database()
-              db.collection("userInfoData").get({
-                success: function (user) {
-                  if (user.data.length == 0) {
-                    db.collection("userInfoData").add({
-                      data: {
-                        publisherId: []
-                      },
-                      success: function () {
-                        this.globalData.publisherId = []
-                        if (this.userInfoReadyCallback) {
-                          this.userInfoReadyCallback(res)
-                        }
-                      }.bind(this)
-                    })
-                  } else {
-                    this.globalData.publisherId = user.data[0].publisherId
-                    if (this.userInfoReadyCallback) {
-                      this.userInfoReadyCallback(res)
-                    }
-                  }
-                }.bind(this)
-              })
-            }
-          })
-        }
-      }
-    })
+    // // 登录
+    // wx.login({
+    //   success: res => {
+    //     // 发送 res.code 到后台换取 openId, sessionKey, unionId
+    //   }
+    // })
+    // // 获取用户信息
+    // wx.getSetting({
+    //   success: res => {
+    //     if (res.authSetting['scope.userInfo']) {
+    //       // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
+    //       wx.getUserInfo({
+    //         success: res => {
+    //           // 可以将 res 发送给后台解码出 unionId
+    //           this.globalData.userInfo = res.userInfo
+    //           console.log(this.globalData.userInfo)
+    //           const db = wx.cloud.database()
+    //           db.collection("userInfoData").get({
+    //             success: function (user) {
+    //               if (user.data.length == 0) {
+    //                 db.collection("userInfoData").add({
+    //                   data: {
+    //                     publisherId: []
+    //                   },
+    //                   success: function () {
+    //                     this.globalData.publisherId = []
+    //                     if (this.userInfoReadyCallback) {
+    //                       this.userInfoReadyCallback(res)
+    //                     }
+    //                   }.bind(this)
+    //                 })
+    //               } else {
+    //                 this.globalData.publisherId = user.data[0].publisherId
+    //                 if (this.userInfoReadyCallback) {
+    //                   this.userInfoReadyCallback(res)
+    //                 }
+    //               }
+    //             }.bind(this)
+    //           })
+    //         }
+    //       })
+    //     }
+    //   }
+    // })
 
     if (!wx.cloud) {
       console.error('请使用 2.2.3 或以上的基础库以使用云能力')
@@ -62,11 +62,16 @@ App({
         env: "msg-push-9ga0xxc9c4aa5242",
         traceUser: true,
       })
+
       wx.cloud.callFunction({
-        name: "getOpenId",
-        success: function (res) {
-          this.globalData.openId = res.result.openId
-        }.bind(this)
+        name: 'getUser'
+      }).then(res => {
+        if (res.result.data.length) {
+          this.globalData.userInfo = res.result.data[0]
+          if (this.onUserInfoReady) {
+            this.onUserInfoReady()
+          }
+        }
       })
     }
   },

+ 8 - 0
miniprogram/components/imagePicker/imagePicker.js

@@ -15,7 +15,15 @@ Component({
    * 组件的初始数据
    */
   data: {
+    imageMargin: 0
+  },
 
+  observers: {
+    'images, max, readonly': function (images, max, readonly) {
+      this.setData({
+        imageMargin: images.length + (images.length < max && !readonly) > 1 ? 5 : 0
+      })
+    }
   },
 
   /**

+ 6 - 4
miniprogram/components/imagePicker/imagePicker.wxml

@@ -1,12 +1,14 @@
 <!--components/imagePicker/imagePicker.wxml-->
-<view style="text-align: center;">
+<view class="image-list">
   <label wx:for="{{images}}" wx:for-item="item" wx:key="*this">
-    <image class="image" style="position: relative; width: {{imageWidth}}rpx; height: {{imageHeight}}rpx;"
+    <image class="image"
+      style="position: relative; margin: {{imageMargin}}rpx; width: {{imageWidth}}rpx; height: {{imageHeight}}rpx;"
       src="{{item}}" mode="aspectFill" data-url="{{item}}" catchtap="previewImage">
       <icon wx:if="{{!readonly}}" style="position: absolute; top: 0; left: 0;" type="cancel" size="20"
         data-url="{{item}}" catchtap="removeImage"></icon>
     </image>
   </label>
-  <image wx:if="{{images.length < max && !readonly}}" class="image" style="width: 150rpx; height: 150rpx;"
-    src="/images/add.png" mode="aspectFill" catchtap="addImage"></image>
+  <image wx:if="{{images.length < max && !readonly}}" class="image"
+    style="margin: {{imageMargin}}rpx; width: 150rpx; height: 150rpx;" src="/images/add.png" mode="aspectFill"
+    catchtap="addImage"></image>
 </view>

+ 7 - 4
miniprogram/components/imagePicker/imagePicker.wxss

@@ -1,7 +1,10 @@
 /* components/imagePicker/imagePicker.wxss */
-/* .image {
-  margin: 5rpx;
+.image-list {
+  text-align: center;
+}
+
+.image {
   border-style: solid;
   border-width: 1rpx;
-  border-color: #D0D0D0;
-} */
+  border-color: #DDDDDD;
+}

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

@@ -17,8 +17,8 @@
   <imagePicker wx:if="{{item.poster != ''}}" images="{{[item.poster]}}" max="1" image-width="700" image-height="350"
     readonly />
   <imagePicker wx:if="{{item.poster == '' && item.photo.length != 0}}" images="{{item.photo}}" max="1"
-    image-width="{{item.photo.length == 1 ? 700 : item.photo.length <= 4 ? 330 : 220}}"
-    image-height="{{item.photo.length == 1 ? 700 : item.photo.length <= 4 ? 330 : 220}}" readonly />
+    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"

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

@@ -10,7 +10,6 @@
 
 .avatar-name {
   display: flex;
-  flex-direction: row;
 }
 
 .publisher-avatar {
@@ -27,7 +26,6 @@
 
 .profile {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   position: relative;
   top: -20rpx;
@@ -69,7 +67,6 @@
   margin-right: 30rpx;
   margin-bottom: 20rpx;
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: flex-end;
 }
@@ -83,7 +80,6 @@
 
 .bottom-line {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: center;
   margin: 10rpx 10rpx 30rpx 10rpx;
@@ -91,13 +87,11 @@
 
 .tags {
   display: flex;
-  flex-direction: row;
   align-items: center;
 }
 
 .to-detail {
   display: flex;
-  flex-direction: row;
   align-items: center;
 }
 

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

@@ -15,7 +15,6 @@
 
 .profile{
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   padding-right: 30rpx;
 }

+ 0 - 3
miniprogram/components/itemmyNews/itemmyNews.wxss

@@ -18,7 +18,6 @@
 
 .top {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: flex-end;
   margin: 0rpx 30rpx 0rpx 30rpx;
@@ -26,7 +25,6 @@
 
 .bottom {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: center;
   margin: 20rpx 30rpx 0rpx 30rpx;
@@ -35,7 +33,6 @@
 
 /* .profile {
   display: flex;
-  flex-direction: row;
   align-items: center;
 } */
 

+ 0 - 3
miniprogram/pages/aboutUs/aboutUs.wxss

@@ -56,7 +56,6 @@
 
 .block {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
   align-items: center;
@@ -64,14 +63,12 @@
 
 .block2 {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
 }
 
 .block22 {
   display: flex;
-  flex-direction: row;
 }
 
 .input {

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

@@ -148,6 +148,7 @@ Page({
     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
         })
@@ -160,7 +161,7 @@ Page({
     }).get({
       success: function (res) {
         for (let i = 0; i < res.data.length; i++) {
-          if (res.data[i].answerTime != "") {
+          if (res.data[i].answerTime !== "") {
             res.data[i].time = util.handleDate(res.data[i].answerTime)
           } else {
             res.data[i].time = ""

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

@@ -1,54 +1,54 @@
 <!--为首页-信息详情页面-->
-<view class="card">
-  <image wx:if="{{activityInfo.poster != ''}}" class="activity-poster" src="{{activityInfo.poster}}"
-    mode="aspectFill" />
-  <view class="activity-info">
-    <view class="profile">
-      <view class="avatar-name" catchtap="getPublisherInfo">
-        <image class="publisher-avatar" src="{{activityInfo.publisherAvatar}}"></image>
-        <view class="publisher-name">{{activityInfo.publisherName}}</view>
+<view class="page">
+  <view class="card">
+    <image wx:if="{{activityInfo.poster != ''}}" class="activity-poster" src="{{activityInfo.poster}}"
+      mode="aspectFill" />
+    <view class="activity-info">
+      <view class="profile">
+        <view class="avatar-name" catchtap="getPublisherInfo">
+          <image class="publisher-avatar" src="{{activityInfo.publisherAvatar}}"></image>
+          <view class="publisher-name">{{activityInfo.publisherName}}</view>
+        </view>
+        <view class="activity-attribute primary-background-color white-text-color" catchtap="filterMsgType">
+          {{activityInfo.attribute[0]}}
+        </view>
       </view>
-      <view class="activity-attribute primary-background-color white-text-color" catchtap="filterMsgType">
-        {{activityInfo.attribute[0]}}
+      <view class="title-time">
+        <view class="title">{{activityInfo.title}}</view>
+        <view class="time primary-text-color">{{activityInfo.time}}</view>
       </view>
+      <view wx:if="{{activityInfo.activityTime != ''}}" class="line light-primary-color"></view>
+      <view wx:if="{{activityInfo.activityTime != ''}}" class="activity-time">{{activityInfo.activityTime}}</view>
+      <view wx:if="{{activityInfo.place != ''}}" class="line light-primary-color"></view>
+      <view wx:if="{{activityInfo.place != ''}}" class="activity-place">{{activityInfo.place}}</view>
+      <view wx:if="{{activityInfo.details != ''}}" class="line light-primary-color"></view>
+      <view wx:if="{{activityInfo.details != ''}}" class="activity-detail">
+        <rich-text class="sub-title">{{activityInfo.details}}</rich-text>
+      </view>
+      <imagePicker wx:if="{{activityInfo.photo.length != 0}}" images="{{activityInfo.photo}}" max="1"
+        image-width="{{activityInfo.photo.length == 1 ? 696 : activityInfo.photo.length <= 4 ? 330 : 220}}"
+        image-height="{{activityInfo.photo.length == 1 ? 696 : activityInfo.photo.length <= 4 ? 330 : 220}}" readonly />
+      <view class="line light-primary-color"></view>
     </view>
-    <view class="title-time">
-      <view class="title">{{activityInfo.title}}</view>
-      <view class="time primary-text-color">{{activityInfo.time}}</view>
-    </view>
-    <view wx:if="{{activityInfo.activityTime != ''}}" class="line light-primary-color"></view>
-    <view wx:if="{{activityInfo.activityTime != ''}}" class="activity-time">{{activityInfo.activityTime}}</view>
-    <view wx:if="{{activityInfo.place != ''}}" class="line light-primary-color"></view>
-    <view wx:if="{{activityInfo.place != ''}}" class="activity-place">{{activityInfo.place}}</view>
-    <view wx:if="{{activityInfo.details != ''}}" class="line light-primary-color"></view>
-    <view wx:if="{{activityInfo.details != ''}}" class="activity-detail">
-      <rich-text class="sub-title">{{activityInfo.details}}</rich-text>
-    </view>
-    <imagePicker wx:if="{{activityInfo.photo.length != 0}}" images="{{activityInfo.photo}}" max="1"
-      image-width="{{activityInfo.photo.length == 1 ? 700 : activityInfo.photo.length <= 4 ? 330 : 220}}"
-      image-height="{{activityInfo.photo.length == 1 ? 700 : activityInfo.photo.length <= 4 ? 330 : 220}}" readonly />
-    <view class="line light-primary-color"></view>
   </view>
 
-</view>
-
+  <image wx:if="{{like != -1}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
+    catchtap="toggleLike" />
 
-<image wx:if="{{like != -1}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
-  catchtap="toggleLike" />
-
-<view class="message-block">
-  <view class="dark-primary-color-font">{{activityComment.length == 0 ? "暂无问答" : "答疑区:"}}</view>
-  <view class="card" wx:for="{{activityComment}}" wx:for-item="item" wx:key="_id">
-    <itemActivityComment comment="{{item}}" time="{{item.time}}" />
+  <view class="message-block">
+    <view class="dark-primary-color-font">{{activityComment.length == 0 ? "暂无问答" : "答疑区:"}}</view>
+    <view class="card" wx:for="{{activityComment}}" wx:for-item="item" wx:key="_id">
+      <itemActivityComment comment="{{item}}" time="{{item.time}}" />
+    </view>
   </view>
-</view>
 
-<view class="comment block-background-color">
-  <view class="comment-inside" style="display: flex; align-items: center;">
-    <icon type="info" size="20" color="#B0B0B0"></icon>
-    <input class="comment-input primary-text-color" style="width: 550rpx;" model:value="{{commentText}}"
-      placeholder="提问" confirm-type="send" bindconfirm="comment"></input>
+  <view class="comment block-background-color">
+    <view class="comment-inside" style="display: flex; align-items: center;">
+      <icon type="info" size="20" color="#B0B0B0"></icon>
+      <input class="comment-input primary-text-color" style="width: 550rpx;" model:value="{{commentText}}"
+        placeholder="提问" confirm-type="send" bindconfirm="comment"></input>
+    </view>
+    <view class="comment-button {{commentText.length < 5 ? 'secondary-text-color' : 'dark-primary-color-font'}}"
+      bindtap="comment">发送</view>
   </view>
-  <view class="comment-button {{commentText.length < 5 ? 'secondary-text-color' : 'dark-primary-color-font'}}"
-    bindtap="comment">发送</view>
 </view>

+ 7 - 9
miniprogram/pages/activity/activity.wxss

@@ -22,14 +22,12 @@
 
 .brief-info{
   display: flex;
-  flex-direction: row;
   align-items: center;
   justify-content: space-between;
 }
 
 .brief-info-left{
   display: flex;
-  flex-direction: row;
   align-items: center;
 }
 
@@ -118,11 +116,17 @@
   text-align: center;
 }
 
-
+.page {
+  display: flex;
+  flex-direction: column;
+  justify-content: flex-start;
+  width: 100%;
+}
 
 .card {
   display: flex;
   flex-direction: column;
+  align-self: center;
   width: 700rpx;
   margin: 50rpx 20rpx;
   padding-bottom: 20rpx;
@@ -133,7 +137,6 @@
 
 .avatar-name {
   display: flex;
-  flex-direction: row;
 }
 
 .publisher-avatar {
@@ -150,7 +153,6 @@
 
 .profile {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   position: relative;
   top: -20rpx;
@@ -192,7 +194,6 @@
   margin-right: 30rpx;
   margin-bottom: 20rpx;
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: flex-end;
 }
@@ -206,7 +207,6 @@
 
 .bottom-line {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: center;
   margin: 10rpx 10rpx 30rpx 10rpx;
@@ -214,13 +214,11 @@
 
 .tags {
   display: flex;
-  flex-direction: row;
   align-items: center;
 }
 
 .to-detail {
   display: flex;
-  flex-direction: row;
   align-items: center;
 }
 

+ 0 - 3
miniprogram/pages/activityPublish/activityPublish.wxss

@@ -57,7 +57,6 @@
 
 .block {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
   align-items: center;
@@ -65,14 +64,12 @@
 
 .block2 {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
 }
 
 .block22 {
   display: flex;
-  flex-direction: row;
 }
 
 .input {

+ 0 - 3
miniprogram/pages/opinion/opinion.wxss

@@ -58,7 +58,6 @@
 
 .block {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
   align-items: center;
@@ -66,14 +65,12 @@
 
 .block2 {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
 }
 
 .block22 {
   display: flex;
-  flex-direction: row;
 }
 
 .input {

+ 0 - 3
miniprogram/pages/publisher/publisher.wxss

@@ -8,7 +8,6 @@
 
 .brief-info {
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
   align-items: center;
   z-index: 1;
@@ -17,7 +16,6 @@
 
 .brief-info-left {
   display: flex;
-  flex-direction: row;
   align-items: center;
   margin: 0rpx 0rpx 0rpx 40rpx;
 }
@@ -59,7 +57,6 @@
 
 .check {
   display: flex;
-  flex-direction: row;
   align-items: center;
   position: absolute;
   right: 50rpx;

+ 0 - 3
miniprogram/pages/publisherLogin/publisherLogin.wxss

@@ -57,7 +57,6 @@
 
 .block {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
   align-items: center;
@@ -65,14 +64,12 @@
 
 .block2 {
   display: flex;
-  flex-direction: row;
   margin: 20rpx 40rpx;
   font-size: 35rpx;
 }
 
 .block22 {
   display: flex;
-  flex-direction: row;
 }
 
 .input {

+ 0 - 1
miniprogram/pages/search/search.wxss

@@ -75,7 +75,6 @@
   margin: 10rpx 40rpx;
   font-size: 24rpx;
   display: flex;
-  flex-direction: row;
   justify-content: space-between;
 }
 

+ 124 - 81
miniprogram/pages/user/user.js

@@ -13,9 +13,38 @@ Page({
     publisherName: ""
   },
 
-  bindGetUserInfo: function (e) {
-    app.globalData.userInfo = e.detail.userInfo
-    this.onShow()
+  // bindGetUserInfo: function (e) {
+  //   app.globalData.userInfo = e.detail.userInfo
+  //   this.onShow()
+  // },
+
+  getUserProfile: function () {
+    wx.getUserProfile({
+      desc: '用于完善个人信息',
+      success: (res) => {
+        app.globalData.userInfo = {
+          name: res.userInfo.nickName,
+          avatar: res.userInfo.avatarUrl,
+          gender: res.userInfo.gender
+        }
+        this.setData({
+          userInfo: app.globalData.userInfo,
+          hasUserInfo: true
+        })
+        wx.cloud.callFunction({
+          name: 'updateUser',
+          data: app.globalData.userInfo
+        })
+      }
+    })
+  },
+
+  previewAvatar: function () {
+    if (this.data.hasUserInfo) {
+      wx.previewImage({
+        urls: [this.data.userInfo.avatar]
+      })
+    }
   },
 
   publisherLogin: function () {
@@ -70,48 +99,48 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    wx.showNavigationBarLoading()
-    if (app.globalData.userInfo && app.globalData.publisherId) {
-      this.setData({
-        userInfo: app.globalData.userInfo,
-        hasUserInfo: true,
-        publisherId: app.globalData.publisherId
-      })
-      if (this.data.publisherId.length != 0) {
-        const db = wx.cloud.database()
-        db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
-          success: function (res) {
-            this.setData({
-              publisherName: res.data.publisherName
-            })
-            wx.hideNavigationBarLoading()
-          }.bind(this)
-        })
-      } else {
-        wx.hideNavigationBarLoading()
-      }
-    } else {
-      app.userInfoReadyCallback = res => {
-        this.setData({
-          userInfo: res.userInfo,
-          hasUserInfo: true,
-          publisherId: app.globalData.publisherId
-        })
-        if (this.data.publisherId.length != 0) {
-          const db = wx.cloud.database()
-          db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
-            success: function (res) {
-              this.setData({
-                publisherName: res.data.publisherName
-              })
-              wx.hideNavigationBarLoading()
-            }.bind(this)
-          })
-        } else {
-          wx.hideNavigationBarLoading()
-        }
-      }
-    }
+    // wx.showNavigationBarLoading()
+    // if (app.globalData.userInfo && app.globalData.publisherId) {
+    //   this.setData({
+    //     userInfo: app.globalData.userInfo,
+    //     hasUserInfo: true,
+    //     publisherId: app.globalData.publisherId
+    //   })
+    //   if (this.data.publisherId.length != 0) {
+    //     const db = wx.cloud.database()
+    //     db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
+    //       success: function (res) {
+    //         this.setData({
+    //           publisherName: res.data.publisherName
+    //         })
+    //         wx.hideNavigationBarLoading()
+    //       }.bind(this)
+    //     })
+    //   } else {
+    //     wx.hideNavigationBarLoading()
+    //   }
+    // } else {
+    //   app.userInfoReadyCallback = res => {
+    //     this.setData({
+    //       userInfo: res.userInfo,
+    //       hasUserInfo: true,
+    //       publisherId: app.globalData.publisherId
+    //     })
+    //     if (this.data.publisherId.length != 0) {
+    //       const db = wx.cloud.database()
+    //       db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
+    //         success: function (res) {
+    //           this.setData({
+    //             publisherName: res.data.publisherName
+    //           })
+    //           wx.hideNavigationBarLoading()
+    //         }.bind(this)
+    //       })
+    //     } else {
+    //       wx.hideNavigationBarLoading()
+    //     }
+    //   }
+    // }
   },
 
   /**
@@ -125,42 +154,56 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-    const db = wx.cloud.database()
-    db.collection("userInfoData").get({
-      success: function (res) {
-        if (res.data.length == 0) {
-          db.collection("userInfoData").add({
-            data: {
-              publisherId: []
-            },
-            success: function (res) {
-              app.globalData.publisherId = []
-              this.setData({
-                userInfo: app.globalData.userInfo,
-                hasUserInfo: true,
-                publisherId: app.globalData.publisherId
-              })
-            }.bind(this)
-          })
-        } else {
-          app.globalData.publisherId = res.data[0].publisherId
-          this.setData({
-            userInfo: app.globalData.userInfo,
-            hasUserInfo: true,
-            publisherId: app.globalData.publisherId
-          })
-          if (this.data.publisherId.length != 0) {
-            db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
-              success: function (res) {
-                this.setData({
-                  publisherName: res.data.publisherName
-                })
-              }.bind(this)
-            })
-          }
-        }
-      }.bind(this)
-    })
+    // const db = wx.cloud.database()
+    // db.collection("userInfoData").get({
+    //   success: function (res) {
+    //     if (res.data.length == 0) {
+    //       db.collection("userInfoData").add({
+    //         data: {
+    //           publisherId: []
+    //         },
+    //         success: function (res) {
+    //           app.globalData.publisherId = []
+    //           this.setData({
+    //             userInfo: app.globalData.userInfo,
+    //             hasUserInfo: true,
+    //             publisherId: app.globalData.publisherId
+    //           })
+    //         }.bind(this)
+    //       })
+    //     } else {
+    //       app.globalData.publisherId = res.data[0].publisherId
+    //       this.setData({
+    //         userInfo: app.globalData.userInfo,
+    //         hasUserInfo: true,
+    //         publisherId: app.globalData.publisherId
+    //       })
+    //       if (this.data.publisherId.length != 0) {
+    //         db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
+    //           success: function (res) {
+    //             this.setData({
+    //               publisherName: res.data.publisherName
+    //             })
+    //           }.bind(this)
+    //         })
+    //       }
+    //     }
+    //   }.bind(this)
+    // })
+
+    if (app.globalData.userInfo) {
+      this.setData({
+        userInfo: app.globalData.userInfo,
+        hasUserInfo: true
+      })
+    } else {
+      app.onUserInfoReady = () => {
+        this.setData({
+          userInfo: app.globalData.userInfo,
+          hasUserInfo: true
+        })
+      }
+    }
   },
 
   /**

+ 5 - 4
miniprogram/pages/user/user.wxml

@@ -1,9 +1,10 @@
 <!--为使用者-我的页面-->
 <view class="card">
-  <cover-image class="avatar" src="{{hasUserInfo ? userInfo.avatarUrl : '/images/user/user.png'}}"></cover-image>
-  <view wx:if="{{hasUserInfo}}" class="nickname primary-text">{{userInfo.nickName}}</view>
-  <view wx:else class="nickname"><button class="block-background-color" size="mini" open-type="getUserInfo"
-      bindgetuserinfo="bindGetUserInfo">微信登录</button></view>
+  <cover-image class="avatar" src="{{hasUserInfo ? userInfo.avatar : '/images/user/user.png'}}" bindtap="previewAvatar">
+  </cover-image>
+  <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">{{publisherId.length == 0 ? '尚未加入任何社团组织' : publisherName}}</view>
 </view>
 

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

@@ -31,7 +31,6 @@
 
 .btn {
   display: flex;
-  flex-direction: row;
   margin-top: 20rpx;
   align-items: center;
 }