Login.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. cc.director.preloadScene('scene')
  18. }
  19. CountDown = 0
  20. SendCode() {
  21. if (!this.checkIphone()) {
  22. Tips.Instance.show('手机号码不正确')
  23. return
  24. }
  25. if (this.CountDown != 0) {
  26. return
  27. }
  28. HTTPS.Instance.post(NetPost.SendIphoneCode, {
  29. mobile: this.Iphone.string
  30. }).then(res => {
  31. if (res.code == 200) {
  32. Tips.Instance.show(res.msg)
  33. let Label = this.node.getChildByName("SendCode").getChildByName("Label").getComponent(cc.Label)
  34. this.CountDown = 60
  35. Label.string = `(${this.CountDown}s)`
  36. this.schedule(() => {
  37. Label.string = `(${--this.CountDown}s)`
  38. if (this.CountDown == 0) {
  39. this.unscheduleAllCallbacks()
  40. Label.string = '验证码'
  41. }
  42. }, 1, 59, 1)
  43. } else {
  44. Tips.Instance.show(res.msg)
  45. }
  46. })
  47. }
  48. login() {
  49. if (!this.checkIphone()) {
  50. Tips.Instance.show('手机号码不正确')
  51. return
  52. }
  53. HTTPS.Instance.post(NetPost.IphoneLogin, {
  54. mobile: this.Iphone.string,
  55. code: this.Code.string
  56. }).then(res => {
  57. if (res.code != 200) {
  58. Tips.Instance.show(res.msg)
  59. return
  60. }
  61. this.node.active = false
  62. HTTPS.Instance.user_info = res.data.user_info
  63. HTTPS.Instance.token = res.data.token
  64. cc.director.loadScene('scene')
  65. })
  66. }
  67. // update (dt) {}
  68. checkIphone() {
  69. function isValidPhoneNumber(phoneNumber: string): boolean {
  70. // 正则表达式,适用于中国手机号码
  71. const phonePattern = /^1[3-9]\d{9}$/;
  72. return phonePattern.test(phoneNumber);
  73. }
  74. return isValidPhoneNumber(this.Iphone.string)
  75. }
  76. //记录广告观看
  77. Setrecord() {
  78. HTTPS.Instance.post(NetPost.record, {
  79. ad_type: 'reward',//广告类型(默认reward)
  80. duration: 'sign_in',//观看时长,单位秒(默认30)
  81. }).then(res => {
  82. console.error(res);
  83. if (res.code == 200) {
  84. }
  85. })
  86. }
  87. openTask() {
  88. let Task = this.node.getChildByName("Task")
  89. Task.active = true
  90. }
  91. openwithdraw() {
  92. let Task = this.node.getChildByName("withdraw")
  93. Task.active = true
  94. }
  95. }