123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- const BuildingManager = require("../utils/BuildingManager");
- const ShareAction = require('./ShareAction');
- const Notikey = require('../utils/GameEnum').GameNotificationKey;
- const HomeApi = require("../net/HomeApi");
- const SkillApi = require("../net/SkillApi");
- const WeChat = require("../net/WeChat");
- const AlertManager = require('../utils/AlertManager');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- window.Global = {
- // 建筑管理
- BuildingManager: BuildingManager.instance,
- debug: true,
- ver: 101, //游戏版本号发版时需要核对
- isCheck: false,
- /**
- * 点击别人分享的链接需要进行的操作 查看群排行
- */
- shareType: ShareAction.NONE,
- /**
- * 点击别人分享的链接获取到这个用户的uid,默认-1
- */
- shareUid: -1,
- //SystemInfo
- os: 1,//1 android,2 ios
- channel: CC_WECHATGAME ? "weixin" : "LuciferChannel",
- user: null,
- /// 游戏是否退出到后台
- isOnHide: false,
- homeUpdate: true,
- wechatScoreKey: 'buildingLevel',
- // 开发中的城市Id
- devCityId: 1,
- buildRes: null,
- prefabsRes: null,
- starAvatarRes: null,
- needLogin: false,
- /// 最后一个缩短技能cd的技能等级
- rcdSkillLevel: 0,
- //是否已领取当天签到奖励
- isSignAward: false,
- //已签到次数
- signCount: 0,
- //分享出去的群id
- shareTicket: '',
- //通用网络请求提示框
- commonAlert: AlertManager
- };
- if (cc.sys.platform === cc.sys.WECHAT_GAME) {
- wx.onShow(({ query, shareTicket }) => {
- 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('Global onShow' + JSON.stringify(query) + '======================================');
- if (query != undefined && query != null) {
- Global.shareType = query.shareType;
- if (Global.shareType == ShareAction.SHOW_GROUP_RANK) {
- console.log('share ticket ' + shareTicket);
- if (shareTicket != undefined && shareTicket != null) {
- Global.shareTicket = shareTicket;
- GameEvent.fire(Notikey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜
- } else {
- Global.shareTicket = '';
- }
- }
- }
- // debugger;
- // console.log(query.from, shareTicket);
- //// 如果是从后台到前台
- if (Global.isOnHide) {
- Global.isOnHide = false;
-
- /// 发通知更新跟定时器相关的数据
- GameEvent.fire(GameNotificationKey.GameShowNotificationKey);
- }
- });
- wx.onHide(() => {
- console.log('Global onHide ===================================');
- Global.isOnHide = true;
- cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
- HomeApi.exitGame();
- });
- wx.showShareMenu({
- withShareTicket: true,
- success: function (res) {
- },
- fail: function (res) {
- },
- complete: function (res) {
- }
- });
- wx.onShareAppMessage(function (res) {
- // 用户点击了“转发”按钮
- if (res.from === 'button') {
- // 来自页面内转发按钮
- } else if (res.from === 'menu') {
- }
- let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10);
- let shareObjct = WeChat.shareArray[randomIndex];
- return {
- title: shareObjct.title,
- imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
- query: 'shareType=' + ShareAction.NONE,
- success: function (res) {
- console.log('分享成功');
- // 分享成功上报
- SkillApi.report(2, (responseData) => {
- console.log('上报分享成功');
- },(error) => {
- });
- },
- fail: function (res) {
- // 转发失败
- console.error(res);
- },
- complete: function (res) {
- }
- }
- });
- }
|