完善登录模块
This commit is contained in:
parent
20886ecf78
commit
8486c6f5f7
@ -1955,12 +1955,12 @@
|
|||||||
"_N$string": "",
|
"_N$string": "",
|
||||||
"_fontSize": 30,
|
"_fontSize": 30,
|
||||||
"_lineHeight": 40,
|
"_lineHeight": 40,
|
||||||
"_enableWrapText": false,
|
"_enableWrapText": true,
|
||||||
"_N$file": null,
|
"_N$file": null,
|
||||||
"_isSystemFontUsed": true,
|
"_isSystemFontUsed": true,
|
||||||
"_spacingX": 0,
|
"_spacingX": 0,
|
||||||
"_N$horizontalAlign": 0,
|
"_N$horizontalAlign": 0,
|
||||||
"_N$verticalAlign": 1,
|
"_N$verticalAlign": 0,
|
||||||
"_N$fontFamily": "Arial",
|
"_N$fontFamily": "Arial",
|
||||||
"_N$overflow": 1,
|
"_N$overflow": 1,
|
||||||
"_id": ""
|
"_id": ""
|
||||||
@ -2054,12 +2054,12 @@
|
|||||||
"_N$string": "",
|
"_N$string": "",
|
||||||
"_fontSize": 20,
|
"_fontSize": 20,
|
||||||
"_lineHeight": 50,
|
"_lineHeight": 50,
|
||||||
"_enableWrapText": false,
|
"_enableWrapText": true,
|
||||||
"_N$file": null,
|
"_N$file": null,
|
||||||
"_isSystemFontUsed": true,
|
"_isSystemFontUsed": true,
|
||||||
"_spacingX": 0,
|
"_spacingX": 0,
|
||||||
"_N$horizontalAlign": 0,
|
"_N$horizontalAlign": 0,
|
||||||
"_N$verticalAlign": 1,
|
"_N$verticalAlign": 0,
|
||||||
"_N$fontFamily": "Arial",
|
"_N$fontFamily": "Arial",
|
||||||
"_N$overflow": 1,
|
"_N$overflow": 1,
|
||||||
"_id": ""
|
"_id": ""
|
||||||
@ -2095,7 +2095,7 @@
|
|||||||
},
|
},
|
||||||
"_N$returnType": 0,
|
"_N$returnType": 0,
|
||||||
"_N$inputFlag": 5,
|
"_N$inputFlag": 5,
|
||||||
"_N$inputMode": 2,
|
"_N$inputMode": 6,
|
||||||
"_N$fontSize": 30,
|
"_N$fontSize": 30,
|
||||||
"_N$lineHeight": 40,
|
"_N$lineHeight": 40,
|
||||||
"_N$fontColor": {
|
"_N$fontColor": {
|
||||||
@ -3192,7 +3192,6 @@
|
|||||||
"codeImg": {
|
"codeImg": {
|
||||||
"__id__": 62
|
"__id__": 62
|
||||||
},
|
},
|
||||||
"needCode": false,
|
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ cc.Class({
|
|||||||
self.node.removeFromParent(true);
|
self.node.removeFromParent(true);
|
||||||
});
|
});
|
||||||
this.submitBtn.on('click', function () {
|
this.submitBtn.on('click', function () {
|
||||||
let mobile = self.mobileInput.string;
|
self.sendJoinInfo();
|
||||||
});
|
});
|
||||||
this.captchaBtn.on('click', function () {
|
this.captchaBtn.on('click', function () {
|
||||||
console.log(self.mobileInput.string);
|
console.log(self.mobileInput.string);
|
||||||
@ -61,7 +61,15 @@ cc.Class({
|
|||||||
alert('请输入有效的手机号码。');
|
alert('请输入有效的手机号码。');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
webapi.sendSms(mobile)
|
let code = '';
|
||||||
|
if(self.top.needCode) {
|
||||||
|
code = self.codeInput.string;
|
||||||
|
if (!stringUtil.checkCaptchaCode(code)) {
|
||||||
|
alert('请输入正确的图形验证码。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webapi.sendSms(mobile, code)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
})
|
})
|
||||||
@ -77,13 +85,12 @@ cc.Class({
|
|||||||
showResultView() {
|
showResultView() {
|
||||||
let result = cc.instantiate(this.resultPrefab);
|
let result = cc.instantiate(this.resultPrefab);
|
||||||
this.top.node.addChild(result, 11);
|
this.top.node.addChild(result, 11);
|
||||||
this.node.removeFromParent(true);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showCaptchaInput() {
|
showCaptchaInput() {
|
||||||
let self = this;
|
let self = this;
|
||||||
cc.loader.load({
|
cc.loader.load({
|
||||||
url: webapi.captchaUrl()+'?'+new Date(),
|
url: webapi.captchaUrl()+'?token='+cc.sys.localStorage.getItem('activity_token')+'&data='+new Date(),
|
||||||
type: 'jpg'
|
type: 'jpg'
|
||||||
}, function (err, texture) {
|
}, function (err, texture) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -92,5 +99,23 @@ cc.Class({
|
|||||||
}
|
}
|
||||||
self.codeImg.spriteFrame = new cc.SpriteFrame(texture);
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var http = require('./utils/http');
|
|
||||||
var onfire = require('./utils/onfire');
|
var onfire = require('./utils/onfire');
|
||||||
|
let webapi = require('./utils/webapi');
|
||||||
|
let stringUtil = require('./utils/string.util');
|
||||||
cc.Class({
|
cc.Class({
|
||||||
extends: cc.Component,
|
extends: cc.Component,
|
||||||
|
|
||||||
@ -56,24 +57,53 @@ cc.Class({
|
|||||||
default: null,
|
default: null,
|
||||||
type: cc.Node
|
type: cc.Node
|
||||||
},
|
},
|
||||||
|
infoView: {
|
||||||
|
default: null,
|
||||||
|
type: cc.Node
|
||||||
|
},
|
||||||
partsY: [],
|
partsY: [],
|
||||||
needCode: true
|
needCode: true,
|
||||||
|
logined: false,
|
||||||
|
mobile: '',
|
||||||
|
images: []
|
||||||
},
|
},
|
||||||
|
|
||||||
// LIFE-CYCLE CALLBACKS:
|
// LIFE-CYCLE CALLBACKS:
|
||||||
|
|
||||||
onLoad () {
|
onLoad () {
|
||||||
let self = this;
|
let self = this;
|
||||||
http.get('http://192.168.100.228/activity/api/index', {} )
|
webapi.preLogin({})
|
||||||
.then(res => {
|
.then(rep => {
|
||||||
console.log(res);
|
if (rep.errcode === 0) {
|
||||||
|
self.needCode = rep.smsCheck;
|
||||||
|
self.logined = rep.isLogin;
|
||||||
|
cc.sys.localStorage.setItem('activity_token', rep.token);
|
||||||
|
if (self.logined) {
|
||||||
|
return webapi.userInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.then(userRep => {
|
||||||
console.error(err);
|
if (userRep) {
|
||||||
|
console.log(userRep);
|
||||||
|
if (userRep.errcode === 0) {
|
||||||
|
self.mobile = userRep.user.username;
|
||||||
|
self.images = userRep.user.images;
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').updateUserName(stringUtil.parseMobile(self.mobile));
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').updatePuzzle(self.images);
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').toggleLoginStatus(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch (err => {
|
||||||
|
console.log(err);
|
||||||
});
|
});
|
||||||
this.partsY = [0, 1560, 2920, 3666, 4686];
|
this.partsY = [0, 1560, 2920, 3666, 4686];
|
||||||
this.mainScrollContent = cc.instantiate(this.mainScrollPrefab);
|
this.mainScrollContent = cc.instantiate(this.mainScrollPrefab);
|
||||||
this.scrollContent.addChild(this.mainScrollContent);
|
this.scrollContent.addChild(this.mainScrollContent);
|
||||||
|
this.mainScrollContent.getComponent('scrollContent').top = this;
|
||||||
this.mainScrollContent.getComponent('scrollContent').joinBtn.on('click', function () {
|
this.mainScrollContent.getComponent('scrollContent').joinBtn.on('click', function () {
|
||||||
self.showInfoMenu();
|
self.showInfoMenu();
|
||||||
});
|
});
|
||||||
@ -129,14 +159,18 @@ cc.Class({
|
|||||||
this.topMenu.active = false;
|
this.topMenu.active = false;
|
||||||
},
|
},
|
||||||
showInfoMenu() {
|
showInfoMenu() {
|
||||||
let infoMenu;
|
|
||||||
if (this.needCode) {
|
if (this.needCode) {
|
||||||
infoMenu = cc.instantiate(this.infoMenuPrefab2);
|
this.infoView = cc.instantiate(this.infoMenuPrefab2);
|
||||||
} else {
|
} else {
|
||||||
infoMenu = cc.instantiate(this.infoMenuPrefab);
|
this.infoView = cc.instantiate(this.infoMenuPrefab);
|
||||||
}
|
}
|
||||||
infoMenu.getComponent('infoMenu').top = this;
|
this.infoView.getComponent('infoMenu').top = this;
|
||||||
this.node.addChild(infoMenu, 11);
|
this.node.addChild(this.infoView, 11);
|
||||||
|
},
|
||||||
|
showResultView() {
|
||||||
|
this.infoView.getComponent('infoMenu').hide();
|
||||||
|
let resultView = cc.instantiate(this.resultPrefab);
|
||||||
|
this.node.addChild(resultView, 11);
|
||||||
},
|
},
|
||||||
showInviteMenu() {
|
showInviteMenu() {
|
||||||
let inviteMenu = cc.instantiate(this.inviteMenuPrefab);
|
let inviteMenu = cc.instantiate(this.inviteMenuPrefab);
|
||||||
@ -156,5 +190,44 @@ cc.Class({
|
|||||||
window.location.href = 'http://qm.qq.com/cgi-bin/qm/qr?k=9OEVDuOyP1BZ_cXOApidE9P2ea8daCVF';
|
window.location.href = 'http://qm.qq.com/cgi-bin/qm/qr?k=9OEVDuOyP1BZ_cXOApidE9P2ea8daCVF';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
userLogin(mobile, code) {
|
||||||
|
let self = this;
|
||||||
|
webapi.login(mobile, code)
|
||||||
|
.then(rep => {
|
||||||
|
if (rep.errcode === 0 || rep.errcode === 102 || rep.errcode === 103) {
|
||||||
|
self.logined = true;
|
||||||
|
self.mobile = rep.user.username;
|
||||||
|
self.images = rep.user.images;
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').updateUserName(stringUtil.parseMobile(self.mobile));
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').updatePuzzle(self.images);
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').toggleLoginStatus(true);
|
||||||
|
self.infoView.getComponent('infoMenu').hide();
|
||||||
|
if (rep.errcode === 103 || rep.errcode === 102) {
|
||||||
|
alert('您已预约');
|
||||||
|
}
|
||||||
|
if (rep.errcode === 0) {
|
||||||
|
self.showResultView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch (err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
userLogout() {
|
||||||
|
let self = this;
|
||||||
|
if (confirm('确定退出?')) {
|
||||||
|
webapi.logout()
|
||||||
|
.then(rep => {
|
||||||
|
if (rep.errcode === 0) {
|
||||||
|
self.mainScrollContent.getComponent('scrollContent').toggleLoginStatus(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -77,13 +77,14 @@ cc.Class({
|
|||||||
// LIFE-CYCLE CALLBACKS:
|
// LIFE-CYCLE CALLBACKS:
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
let self = this;
|
||||||
this.loginStatusLabel.node.active = false;
|
this.loginStatusLabel.node.active = false;
|
||||||
var processBar = cc.instantiate(this.processBarPrefab);
|
var processBar = cc.instantiate(this.processBarPrefab);
|
||||||
// processBar.getComponent('progressBar').currentVal = 50000;
|
// processBar.getComponent('progressBar').currentVal = 50000;
|
||||||
this.part1.addChild(processBar);
|
this.part1.addChild(processBar);
|
||||||
processBar.getComponent('progressBar').updateShow(50000);
|
processBar.getComponent('progressBar').updateShow(50000);
|
||||||
var puzzle = cc.instantiate(this.puzzlePrefab);
|
this.puzzle = cc.instantiate(this.puzzlePrefab);
|
||||||
this.part2.addChild(puzzle);
|
this.part2.addChild(this.puzzle);
|
||||||
var tip = cc.instantiate(this.tipPrefab);
|
var tip = cc.instantiate(this.tipPrefab);
|
||||||
this.part2.addChild(tip);
|
this.part2.addChild(tip);
|
||||||
tip.getComponent('inviteTip').setLabelTxt('xx接受了您的邀请');
|
tip.getComponent('inviteTip').setLabelTxt('xx接受了您的邀请');
|
||||||
@ -91,11 +92,14 @@ cc.Class({
|
|||||||
this.part4.addChild(imageSwiper, 0);
|
this.part4.addChild(imageSwiper, 0);
|
||||||
var bottomSwiper = cc.instantiate(this.bottomSwiperPrefab);
|
var bottomSwiper = cc.instantiate(this.bottomSwiperPrefab);
|
||||||
this.part5.addChild(bottomSwiper);
|
this.part5.addChild(bottomSwiper);
|
||||||
let self = this;
|
this.logoutBtn.on('click', function () {
|
||||||
this.scheduleOnce(function () {
|
self.top.userLogout();
|
||||||
processBar.getComponent('progressBar').updateShow(35000);
|
})
|
||||||
puzzle.getComponent('puzzle').updateValues([0, 1, 0, 1, 0, 1, 1, 0, 1])
|
|
||||||
}, 5);
|
// this.scheduleOnce(function () {
|
||||||
|
// processBar.getComponent('progressBar').updateShow(35000);
|
||||||
|
// self.puzzle.getComponent('puzzle').updateValues([])
|
||||||
|
// }, 5);
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
@ -124,4 +128,14 @@ cc.Class({
|
|||||||
this.time = 0;
|
this.time = 0;
|
||||||
this.startup = false;
|
this.startup = false;
|
||||||
},
|
},
|
||||||
|
updatePuzzle(valArr) {
|
||||||
|
this.puzzle.getComponent('puzzle').updateValues(valArr)
|
||||||
|
},
|
||||||
|
updateUserName(username) {
|
||||||
|
this.loginStatusLabel.string = username;
|
||||||
|
},
|
||||||
|
toggleLoginStatus(status) {
|
||||||
|
this.loginStatusLabel.node.active = status;
|
||||||
|
this.joinBtn.active = !status;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -19,12 +19,16 @@ const post = (url, data, header) => {
|
|||||||
|
|
||||||
const Ajax = (url, method, data, header) => {
|
const Ajax = (url, method, data, header) => {
|
||||||
header = header || {};
|
header = header || {};
|
||||||
|
let token = cc.sys.localStorage.getItem('activity_token');
|
||||||
|
if (token) {
|
||||||
|
header['token'] = token;
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (xhr.readyState === 4 ){
|
if (xhr.readyState === 4 ){
|
||||||
if(xhr.status >= 200 && xhr.status < 400) {
|
if(xhr.status >= 200 && xhr.status < 400) {
|
||||||
resolve(xhr.responseText);
|
resolve(JSON.parse(xhr.responseText));
|
||||||
}else{
|
}else{
|
||||||
reject(xhr.statusText);
|
reject(xhr.statusText);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,10 @@ export default {
|
|||||||
checkAuthCode(code) {
|
checkAuthCode(code) {
|
||||||
return /^\d{6}$/.test(code);
|
return /^\d{6}$/.test(code);
|
||||||
},
|
},
|
||||||
checkCaptcheCode(code) {
|
checkCaptchaCode(code) {
|
||||||
|
return /^[a-z,0-9]{4}$/.test(code);
|
||||||
|
},
|
||||||
|
parseMobile(mobile) {
|
||||||
|
return mobile.slice(0,3) + '****' + mobile.slice(7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var http = require('./http');
|
var http = require('./http');
|
||||||
|
|
||||||
const baseUrl = 'http://192.168.100.228';
|
const baseUrl = 'http://192.168.100.228:3000';
|
||||||
export default {
|
export default {
|
||||||
sendSms: (mobile, captcha) => {
|
sendSms: (mobile, captcha) => {
|
||||||
let data = {mobile: mobile};
|
let data = {mobile: mobile};
|
||||||
@ -12,6 +12,26 @@ export default {
|
|||||||
return http.post(url, data);
|
return http.post(url, data);
|
||||||
},
|
},
|
||||||
captchaUrl: () => {
|
captchaUrl: () => {
|
||||||
return baseUrl + '/captcha/ch/login'
|
return baseUrl + '/activity/ch/login'
|
||||||
|
},
|
||||||
|
preLogin: (data) => {
|
||||||
|
let url = baseUrl + '/activity/api/pre_login';
|
||||||
|
return http.post(url, data);
|
||||||
|
},
|
||||||
|
userInfo: () => {
|
||||||
|
let url = baseUrl + '/activity/api/user_info';
|
||||||
|
return http.get(url);
|
||||||
|
},
|
||||||
|
login: (mobile, code) => {
|
||||||
|
let data = {
|
||||||
|
mobile: mobile,
|
||||||
|
captcha: code
|
||||||
|
};
|
||||||
|
let url = baseUrl + '/activity/api/join';
|
||||||
|
return http.post(url, data);
|
||||||
|
},
|
||||||
|
logout: () => {
|
||||||
|
let url = baseUrl + '/activity/api/logout';
|
||||||
|
return http.post(url, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user