|
@@ -9,7 +9,10 @@ const GameModule = require("../utils/GameModule");
|
|
|
/// 处理
|
|
|
class Platform {
|
|
|
static initPlatform() {
|
|
|
- if (cc.sys.platform === cc.sys.WECHAT_GAME) {
|
|
|
+
|
|
|
+ if (window.tt != undefined) {
|
|
|
+ this.handelTTLifeCyle();
|
|
|
+ }else if (CC_WECHATGAME) {
|
|
|
this.handelWxLifeCyle();
|
|
|
} else if (CC_QQPLAY) {
|
|
|
this.handelQQLifeCycle();
|
|
@@ -71,6 +74,151 @@ class Platform {
|
|
|
// })
|
|
|
}
|
|
|
|
|
|
+ static handelTTLifeCyle() {
|
|
|
+ tt.onShow((query) => {
|
|
|
+ // if (typeof wx.getUpdateManager === 'function') {
|
|
|
+ // const updateManager = wx.getUpdateManager();
|
|
|
+ //
|
|
|
+ // updateManager.onCheckForUpdate(function (res) {
|
|
|
+ // // 请求完新版本信息的回调
|
|
|
+ // console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // updateManager.onUpdateReady(function () {
|
|
|
+ // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
+ // updateManager.applyUpdate();
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // updateManager.onUpdateFailed(function () {
|
|
|
+ // // 新的版本下载失败
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+ //进入游戏的场景值
|
|
|
+ // console.log('scene ' + scene + '==============================game ===============================');
|
|
|
+ // if (scene == 1104) {
|
|
|
+ // GameGlobal.isMineEnter = true; //从我的小程序进入游戏
|
|
|
+ // } else {
|
|
|
+ // GameGlobal.isMineEnter = false; //从我的小程序进入游戏
|
|
|
+ // }
|
|
|
+ console.log('Global onShow' + JSON.stringify(query) + '======================================');
|
|
|
+ if (query != undefined && query != null) {
|
|
|
+ if (typeof query == "string") {
|
|
|
+ query = JSON.parse(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ GameGlobal.shareType = query.shareType;
|
|
|
+
|
|
|
+ // if (GameGlobal.shareType == ShareAction.SHOW_GROUP_RANK) {
|
|
|
+ // if (shareTicket != undefined && shareTicket != null) {
|
|
|
+ // GameGlobal.shareTicket = shareTicket;
|
|
|
+ // GameEvent.fire(GameNotificationKey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜
|
|
|
+ // } else {
|
|
|
+ // GameGlobal.shareTicket = '';
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (query.uid != undefined && GameGlobal.shareType == ShareAction.INVITE_FRIEND) {
|
|
|
+ GameGlobal.shareUid = query.uid;
|
|
|
+ GameEvent.fire(GameNotificationKey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友.....
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //// 如果是从后台到前台
|
|
|
+ Platform.handelOnShow();
|
|
|
+ });
|
|
|
+
|
|
|
+ tt.onHide(() => {
|
|
|
+ console.log('Global onHide ===================================');
|
|
|
+ GameGlobal.isOnHide = true;
|
|
|
+ if (GameModule.userInfo) {
|
|
|
+ GameModule.userInfo.doReport();
|
|
|
+ }
|
|
|
+
|
|
|
+ // /// 关闭socket 如果socket是打开的状态 其它的状态就不管 打开之后直接重连 && Global._wxSocket.readyState == 'open'
|
|
|
+ // if (Global._wxSocket != undefined && Global._wxSocket != null ) {
|
|
|
+ // Global._wxSocket.close();
|
|
|
+ // }
|
|
|
+ cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
|
|
|
+ HomeApi.exitGame();
|
|
|
+ if (GameModule.audioMng) {
|
|
|
+ GameModule.audioMng.stopAll();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ tt.showShareMenu({
|
|
|
+ withShareTicket: true,
|
|
|
+ success: function (res) {
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+
|
|
|
+ },
|
|
|
+ complete: function (res) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ tt.onShareAppMessage(function () {
|
|
|
+ if (GameGlobal.isCheck) {
|
|
|
+
|
|
|
+ var uid = -1;
|
|
|
+ if (GameGlobal.user != undefined && GameGlobal.user.uid != undefined) {
|
|
|
+ uid = GameGlobal.user.uid;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: '猜猜他是谁?',
|
|
|
+ imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_3.png',
|
|
|
+ query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('onShareAppMessage 分享成功');
|
|
|
+ // 分享成功上报
|
|
|
+ SkillApi.report(2, (responseData) => {
|
|
|
+ console.log('上报分享成功');
|
|
|
+ },(error) => {
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ // 转发失败
|
|
|
+ console.log('onShareAppMessage 取消或分享失败');
|
|
|
+ },
|
|
|
+ complete: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10);
|
|
|
+ let shareObjct = WeChat.shareArray[randomIndex];
|
|
|
+ var uid = -1;
|
|
|
+ if (GameGlobal.user != undefined && GameGlobal.user.uid != undefined) {
|
|
|
+ uid = GameGlobal.user.uid;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: shareObjct.title,
|
|
|
+ imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
|
|
|
+ query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('onShareAppMessage 分享成功');
|
|
|
+ // 分享成功上报
|
|
|
+ SkillApi.report(2, (responseData) => {
|
|
|
+ console.log('上报分享成功');
|
|
|
+ },(error) => {
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ // 转发失败
|
|
|
+ console.log('onShareAppMessage 取消或分享失败');
|
|
|
+ },
|
|
|
+ complete: function () {
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
static handelWxLifeCyle() {
|
|
|
wx.onShow(({scene, query, shareTicket }) => {
|
|
|
if (typeof wx.getUpdateManager === 'function') {
|