// 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 } }) } // update (dt) {} checkIphone() { function isValidPhoneNumber(phoneNumber: string): boolean { // 正则表达式,适用于中国手机号码 const phonePattern = /^1[3-9]\d{9}$/; return phonePattern.test(phoneNumber); } return isValidPhoneNumber(this.Iphone.string) } getTask() { HTTPS.Instance.get(NetGet.Task).then(res => { console.error(res); }) } setTask() { HTTPS.Instance.post(NetPost.complete, { task_type: 'sign_in', }).then(res => { console.error(res); if (res.code == 200) { } }) } //获取规则 getRule() { HTTPS.Instance.get(NetGet.rule).then(res => { console.error(res); }) } //申请提现 requsetWithdraw() { HTTPS.Instance.post(NetPost.withdraw, { amount: 'sign_in',//提现金额 withdraw_type: 'sign_in',//提现方式(alipay/wxpay/bank) account: 'sign_in',//提现账号 real_name: 'sign_in',// 真实姓名 }).then(res => { console.error(res); if (res.code == 200) { } }) } //体现记录 requsetWithdrawHistory() { HTTPS.Instance.get(NetGet.withdrawHistory).then(res => { console.error(res); }) } //记录广告观看 Setrecord() { HTTPS.Instance.post(NetPost.record, { ad_type: 'sign_in',//广告类型(默认reward) duration: 'sign_in',//观看时长,单位秒(默认30) }).then(res => { console.error(res); if (res.code == 200) { } }) } }