123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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 (Global.shareTicket.length > 0) {
- this.isShowRank = true;
- if (window.wx != undefined) {
- window.wx.postMessage({
- messageType: 3,
- key1: Global.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];
- Global.shareTicket = shareTicket;
- this.postGroupMessage(true);
- } else {
- }
- },
- fail: (res) => {
- console.log('分享失败或取消');
- }
- });
- }
- }
- });
|