ChangeEmail.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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('ChangeEmail')
  10. export class ChangeEmail extends UIPopup {
  11. readonly viewId = UIViewID.ChangeEmail;
  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 cur_email_code: EditBox = null;
  22. @property(EditBox)
  23. private new_email: EditBox = null;
  24. @property(EditBox)
  25. private psd: EditBox = null;
  26. @property(EditBox)
  27. private verify_code: EditBox = null;
  28. @property(Label)
  29. private cur_email: Label = null;
  30. private _cur_email_code: string = '';
  31. private _new_email: string = '';
  32. private _psd: string = '';
  33. private _verify_code: string = '';
  34. protected onCreate(): void | Promise<void> {
  35. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  36. addBtnClick(this.btn_cancel, this.onBtnCloseClick, this);
  37. addBtnClick(this.btn_confirm, this.onBtnConfirmClick, this);
  38. this.cur_email_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onCurEmailCodeTextChanged, this);
  39. this.new_email.node.on(EditBox.EventType.TEXT_CHANGED, this.onNewEmailTextChanged, this);
  40. this.psd.node.on(EditBox.EventType.TEXT_CHANGED, this.onPsdTextChanged, this);
  41. this.verify_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onVerifyCodeTextChanged, this);
  42. const { Email } = AppKernel.stores.mainStore.userInfo;
  43. this.cur_email.string = "Current Email:" + Email;
  44. }
  45. private onBtnCloseClick() {
  46. AppKernel.ui.close(UIViewID.ChangeEmail);
  47. }
  48. private async onBtnConfirmClick() {
  49. const old_code = this.cur_email_code.string;
  50. const email = this.new_email.string;
  51. const pwd = this.psd.string;
  52. const new_code = this.verify_code.string;
  53. const isReady = !!old_code && !!email && !!pwd && !!new_code;
  54. if (!isReady) return;
  55. const res = await AppKernel.stores.mailStore.reqChangeEmailConfirm({
  56. account: email,
  57. old_code,
  58. new_code,
  59. password: pwd
  60. });
  61. if (res) {
  62. await AppKernel.ui.close(UIViewID.ChangeEmail);
  63. AppKernel.ui.toast("Change success");
  64. }
  65. }
  66. private onTextChanged() {
  67. const isReady = !!this._cur_email_code && !!this._new_email && !!this._psd && !!this._verify_code;
  68. this.btn_grey.active = !isReady;
  69. this.btn_confirm.active = isReady;
  70. }
  71. private onCurEmailCodeTextChanged(editBox: EditBox) {
  72. console.log('onCurEmailCodeTextChanged', editBox.string);
  73. this._cur_email_code = editBox.string;
  74. this.onTextChanged();
  75. }
  76. private onNewEmailTextChanged(editBox: EditBox) {
  77. console.log('onNewEmailTextChanged', editBox.string);
  78. this._new_email = editBox.string;
  79. this.onTextChanged();
  80. }
  81. private onPsdTextChanged(editBox: EditBox) {
  82. console.log('onPsdTextChanged', editBox.string);
  83. this._psd = editBox.string;
  84. this.onTextChanged();
  85. }
  86. private onVerifyCodeTextChanged(editBox: EditBox) {
  87. console.log('onVerifyCodeTextChanged', editBox.string);
  88. this._verify_code = editBox.string;
  89. this.onTextChanged();
  90. }
  91. }