| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { _decorator } from "cc";
- import { GameUILayers, gui } from "../../../core/ui/ui";
- import ui_base from "../../../core/ui/ui_base";
- import { ModuleDef } from "../../../Scripts/ModuleDef";
- import { ani_ui } from "../UI_Main/UI_Main";
- import { Layout_Invite } from "./Layout_Invite";
- const { ccclass, property } = _decorator;
- @ccclass('UI_Invite')
- export class UI_Invite extends ui_base {
- constructor() {
- super(ModuleDef.GAME, 'ui/UI_Invite/Invite', GameUILayers.HUD, Layout_Invite);
- }
- protected async onCreated() {
- // 拉取通过邀请进入该游戏的好友数量
- this.get_Count();
- this.show();
- const layout = this.getLayout<Layout_Invite>();
- ani_ui(layout.Close_Btn.node.parent);
- this.onButtonEvent(layout.Close_Btn, () => {
- gui.close(UI_Invite);
- });
- this.onButtonEvent(layout.Invite_Friend_Btn, () => {
- //分享给好友
- chsdk.shareAppMessage();
- });
- this.onButtonEvent(layout.Refresh_Btn, () => {
- //刷新好友列表
- this.get_Count();
- this.show();
- })
- }
- get_Count(){
- chsdk.getShareList().then((res) => {
- if (res.code === 0 && res.data) {
- // 确保数据有效
- const friendCount = res.data.length; // 计算人数
- console.log(`通过邀请进入游戏的好友数量: ${friendCount}`);
- } else {
- // 错误处理
- console.error(`获取分享列表失败: ${res.err || "未知错误"}`);
- }
- }).catch((err) => {
- // 捕获 promise 的异常
- console.error(`请求失败: ${err.message}`);
- });
- }
- show(){
- const layout=this.getLayout<Layout_Invite>();
- layout.progressBar.progress = layout.count/layout.target_count;
- layout.Txt.string = layout.count + '/' + layout.target_count;
- }
- }
|