| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- import { _decorator, Button, Color, EditBox, instantiate, Label, Node, RichText, Sprite, SpriteFrame, UITransform } from 'cc';
- import { UIView } from '@scripts/framework/ui/UIView';
- import { AppKernel } from '@scripts/app/AppKernel';
- 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';
- import { setSpriteFrame } from '@scripts/utils/ResHelper';
- const { ccclass, property } = _decorator;
- @ccclass('UserInfoView')
- export class UserInfoView extends UIView {
- readonly viewId = UIViewID.UserInfoView;
- @property(Node)
- btn_close: Node;
- @property(Node)
- btn_email: Node;
- @property(Node)
- btn_phone: Node;
- @property(Node)
- btn_avatar: Node;
- @property(Node)
- btn_name: Node;
- @property(Node)
- btn_copy_id: Node;
- @property(Node)
- btn_bind_google: Node;
- @property(Node)
- btn_bind_facebook: Node;
- @property(Node)
- btn_unlink_third_party: Node;
- @property(Sprite)
- avatar: Sprite;
- @property(Label)
- nickname: Label;
- @property(Label)
- id: Label;
- @property(Label)
- level: Label;
- @property(Label)
- vip_level: Label;
- @property(Label)
- score: Label;
- @property(Label)
- gold_score: Label;
- @property(Label)
- email: Label;
- @property(Label)
- phone: Label;
- @property(Node)
- third_party: Node;
- private _userInfo: any;
- private _googleWebBtn;
- private listenViews: UIViewID[] = [
- UIViewID.BindEmail,
- UIViewID.ChangeEmail,
- UIViewID.BindPhone,
- UIViewID.ChangePhone,
- UIViewID.ChangeAvatar,
- UIViewID.ChangeName,
- UIViewID.UnbindAccount,
- ];
- protected onCreate(): void | Promise<void> {
- AppKernel.events.on('user:update', this.updateUserInfo, this);
- AppKernel.events.on('open:ui-view', this.handleSubViewOpen, this);
- AppKernel.events.on('close:ui-view', this.handleSubViewClose, this);
- addBtnClick(this.btn_close, this.onBtnCloseClick, this);
- addBtnClick(this.btn_email, this.onBtnEmailClick, this);
- addBtnClick(this.btn_phone, this.onBtnPhoneClick, this);
- addBtnClick(this.btn_avatar, this.onBtnAvatarClick, this);
- addBtnClick(this.btn_name, this.onBtnNameClick, this);
- addBtnClick(this.btn_copy_id, this.onBtnCopyIDClick, this);
- addBtnClick(this.btn_bind_google, this.onBtnBindGoogleClick, this);
- addBtnClick(this.btn_bind_facebook, this.onBtnBindFacebookClick, this);
- addBtnClick(this.btn_unlink_third_party, this.onBtnUnlinkThirdPartyClick, this);
- this._googleWebBtn = AppKernel.google.createLoginBtn(
- this.btn_bind_google,
- res => this.onGoogleWebLogin(res),
- );
- }
- protected onOpen(_params: unknown): void | Promise<void> {
- /// 播放完打开动画后 再显示h5 google login btn dom
- this._googleWebBtn?.setActive(true);
- this.updateUserInfo();
- }
- protected onClose(_reason: UICloseReason): void | Promise<void> {
- this._googleWebBtn?.setActive(false);
- }
- protected onDestroy(): void {
- this._googleWebBtn?.clear();
- super.onDestroy();
- }
- private updateUserInfo() {
- this._userInfo = AppKernel.stores.mainStore.userInfo;
- const {
- FaceID,
- NickName,
- GameID,
- Level,
- vipLevel,
- Score,
- InsureScore,
- Email,
- Phone,
- third_party
- } = this._userInfo; // TODO: 获取用户信息
- console.log("updateUserInfo", this._userInfo);
- if (FaceID >= 1) setSpriteFrame(this.avatar, "public/avatar/" + FaceID, "lobbyRes");
- this.nickname.string = NickName;
- this.id.string = `ID:${GameID}`;
- this.level.string = `LV.${Level}`;
- this.vip_level.string = `VIP.${vipLevel}`;
- this.score.string = Score;
- this.gold_score.string = InsureScore;
- this.email.string = Email ? Email : "Not bound";
- const btn_email_label = this.btn_email.getChildByName("label");
- btn_email_label.getComponent(Label).string = Email ? "CHANGE" : "BIND";
- this.phone.string = Phone ? Phone : "Not bound";
- const btn_phone_label = this.btn_phone.getChildByName("label");
- btn_phone_label.getComponent(Label).string = Phone ? "CHANGE" : "BIND";
- if (third_party) {
- const third_party_unlink = this.third_party.getChildByName("unlink");
- const third_party_linked = this.third_party.getChildByName("linked");
- const { bound, provider } = third_party;
- third_party_linked.active = bound;
- third_party_unlink.active = !bound;
- if (bound) {
- const google = third_party_linked.getChildByName("google");
- const facebook = third_party_linked.getChildByName("facebook");
- google.active = provider === "google";
- facebook.active = provider === "facebook";
- }
- }
- }
- private onBtnCloseClick() {
- AppKernel.ui.close(UIViewID.UserInfoView);
- }
- private onBtnEmailClick() {
- const { Email } = this._userInfo;
- AppKernel.ui.open(Email ? UIViewID.ChangeEmail : UIViewID.BindEmail);
- }
- private onBtnPhoneClick() {
- const { Phone } = this._userInfo;
- AppKernel.ui.open(Phone ? UIViewID.ChangePhone : UIViewID.BindPhone);
- }
- private onBtnAvatarClick() {
- AppKernel.ui.open(UIViewID.ChangeAvatar);
- }
- private onBtnNameClick() {
- AppKernel.ui.open(UIViewID.ChangeName);
- }
- private onBtnCopyIDClick() {
- const { GameID } = this._userInfo;
- }
- private async onBtnBindGoogleClick() {
- AppKernel.ui.loading(true);
- const res = await AppKernel.stores.mainStore.reqBindGoogle();
- AppKernel.ui.loading(false);
- if (res) AppKernel.ui.toast("Bind success");
- }
- private async onGoogleWebLogin(res) {
- AppKernel.ui.loading(true);
- const result = await AppKernel.stores.mainStore.reqBindGoogle(res);
- AppKernel.ui.loading(false);
- if (result) AppKernel.ui.toast("Bind success");
- }
- private async onBtnBindFacebookClick() {
- AppKernel.ui.loading(true);
- const res = await AppKernel.stores.mainStore.reqBindFacebook();
- AppKernel.ui.loading(false);
- if (res) AppKernel.ui.toast("Bind success");
- }
- private onBtnUnlinkThirdPartyClick() {
- const { Phone, Email } = this._userInfo;
- console.log("onBtnUnlinkThirdPartyClick", Phone, Email);
- if (!Phone && !Email) {
- AppKernel.ui.dialog({
- message: "Bind an email or phone number before unlinking this account.",
- callBack: (res) => {
- // AppKernel.appLobby.openLogin();
- // console.log("close dialog");
- return true;
- }
- })
- } else {
- AppKernel.ui.open(UIViewID.UnbindAccount);
- }
- }
- private handleSubViewOpen(payload: UIViewID) {
- if (this.listenViews.includes(payload)) {
- this._googleWebBtn?.setActive(false);
- console.log("UserInfoView handleSubUIOpen", payload);
- }
- }
- private handleSubViewClose(payload: UIViewID) {
- if (this.listenViews.includes(payload)) {
- this._googleWebBtn?.setActive(true);
- console.log("UserInfoView handleSubUIClose", payload);
- }
- }
- }
|