// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import HTTPS, { NetGet, NetPost } from "./HTTPS"; import Tips from "./Tips"; const { ccclass, property } = cc._decorator; @ccclass export default class Login extends cc.Component { @property(cc.EditBox) Iphone: cc.EditBox = null; @property(cc.EditBox) Code: cc.EditBox = null; protected onLoad(): void { } CountDown = 0 SendCode() { if (!this.checkIphone()) { Tips.Instance.show('手机号码不正确') return } if (this.CountDown != 0) { return } HTTPS.Instance.post(NetPost.SendIphoneCode, { mobile: this.Iphone.string }).then(res => { if (res.code == 200) { Tips.Instance.show(res.msg) let Label = this.node.getChildByName("SendCode").getChildByName("Label").getComponent(cc.Label) this.CountDown = 60 Label.string = `(${this.CountDown}s)` this.schedule(() => { Label.string = `(${--this.CountDown}s)` if (this.CountDown == 0) { this.unscheduleAllCallbacks() Label.string = '验证码' } }, 1, 59, 1) } else { Tips.Instance.show(res.msg) } }) } login() { if (!this.checkIphone()) { Tips.Instance.show('手机号码不正确') return } HTTPS.Instance.post(NetPost.IphoneLogin, { mobile: this.Iphone.string, code: this.Code.string }).then(res => { if (res.code == 200) { // "token": "xxx", // "user_info": { // "id": 1, // "username": "13800138000", // "nickname": "138****8000", // "avatar": "", // "balance": "0.00" // } res.data.user_info HTTPS.Instance.token = res.data.token HTTPS.Instance.get(NetGet.Task).then(res => { }) } }) } // update (dt) {} checkIphone() { function isValidPhoneNumber(phoneNumber: string): boolean { // 正则表达式,适用于中国手机号码 const phonePattern = /^1[3-9]\d{9}$/; return phonePattern.test(phoneNumber); } return isValidPhoneNumber(this.Iphone.string) } }