WxMiniGameUtil.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__awaiter) ||
  6. function (t, n, r, l) {
  7. return new (r = r || Promise)(function (i, e) {
  8. function s(t) {
  9. try {
  10. a(l.next(t));
  11. } catch (t) {
  12. e(t);
  13. }
  14. }
  15. function o(t) {
  16. try {
  17. a(l.throw(t));
  18. } catch (t) {
  19. e(t);
  20. }
  21. }
  22. function a(t) {
  23. var e;
  24. t.done
  25. ? i(t.value)
  26. : ((e = t.value) instanceof r
  27. ? e
  28. : new r(function (t) {
  29. t(e);
  30. })
  31. ).then(s, o);
  32. }
  33. a((l = l.apply(t, n || [])).next());
  34. });
  35. };
  36. Object.defineProperty(i, "__esModule", {value: !0}), (i.WxMiniGameUtil = void 0);
  37. const o = t("ControllerConst"),
  38. a = t("App"),
  39. n = t("GamePlatform");
  40. class r {
  41. static getSettings() {
  42. return "undefined" == typeof wx
  43. ? Promise.resolve(null)
  44. : null != r.s_authSetting
  45. ? Promise.resolve(r.s_authSetting)
  46. : new Promise(function (t) {
  47. wx.getSetting({
  48. success: function (t) {
  49. r.s_authSetting = t.authSetting;
  50. },
  51. fail: function () {
  52. r.s_authSetting = null;
  53. },
  54. complete: function () {
  55. t(r.s_authSetting);
  56. }
  57. });
  58. });
  59. }
  60. static checkUserInfoAuth() {
  61. return s(this, void 0, void 0, function* () {
  62. var t = yield r.getSettings();
  63. return !!t && !0 === t["scope.userInfo"];
  64. });
  65. }
  66. static checkWxFriendInteractionAuth() {
  67. return s(this, void 0, void 0, function* () {
  68. var t = yield r.getSettings();
  69. return !!t && !0 === t["scope.WxFriendInteraction"];
  70. });
  71. }
  72. static updateUserInfo(t, e) {
  73. (a.default.GameDataMsr.playerInfo.nickName = t), (a.default.GameDataMsr.playerInfo.head = e);
  74. }
  75. static tryGetInfo() {
  76. return s(this, void 0, void 0, function* () {
  77. (yield r.checkUserInfoAuth()) && r.getUserInfo();
  78. });
  79. }
  80. static getUserInfo() {
  81. wx.getUserInfo({
  82. success: function (t) {
  83. t && r.updateUserInfo(t.userInfo.nickName, t.userInfo.avatarUrl);
  84. },
  85. fail: function () {}
  86. });
  87. }
  88. static copyFunc(t) {
  89. wx.setClipboardData({
  90. data: t,
  91. success: function () {
  92. wx.getClipboardData({success: function () {}});
  93. }
  94. });
  95. }
  96. static enablePassiveShare() {
  97. if ("undefined" == typeof wx) return null;
  98. wx.showShareMenu({withShareTicket: !0, menus: ["shareAppMessage", "shareTimeline"]}),
  99. wx.onShareAppMessage(function () {
  100. var t = a.default.ControllerManager.getControllerModel(o.ControllerConst.AD).getShareData();
  101. return {
  102. title: t.message,
  103. imageUrl: t.image_src,
  104. imageUrlId: t.id,
  105. query: "fromUser=" + n.GamePlatform.getServerUID()
  106. };
  107. }),
  108. wx.onShareTimeline(function () {
  109. var t = n.GamePlatform.randomShareData();
  110. return {
  111. title: t[2],
  112. imageUrl: t[0],
  113. imageUrlId: t[1],
  114. imagePreviewUrl: n.WechatPreviewImageURL,
  115. imagePreviewUrlId: n.WechatPreviewImageURLId,
  116. query: "fromUser=" + n.GamePlatform.getServerUID()
  117. };
  118. });
  119. }
  120. }
  121. (i.WxMiniGameUtil = r), (r.s_authSetting = null);