GameCrowdRank.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const SkillApi = require('../net/SkillApi');
  2. const ShareAction = require('../utils/ShareAction');
  3. const GameModule = require('../utils/GameModule');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. shareNode: cc.Node,
  8. rankNode: cc.Node,
  9. isShowRank: {
  10. get: function() {
  11. if (!this._isShowRank) {
  12. this._isShowRank = false;
  13. }
  14. return this._isShowRank;
  15. },
  16. set: function(value) {
  17. this._isShowRank = value;
  18. if (this._isShowRank) {
  19. this.shareNode.active = false;
  20. this.rankNode.active = true;
  21. this.refreshPageButton();
  22. } else {
  23. this.shareNode.active = true;
  24. this.rankNode.active = false;
  25. this.refreshPageButton();
  26. }
  27. }
  28. },
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. // onLoad () {},
  32. // start () {
  33. // },
  34. onEnable() {
  35. this.postGroupMessage();
  36. this.refreshPageButton()
  37. },
  38. // update (dt) {},
  39. init (parent) {
  40. this.parent = parent;
  41. this.refreshPageButton();
  42. },
  43. refreshPageButton() {
  44. if (this.parent) {
  45. if (this.isShowRank) {
  46. this.parent.showPageButton();
  47. } else {
  48. this.parent.hidePageButton();
  49. }
  50. }
  51. },
  52. previousPage() {
  53. if (window.wx != undefined) {
  54. window.wx.postMessage({
  55. messageType: 1
  56. });
  57. }
  58. },
  59. nextPage() {
  60. if (window.wx != undefined) {
  61. window.wx.postMessage({
  62. messageType: 2
  63. });
  64. }
  65. },
  66. postGroupMessage(isRefresh = false) {
  67. if (Global.shareTicket.length > 0) {
  68. this.isShowRank = true;
  69. if (window.wx != undefined) {
  70. window.wx.postMessage({
  71. messageType: 3,
  72. key1: Global.shareTicket,
  73. key2: isRefresh
  74. });
  75. }
  76. } else {
  77. this.isShowRank = false;
  78. }
  79. },
  80. shareToCrowd() {
  81. GameModule.audioMng.playClickButton();
  82. if (CC_WECHATGAME) {
  83. wx.shareAppMessage({
  84. title: '我榜上有名,你呢?',
  85. imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_paihan.png',
  86. query: 'shareType=' + ShareAction.SHOW_GROUP_RANK,
  87. success: (res) => {
  88. console.log('分享成功');
  89. SkillApi.report(2, (responseData) => {
  90. },(error) => {
  91. });
  92. //判断是否分享到群
  93. if (res.hasOwnProperty('shareTickets')) {
  94. let shareTicket = res.shareTickets[0];
  95. Global.shareTicket = shareTicket;
  96. this.postGroupMessage(true);
  97. // wx.getShareInfo({
  98. // shareTicket: shareTicket,
  99. // success: (res) => {
  100. // console.log(res);
  101. // }
  102. // })
  103. } else {
  104. }
  105. },
  106. fail: (res) => {
  107. console.log('分享失败或取消');
  108. }
  109. });
  110. }
  111. }
  112. });