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('Register') export class Register extends UIPopup { readonly viewId = UIViewID.Register; @property(Node) private btn_close: Node = null; @property(Node) private btn_signup: Node = null; @property(Node) private btn_grey: Node = null; @property(EditBox) private account: EditBox; @property(EditBox) private code: EditBox; @property(EditBox) private psd: EditBox; @property(EditBox) private inviteCode: EditBox; private _isSigningUp: boolean = false; protected onCreate(): void | Promise { addBtnClick(this.btn_close, this.closeSelf, this); addBtnClick(this.btn_signup, this.onBtnSignUpClick, 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); this.btn_signup.active = false; this.btn_grey.active = true; } private async onBtnSignUpClick() { if (this._isSigningUp) return; this._isSigningUp = true; AppKernel.ui.loading(true); const account = this.account.string.trim(); const code = this.code.string.trim(); const password = this.psd.string.trim(); const act = this.inviteCode.string.trim(); try { if (account && code && password) { const res = checkIsEmail(account) ? await AppKernel.stores.mailStore.reqRegister({ account, code, password, act }) : await AppKernel.services.loginService.register({ account, code, password, act }); if (res) { await AppKernel.services.loginService.loginAccount(account, password); await AppKernel.ui.close(UIViewID.Register); await AppKernel.ui.open(UIViewID.LoginSuccess); } else { // log error } } } finally { AppKernel.ui.loading(false); this._isSigningUp = 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_signup.active = isReady; this.btn_grey.active = !isReady; } }