Kaynağa Gözat

add to locak

stanley-king 4 yıl önce
ebeveyn
işleme
8faf3bc2a9

+ 108 - 0
pages/components/auth2/auth2.js

@@ -0,0 +1,108 @@
+// pages/components/auth/auth.js
+const api = require('../../../config');
+const getReq = require('../../../config').getReq;
+const ald = require('../../../utils/ald-stat.js')
+
+let app = getApp();
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    item_data: {
+      type: Object
+    }
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    phone_iv: '',
+    phone_encryptedData: '',
+    userInfoE: {},
+    showAuthName: true,
+    showAuthPhone: false,
+  },
+
+  lifetimes: {
+    attached: function () {
+      if (!app.globalData.userInfo) {
+        this.setData({ showAuthName: true, showAuthPhone: false })
+      }
+      else if (!app.globalData.hasmobile) {
+        this.setData({ showAuthName: false, showAuthPhone: true })
+      }
+    },
+    detached: function () {
+    },
+  },
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    userPhoneHandler: function (e) {
+      if (e.detail.errMsg == "getPhoneNumber:ok") {
+        wx.aldstat.sendEvent('wxAuthen', { phone: true })
+        this.phone_encryptedData = e.detail.encryptedData
+        this.phone_iv = e.detail.iv
+        this.wxauthen(this.userInfoE)
+      }
+    },
+    userInfoHandler(e) {
+      if (e.detail.errMsg == "getUserInfo:ok") {
+        app.globalData.userInfo = e.detail.userInfo;
+        app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
+        this.userInfoE = e
+        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 phoneInfo = { iv: this.phone_iv, encryptedData: this.phone_encryptedData }
+      let params = {
+        user_info: userInfo,
+        phone_info: phoneInfo,
+        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
+
+          if (datas.hasmobile == false) {
+            self.setData({ showAuthName: false, showAuthPhone: true })
+          }
+          else {
+            self.triggerEvent('getAuth', {
+              userInfo
+            })
+          }
+        }
+        else {
+          app.relogin();
+          wx.showToast({
+            icon: 'none',
+            title: '登陆遇到一点麻烦,请重试~~~',
+            duration: 2000
+          })
+        }
+      })
+    }
+  }
+})

+ 4 - 0
pages/components/auth2/auth2.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 15 - 0
pages/components/auth2/auth2.wxml

@@ -0,0 +1,15 @@
+<!--pages/components/auth/auth.wxml-->
+<view class="auth_container">
+  <button wx:if="{{showAuthName && item_data.show_data==='getUserInfo'}}" 
+          style="border:none; " 
+          open-type="getUserInfo"
+          bindgetuserinfo="userInfoHandler">
+          <image src="{{item_data.image}}" style="width:100%; height: 170rpx"></image>
+  </button>
+</view>
+
+
+  <!-- <button style="background-image:url({{item_data.image}});width:100%;height:{{(item_data.height/1080*750)+'rpx'}}"
+            open-type="getUserInfo"
+            bindgetuserinfo="userInfoHandler">
+  </button> -->

+ 20 - 0
pages/components/auth2/auth2.wxss

@@ -0,0 +1,20 @@
+/* pages/components/auth/auth.wxss */
+.auth_container {
+  position: fixed;
+  left: 0;
+  right: 0;
+  top: 0;
+  bottom: 0;
+  z-index: 999;
+  padding-top: 100rpx;
+  box-sizing: border-box;
+  background: #fff;
+}
+.auth_text {
+  width: 100%;
+  margin: auto;
+  font-size: 28rpx;
+  color: #333;
+  line-height: 42rpx;
+  text-align: center;
+}

+ 1 - 1
pages/components/blockItem/blockItem.json

@@ -1,6 +1,6 @@
 {
   "component": true,
   "usingComponents": {
-    "auth": "/pages/components/auth/auth"
+    "auth2": "/pages/components/auth2/auth2"
   }
 }

+ 6 - 0
pages/components/blockItem/blockItem.wxml

@@ -44,8 +44,14 @@
 </block>
 
 <block wx:elif="{{item_data.show_type == 'wxbutton'}}">
+<!-- <<<<<<< HEAD
   <button style="background-image:url({{item_data.image}});width:100%;height:{{(item_data.height/1080*750)+'rpx'}}"
             open-type="getUserInfo"
             bindgetuserinfo="userInfoHandler">
   </button>
+======= -->
+   <view bindtap="handleAuth">
+    <auth2 bind:getAuth="getAuth" item_data="{{item_data}}"></auth2>
+   </view>
+<!-- >>>>>>> a49f2d3af0110e238df86657a2c26d74186d9798 -->
 </block>