LoginView.ts 4.5 KB

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