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: false, 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: "", mobile: '', cp:'', sms:'' }, 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(); } }) } }, reloadQr(){ let that=this; if (that.data.mobile && that.data.mobile.length == 11) { that.setData({ img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/13402043655.png?sign=ec737db7a9917ba35262942fe424565c&t=1713774392' }) if(that.data.sms==null){ return; } wx.showLoading({ title: '加载中', }); // 这里分了cp(企微号)或sms短信配置 util.request(api.CPQrCode, { mobile: that.data.mobile, cp: that.data.cp ? that.data.cp : '', sms: that.data.sms ? that.data.sms : '' }).then(function (res) { wx.hideLoading(); if (res.errno == 0) { that.setData({ img: res.data }) } else { util.showErrorToast(res.errmsg); } }).catch(res => { console.info(res) wx.hideLoading(); util.showErrorToast(res.errMsg); }) } else if (that.data.cp) { //根据传的参数 加载二维码 that.setData({ img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/' + that.data.cp + '.png' }) }else{ that.setData({ img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/13402043655.png?sign=ec737db7a9917ba35262942fe424565c&t=1713774392' }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; //这里写个兼容 //老的只有cp参数 新接口 加入客户手机mobile console.info(options.mobile) that.setData({ mobile: options.mobile, cp:options.cp?options.cp:null, sms:options.sms?options.sms:null }) console.info(that.data.cp) this.reloadQr(); }, showMyQr() { if(this.data.mobile==undefined||this.data.mobile==''){//不带手机号或者工单号的 不用授权 this.setData({ myqr_blur: 0, myqr_show: false }); return; } //如果携带了手机号 不弹出授权框 if (!this.data.mobile&&this.data.mobile!=undefined&&this.data.mobile!='') return; this.setData({ myqr_blur: 8, myqr_show: true }); let that = this; user.login().then(res => { console.info(res) that.setData({ code: res.code }) }) }, 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(); } else { this.goCloseMyqr(); } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })