Global.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const BuildingManager = require("../utils/BuildingManager");
  2. const ShareAction = require('./ShareAction');
  3. const Notikey = require('../utils/GameEnum').GameNotificationKey;
  4. const HomeApi = require("../net/HomeApi");
  5. const SkillApi = require("../net/SkillApi");
  6. const WeChat = require("../net/WeChat");
  7. const AlertManager = require('../utils/AlertManager');
  8. window.Global = {
  9. // 建筑管理
  10. BuildingManager: BuildingManager.instance,
  11. debug: false,
  12. /**
  13. * 点击别人分享的链接需要进行的操作 查看群排行
  14. */
  15. shareType: ShareAction.NONE,
  16. /**
  17. * 点击别人分享的链接获取到这个用户的uid,默认-1
  18. */
  19. shareUid: -1,
  20. //SystemInfo
  21. ver: 1,
  22. os: 1,//1 android,2 ios
  23. channel: CC_WECHATGAME ? "weixin" : "LuciferChannel",
  24. user: null,
  25. homeUpdate: true,
  26. wechatScoreKey: 'buildingLevel',
  27. // 开发中的城市Id
  28. devCityId: 1,
  29. buildRes: null,
  30. prefabsRes: null,
  31. starAvatarRes: null,
  32. needLogin: false,
  33. /// 最后一个缩短技能cd的技能等级
  34. rcdSkillLevel: 0,
  35. //是否已领取当天签到奖励
  36. isSignAward: false,
  37. //已签到次数
  38. signCount: 0,
  39. //分享出去的群id
  40. shareTicket: '',
  41. //通用网络请求提示框
  42. commonAlert: AlertManager
  43. };
  44. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  45. wx.onShow(({ query, shareTicket }) => {
  46. if (typeof wx.getUpdateManager === 'function') {
  47. const updateManager = wx.getUpdateManager()
  48. updateManager.onCheckForUpdate(function (res) {
  49. // 请求完新版本信息的回调
  50. console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
  51. })
  52. updateManager.onUpdateReady(function () {
  53. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  54. updateManager.applyUpdate()
  55. })
  56. updateManager.onUpdateFailed(function () {
  57. // 新的版本下载失败
  58. })
  59. }
  60. console.log('Global onShow' + JSON.stringify(query) + '======================================');
  61. if (query != undefined && query != null) {
  62. Global.shareType = query.shareType;
  63. if (Global.shareType == ShareAction.SHOW_GROUP_RANK) {
  64. console.log('share ticket ' + shareTicket);
  65. if (shareTicket != undefined && shareTicket != null) {
  66. Global.shareTicket = shareTicket;
  67. GameEvent.fire(Notikey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜
  68. } else {
  69. Global.shareTicket = '';
  70. }
  71. }
  72. }
  73. });
  74. wx.onHide(() => {
  75. console.log('Global onHide ===================================');
  76. cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
  77. });
  78. wx.showShareMenu({
  79. withShareTicket: true,
  80. success: function (res) {
  81. },
  82. fail: function (res) {
  83. },
  84. complete: function (res) {
  85. }
  86. });
  87. wx.onShareAppMessage(function (res) {
  88. // 用户点击了“转发”按钮
  89. if (res.from === 'button') {
  90. // 来自页面内转发按钮
  91. } else if (res.from === 'menu') {
  92. }
  93. let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10);
  94. let shareObjct = WeChat.shareArray[randomIndex];
  95. return {
  96. title: shareObjct.title,
  97. imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
  98. query: 'shareType=' + ShareAction.NONE,
  99. success: function (res) {
  100. console.log('分享成功');
  101. // 转发成功
  102. const SkillApi = require('../net/SkillApi');
  103. SkillApi.report(2, (responseData) => {
  104. },(error) => {
  105. });
  106. },
  107. fail: function (res) {
  108. // 转发失败
  109. console.error(res);
  110. },
  111. complete: function (res) {
  112. }
  113. }
  114. });
  115. }