Login.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. console.error(HTTPS.Instance.user_info);
  49. cc.director.loadScene('scene')
  50. return
  51. if (!this.checkIphone()) {
  52. Tips.Instance.show('手机号码不正确')
  53. return
  54. }
  55. HTTPS.Instance.post(NetPost.IphoneLogin, {
  56. mobile: this.Iphone.string,
  57. code: this.Code.string
  58. }).then(res => {
  59. if (res.code != 200) {
  60. Tips.Instance.show(res.msg)
  61. return
  62. }
  63. this.node.active = false
  64. HTTPS.Instance.user_info = res.data.user_info
  65. HTTPS.Instance.token = res.data.token
  66. cc.director.loadScene('scene')
  67. })
  68. }
  69. // update (dt) {}
  70. checkIphone() {
  71. function isValidPhoneNumber(phoneNumber: string): boolean {
  72. // 正则表达式,适用于中国手机号码
  73. const phonePattern = /^1[3-9]\d{9}$/;
  74. return phonePattern.test(phoneNumber);
  75. }
  76. return isValidPhoneNumber(this.Iphone.string)
  77. }
  78. //记录广告观看
  79. Setrecord() {
  80. HTTPS.Instance.post(NetPost.record, {
  81. ad_type: 'sign_in',//广告类型(默认reward)
  82. duration: 'sign_in',//观看时长,单位秒(默认30)
  83. }).then(res => {
  84. console.error(res);
  85. if (res.code == 200) {
  86. }
  87. })
  88. }
  89. openTask() {
  90. let Task = this.node.getChildByName("Task")
  91. Task.active = true
  92. }
  93. openwithdraw() {
  94. let Task = this.node.getChildByName("withdraw")
  95. Task.active = true
  96. }
  97. }