Bladeren bron

ADD

个人ID展示
mulioid 4 jaren geleden
bovenliggende
commit
d4f4ed56d0

+ 9 - 5
miniprogram/app.js

@@ -29,7 +29,7 @@ App({
         name: 'getUser'
       }).then(res => {
         if (res.result.status !== 'OK') {
-          return res.result
+          return res
         }
         this.globalData.userInfo = res.result.data
         return wx.cloud.callFunction({
@@ -42,12 +42,16 @@ App({
         })
       }).then(res => {
         if (res.result.status !== 'OK') {
+          this.globalData.userNotFound = true
+          if (this.onUserInfoChange) {
+            this.onUserInfoChange()
+          }
           return
         }
         this.globalData.pubInfo = res.result.list
         this.globalData.hasUserInfo = true
-        if (this.onUserInfoReady) {
-          this.onUserInfoReady()
+        if (this.onUserInfoChange) {
+          this.onUserInfoChange()
         }
       })
     }
@@ -57,8 +61,8 @@ App({
     userInfo: {},
     pubInfo: [],
     hasUserInfo: false,
+    userNotFound: false,
     openId: null,
-    noticeIndex: null,
-    vibrate: null
+    noticeForm: 0
   }
 })

+ 4 - 0
miniprogram/pages/activity/activity.js

@@ -7,6 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    hasUserInfo: false,
     messageId: '',
     activityInfo: {},
     like: false,
@@ -192,6 +193,9 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    this.setData({
+      hasUserInfo: app.globalData.hasUserInfo
+    })
     if (options.id) {
       this.setData({
         messageId: options.id

+ 3 - 2
miniprogram/pages/activity/activity.wxml

@@ -51,14 +51,15 @@
   <view class="message-block">
     <view style="display: flex; justify-content: space-between;">
       <view class="title2">{{activityComment.length === 0 ? "暂无问答" : "答疑区:"}}</view>
-      <image class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png" catchtap="toggleLike" />
+      <image wx:if="{{hasUserInfo}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
+        catchtap="toggleLike" />
     </view>
     <view class="card1" wx:for="{{activityComment}}" wx:for-item="comm" wx:key="_id">
       <itemActivityComment comment="{{comm}}" />
     </view>
   </view>
 
-  <view class="comment secondary-background-color">
+  <view wx:if="{{hasUserInfo}}" class="comment secondary-background-color">
     <view class="comment-inside" style="display: flex; align-items: center;">
       <icon type="info" size="20" color="#B0B0B0"></icon>
       <input class="comment-input" style="width: 550rpx;" model:value="{{commentText}}" placeholder="提问"

+ 5 - 0
miniprogram/pages/publisher/publisher.js

@@ -1,3 +1,4 @@
+const app = getApp()
 const util = require('../../utils/util.js')
 
 Page({
@@ -6,6 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    hasUserInfo: false,
     publisherId: '',
     publisherInfo: {},
     like: false,
@@ -104,6 +106,9 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    this.setData({
+      hasUserInfo: app.globalData.hasUserInfo
+    })
     if (options.id) {
       this.setData({
         publisherId: options.id

+ 2 - 1
miniprogram/pages/publisher/publisher.wxml

@@ -5,7 +5,8 @@
       <image class="publisher-avatar" src="{{publisherInfo.avatar}}" mode="aspectFill" bindtap="viewAvatar" />
       <text class="publisher-name">{{publisherInfo.name}}</text>
     </view>
-    <image class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png" bindtap="toggleLike" />
+    <image wx:if="{{hasUserInfo}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
+      bindtap="toggleLike" />
   </view>
 
   <view class="detailed-info">

+ 22 - 20
miniprogram/pages/setting/setting.js

@@ -3,34 +3,36 @@ const app = getApp()
 
 Page({
   data: {
-    noticeIndex: 0,
-    noticeForm: ['数字', '红点', '不显示'],
-    vibrate: false
+    userInfo: null,
+    hasUserInfo: false,
+    noticeForm: 0,
+    noticeFormType: ['数字', '红点', '不显示']
   },
 
-  myColor: function () {
-    wx.navigateTo({
-      url: '/pages/myColor/myColor'
-    })
-  },
-
-  noticeIndexChange: function (e) {
+  noticeFormChange: function (e) {
+    app.globalData.noticeForm = e.detail.value
     this.setData({
-      noticeIndex: e.detail.value
+      noticeForm: app.globalData.noticeForm
     })
-    app.globalData.noticeIndex = e.detail.value
   },
 
-  vibrateChange: function (e) {
-    this.setData({
-      vibrate: e.detail.value
-    })
-    app.globalData.vibrate = e.detail.value
+  logout: function () {
+    app.globalData.hasUserInfo = false
+    wx.navigateBack()
   },
 
   onLoad: function () {
-    this.data.noticeIndex = app.globalData.noticeIndex
-    this.data.vibrate = app.globalData.vibrate
+    if (app.globalData.hasUserInfo) {
+      this.setData({
+        userInfo: app.globalData.userInfo,
+        hasUserInfo: true,
+        noticeForm: app.globalData.noticeForm
+      })
+    } else {
+      wx.showToast({
+        title: '请先登录',
+        icon: 'none'
+      })
+    }
   }
-
 })

+ 4 - 4
miniprogram/pages/setting/setting.wxml

@@ -25,17 +25,17 @@
     <image class="btn-icon" mode="aspectFit" src="/images/user/id.png"></image>
     <view>个人ID</view>
   </view>
-  <view>87654332</view>
+  <view>{{userInfo._id}}</view>
 </view>
 
-<picker bindchange="noticeIndexChange" value="{{noticeIndex}}" range="{{noticeForm}}">
+<picker bindchange="noticeFormChange" value="{{noticeForm}}" range="{{noticeFormType}}">
   <view class="block" hover-class="btn-hover">
     <view class="left">
       <image class=" btn-icon" mode="aspectFit" src="/images/user/question.png">
       </image>
       <view>消息通知形式</view>
     </view>
-    <view>{{noticeForm[noticeIndex]}}</view>
+    <view>{{noticeFormType[noticeForm]}}</view>
   </view>
 </picker>
 
@@ -45,7 +45,7 @@
   <switch class="btn-arrow secondary-text" checked="{{vibrate}}" bindchange="vibrateChange" />
 </view> -->
 
-<view class="block" hover-class="btn-hover" bindtap="opinion">
+<view class="block" hover-class="btn-hover" bindtap="logout">
   <view class="left">
     <image class="btn-icon" mode="aspectFit" src="/images/user/feedback.png"></image>
     <view>退出登录</view>

+ 9 - 3
miniprogram/pages/user/user.js

@@ -138,12 +138,18 @@ Page({
   onShow: function () {
     if (app.globalData.hasUserInfo) {
       this.setUserInfo()
-    } else {
+    } else if (!app.globalData.userNotFound) {
       wx.showNavigationBarLoading()
-      app.onUserInfoReady = () => {
+      app.onUserInfoChange = () => {
         wx.hideNavigationBarLoading()
-        this.setUserInfo()
+        if (app.globalData.hasUserInfo) {
+          this.setUserInfo()
+        }
       }
+    } else {
+      this.setData({
+        hasUserInfo: false
+      })
     }
   },