Login.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import HTTPS, { NetGet, NetPost } from "./HTTPS";
  8. import Tips from "./Tips";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class Login extends cc.Component {
  12. @property(cc.EditBox)
  13. Iphone: cc.EditBox = null;
  14. @property(cc.EditBox)
  15. Code: cc.EditBox = null;
  16. protected onLoad(): void {
  17. }
  18. CountDown = 0
  19. SendCode() {
  20. if (!this.checkIphone()) {
  21. Tips.Instance.show('手机号码不正确')
  22. return
  23. }
  24. if (this.CountDown != 0) {
  25. return
  26. }
  27. HTTPS.Instance.post(NetPost.SendIphoneCode, {
  28. mobile: this.Iphone.string
  29. }).then(res => {
  30. if (res.code == 200) {
  31. Tips.Instance.show(res.msg)
  32. let Label = this.node.getChildByName("SendCode").getChildByName("Label").getComponent(cc.Label)
  33. this.CountDown = 60
  34. Label.string = `(${this.CountDown}s)`
  35. this.schedule(() => {
  36. Label.string = `(${--this.CountDown}s)`
  37. if (this.CountDown == 0) {
  38. this.unscheduleAllCallbacks()
  39. Label.string = '验证码'
  40. }
  41. }, 1, 59, 1)
  42. } else {
  43. Tips.Instance.show(res.msg)
  44. }
  45. })
  46. }
  47. login() {
  48. if (!this.checkIphone()) {
  49. Tips.Instance.show('手机号码不正确')
  50. return
  51. }
  52. HTTPS.Instance.post(NetPost.IphoneLogin, {
  53. mobile: this.Iphone.string,
  54. code: this.Code.string
  55. }).then(res => {
  56. if (res.code != 200) {
  57. Tips.Instance.show(res.msg)
  58. return
  59. }
  60. this.node.active = false
  61. HTTPS.Instance.user_info = res.data.user_info
  62. HTTPS.Instance.token = res.data.token
  63. cc.director.loadScene('scene')
  64. })
  65. }
  66. // update (dt) {}
  67. checkIphone() {
  68. function isValidPhoneNumber(phoneNumber: string): boolean {
  69. // 正则表达式,适用于中国手机号码
  70. const phonePattern = /^1[3-9]\d{9}$/;
  71. return phonePattern.test(phoneNumber);
  72. }
  73. return isValidPhoneNumber(this.Iphone.string)
  74. }
  75. //记录广告观看
  76. Setrecord() {
  77. HTTPS.Instance.post(NetPost.record, {
  78. ad_type: 'sign_in',//广告类型(默认reward)
  79. duration: 'sign_in',//观看时长,单位秒(默认30)
  80. }).then(res => {
  81. console.error(res);
  82. if (res.code == 200) {
  83. }
  84. })
  85. }
  86. openTask() {
  87. let Task = this.node.getChildByName("Task")
  88. Task.active = true
  89. }
  90. openwithdraw() {
  91. let Task = this.node.getChildByName("withdraw")
  92. Task.active = true
  93. }
  94. }