ResetPsd.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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('ResetPsd')
  9. export class ResetPsd extends UIPopup {
  10. readonly viewId = UIViewID.ResetPsd;
  11. @property(Node)
  12. private btn_close: Node = null;
  13. @property(Node)
  14. private btn_grey: Node = null;
  15. @property(Node)
  16. private btn_reset: Node = null;
  17. @property(EditBox)
  18. account: EditBox;
  19. @property(EditBox)
  20. code: EditBox;
  21. @property(EditBox)
  22. psd: EditBox;
  23. private _isResetting: boolean = false;
  24. protected onCreate(): void | Promise<void> {
  25. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  26. addBtnClick(this.btn_reset, this.onBtnResetClick, this);
  27. const Event = EditBox.EventType.TEXT_CHANGED;
  28. this.account.node.on(Event, this.handleCheckForm, this);
  29. this.code.node.on(Event, this.handleCheckForm, this);
  30. this.psd.node.on(Event, this.handleCheckForm, this);
  31. }
  32. private onBtnCloseClick() {
  33. AppKernel.ui.close(UIViewID.ResetPsd);
  34. }
  35. private async onBtnResetClick() {
  36. if (this._isResetting) return;
  37. this._isResetting = true;
  38. AppKernel.ui.loading(true);
  39. const account = this.account.string;
  40. const code = this.code.string;
  41. const password = this.psd.string;
  42. try {
  43. if (account && code && password) {
  44. const res = checkIsEmail(account)
  45. ? await AppKernel.stores.mailStore.reqResetPsd({
  46. account,
  47. code,
  48. newpassword: password
  49. })
  50. : await AppKernel.stores.mainStore.reqForgetPass({
  51. phone: account,
  52. code,
  53. newpassword: password,
  54. });
  55. if (res) {
  56. await AppKernel.services.loginService.loginAccount(account, password);
  57. await AppKernel.ui.close(UIViewID.ResetPsd);
  58. await AppKernel.ui.open(UIViewID.LoginSuccess);
  59. }
  60. }
  61. } finally {
  62. AppKernel.ui.loading(false);
  63. this._isResetting = false;
  64. }
  65. }
  66. private handleCheckForm() {
  67. const account = !!this.account.string.trim();
  68. const code = !!this.code.string.trim();
  69. const password = !!this.psd.string.trim();
  70. const isReady = account && code && password;
  71. this.btn_reset.active = isReady;
  72. this.btn_grey.active = !isReady;
  73. }
  74. }