import { _decorator, Button, EditBox, Node } from 'cc'; import { UIView } from '@scripts/framework/ui/UIView'; import { AppKernel } from '@scripts/app/AppKernel'; import { APP_LOGIN_TYPE } from '@scripts/define/Define'; import { UIViewID } from '@scripts/define/UIDefine'; import { UICloseReason } from '@scripts/framework/ui/UILayer'; import { formatCurrency } from '@scripts/utils/Helper'; import { addBtnClick } from '@scripts/utils/UIHelper'; const { ccclass, property } = _decorator; @ccclass('LoginView') export class LoginView extends UIView { readonly viewId = UIViewID.LoginView; @property(Button) btnGuest: Button; @property(Button) btnFacebook: Button; @property(Button) btnGoogle: Button; @property(Button) btnLogOut: Button; @property(Node) registerNode: Node; @property(Node) loginNode: Node; @property(Node) btnRegisterNode: Node; @property(Node) btnLoginNode: Node; @property(EditBox) loginAccount: EditBox; @property(EditBox) loginPassword: EditBox; @property(EditBox) registerAccount: EditBox; @property(EditBox) registerCode: EditBox; @property(EditBox) registerPw: EditBox; @property(Node) btnRegister: Node; @property(Node) btnLogin: Node; @property(Node) btnSend: Node; private _googleWebBtn; protected onCreate(): void | Promise { addBtnClick(this.btnGuest.node, this.onBtnGuestClick, this); addBtnClick(this.btnFacebook.node, this.onBtnFBClick, this); addBtnClick(this.btnGoogle.node, this.onBtnGoogleClick, this); addBtnClick(this.btnLogOut.node, this.onBtnLogOutClick, this); this._googleWebBtn = AppKernel.google.createLoginBtn( this.btnGoogle.node, res => this.onGoogleWebLogin(res), ); ///////////////// Test addBtnClick(this.btnLoginNode, this.onShowLoginNode, this); addBtnClick(this.btnRegisterNode, this.onShowRegisterNode, this); addBtnClick(this.btnLogin, this.onBtnLoginClick, this); addBtnClick(this.btnRegister, this.onBtnRegisterClick, this); addBtnClick(this.btnSend, this.onBtnSendClick, this); console.log(">>>>>>>>>", formatCurrency(12345678.9), formatCurrency(12345678.9, 2)) } protected onOpen(_params: unknown): void | Promise { /// 播放完打开动画后 再显示h5 google login btn dom this._googleWebBtn?.setActive(true); } protected onClose(_reason: UICloseReason): void | Promise { this._googleWebBtn?.setActive(false); } protected onDestroy(): void { this._googleWebBtn?.clear(); } private async onBtnGuestClick() { AppKernel.ui.loading(true); await AppKernel.services.loginService.guestLogin(); AppKernel.ui.loading(false); } private async onBtnFBClick() { AppKernel.ui.loading(true); await AppKernel.services.loginService.fbLogin(); AppKernel.ui.loading(false); } private async onBtnLogOutClick() { // AppKernel.ui.loading(true); // const res = await AppKernel.fb.logOut(); // console.log('facebook logout res: ', res); // AppKernel.ui.loading(false); } private async onGoogleWebLogin(res) { AppKernel.ui.loading(true); await AppKernel.services.loginService.googleLogin(res); AppKernel.ui.loading(false); } private async onBtnGoogleClick() { AppKernel.ui.loading(true); await AppKernel.services.loginService.googleLogin(); AppKernel.ui.loading(false); } ///////////////// Test private onShowLoginNode() { this.loginNode.active = !this.loginNode.active; } private onShowRegisterNode() { this.registerNode.active = !this.registerNode.active; } private onBtnLoginClick() { const account = this.loginAccount.string; const password = this.loginPassword.string; AppKernel.services.loginService.loginAccount(account, password); } private onBtnRegisterClick() { const account = this.registerAccount.string; const code = this.registerCode.string; const password = this.registerPw.string; AppKernel.services.loginService.register({ account, code, password }); } private onBtnSendClick() { const account = this.registerAccount.string; const mainStore = AppKernel.stores.mainStore; mainStore.reqSendCode(account); } }