BindEmail.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Button, Color, EditBox, instantiate, Label, Node, RichText, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { UIViewID } from '@scripts/define/UIDefine';
  3. import { UICloseReason } from '@scripts/framework/ui/UILayer';
  4. import { addBtnClick } from '@scripts/utils/UIHelper';
  5. import { AppKernel } from '@scripts/app/AppKernel';
  6. import { SelectBox } from '@scripts/components/selectBox/SelectBox';
  7. import { UIPopup } from '@scripts/framework/ui/UIPopup';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('BindEmail')
  10. export class BindEmail extends UIPopup {
  11. readonly viewId = UIViewID.BindEmail;
  12. @property(Node)
  13. private btn_close: Node = null;
  14. @property(Node)
  15. private btn_cancel: Node = null;
  16. @property(Node)
  17. private btn_confirm: Node = null;
  18. @property(Node)
  19. private btn_grey: Node = null;
  20. @property(EditBox)
  21. private new_email: EditBox = null;
  22. @property(EditBox)
  23. private psd: EditBox = null;
  24. @property(EditBox)
  25. private verify_code: EditBox = null;
  26. @property(Label)
  27. private psd_label: Label = null;
  28. private _new_email: string = '';
  29. private _psd: string = '';
  30. private _verify_code: string = '';
  31. protected onCreate(): void | Promise<void> {
  32. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  33. addBtnClick(this.btn_cancel, this.onBtnCloseClick, this);
  34. addBtnClick(this.btn_confirm, this.onBtnConfirmClick, this);
  35. this.new_email.node.on(EditBox.EventType.TEXT_CHANGED, this.onNewEmailTextChanged, this);
  36. this.psd.node.on(EditBox.EventType.TEXT_CHANGED, this.onPsdTextChanged, this);
  37. this.verify_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onVerifyCodeTextChanged, this);
  38. const { isGuest } = AppKernel.stores.mainStore.userInfo;
  39. const hasPsd = isGuest ? false : true;
  40. this.psd_label.string = hasPsd ? 'Current Password' : 'Set Password';
  41. this.psd.placeholder = hasPsd ? 'Current Password' : 'Set Password';
  42. }
  43. private onBtnCloseClick() {
  44. AppKernel.ui.close(UIViewID.BindEmail);
  45. }
  46. private async onBtnConfirmClick() {
  47. const email = this.new_email.string;
  48. const pwd = this.psd.string;
  49. const code = this.verify_code.string;
  50. const isReady = !!email && !!pwd && !!code;
  51. if (!isReady) return;
  52. const res = await AppKernel.stores.mailStore.reqBindEmailConfirm({
  53. account: email,
  54. password: pwd,
  55. code: code
  56. });
  57. if (res) {
  58. await AppKernel.ui.close(UIViewID.BindEmail);
  59. AppKernel.ui.toast("Bind success");
  60. }
  61. }
  62. private onTextChanged() {
  63. const isReady = !!this._new_email && !!this._psd && !!this._verify_code;
  64. this.btn_grey.active = !isReady;
  65. this.btn_confirm.active = isReady;
  66. }
  67. private onNewEmailTextChanged(editBox: EditBox) {
  68. console.log('onNewEmailTextChanged', editBox.string);
  69. this._new_email = editBox.string;
  70. this.onTextChanged();
  71. }
  72. private onPsdTextChanged(editBox: EditBox) {
  73. console.log('onPsdTextChanged', editBox.string);
  74. this._psd = editBox.string;
  75. this.onTextChanged();
  76. }
  77. private onVerifyCodeTextChanged(editBox: EditBox) {
  78. console.log('onVerifyCodeTextChanged', editBox.string);
  79. this._verify_code = editBox.string;
  80. this.onTextChanged();
  81. }
  82. }