WxCommon.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. class WxCommon {
  2. constructor() {
  3. this.otherGameCount = 2;
  4. this.otherGameMap = new Map();
  5. this.otherGameMap.set(0, 'https://pub.dwstatic.com/wxgame/buildingGame/share/xcxm.jpg');//布丁小程序码
  6. this.otherGameMap.set(1, 'https://pub.dwstatic.com/wxgame/escape/share/xcxm.jpg');//吃鸡小程序码
  7. // this.otherGameMap.set(2, 'https://images.haoyou998.com/mp/share/GridFlee/xcxm.jpg');//方格小程序码
  8. }
  9. static getInstance() {
  10. if (!WxCommon.instance) {
  11. WxCommon.instance = new WxCommon();
  12. }
  13. return WxCommon.instance;
  14. }
  15. ShowShareMenu() {
  16. wx.showShareMenu({
  17. withShareTicket: true,
  18. success: function (res) {
  19. },
  20. fail: function (res) {
  21. },
  22. complete: function (res) {
  23. }
  24. })
  25. }
  26. OnShareAppMessage(data, target, callback) {
  27. wx.onShareAppMessage(function (res) {
  28. // 用户点击了“转发”按钮
  29. if (res.from === 'button') {
  30. // 来自页面内转发按钮
  31. } else if (res.from === 'menu') {
  32. }
  33. return {
  34. title: UserInfo.shareDesc,
  35. imageUrl: UserInfo.shareUrl,
  36. success: function (res) {
  37. console.error(res);
  38. // 转发成功
  39. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  40. callback.call(target, res.shareTickets);//res.shareTickets不为空则是群
  41. }
  42. },
  43. fail: function (res) {
  44. // 转发失败
  45. console.error(res);
  46. },
  47. complete: function (res) {
  48. }
  49. }
  50. })
  51. }
  52. OnShow(data, target, callback) {
  53. var self = this;
  54. wx.onShow(function (obj) {
  55. cc.audioEngine.resumeAll();
  56. self.GetSystemInfo(null, null, null);
  57. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  58. callback.call(target, true);
  59. }
  60. })
  61. }
  62. //data结构 {titleData:titleData,imgurlData:imgurlData,queryData:queryData}
  63. ShareAppMessage(data, target, callback) {//微信分享
  64. wx.shareAppMessage({
  65. // title: '好游砀山麻将,你的贴身麻将馆,免费领房卡!',
  66. // imageUrl: 'https://images.haoyou998.com/mp/share/share.jpg',
  67. // query: 'key1=111&key2=222',
  68. title: data.titleData,
  69. imageUrl: data.imgurlData,
  70. query: data.queryData,
  71. success: function (res) {
  72. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  73. callback.call(target, res.shareTickets);//res.shareTickets不为空则是群
  74. }
  75. },
  76. fail: function (res) {
  77. console.error(res);
  78. },
  79. complete: function (res) {
  80. }
  81. });
  82. }
  83. GetSystemInfo(data, target, callback) {//获取系统信息
  84. if (cc.vv == undefined) {
  85. cc.vv = {};
  86. }
  87. wx.getSystemInfo({
  88. success: function (res) {
  89. if (res.version >= UserInfo.wxversion) {
  90. cc.vv.isRank = true;
  91. } else {
  92. cc.vv.isRank = false;
  93. // if (cc.vv.isAlreadyShow != true) {
  94. // }
  95. wx.showModal({
  96. title:'版本提示',
  97. content:'您的微信版本太低,将不支持排行榜,请更新最新版本微信客户端',
  98. showCancel:false,
  99. cancelText:'取消',
  100. cancelColor:'#000000',
  101. confirmText:'退出程序',
  102. confirmColor:'#3cc51f',
  103. success: function(res) {
  104. cc.vv.isAlreadyShow = true;
  105. wx.exitMiniProgram();
  106. }
  107. })
  108. }
  109. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  110. callback.call(target, res);
  111. //res.batteryLevel 电量,范围 1 - 100, number
  112. //res.wifiSignal wifi 信号强度,范围 0 - 4, number
  113. //res.version 微信版本号
  114. }
  115. },
  116. fail: function (res) {
  117. console.error(res);
  118. },
  119. complete: function (res) {
  120. }
  121. })
  122. }
  123. SetEnableDebug(type) {
  124. wx.setEnableDebug({
  125. enableDebug: type
  126. })
  127. }
  128. PreviewImage(data, target, callback) {//预览图片
  129. wx.previewImage({
  130. urls:[data],
  131. success: function (res) {
  132. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  133. callback.call(target, true);
  134. }
  135. },
  136. fail: function (res) {
  137. },
  138. complete: function (res) {
  139. }
  140. });
  141. }
  142. SaveImageToPhotosAlbum(data, target, callback){//保存相册
  143. wx.downloadFile({
  144. url: data,
  145. success: function (res) {
  146. wx.saveImageToPhotosAlbum({
  147. filePath:res.tempFilePath,
  148. success: function (res) {
  149. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  150. callback.call(target, res.shareTickets);
  151. }
  152. },
  153. fail: function (res) {
  154. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  155. callback.call(target, res.shareTickets);
  156. }
  157. },
  158. complete: function (res) {
  159. }
  160. })
  161. },
  162. fail: function (res) {
  163. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  164. callback.call(target, res.shareTickets);
  165. }
  166. },
  167. })
  168. }
  169. RemoveUserCloudStorage(removeKey, target, callback) {
  170. if (UserInfo.platform != 1) {
  171. return;
  172. }
  173. if (typeof removeKey == "undefined" || removeKey == null || removeKey == "") {
  174. return;
  175. }
  176. wx.removeUserCloudStorage({
  177. keyList:removeKey,
  178. success: function (res) {
  179. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  180. callback.call(target, removeKey, true);
  181. }
  182. },
  183. fail: function (res) {
  184. if (!UserInfo.IsEmpty(target) && !UserInfo.IsEmpty(callback)) {
  185. callback.call(target, removeKey, false);
  186. }
  187. },
  188. complete: function (res) {
  189. removeKey = null;
  190. }
  191. })
  192. }
  193. }
  194. module.exports = WxCommon.getInstance();