class WxCommon { constructor() { this.otherGameCount = 2; this.otherGameMap = new Map(); this.otherGameMap.set(0, 'https://pub.dwstatic.com/wxgame/budingGame/share/xcxm.jpg');//布丁小程序码 this.otherGameMap.set(1, 'https://pub.dwstatic.com/wxgame/budingGame/share/football.jpg');//勇闯世界杯小程序码 } static getInstance() { if (!WxCommon.instance && CC_WECHATGAME) { WxCommon.instance = new WxCommon(); } return WxCommon.instance; } ShowShareMenu() { wx.showShareMenu({ withShareTicket: true, success: function (res) { }, fail: function (res) { }, complete: function (res) { } }) } OnShareAppMessage(data, target, callback) { wx.onShareAppMessage(function (res) { // 用户点击了“转发”按钮 if (res.from === 'button') { // 来自页面内转发按钮 } else if (res.from === 'menu') { } return { title: UserInfo.shareDesc, imageUrl: UserInfo.shareUrl, success: function (res) { console.error(res); // 转发成功 if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res.shareTickets);//res.shareTickets不为空则是群 } }, fail: function (res) { // 转发失败 console.error(res); }, complete: function (res) { } } }) } OnShow(data, target, callback) { var self = this; wx.onShow(function (obj) { cc.audioEngine.resumeAll(); self.GetSystemInfo(null, null, null); if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, true); } }) } //data结构 {titleData:titleData,imgurlData:imgurlData,queryData:queryData} ShareAppMessage(data, target, callback) {//微信分享 wx.shareAppMessage({ // title: '好游砀山麻将,你的贴身麻将馆,免费领房卡!', // imageUrl: 'https://images.haoyou998.com/mp/share/share.jpg', // query: 'key1=111&key2=222', title: data.titleData, imageUrl: data.imgurlData, query: data.queryData, success: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res.shareTickets);//res.shareTickets不为空则是群 } }, fail: function (res) { console.error(res); }, complete: function (res) { } }); } GetSystemInfo(data, target, callback) {//获取系统信息 if (cc.vv == undefined) { cc.vv = {}; } wx.getSystemInfo({ success: function (res) { if (res.version >= UserInfo.wxversion) { cc.vv.isRank = true; } else { cc.vv.isRank = false; // if (cc.vv.isAlreadyShow != true) { // } wx.showModal({ title:'版本提示', content:'您的微信版本太低,将不支持排行榜,请更新最新版本微信客户端', showCancel:false, cancelText:'取消', cancelColor:'#000000', confirmText:'退出程序', confirmColor:'#3cc51f', success: function(res) { cc.vv.isAlreadyShow = true; wx.exitMiniProgram(); } }) } if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res); //res.batteryLevel 电量,范围 1 - 100, number //res.wifiSignal wifi 信号强度,范围 0 - 4, number //res.version 微信版本号 } }, fail: function (res) { console.error(res); }, complete: function (res) { } }) } SetEnableDebug(type) { // wx.setEnableDebug({ // enableDebug: type // }) } PreviewImage(data, target, callback) {//预览图片 wx.previewImage({ urls:[data], success: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, true); } }, fail: function (res) { }, complete: function (res) { } }); } SaveImageToPhotosAlbum(data, target, callback){//保存相册 wx.downloadFile({ url: data, success: function (res) { wx.saveImageToPhotosAlbum({ filePath:res.tempFilePath, success: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res.shareTickets); } }, fail: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res.shareTickets); } }, complete: function (res) { } }) }, fail: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, res.shareTickets); } }, }) } RemoveUserCloudStorage(removeKey, target, callback) { if (UserInfo.platform != 1) { return; } if (typeof removeKey == "undefined" || removeKey == null || removeKey == "") { return; } wx.removeUserCloudStorage({ keyList:removeKey, success: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, removeKey, true); } }, fail: function (res) { if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) { callback.call(target, removeKey, false); } }, complete: function (res) { removeKey = null; } }) } } module.exports = WxCommon.getInstance();