122 lines
3.2 KiB
JavaScript
122 lines
3.2 KiB
JavaScript
let webapi = require('./utils/webapi');
|
|
let stringUtil = require('./utils/string.util');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
closeBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
submitBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
captchaBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
resultPrefab: {
|
|
default: null,
|
|
type: cc.Prefab
|
|
},
|
|
mobileInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
captchaInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
codeInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
codeImg: {
|
|
default: null,
|
|
type: cc.Sprite
|
|
}
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad () {
|
|
let self = this;
|
|
if (this.top.needCode) {
|
|
this.showCaptchaInput();
|
|
this.codeImg.node.on('click', function () {
|
|
self.showCaptchaInput();
|
|
})
|
|
}
|
|
this.closeBtn.on('click', function () {
|
|
self.node.removeFromParent(true);
|
|
});
|
|
this.submitBtn.on('click', function () {
|
|
self.sendJoinInfo();
|
|
});
|
|
this.captchaBtn.on('click', function () {
|
|
console.log(self.mobileInput.string);
|
|
let mobile = self.mobileInput.string;
|
|
if (!stringUtil.checkMobile(mobile)) {
|
|
alert('请输入有效的手机号码。');
|
|
return false;
|
|
}
|
|
let code = '';
|
|
if(self.top.needCode) {
|
|
code = self.codeInput.string;
|
|
if (!stringUtil.checkCaptchaCode(code)) {
|
|
alert('请输入正确的图形验证码。');
|
|
return false;
|
|
}
|
|
}
|
|
webapi.sendSms(mobile, code)
|
|
.then(res => {
|
|
console.log(res);
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
})
|
|
})
|
|
},
|
|
|
|
start () {
|
|
},
|
|
|
|
showResultView() {
|
|
let result = cc.instantiate(this.resultPrefab);
|
|
this.top.node.addChild(result, 11);
|
|
},
|
|
|
|
showCaptchaInput() {
|
|
let self = this;
|
|
cc.loader.load({
|
|
url: webapi.captchaUrl()+'?token='+cc.sys.localStorage.getItem('activity_token')+'&data='+new Date(),
|
|
type: 'jpg'
|
|
}, function (err, texture) {
|
|
if (err) {
|
|
console.log('load avatar error === ', err);
|
|
return;
|
|
}
|
|
self.codeImg.spriteFrame = new cc.SpriteFrame(texture);
|
|
});
|
|
},
|
|
hide() {
|
|
this.node.removeFromParent(true);
|
|
},
|
|
|
|
sendJoinInfo() {
|
|
let self = this;
|
|
let mobile = self.mobileInput.string;
|
|
if (!stringUtil.checkMobile(mobile)) {
|
|
alert('请输入有效的手机号码。');
|
|
return false;
|
|
}
|
|
let moileCaptcha = self.captchaInput.string;
|
|
if (!stringUtil.checkAuthCode(moileCaptcha)) {
|
|
alert('请输入正确的验证码。');
|
|
return false;
|
|
}
|
|
this.top.userLogin(mobile, moileCaptcha);
|
|
}
|
|
});
|