Browse Source

修复获取用户授权问题

Your Name 1 year ago
parent
commit
ee0cc4b69a
3 changed files with 44 additions and 2 deletions
  1. 32 1
      pages/apply/apply.js
  2. 11 0
      pages/apply/apply.wxml
  3. 1 1
      pages/index/index.js

+ 32 - 1
pages/apply/apply.js

@@ -7,7 +7,8 @@ Page({
    * 页面的初始数据
    */
   data: {
-    list:[]
+    list:[],
+    show:1
   },
 
   /**
@@ -21,6 +22,14 @@ Page({
       openid: app.globalData.openid
     })
     this.getData();
+    wx.getStorage({
+      key: 'userInfo',
+      success: res=> {
+        if(res.data){
+          this.setData({show:0})
+        }
+      },
+    })
   },
   getData:function(){
     wx.request({
@@ -77,6 +86,28 @@ Page({
       url: '../pay/pay?id='+e.target.dataset.id,
     })
   },
+  onGotUserInfo: function (e) {
+    wx.setStorage({
+      key: 'userInfo',
+      data: e.detail.userInfo,
+    })
+    console.log(app.globalData.openid)
+    wx.request({
+      url: host+'/api/wx/auth',
+      method:'POST',
+      data:{
+        nickname: e.detail.userInfo.nickName, 
+        avatar: e.detail.userInfo.avatarUrl, 
+        openid: app.globalData.openid, 
+      },
+      success:res=>{
+          console.log(res)
+          this.setData({
+            show:0
+          })
+      }
+    })
+  },
 
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 11 - 0
pages/apply/apply.wxml

@@ -60,3 +60,14 @@
     <navigator url="../onlinePost/onlinePost" class="post">立即报名</navigator>
 </view>
 
+<view class="login" wx:if='{{show}}'>
+    <view>
+        <view>
+          <image src="../../images/logo.png" mode="widthFix"></image>
+          <text class="slogen">巴中逸沣安全培训</text>
+        </view>
+        <text class="xx">申请获取您的用户信息(头像、昵称等)</text>
+        <button bindgetuserinfo="onGotUserInfo" open-type="getUserInfo">确定</button>
+    </view>
+</view>
+

+ 1 - 1
pages/index/index.js

@@ -6,7 +6,7 @@ Page({
   data: {
     act:6,
     openid:'',
-    show:1,
+    show:0,
     data:[],
     news: ['国家安全生产监督管理总局30号令'],
     animationData:{}