var e = getApp(),app=e, a = e.request, t = e.globalData.setting,os=t, i = require("../../../utils/common.js"); Page({ data: { url: t.url, iurl: t.imghost, nickName: "", userHeadPic: "", isRegist: !1, bindMobile: "", bindCode: "", regMobile: "", regCode: "", regPwd: "", isAgree: !1, canGetCode: !1, config:null, store: null, imghots: os.imghost, gettime:0, }, onLoad: function(e) { var th=this; app.getConfig(function (e) { th.setData({ store: e }); }) app.getConfig2(function (e) { var cf = JSON.parse(e.sms_send_type); th.setData({ config: cf }); console.log(th.data.config); }) }, account: function() { this.setData({ isRegist: !1 }); }, regist: function() { this.setData({ isRegist: !0 }); }, setMobile: function(e) { this.data.bindMobile = e.detail.value; }, setCode: function(e) { this.data.bindCode = e.detail.value; }, //---获取短信验证码--- getCode: function(t) { var th=this; if ("" != this.data.bindMobile) { var s = this; a.get("/api/weshop/smslog/sendsms", { data: { mobile: this.data.bindMobile, store_id: os.stoid, wxopenid: app.globalData.openid, }, success: function(e) { if(e.data.code==0){ th.setData({ gettime: th.data.config.time_out, canGetCode:1}); th.setInt(); } } }); } else e.showWarning("请输入手机号码"); }, //----发送验证码的推送时间倒计时--- setInt:function(){ var th=this; var it=setInterval(function(){ var ti = th.data.gettime-1; if (ti<=0){ th.setData({ gettime:0, canGetCode: !1 }); clearInterval(it); } else{ th.setData({ gettime: ti,}); } },1000); }, setRegMobile: function(e) { this.data.regMobile = e.detail.value; }, setRegPwd: function(e) { this.data.regPwd = e.detail.value; }, setRegCode: function(e) { this.data.regCode = e.detail.value; }, getRegCode: function(t) { if ("" != this.data.regMobile) { var s = this; a.post("/Home/Api/checkRegMobile", { data: { mobile: this.data.regMobile }, success: function(e) { i.sendBindSmsCode(s.data.regMobile); } }); } else e.showWarning("请输入手机号码"); }, check: function() { this.setData({ isAgree: !this.data.isAgree }); }, bindAccount: function() { var t = this; var r = getApp().globalData.getu; var openid = getApp().globalData.openid; "" != this.data.bindMobile ? "" != this.data.bindCode ? a.get("/api/weshop/users/thirdLogin", { data: { mobile: t.data.bindMobile, code: t.data.bindCode, openid: openid, nickname: r.nickName, head_pic: r.avatarUrl, sex: r.gender, store_id:os.stoid, }, success: function(a) { if(a.data.code==0){ wx.setStorageSync("isAuth", !0), e.globalData.userInfo = a.data.data, e.globalData.user_id = e.globalData.userInfo.user_id, e.globalData.userInfo.head_pic = i.getFullUrl(e.globalData.userInfo.head_pic), "function" == typeof cb && cb(e.globalData.userInfo, e.globalData.wechatUser); e.showWarning("绑定成功"); setTimeout(function(){ wx.switchTab({ url: '/pages/user/index/index', }) },1000); }else{ e.showWarning("请输入验证码") } } }) : e.showWarning("请输入验证码") : e.showWarning("请输入手机号码"); }, bindReg: function() { var t = this; if( "" != this.data.regMobile ){ e.showWarning("请输入手机号码"); return false; }else if( "" != this.data.regCode){ e.showWarning("请输入验证码"); return false; }else { var openid = getApp().globalData.openid; var r = getApp().globalData.getu; a.post("/api/weshop/users/thirdLogin", { data: { mobile: t.data.regMobile, verify_code: t.data.regCode, openid: openid, nickname: r.nickName, head_pic: r.avatarUrl, sex: r.gender, }, success: function(a) { console.log("thirdLogin"); console.log(e); if (e.data.code == 0) { app.globalData.user_id = e.data.data.user_id; } else { return app.showWarning("授权登入失败!"); } wx.setStorageSync("isAuth", !0), a.globalData.userInfo = e.data.data, a.globalData.userInfo.head_pic = t.getFullUrl(a.globalData.userInfo.head_pic); wx.navigateBack({ delta: 1 }) } }) } } }); function randomNum(min, max) { return Math.floor(Math.random() * (max - min) + min); } /**生成一个随机色**/ function randomColor(min, max) { var r = randomNum(min, max); var g = randomNum(min, max); var b = randomNum(min, max); return "rgb(" + r + "," + g + "," + b + ")"; } /**绘制验证码图片**/ function drawPic(that) { ctx = wx.createCanvasContext('canvas'); /**绘制背景色**/ ctx.fillStyle = randomColor(180, 240); //颜色若太深可能导致看不清 ctx.fillRect(0, 0, 90, 28) /**绘制文字**/ var arr; var text = ''; var str = 'ABCEFGHJKLMNPQRSTWXY123456789'; for (var i = 0; i < 4; i++) { var txt = str[randomNum(0, str.length)]; ctx.fillStyle = randomColor(50, 160); //随机生成字体颜色 ctx.font = randomNum(20, 26) + 'px SimHei'; //随机生成字体大小 var x = 5 + i * 20; var y = randomNum(20, 25); var deg = randomNum(-20, 20); //修改坐标原点和旋转角度 ctx.translate(x, y); ctx.rotate(deg * Math.PI / 180); ctx.fillText(txt, 5, 0); text = text + txt; //恢复坐标原点和旋转角度 ctx.rotate(-deg * Math.PI / 180); ctx.translate(-x, -y); } /**绘制干扰线**/ for (var i = 0; i < 4; i++) { ctx.strokeStyle = randomColor(40, 180); ctx.beginPath(); ctx.moveTo(randomNum(0, 90), randomNum(0, 28)); ctx.lineTo(randomNum(0, 90), randomNum(0, 28)); ctx.stroke(); } /**绘制干扰点**/ for (var i = 0; i < 20; i++) { ctx.fillStyle = randomColor(0, 255); ctx.beginPath(); ctx.arc(randomNum(0, 90), randomNum(0, 28), 1, 0, 2 * Math.PI); ctx.fill(); } ctx.draw(false, function () { that.setData({ text: text }) }); }