import { _decorator, EditBox, Node } from 'cc'; import { UIViewID } from '@scripts/define/UIDefine'; import { addBtnClick } from '@scripts/utils/UIHelper'; import { AppKernel } from '@scripts/app/AppKernel'; import { UIPopup } from '@scripts/framework/ui/UIPopup'; import { checkIsEmail } from '@scripts/utils/Helper'; const { ccclass, property } = _decorator; @ccclass('ResetPsd') export class ResetPsd extends UIPopup { readonly viewId = UIViewID.ResetPsd; @property(Node) private btn_close: Node = null; @property(Node) private btn_grey: Node = null; @property(Node) private btn_reset: Node = null; @property(EditBox) account: EditBox; @property(EditBox) code: EditBox; @property(EditBox) psd: EditBox; private _isResetting: boolean = false; protected onCreate(): void | Promise { addBtnClick(this.btn_close, this.onBtnCloseClick, this); addBtnClick(this.btn_reset, this.onBtnResetClick, this); const Event = EditBox.EventType.TEXT_CHANGED; this.account.node.on(Event, this.handleCheckForm, this); this.code.node.on(Event, this.handleCheckForm, this); this.psd.node.on(Event, this.handleCheckForm, this); } private onBtnCloseClick() { AppKernel.ui.close(UIViewID.ResetPsd); } private async onBtnResetClick() { if (this._isResetting) return; this._isResetting = true; AppKernel.ui.loading(true); const account = this.account.string; const code = this.code.string; const password = this.psd.string; try { if (account && code && password) { const res = checkIsEmail(account) ? await AppKernel.stores.mailStore.reqResetPsd({ account, code, newpassword: password }) : await AppKernel.stores.mainStore.reqForgetPass({ phone: account, code, newpassword: password, }); if (res) { await AppKernel.services.loginService.loginAccount(account, password); await AppKernel.ui.close(UIViewID.ResetPsd); await AppKernel.ui.open(UIViewID.LoginSuccess); } } } finally { AppKernel.ui.loading(false); this._isResetting = false; } } private handleCheckForm() { const account = !!this.account.string.trim(); const code = !!this.code.string.trim(); const password = !!this.psd.string.trim(); const isReady = account && code && password; this.btn_reset.active = isReady; this.btn_grey.active = !isReady; } }