Register.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { _decorator, EditBox, Node } from 'cc';
  2. import { UIViewID } from '@scripts/define/UIDefine';
  3. import { addBtnClick } from '@scripts/utils/UIHelper';
  4. import { AppKernel } from '@scripts/app/AppKernel';
  5. import { UIPopup } from '@scripts/framework/ui/UIPopup';
  6. import { checkIsEmail } from '@scripts/utils/Helper';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('Register')
  9. export class Register extends UIPopup {
  10. readonly viewId = UIViewID.Register;
  11. @property(Node)
  12. private btn_close: Node = null;
  13. @property(Node)
  14. private btn_signup: Node = null;
  15. @property(Node)
  16. private btn_grey: Node = null;
  17. @property(EditBox)
  18. private account: EditBox;
  19. @property(EditBox)
  20. private code: EditBox;
  21. @property(EditBox)
  22. private psd: EditBox;
  23. @property(EditBox)
  24. private inviteCode: EditBox;
  25. private _isSigningUp: boolean = false;
  26. protected onCreate(): void | Promise<void> {
  27. addBtnClick(this.btn_close, this.closeSelf, this);
  28. addBtnClick(this.btn_signup, this.onBtnSignUpClick, this);
  29. const Event = EditBox.EventType.TEXT_CHANGED;
  30. this.account.node.on(Event, this.handleCheckForm, this);
  31. this.code.node.on(Event, this.handleCheckForm, this);
  32. this.psd.node.on(Event, this.handleCheckForm, this);
  33. this.btn_signup.active = false;
  34. this.btn_grey.active = true;
  35. }
  36. private async onBtnSignUpClick() {
  37. if (this._isSigningUp) return;
  38. this._isSigningUp = true;
  39. AppKernel.ui.loading(true);
  40. const account = this.account.string.trim();
  41. const code = this.code.string.trim();
  42. const password = this.psd.string.trim();
  43. const act = this.inviteCode.string.trim();
  44. try {
  45. if (account && code && password) {
  46. const res = checkIsEmail(account)
  47. ? await AppKernel.stores.mailStore.reqRegister({ account, code, password, act })
  48. : await AppKernel.services.loginService.register({ account, code, password, act });
  49. if (res) {
  50. await AppKernel.services.loginService.loginAccount(account, password);
  51. await AppKernel.ui.close(UIViewID.Register);
  52. await AppKernel.ui.open(UIViewID.LoginSuccess);
  53. } else {
  54. // log error
  55. }
  56. }
  57. } finally {
  58. AppKernel.ui.loading(false);
  59. this._isSigningUp = false;
  60. }
  61. }
  62. private handleCheckForm() {
  63. const account = !!this.account.string.trim();
  64. const code = !!this.code.string.trim();
  65. const password = !!this.psd.string.trim();
  66. const isReady = account && code && password;
  67. this.btn_signup.active = isReady;
  68. this.btn_grey.active = !isReady;
  69. }
  70. }