Global.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. window.Global = {
  6. // 建筑管理
  7. BuildingManager: BuildingManager.instance,
  8. debug: true,
  9. /**
  10. * 点击别人分享的链接需要进行的操作 加好友
  11. */
  12. shareType: ShareAction.NONE,
  13. /**
  14. * 点击别人分享的链接获取到这个用户的uid,默认-1
  15. */
  16. shareUid: -1,
  17. //SystemInfo
  18. ver: 1,
  19. os: 1,//1 android,2 ios
  20. channel: CC_WECHATGAME ? "weixin" : "LuciferChannel",
  21. user: null,
  22. homeUpdate: true,
  23. wechatScoreKey: 'starCount',
  24. // 开发中的城市Id
  25. devCityId: 1,
  26. buildRes: null,
  27. needLogin: false,
  28. /// 最后一个缩短技能cd的技能等级
  29. rcdSkillLevel: 0,
  30. };
  31. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  32. wx.onShow(({ query, shareTicket }) => {
  33. if (typeof wx.getUpdateManager === 'function') {
  34. const updateManager = wx.getUpdateManager()
  35. updateManager.onCheckForUpdate(function (res) {
  36. // 请求完新版本信息的回调
  37. console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
  38. })
  39. updateManager.onUpdateReady(function () {
  40. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  41. updateManager.applyUpdate()
  42. })
  43. updateManager.onUpdateFailed(function () {
  44. // 新的版本下载失败
  45. })
  46. }
  47. console.log('Global onShow' + JSON.stringify(query) + '======================================');
  48. if (query != undefined && query != null) {
  49. if (query.uid != undefined) {
  50. // Global.processShareAction(query.uid, query.shareType);
  51. Global.shareUid = query.uid;
  52. Global.shareType = query.shareType;
  53. GameEvent.fire(Notikey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友.....
  54. }
  55. if (shareTicket != undefined && shareTicket != null) {
  56. }
  57. }
  58. // let onShowTimestamp = Date.parse(new Date());
  59. // let onHideTimestamp = cc.sys.localStorage.getItem("onHideTimestamp");
  60. //
  61. // if (onHideTimestamp !== 0) {
  62. // let sec = (onShowTimestamp - onHideTimestamp) / 1000;
  63. // if (sec > 180) {
  64. // GameEvent.fire(Notikey.HomeReloadData);
  65. // } else {
  66. // GameEvent.fire(Notikey.HomeUpdateData, sec);
  67. // }
  68. // }
  69. //
  70. // console.log("onShowTimestamp: " + onShowTimestamp);
  71. // console.log("onHideTimestamp: " + onHideTimestamp);
  72. });
  73. wx.onHide(() => {
  74. console.log('Global onHide ===================================');
  75. cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
  76. });
  77. wx.showShareMenu({
  78. withShareTicket: false,
  79. success: function (res) {
  80. },
  81. fail: function (res) {
  82. },
  83. complete: function (res) {
  84. }
  85. });
  86. wx.onShareAppMessage(function (res) {
  87. // 用户点击了“转发”按钮
  88. if (res.from === 'button') {
  89. // 来自页面内转发按钮
  90. } else if (res.from === 'menu') {
  91. }
  92. return {
  93. title: '确认过眼神,你就是我要的C位',
  94. imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share1.jpg',
  95. success: function (res) {
  96. console.error(res);
  97. // 转发成功
  98. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  99. callback.call(target, res.shareTickets);
  100. //res.shareTickets不为空则是群
  101. }
  102. },
  103. fail: function (res) {
  104. // 转发失败
  105. console.error(res);
  106. },
  107. complete: function (res) {
  108. }
  109. }
  110. });
  111. }