149 lines
4.9 KiB
JavaScript
149 lines
4.9 KiB
JavaScript
"use strict";
|
|
const Module_Remote=require('Module_Remote')
|
|
const _bRemoteResourceNotLocalMD5 = true;
|
|
|
|
const _LocalMD5ResourceUrl = 'resources/texture/';//本地资源路径
|
|
const _ContentJsonName = 'content.json';
|
|
|
|
module.exports = {
|
|
_isInit: false,
|
|
|
|
//每个项目定制 ShareConfig ConfigRoomShare ConfigShare
|
|
ShareConfig: {
|
|
Comment:
|
|
{
|
|
BussinessId: 1,
|
|
url: 'share.png',
|
|
title: '威化饼'
|
|
},
|
|
vs:
|
|
{
|
|
BussinessId: 2,
|
|
url: 'vs_share.png',
|
|
title: '威化饼对战等你来'
|
|
},
|
|
|
|
},
|
|
ConfigRoomShare:function(account_id,roomid,sdt){
|
|
console.log("ConfigRoomShare");
|
|
let prama = {room: true, room_id: roomid}
|
|
// if (cc.sys.platform == cc.sys.WECHAT_GAME) {
|
|
// prama = `room_id=${roomid}`
|
|
// }
|
|
this.ConfigShare(account_id,sdt,prama);
|
|
},
|
|
ConfigShare: function (account_id, sdt, prama, CallBackFunc) {
|
|
console.log(`ConfigShare prama= ${prama}`);
|
|
let wxprama = null;
|
|
if (cc.sys.platform == cc.sys.WECHAT_GAME) {
|
|
if (prama == null) {
|
|
wxprama = `inviter_id=${account_id}`
|
|
} else if (prama['room']) {
|
|
wxprama = `room_id=${prama.room_id}&inviter_id=${account_id}`
|
|
} else {
|
|
wxprama = `sharetype=${prama}&inviter_id=${account_id}`
|
|
}
|
|
this._wxShare(sdt, wxprama, CallBackFunc);
|
|
}
|
|
},
|
|
|
|
|
|
|
|
Init: function (finishCallback) {
|
|
if (this._isInit === true) { return; }
|
|
this._isInit = true;
|
|
const self = this;
|
|
Module_Remote.Get(_ContentJsonName, (data) => {
|
|
if (data) {
|
|
const configinfo = data;
|
|
if (configinfo && configinfo.ShareConfig) {
|
|
self.ShareConfig = configinfo.ShareConfig;
|
|
}
|
|
if (finishCallback) finishCallback();
|
|
}
|
|
if (CC_WECHATGAME) {
|
|
const wxurl = this._getImageUrlByShareConfig(self.ShareConfig.Comment);
|
|
wx.showShareMenu({
|
|
withShareTicket: true,
|
|
});
|
|
if (cc.jc.channelID === cc.jc.channel.TT) {
|
|
wx.onShareAppMessage(function () {
|
|
return {
|
|
title: self.ShareConfig.Comment.title,
|
|
imageUrl: wxurl,
|
|
success() {
|
|
console.log('分享成功')
|
|
tt.showToast({title: '分享成功'});
|
|
},
|
|
fail(e) {
|
|
console.log('分享失败', e)
|
|
tt.showToast({title: '分享失败', icon: 'none'});
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
wx.onShareAppMessage(function () {
|
|
return {
|
|
title: self.ShareConfig.Comment.title,
|
|
imageUrl: wxurl
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
});
|
|
},
|
|
getRemoteServerURL: function (url) {
|
|
if (url == null) {
|
|
return Module_Remote.getRemoteServerURL();
|
|
} else {
|
|
return _getImageUrl(url);
|
|
}
|
|
},
|
|
|
|
ConfigDailyShareRegister: function (bussinessid, inviter_id) {
|
|
cc.jc.share.acceptDailyInvite(bussinessid, inviter_id);
|
|
cc.jc.gamelog.logShareInvite(inviter_id, bussinessid);
|
|
},
|
|
|
|
|
|
|
|
|
|
_getImageUrlByShareConfig: function (scd) {
|
|
if (scd && scd.url) {
|
|
return this._getImageUrl(scd.url);
|
|
} else {
|
|
return null;
|
|
}
|
|
},
|
|
_getImageUrl: function (filename) {
|
|
if (_bRemoteResourceNotLocalMD5) {//读远程cdn RemoteResource/下的资源
|
|
return `${Module_Remote.getRemoteServerURL()}tex/${filename}`;
|
|
} else {//读本地资源 要选用MD5 cache
|
|
var path = cc.url.raw(`${_LocalMD5ResourceUrl}${filename}`);
|
|
if (cc.loader.md5Pipe) {
|
|
path = cc.loader.md5Pipe.transformURL(path);
|
|
if (CC_DEBUG) console(`_getImageUrl MD5ResourceUrl :${path}`);
|
|
return path;
|
|
}
|
|
}
|
|
if (CC_DEBUG) console(`_getImageUrl faild`);
|
|
return null;
|
|
},
|
|
_wxShare: function (sdt, prama, CallBackFunc) {
|
|
if (CC_WECHATGAME) {
|
|
const iconUrl = this._getImageUrlByShareConfig(sdt);
|
|
wx.shareAppMessage({
|
|
title: sdt.title,
|
|
imageUrl: iconUrl,
|
|
query: prama,
|
|
});
|
|
cc.jc.gamelog.logShare(sdt.bussinessid);
|
|
if (CallBackFunc) { CallBackFunc(); }
|
|
}else{
|
|
if (CC_DEBUG) { console.log('wxShare CC_WECHATGAME==false'); }
|
|
return;
|
|
}
|
|
},
|
|
};
|