Login.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // "token": "xxx",
  58. // "user_info": {
  59. // "id": 1,
  60. // "username": "13800138000",
  61. // "nickname": "138****8000",
  62. // "avatar": "",
  63. // "balance": "0.00"
  64. // }
  65. res.data.user_info
  66. HTTPS.Instance.token = res.data.token
  67. }
  68. })
  69. }
  70. // update (dt) {}
  71. checkIphone() {
  72. function isValidPhoneNumber(phoneNumber: string): boolean {
  73. // 正则表达式,适用于中国手机号码
  74. const phonePattern = /^1[3-9]\d{9}$/;
  75. return phonePattern.test(phoneNumber);
  76. }
  77. return isValidPhoneNumber(this.Iphone.string)
  78. }
  79. getTask() {
  80. HTTPS.Instance.get(NetGet.Task).then(res => {
  81. console.error(res);
  82. })
  83. }
  84. setTask() {
  85. HTTPS.Instance.post(NetPost.complete, {
  86. task_type: 'sign_in',
  87. }).then(res => {
  88. console.error(res);
  89. if (res.code == 200) {
  90. }
  91. })
  92. }
  93. //获取规则
  94. getRule() {
  95. HTTPS.Instance.get(NetGet.rule).then(res => {
  96. console.error(res);
  97. })
  98. }
  99. //申请提现
  100. requsetWithdraw() {
  101. HTTPS.Instance.post(NetPost.withdraw, {
  102. amount: 'sign_in',//提现金额
  103. withdraw_type: 'sign_in',//提现方式(alipay/wxpay/bank)
  104. account: 'sign_in',//提现账号
  105. real_name: 'sign_in',// 真实姓名
  106. }).then(res => {
  107. console.error(res);
  108. if (res.code == 200) {
  109. }
  110. })
  111. }
  112. //体现记录
  113. requsetWithdrawHistory() {
  114. HTTPS.Instance.get(NetGet.withdrawHistory).then(res => {
  115. console.error(res);
  116. })
  117. }
  118. //记录广告观看
  119. Setrecord() {
  120. HTTPS.Instance.post(NetPost.record, {
  121. ad_type: 'sign_in',//广告类型(默认reward)
  122. duration: 'sign_in',//观看时长,单位秒(默认30)
  123. }).then(res => {
  124. console.error(res);
  125. if (res.code == 200) {
  126. }
  127. })
  128. }
  129. }