xiaohuangmao преди 4 години
родител
ревизия
5d5aa2c7aa
променени са 2 файла, в които са добавени 44 реда и са изтрити 11 реда
  1. 43 10
      pages/components/wxbutton/wxbutton.js
  2. 1 1
      pages/components/wxbutton/wxbutton.wxml

+ 43 - 10
pages/components/wxbutton/wxbutton.js

@@ -1,4 +1,9 @@
 // pages/components/wxbutton/wxbutton.js
+const api = require('../../../config');
+const getReq = require('../../../config').getReq;
+const ald = require('../../../utils/ald-stat.js')
+
+let app = getApp();
 Component({
  /**
   * 组件的属性列表
@@ -23,14 +28,42 @@ Component({
   * 组件的方法列表
   */
  methods: {
-    userInfoHandler() {
-        console.log('userInfoHandler');
-    },
-    
-    navigator(e) {
-        wx.switchTab({
-          url: '/pages/myhome/myhome',
-        })
-    }
-}
+     onGetUserInfo(e) {
+         console.log('onGetUserInfo');
+         if (e.detail.errMsg == "getUserInfo:ok") {
+             app.globalData.userInfo = e.detail.userInfo;
+             app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
+             this.wxauthen(e)
+         }
+     },
+     wxauthen: function (eInfo) {
+         let userInfo;
+         if (app.globalData.userId.unionid) {
+             userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
+         }
+         else {
+             userInfo = eInfo.detail.userInfo;
+             let { encryptedData, iv, signature } = eInfo.detail
+             userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
+         }
+
+         let params = {
+             user_info: userInfo,
+             act: "login",
+             op: "wxauthen",
+             relay_id: app.globalData.relay_id,
+             channel: app.globalData.channel_num
+         }
+
+         let self = this;
+         getReq(app, params, function (res) {
+             if (res.code == 200) {
+                 let datas = res.datas;
+                 app.globalData.member_id = datas.member_id
+                 app.globalData.hasmobile = datas.hasmobile
+             }
+             app.switchtab('/pages/myhome/myhome') 
+         })
+     }
+   }
 })

+ 1 - 1
pages/components/wxbutton/wxbutton.wxml

@@ -1,7 +1,7 @@
 <!--pages/components/wxbutton/wxbutton.wxml-->
 <view wx:if="{{item_data.show_data==='getUserInfo'}}">
 	<button class="btn" bindtap="navigator" open-type="getUserInfo" bindgetuserinfo="onGetUserInfo">
-		<image bindtap="navigator" mode="widthFix" src="{{item_data.image}}" style="width:'100%'; height:'100%';">
+		<image mode="widthFix" src="{{item_data.image}}" style="width:'100%'; height:'100%';">
 		</image>
 	</button>
 </view>