const SkillApi = require('../net/SkillApi'); const ShareAction = require('../utils/ShareAction'); const GameModule = require('../utils/GameModule'); cc.Class({ extends: cc.Component, properties: { shareNode: cc.Node, rankNode: cc.Node, isShowRank: { get: function() { if (!this._isShowRank) { this._isShowRank = false; } return this._isShowRank; }, set: function(value) { this._isShowRank = value; if (this._isShowRank) { this.shareNode.active = false; this.rankNode.active = true; this.refreshPageButton(); } else { this.shareNode.active = true; this.rankNode.active = false; this.refreshPageButton(); } } }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, // start () { // }, onEnable() { this.postGroupMessage(); this.refreshPageButton() }, // update (dt) {}, init (parent) { this.parent = parent; this.refreshPageButton(); }, refreshPageButton() { if (this.parent) { if (this.isShowRank) { this.parent.showPageButton(); } else { this.parent.hidePageButton(); } } }, previousPage() { if (window.wx != undefined) { window.wx.postMessage({ messageType: 1 }); } }, nextPage() { if (window.wx != undefined) { window.wx.postMessage({ messageType: 2 }); } }, postGroupMessage(isRefresh = false) { if (GameGlobal.shareTicket.length > 0) { this.isShowRank = true; if (window.wx != undefined) { window.wx.postMessage({ messageType: 3, key1: GameGlobal.shareTicket, key2: isRefresh }); } } else { this.isShowRank = false; } }, shareToCrowd() { GameModule.audioMng.playClickButton(); if (CC_WECHATGAME) { wx.shareAppMessage({ title: '我榜上有名,你呢?', imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_paihan.png', query: 'shareType=' + ShareAction.SHOW_GROUP_RANK, success: (res) => { console.log('分享成功'); SkillApi.report(2, (responseData) => { },(error) => { }); //判断是否分享到群 if (res.hasOwnProperty('shareTickets')) { let shareTicket = res.shareTickets[0]; GameGlobal.shareTicket = shareTicket; this.postGroupMessage(true); // wx.getShareInfo({ // shareTicket: shareTicket, // success: (res) => { // console.log(res); // } // }) } else { } }, fail: (res) => { console.log('分享失败或取消'); } }); } } });