修改分享

This commit is contained in:
huanghaipeng 2025-10-11 14:10:27 +08:00
parent 956735a8b0
commit 9367d57c7e
5 changed files with 182 additions and 136 deletions

View File

@ -211,7 +211,17 @@ export default class JiaZai extends cc.Component {
AudioManager._instance.playMusicGame();
this.onGames();
if (cc.fx.GameConfig.GM_INFO.openHeath) {
cc.fx.GameConfig.GM_INFO.openHeath = false
setTimeout(() => {
console.log("打开体力界面");
this.openHeath();
}, 100);
}
}
//监听后台
onGames() {
//@ts-ignore
@ -844,24 +854,29 @@ export default class JiaZai extends cc.Component {
// share
// MiniGameManager.instance.onShare();
const now = Date.now();
if (now - this.lastPauseClickTime < 300) {
// 0.3秒内禁止再次点击
return;
}
this.lastPauseClickTime = now;
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
if (cc.fx.GameConfig.GM_INFO.openid == undefined) {
cc.fx.GameConfig.GM_INFO.openid = "";
}
if (!this.setUi.active) {
// 第一次点击,打开并播放动画
this.setUi.active = true;
this.setUi.getComponent(cc.Animation).play();
} else {
// 再次点击,关闭节点
this.setUi.active = false;
}
cc.fx.GameTool.shareToWX(() => {
MiniGameSdk.API.showToast("分享成功!");
console.log("分享成功!!!!!");
});
// const now = Date.now();
// if (now - this.lastPauseClickTime < 300) {
// // 0.3秒内禁止再次点击
// return;
// }
// this.lastPauseClickTime = now;
// cc.fx.AudioManager._instance.playEffect("anniu_little", null);
// if (cc.fx.GameConfig.GM_INFO.openid == undefined) {
// cc.fx.GameConfig.GM_INFO.openid = "";
// }
// if (!this.setUi.active) {
// // 第一次点击,打开并播放动画
// this.setUi.active = true;
// this.setUi.getComponent(cc.Animation).play();
// } else {
// // 再次点击,关闭节点
// this.setUi.active = false;
// }
}
closeReward() {

View File

@ -1912,7 +1912,10 @@ export default class MapConroler extends cc.Component {
MiniGameSdk.API.showToast("体力值不足");
setTimeout(() => {
// this.openShop();
console.log("此处需修改-体力不足");
this.returnHome();
cc.fx.GameConfig.GM_INFO.openHeath = true;
console.log("体力不足");
}, 500);
return;
}
@ -1947,14 +1950,17 @@ export default class MapConroler extends cc.Component {
}
this.reviewState = true;
cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
cc.fx.GameTool.shareToWX();
// let coin = 500;
let data = {
type: type,
// coin: -coin
}
cc.fx.GameTool.shareToWX(() => {
this.runRewive(data);
});
// let coin = 500;
// if (type == "time") {
// if (cc.fx.GameConfig.GM_INFO.review == 1) coin = 1000;
// else if (cc.fx.GameConfig.GM_INFO.review == 2) coin = 1500;
@ -1984,7 +1990,7 @@ export default class MapConroler extends cc.Component {
// return;
// }
// else {
this.runRewive(data);
// this.runRewive(data);
// }
}

View File

@ -67,50 +67,50 @@ export default class NewClass extends cc.Component {
//获取当前金币
// let curCoin = cc.fx.GameConfig.GM_INFO.coin;
// if (curCoin >= 1000) {
cc.fx.GameTool.shareToWX();
//// 分享成功后才执行以下代码
this.switchButtons[1].active = false;
// cc.fx.GameTool.changeCoin(-1000);
// const data = {
// change_reason: "首页购买体力",
// id: (1001 + ""),
// num: -1000
// }
// cc.fx.GameTool.shushu_Track("resource_cost", data);
cc.fx.GameConfig.GM_INFO.hp = cc.fx.GameConfig.GM_INFO.hp_Max;
cc.fx.GameConfig.GM_INFO.min_Time = 0;
const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
if (parentNode) {
const jiazaiComp = parentNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.setHealthInfo(false);
// jiazaiComp.updateCoin();
// cc.fx.GameConfig.GM_INFO.hp = 1; // 测试时不通过微信分享使用
cc.fx.GameTool.shareToWX(() => {
//// 分享成功后才执行以下代码
this.switchButtons[1].active = false;
// cc.fx.GameTool.changeCoin(-1000);
// const data = {
// change_reason: "首页购买体力",
// id: (1001 + ""),
// num: -1000
// }
// cc.fx.GameTool.shushu_Track("resource_cost", data);
// cc.fx.GameConfig.GM_INFO.hp = cc.fx.GameConfig.GM_INFO.hp_Max;
cc.fx.GameConfig.GM_INFO.hp = 1;
cc.fx.GameConfig.GM_INFO.min_Time = 0;
const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
if (parentNode) {
const jiazaiComp = parentNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.setHealthInfo(false);
// jiazaiComp.updateCoin();
}
}
}
this.switchButtons[0].active = true;
cc.fx.GameTool.setUserHealth(0, (data) => {
cc.fx.GameTool.getHealth(null);
})
// const buyData = {
// item_id: "refill_health",
// item_num: 3,
// item_price: 1000,
// cost_type: "gold"
// }
// // console.log("____________即将上传Shop_buy", buyData);
// cc.fx.GameTool.shushu_Track("shop_buy", buyData);
// }
// else {
// MiniGameSdk.API.showToast("金币不足,无法购买体力");
// setTimeout(() => {
// this.btn_Touch = true;
// this.openShop();
// }, 500);
// }
this.switchButtons[0].active = true;
cc.fx.GameTool.setUserHealth(0, (data) => {
cc.fx.GameTool.getHealth(null);
})
// const buyData = {
// item_id: "refill_health",
// item_num: 3,
// item_price: 1000,
// cost_type: "gold"
// }
// // console.log("____________即将上传Shop_buy", buyData);
// cc.fx.GameTool.shushu_Track("shop_buy", buyData);
// }
// else {
// MiniGameSdk.API.showToast("金币不足,无法购买体力");
// setTimeout(() => {
// this.btn_Touch = true;
// this.openShop();
// }, 500);
// }
});
}
//关闭弹窗

View File

@ -122,8 +122,9 @@ export class GameConfig {
wxFriend: boolean; //微信好友信息授权
wxUserInfo: boolean; //微信用户信息授权
winStreak: number; //连胜次数
winState: boolean //是否延续连胜状态
winState: boolean; //是否延续连胜状态
tasks: {}; //任务
openHeath: boolean; // 是否体力不足
};
@ -287,7 +288,8 @@ export class GameConfig {
wxUserInfo: false, //微信用户信息授权
winState: false, //是否延续连胜状态
winStreak: 0, //连胜
tasks: { levelPass: { value: 0, target: 0, state: 0 }, share: { value: 0, target: 0, state: 0 }, useEnergy: { value: 0, target: 0, state: 0 }, useProp: { value: 0, target: 0, state: 0 } }
tasks: { levelPass: { value: 0, target: 0, state: 0 }, share: { value: 0, target: 0, state: 0 }, useEnergy: { value: 0, target: 0, state: 0 }, useProp: { value: 0, target: 0, state: 0 } },
openHeath: false,
};
// this.setCode(this.getKey("scode"));
// this.GM_INFO.level = 0;

View File

@ -11,6 +11,8 @@ var GameTool = {
_endTime: 0,
_totalTime: 0,
_sharing: false,
//获取userId
Authentication() {
let name = "user_" + cc.fx.GameConfig.GM_INFO.gameId;
@ -659,67 +661,69 @@ var GameTool = {
buyProp(propid, callback: Function) {
//@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) {
cc.fx.GameConfig.shareToWX();
let num = 1; //3
// let cost = 600;
cc.fx.GameConfig.shareToWX(() => {
let num = 1; //3
// let cost = 600;
if (propid == 2003) {
// cost = 900;
num = 1; // 3
}
else if (propid == 2002) {
num = 1;
}
//console.log("_____________新版本", num);
// cc.fx.GameTool.changeCoin(-cost);
if (propid == 2003) {
// cost = 900;
num = 1; // 3
}
else if (propid == 2002) {
num = 1;
}
//console.log("_____________新版本", num);
// cc.fx.GameTool.changeCoin(-cost);
// const dataTemp = {
// change_reason: "商城购买道具消耗",
// id: (1001 + ""),
// num: -cost
// }
// cc.fx.GameTool.shushu_Track("resource_cost", dataTemp);
// const dataTemp = {
// change_reason: "商城购买道具消耗",
// id: (1001 + ""),
// num: -cost
// }
// cc.fx.GameTool.shushu_Track("resource_cost", dataTemp);
let _id = "";
let propNumber = 0;
if (propid == 2001) {
_id = "freeze_in_game";
cc.fx.GameConfig.GM_INFO.freezeAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.freezeAmount;
}
else if (propid == 2002) {
_id = "hammer_in_game";
cc.fx.GameConfig.GM_INFO.hammerAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.hammerAmount;
}
else if (propid == 2003) {
_id = "wand_in_game";
cc.fx.GameConfig.GM_INFO.magicAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.magicAmount;
}
let _id = "";
let propNumber = 0;
if (propid == 2001) {
_id = "freeze_in_game";
cc.fx.GameConfig.GM_INFO.freezeAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.freezeAmount;
}
else if (propid == 2002) {
_id = "hammer_in_game";
cc.fx.GameConfig.GM_INFO.hammerAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.hammerAmount;
}
else if (propid == 2003) {
_id = "wand_in_game";
cc.fx.GameConfig.GM_INFO.magicAmount += num;
propNumber = cc.fx.GameConfig.GM_INFO.magicAmount;
}
//console.log("购买道具:", num);
cc.fx.GameTool.setUserProp(propid, propNumber, (data) => {
})
//console.log("购买道具:", num);
cc.fx.GameTool.setUserProp(propid, propNumber, (data) => {
})
const data = {
change_reason: "share",
id: propid,
num: num,
compensate: false
}
cc.fx.GameTool.shushu_Track("resource_get", data);
const data = {
change_reason: "share",
id: propid,
num: num,
compensate: false
}
cc.fx.GameTool.shushu_Track("resource_get", data);
//// const buyData = {
// item_id: _id,
// item_num: num,
// item_price: cost,
// cost_type: "gold"
// }
// //console.log("____________即将上传Shop_buy", buyData);
// cc.fx.GameTool.shushu_Track("shop_buy", buyData);
//// const buyData = {
// item_id: _id,
// item_num: num,
// item_price: cost,
// cost_type: "gold"
// }
// //console.log("____________即将上传Shop_buy", buyData);
// cc.fx.GameTool.shushu_Track("shop_buy", buyData);
callback();
});
callback();
}
},
@ -1289,8 +1293,11 @@ var GameTool = {
return null;
},
shareToWX() {
shareToWX(callback: Function) {
console.log("Share to WX");
if (this._sharing) return;
this._sharing = true;
let iphoneArr = [
"https://mmocgame.qpic.cn/wechatgame/Lf3SBqy9XpNkakoIZygRzXqww3HTibq6VyibazqmicwibjCS3YpgqbZtkdyABm4Y1wAr/0",
"https://mmocgame.qpic.cn/wechatgame/TWKuFxnCn7ksT3KXfhCC4yOfZeD4b0hrptDSJ2DFmwz02Yc8SppcwyPAOoS1MsMr/0",
@ -1305,21 +1312,37 @@ var GameTool = {
const shareParams = {
title: '如果你突然打了个喷嚏,那一定是我在等你帮忙过关!', // 分享标题
imageUrl: img, // 分享图片链接
success: function (res) {
console.log('主动拉起分享成功');
},
fail: function (res) {
console.log('主动拉起分享失败');
}
// success: function (res) {
// console.log('主动拉起分享成功');
// },
// fail: function (res) {
// console.log('主动拉起分享失败');
// }
};
// 调用微信分享 API
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
//@ts-ignore
wx.shareAppMessage(shareParams);
// 可以模拟一个3秒的延迟模拟分享成功
setTimeout(() => {
}, 3000);
// 2. 3 秒定时器:到点就视为成功
const timer = setTimeout(() => done(true), 3000);
// 3. 只要用户点开分享面板也立即成功(比 3 秒先到就先触发)
const done = (succ: boolean) => {
if (!this._sharing) return; // 已经回调过了
this._sharing = false;
clearTimeout(timer);
console.log('分享成功');
succ && wx.showToast({
title: '分享成功',
icon: 'success',
duration: 2000
});
callback(); // 业务层回调
};
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.shareAppMessage(shareParams);
// 监听「分享面板弹出」事件,触发即成功
wx.onShow(() => done(true)); // 用户点完分享弹窗会触发 onShow
} else {
// 非微信环境直接 3 秒后成功
}
},