LoginView.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { _decorator, Button, EditBox, Node, Sprite, SpriteFrame } from 'cc';
  2. import { UIView } from '@scripts/framework/ui/UIView';
  3. import { AppKernel } from '@scripts/app/AppKernel';
  4. import { UIViewID } from '@scripts/define/UIDefine';
  5. import { UICloseReason } from '@scripts/framework/ui/UILayer';
  6. import { formatCurrency } from '@scripts/utils/Helper';
  7. import { addBtnClick } from '@scripts/utils/UIHelper';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('LoginView')
  10. export class LoginView extends UIView {
  11. readonly viewId = UIViewID.LoginView;
  12. @property(Button)
  13. btnGuest: Button;
  14. @property(Button)
  15. btnFacebook: Button;
  16. @property(Button)
  17. btnGoogle: Button;
  18. @property(Button)
  19. btnLogOut: Button;
  20. @property(Node)
  21. registerNode: Node;
  22. @property(Node)
  23. loginNode: Node;
  24. @property(Node)
  25. forgetNode: Node;
  26. @property(Node)
  27. btnForgetOpen: Node;
  28. @property(Node)
  29. btnForget: Node;
  30. @property(EditBox)
  31. forgetAccount: EditBox;
  32. @property(EditBox)
  33. forgetPassword: EditBox;
  34. @property(EditBox)
  35. forgetCode: EditBox;
  36. @property(Node)
  37. btnRegisterNode: Node;
  38. @property(Node)
  39. btnLoginNode: Node;
  40. @property(EditBox)
  41. loginAccount: EditBox;
  42. @property(EditBox)
  43. loginPassword: EditBox;
  44. @property(EditBox)
  45. registerAccount: EditBox;
  46. @property(EditBox)
  47. registerCode: EditBox;
  48. @property(EditBox)
  49. registerPw: EditBox;
  50. @property(Node)
  51. btnRegister: Node;
  52. @property(Node)
  53. btnLogin: Node;
  54. private _googleWebBtn;
  55. protected onCreate(): void | Promise<void> {
  56. addBtnClick(this.btnGuest.node, this.onBtnGuestClick, this);
  57. addBtnClick(this.btnFacebook.node, this.onBtnFBClick, this);
  58. addBtnClick(this.btnGoogle.node, this.onBtnGoogleClick, this);
  59. addBtnClick(this.btnLogOut.node, this.onBtnLogOutClick, this);
  60. this._googleWebBtn = AppKernel.google.createLoginBtn(
  61. this.btnGoogle.node,
  62. res => this.onGoogleWebLogin(res),
  63. );
  64. ///////////////// Test
  65. addBtnClick(this.btnLoginNode, this.onShowLoginNode, this);
  66. addBtnClick(this.btnRegisterNode, this.onShowRegisterNode, this);
  67. addBtnClick(this.btnLogin, this.onBtnLoginClick, this);
  68. addBtnClick(this.btnRegister, this.onBtnRegisterClick, this);
  69. addBtnClick(this.btnForget, this.onBtnForgetClick, this);
  70. addBtnClick(this.btnForgetOpen, this.onShowForgetNode, this);
  71. console.log(">>>>>>>>>", formatCurrency(12345678.9), formatCurrency(12345678.9, 2))
  72. }
  73. protected onOpen(_params: unknown): void | Promise<void> {
  74. /// 播放完打开动画后 再显示h5 google login btn dom
  75. this._googleWebBtn?.setActive(true);
  76. }
  77. protected onClose(_reason: UICloseReason): void | Promise<void> {
  78. this._googleWebBtn?.setActive(false);
  79. }
  80. protected onDestroy(): void {
  81. this._googleWebBtn?.clear();
  82. }
  83. private async onBtnGuestClick() {
  84. AppKernel.ui.loading(true);
  85. await AppKernel.services.loginService.guestLogin();
  86. AppKernel.ui.loading(false);
  87. }
  88. private async onBtnFBClick() {
  89. AppKernel.ui.loading(true);
  90. await AppKernel.services.loginService.fbLogin();
  91. AppKernel.ui.loading(false);
  92. }
  93. private async onBtnLogOutClick() {
  94. // AppKernel.ui.loading(true);
  95. // const res = await AppKernel.fb.logOut();
  96. // console.log('facebook logout res: ', res);
  97. // AppKernel.ui.loading(false);
  98. }
  99. private async onGoogleWebLogin(res) {
  100. AppKernel.ui.loading(true);
  101. await AppKernel.services.loginService.googleLogin(res);
  102. AppKernel.ui.loading(false);
  103. }
  104. private async onBtnGoogleClick() {
  105. AppKernel.ui.loading(true);
  106. await AppKernel.services.loginService.googleLogin();
  107. AppKernel.ui.loading(false);
  108. }
  109. ///////////////// Test
  110. private onShowLoginNode() {
  111. this.loginNode.active = !this.loginNode.active;
  112. }
  113. private onShowRegisterNode() {
  114. this.registerNode.active = !this.registerNode.active;
  115. }
  116. private onBtnLoginClick() {
  117. const account = this.loginAccount.string;
  118. const password = this.loginPassword.string;
  119. AppKernel.services.loginService.loginAccount(account, password);
  120. }
  121. private onBtnRegisterClick() {
  122. const account = this.registerAccount.string;
  123. const code = this.registerCode.string;
  124. const password = this.registerPw.string;
  125. AppKernel.services.loginService.register({ account, code, password });
  126. }
  127. private onShowForgetNode() {
  128. this.forgetNode.active = !this.forgetNode.active;
  129. }
  130. private onBtnForgetClick() {
  131. const account = this.forgetAccount.string;
  132. const password = this.forgetPassword.string;
  133. const code = this.forgetCode.string;
  134. AppKernel.stores.mainStore.reqForgetPass({
  135. phone: account,
  136. code,
  137. newpassword: password,
  138. })
  139. const sp = new Sprite();
  140. }
  141. }