123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- // 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;
- @property(cc.Node)
- Login: cc.Node = null;
- clickLogin() {
- this.Login.active = true
- }
- protected onLoad(): void {
- cc.director.preloadScene('scene')
- }
- 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) {
- Tips.Instance.show(res.msg)
- return
- }
- Tips.Instance.show('登录成功')
- this.Login.active = false
- HTTPS.Instance.user_info = res.data.user_info
- HTTPS.Instance.token = res.data.token
- let startBtn = cc.Canvas.instance.node.getChildByName("0startPage").getChildByName("startBtn")
- let login = cc.Canvas.instance.node.getChildByName("0startPage").getChildByName("login")
- startBtn.active = true
- login.active = false
- })
- }
- // update (dt) {}
- checkIphone() {
- function isValidPhoneNumber(phoneNumber: string): boolean {
- // 正则表达式,适用于中国手机号码
- const phonePattern = /^1[3-9]\d{9}$/;
- return phonePattern.test(phoneNumber);
- }
- return isValidPhoneNumber(this.Iphone.string)
- }
- //记录广告观看
- Setrecord() {
- HTTPS.Instance.post(NetPost.record, {
- ad_type: 'reward',//广告类型(默认reward)
- duration: 'sign_in',//观看时长,单位秒(默认30)
- }).then(res => {
- console.error(res);
- if (res.code == 200) {
- }
- })
- }
- openTask() {
- let Task = this.node.getChildByName("Task")
- Task.active = true
- }
- openwithdraw() {
- let Task = this.node.getChildByName("withdraw")
- Task.active = true
- }
- }
|