123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // pages/components/auth/auth.js
- const api = require('../../../config');
- const getReq = require('../../../config').getReq;
- let app = getApp();
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- phone_iv: '',
- phone_encryptedData: '',
- userInfoE:{},
- showAuthName: true,
- showAuthPhone: false,
- },
- lifetimes: {
- attached: function () {
- if (!app.globalData.hasmobile) {
- this.setData({ showAuthName: false, showAuthPhone: true })
- }
- },
- detached: function () {
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- onLoad: function () {
- },
- userPhoneHandler: function(e) {
- 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 = eInfo.detail.userInfo;
- if (app.globalData.userId.unionid) {
- userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
- }
- else {
- 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
- }
- 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
- })
- }
- })
- }
- }
- })
|