修改分享
This commit is contained in:
parent
92974027cc
commit
fc0d24d783
|
|
@ -851,32 +851,29 @@ export default class JiaZai extends cc.Component {
|
|||
}
|
||||
|
||||
openSet() {
|
||||
// share
|
||||
// MiniGameManager.instance.onShare();
|
||||
// 测试分享代码
|
||||
// cc.fx.GameTool.shareToWX(() => {
|
||||
// MiniGameSdk.API.showToast("分享成功!");
|
||||
// });
|
||||
|
||||
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;
|
||||
// }
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -1941,9 +1941,7 @@ export default class MapConroler extends cc.Component {
|
|||
|
||||
//时间到了复活
|
||||
reviewLevel(event, type) {
|
||||
console.log("该处需要改-时间到了复活 这个方法没有加必须跳转微信 功能直接通过");
|
||||
|
||||
|
||||
console.log("该处需要改-时间到了复活");
|
||||
|
||||
if (this.reviewState == true) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -661,7 +661,7 @@ var GameTool = {
|
|||
buyProp(propid, callback: Function) {
|
||||
//@ts-ignore
|
||||
if (typeof wx !== 'undefined' && wx !== null) {
|
||||
cc.fx.GameConfig.shareToWX(() => {
|
||||
cc.fx.GameTool.shareToWX(() => {
|
||||
let num = 1; //3
|
||||
// let cost = 600;
|
||||
|
||||
|
|
@ -1295,8 +1295,8 @@ var GameTool = {
|
|||
|
||||
shareToWX(callback: Function) {
|
||||
console.log("Share to WX");
|
||||
if (this._sharing) return;
|
||||
this._sharing = true;
|
||||
// if (this._sharing) return;
|
||||
// this._sharing = true;
|
||||
|
||||
let iphoneArr = [
|
||||
"https://mmocgame.qpic.cn/wechatgame/Lf3SBqy9XpNkakoIZygRzXqww3HTibq6VyibazqmicwibjCS3YpgqbZtkdyABm4Y1wAr/0",
|
||||
|
|
@ -1312,38 +1312,104 @@ var GameTool = {
|
|||
const shareParams = {
|
||||
title: '如果你突然打了个喷嚏,那一定是我在等你帮忙过关!', // 分享标题
|
||||
imageUrl: img, // 分享图片链接
|
||||
// success: function (res) {
|
||||
// console.log('主动拉起分享成功');
|
||||
// },
|
||||
// fail: function (res) {
|
||||
// console.log('主动拉起分享失败');
|
||||
// }
|
||||
};
|
||||
|
||||
// 2. 3 秒定时器:到点就视为成功
|
||||
const timer = setTimeout(() => done(true), 3000);
|
||||
let hideTime: number = 0; // 记录进入后台的时间
|
||||
let timer: any = null; // 定时器引用
|
||||
// 分享成功的处理函数
|
||||
const handleShareSuccess = () => {
|
||||
// if (!this._sharing) return; // 已经回调过了
|
||||
// this._sharing = false;
|
||||
|
||||
// 清除定时器
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
|
||||
// 取消监听事件
|
||||
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
|
||||
//@ts-ignore
|
||||
wx.offHide(hideListener);
|
||||
//@ts-ignore
|
||||
wx.offShow(showListener);
|
||||
}
|
||||
|
||||
// 3. 只要用户点开分享面板也立即成功(比 3 秒先到就先触发)
|
||||
const done = (succ: boolean) => {
|
||||
if (!this._sharing) return; // 已经回调过了
|
||||
this._sharing = false;
|
||||
clearTimeout(timer);
|
||||
console.log('分享成功');
|
||||
succ && wx.showToast({
|
||||
//@ts-ignore
|
||||
wx.showToast({
|
||||
title: '分享成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
callback(); // 业务层回调
|
||||
callback(true); // 回调表示分享成功
|
||||
};
|
||||
|
||||
// 分享失败的处理函数
|
||||
const handleShareFail = () => {
|
||||
// if (!this._sharing) return; // 已经回调过了
|
||||
// this._sharing = false;
|
||||
|
||||
// 清除定时器
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
|
||||
// // 取消监听事件
|
||||
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
|
||||
//@ts-ignore
|
||||
wx.offHide(hideListener);
|
||||
//@ts-ignore
|
||||
wx.offShow(showListener);
|
||||
}
|
||||
|
||||
console.log('分享失败');
|
||||
// callback(false); // 回调表示分享失败
|
||||
};
|
||||
|
||||
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
|
||||
//@ts-ignore
|
||||
wx.shareAppMessage(shareParams);
|
||||
// 监听「分享面板弹出」事件,触发即成功
|
||||
wx.onShow(() => done(true)); // 用户点完分享弹窗会触发 onShow
|
||||
|
||||
// 进入后台的监听函数
|
||||
const hideListener = () => {
|
||||
hideTime = Date.now(); // 记录进入后台的时间
|
||||
console.log("进入后台时间:", hideTime);
|
||||
};
|
||||
|
||||
// 从后台返回的监听函数
|
||||
const showListener = () => {
|
||||
if (hideTime > 0) {
|
||||
const showTime = Date.now(); // 记录返回时间
|
||||
const duration = showTime - hideTime; // 计算后台停留时间
|
||||
console.log("从后台返回时间:", showTime, "停留时间:", duration, "毫秒");
|
||||
|
||||
// 如果后台停留时间大于等于3秒,则认为分享成功
|
||||
if (duration >= 3000) {
|
||||
handleShareSuccess();
|
||||
} else {
|
||||
// 停留时间不足3秒,认为分享失败
|
||||
handleShareFail();
|
||||
}
|
||||
} else {
|
||||
// 没有记录到进入后台时间,认为分享失败
|
||||
handleShareFail();
|
||||
}
|
||||
};
|
||||
|
||||
// 注册监听事件
|
||||
//@ts-ignore
|
||||
wx.onHide(hideListener);
|
||||
//@ts-ignore
|
||||
wx.onShow(showListener);
|
||||
} else {
|
||||
// 非微信环境直接 3 秒后成功
|
||||
// 非微信环境直接失败
|
||||
setTimeout(() => {
|
||||
handleShareFail();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
isFromShareByScene(): boolean {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user