|
@@ -5,6 +5,7 @@ import { UIViewID } from '@scripts/define/UIDefine';
|
|
|
import { UICloseReason } from '@scripts/framework/ui/UILayer';
|
|
import { UICloseReason } from '@scripts/framework/ui/UILayer';
|
|
|
import { formatCurrency } from '@scripts/utils/Helper';
|
|
import { formatCurrency } from '@scripts/utils/Helper';
|
|
|
import { addBtnClick } from '@scripts/utils/UIHelper';
|
|
import { addBtnClick } from '@scripts/utils/UIHelper';
|
|
|
|
|
+import { setSpriteFrame } from '@scripts/utils/ResHelper';
|
|
|
|
|
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
@@ -12,50 +13,242 @@ const { ccclass, property } = _decorator;
|
|
|
export class UserInfoView extends UIView {
|
|
export class UserInfoView extends UIView {
|
|
|
readonly viewId = UIViewID.UserInfoView;
|
|
readonly viewId = UIViewID.UserInfoView;
|
|
|
|
|
|
|
|
- @property(Button)
|
|
|
|
|
- btnGuest: Button;
|
|
|
|
|
-
|
|
|
|
|
- @property(Button)
|
|
|
|
|
- btnFacebook: Button;
|
|
|
|
|
|
|
+ @property(Node)
|
|
|
|
|
+ btn_close: Node;
|
|
|
|
|
|
|
|
- @property(Button)
|
|
|
|
|
- btnGoogle: Button;
|
|
|
|
|
|
|
+ @property(Node)
|
|
|
|
|
+ btn_email: Node;
|
|
|
|
|
|
|
|
- @property(EditBox)
|
|
|
|
|
- loginAccount: EditBox;
|
|
|
|
|
|
|
+ @property(Node)
|
|
|
|
|
+ btn_phone: Node;
|
|
|
|
|
|
|
|
- @property(EditBox)
|
|
|
|
|
- loginPassword: EditBox;
|
|
|
|
|
|
|
+ @property(Node)
|
|
|
|
|
+ btn_avatar: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
@property(Node)
|
|
|
- psd_visible_control: Node;
|
|
|
|
|
|
|
+ btn_name: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
@property(Node)
|
|
|
- btnLogin: Node;
|
|
|
|
|
|
|
+ btn_copy_id: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
@property(Node)
|
|
|
- btnRegister: Node;
|
|
|
|
|
|
|
+ btn_bind_google: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
@property(Node)
|
|
|
- btnResetPsd: Node;
|
|
|
|
|
|
|
+ btn_bind_facebook: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
@property(Node)
|
|
|
- btnSupport: 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)
|
|
@property(Node)
|
|
|
- policyContainer: 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> {
|
|
protected onCreate(): void | Promise<void> {
|
|
|
- // addBtnClick(this.btnGuest.node, this.onBtnGuestClick, this);
|
|
|
|
|
- // addBtnClick(this.btnFacebook.node, this.onBtnFBClick, this);
|
|
|
|
|
- // addBtnClick(this.btnGoogle.node, this.onBtnGoogleClick, this);
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // this.initPsdInput();
|
|
|
|
|
- // this.initPolicyDesc();
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|