123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- var api = require('../../../config/api.js');
- var util = require('../../../utils/util.js');
- var user = require('../../../utils/user.js');
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- img: '',
- myqr_blur: 0, //背景模糊值
- myqr_show: true,
- authImg: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/sq.png',
- authBtn: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/sq-btn.png',
- code: ""
- },
- getPhoneNumber: function (e) {
- var ivObj = e.detail.iv
- var telObj = e.detail.encryptedData
- var that = this;
- let r_userid = r_userid = 0;
- console.log("请求授权登录:code:" + that.data.code + "encryptedData," + telObj + "iv," + ivObj + 'r_userid,' + r_userid);
- //------执行Login---------
- util.request(api.AuthRegister, {
- code: that.data.code,
- encryptedData: telObj,
- iv: ivObj,
- r_userid: r_userid
- }).then(function (res) {
- if (res.errno === 0) {
- //存储用户信息
- app.globalData.hasLogin = true;
- app.globalData.userInfo = res.data.userInfo;
- wx.setStorageSync('userInfo', res.data.userInfo);
- wx.setStorageSync('token', res.data.token);
- wx.showToast({
- title: '授权注册成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- setTimeout(function () {
- that.goCloseMyqr();
- }, 2000);
- }
- })
- } else {
- console.info(res);
- wx.showToast({
- title: '授权失败请重试',
- icon: 'error',
- duration: 3000
- });
- }
- });
- //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面
- if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝
- wx.showModal({
- title: '警告',
- content: '您点击了拒绝授权,部分功能无法使用!!!',
- showCancel: false,
- confirmText: '确定',
- success: function (res) {
- that.goCloseMyqr();
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let that = this;
- //这里写个兼容
- //老的只有cp参数 新接口 加入客户手机mobile
- console.info(options.mobile)
- if (options.mobile&&options.mobile.length==11) {
- util.request(api.CPQrCode, {
- mobile: options.mobile,
- cp: options.cp
- }).then(function (res) {
- if (res.errno == 0) {
- that.setData({
- img: res.data
- })
- } else {
- util.showErrorToast(res.errmsg);
- }
- }).catch(res => {
- console.info(res)
- util.showErrorToast(res.errMsg);
- })
- } else if (options.cp) { //根据传的参数 加载二维码
- that.setData({
- img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/' + options.cp + '.png'
- })
- }
- },
- showMyQr() {
- this.setData({
- myqr_blur: 8,
- myqr_show: true
- });
- },
- goCloseMyqr: function () { //关闭分享图片的弹层
- this.setData({
- myqr_blur: 0,
- myqr_show: false
- });
- },
- qrtouchstart: function () {
- this.setData({
- myqr_blur: 0,
- myqr_show: false
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- wx.hideHomeButton();
- console.info(app.globalData.hasLogin);
- if (!app.globalData.hasLogin) {
- this.showMyQr();
- let that = this;
- user.login().then(res => {
- console.info(res)
- that.setData({
- code: res.code
- })
- })
- }else{
- this.goCloseMyqr();
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|