ef8fbfe139707974b3c4b369647c0d1d5047f681.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, Adapter, Constants, PlatformWX, _crd, WX_CONFIG, delayTime;
  4. function _reportPossibleCrUseOfAdapter(extras) {
  5. _reporterNs.report("Adapter", "../adapter/Adapter", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfConstants(extras) {
  8. _reporterNs.report("Constants", "../data/Constants", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. }, function (_unresolved_2) {
  16. Adapter = _unresolved_2.Adapter;
  17. }, function (_unresolved_3) {
  18. Constants = _unresolved_3.Constants;
  19. }],
  20. execute: function () {
  21. _crd = true;
  22. _cclegacy._RF.push({}, "d1121qicJhCnZMiZ3CzCLbc", "PlatformWX", undefined);
  23. WX_CONFIG = {
  24. AD_ID: {
  25. /** banner广告 */
  26. banner: 'adunit-fa7b08ac6d8cf200',
  27. /** 视频广告 */
  28. video: 'adunit-29b5f0955ee77f59',
  29. /** 插屏广告 */
  30. interstitial: 'adunit-a3615ebe31eba64a',
  31. /** 原生模板多个格子广告 */
  32. multiGridCustom: 'adunit-xxx',
  33. /** 原生模版单格格子广告 */
  34. sigleGridCustom: 'adunit-d4f43001efd879de'
  35. }
  36. };
  37. delayTime = 1900;
  38. PlatformWX = class PlatformWX {
  39. constructor() {
  40. this._onHideTime = Infinity;
  41. this._rewardVideo = void 0;
  42. this._bannerAd = void 0;
  43. this._interstitialAd = void 0;
  44. this._customAd = void 0;
  45. this._sigleCustomAd = void 0;
  46. this._shareSuccessHandler = null;
  47. this._videoSuccessHandler = null;
  48. this._customAdCloseHandler = null;
  49. this._showInterstitialAdTime = null;
  50. this._shareModalIsActive = false;
  51. this._shareStr = "东北F4来到美国西部拓荒时代,保卫城镇,完成自我救赎。";
  52. }
  53. initialize() {
  54. console.log("初始化微信框架");
  55. wx.showShareMenu({
  56. withShareTicket: true,
  57. menus: ['shareAppMessage', 'shareTimeline'],
  58. success: () => {},
  59. fail: () => {},
  60. complete: () => {}
  61. }); //发送给朋友
  62. wx.onShareAppMessage(function () {
  63. wx.shareAppMessage({
  64. imageUrl: "share.jpg",
  65. title: this._shareStr,
  66. query: 'shareMsg=' + 'a=1'
  67. });
  68. }.bind(this));
  69. wx.onShow(res => {
  70. if (this._shareSuccessHandler == null) return;
  71. if (this._shareModalIsActive) return;
  72. if (Date.now() - this._onHideTime >= delayTime) {
  73. if (this._shareSuccessHandler) this._shareSuccessHandler(true);
  74. } else {
  75. wx.showModal({
  76. title: '分享提示',
  77. content: '成功分享到群即可获得奖励',
  78. success: res => {
  79. if (res.confirm) {
  80. this.shareShowReward(this._shareSuccessHandler(false));
  81. } else if (res.cancel) {
  82. this._shareSuccessHandler = null;
  83. }
  84. this._shareModalIsActive = false;
  85. }
  86. });
  87. this._shareModalIsActive = true;
  88. }
  89. this._onHideTime = Infinity;
  90. }); //this.__createBannerAd();
  91. this.__createVideoAd(); //this.__createCustomAd();
  92. //this.__createSigleCustomAd();
  93. //this.__createInterstitialAd();
  94. //this.__customAdExist();
  95. //this.__customSigleAdExist();
  96. }
  97. showToast(param) {
  98. var finalParam = {
  99. title: '',
  100. icon: 'none',
  101. duration: 2000
  102. };
  103. Object.assign(finalParam, param);
  104. wx.showToast(finalParam);
  105. }
  106. shareAppMessage(param) {
  107. if (param === void 0) {
  108. param = {};
  109. }
  110. wx.shareAppMessage(param);
  111. }
  112. vibrateShort(param) {
  113. if (param === void 0) {
  114. param = {};
  115. }
  116. wx.vibrateShort(param);
  117. }
  118. vibrateLong(param) {
  119. if (param === void 0) {
  120. param = {};
  121. }
  122. wx.vibrateLong(param);
  123. }
  124. /**
  125. * 是否支持添加桌面
  126. * @returns
  127. */
  128. isSupportDesk() {
  129. //@ts-ignore
  130. if (wx.canAddToFavorites) {
  131. return true;
  132. } else {
  133. return false;
  134. }
  135. } //添加到桌面
  136. addDesk() {
  137. //@ts-ignore
  138. if (wx.canAddToFavorites) {
  139. //@ts-ignore
  140. wx.canAddToFavorites({
  141. success(res) {
  142. if (res.canAdd) {
  143. //可以添加到桌面
  144. //@ts-ignore
  145. wx.addToFavorites({
  146. // 小程序的相关信息
  147. title: (_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  148. error: Error()
  149. }), Constants) : Constants).gameName,
  150. query: '',
  151. // 可以携带参数
  152. success() {
  153. this.showToast({
  154. title: '添加到桌面成功'
  155. });
  156. },
  157. fail(err) {
  158. this.showToast({
  159. title: '添加到桌面失败',
  160. err
  161. });
  162. }
  163. });
  164. } else {
  165. // 不支持添加到桌面
  166. this.showToast({
  167. title: '当前环境不支持添加到桌面'
  168. });
  169. }
  170. },
  171. fail(err) {
  172. this.showToast({
  173. title: '检查添加到桌面权限失败',
  174. err
  175. });
  176. }
  177. });
  178. } else {
  179. this.showToast({
  180. title: "当前环境不支持添加到桌面"
  181. });
  182. }
  183. } //分享
  184. shareShowReward(handler) {
  185. if (handler === void 0) {
  186. handler = null;
  187. }
  188. if (handler) {
  189. this._shareSuccessHandler = handler;
  190. }
  191. this._onHideTime = Date.now();
  192. this.shareAppMessage({
  193. imageUrl: "share.jpg",
  194. title: this._shareStr,
  195. query: 'shareMsg=' + 'a=1'
  196. });
  197. }
  198. showRewardVideo(handler) {
  199. if (handler === void 0) {
  200. handler = null;
  201. }
  202. //console.log('当日视频次数: ', ArchiveSystem.localData.videoRewardTimesToday);
  203. /*if (ArchiveSystem.localData.videoRewardTimesToday % 2 === 1) {
  204. cc.log(ArchiveSystem.localData.videoRewardTimesToday, '转为分享');
  205. this.__turnVideoToShare(handler);
  206. return;
  207. }*/
  208. if (!this._rewardVideo) {
  209. this.__turnVideoToShare(handler);
  210. return;
  211. }
  212. this._videoSuccessHandler = handler;
  213. this._rewardVideo.show().then(() => {
  214. console.log("视频播放成功");
  215. }).catch(err => {
  216. this._rewardVideo.load().then(() => {
  217. this._rewardVideo.show().then(() => {
  218. console.log("视频重新加载,播放成功");
  219. });
  220. }).catch(err2 => {
  221. var _this$_videoSuccessHa;
  222. (_this$_videoSuccessHa = this._videoSuccessHandler) == null || _this$_videoSuccessHa.call(this, false);
  223. this.shareShowReward(handler);
  224. this._videoSuccessHandler = null;
  225. });
  226. });
  227. }
  228. showBannerAd() {
  229. if (!this._bannerAd) return;
  230. var {
  231. screenWidth,
  232. screenHeight
  233. } = wx.getSystemInfoSync();
  234. this._bannerAd.show().then(() => {
  235. this._bannerAd.style.left = (screenWidth - this._bannerAd.style.realWidth) / 2;
  236. this._bannerAd.style.top = screenHeight - this._bannerAd.style.realHeight;
  237. }).catch(e => {
  238. console.log('banner广告显示出错', e);
  239. });
  240. }
  241. hideBannerAd(recreate) {
  242. if (recreate === void 0) {
  243. recreate = false;
  244. }
  245. if (!this._bannerAd) return;
  246. this._bannerAd.hide();
  247. if (recreate) {
  248. this.refreshBannerAd();
  249. }
  250. }
  251. refreshBannerAd() {
  252. if (!this._bannerAd) return;
  253. this._bannerAd.destroy();
  254. this.__createBannerAd();
  255. }
  256. showInterstitialAd(force) {
  257. if (force === void 0) {
  258. force = false;
  259. }
  260. if (force) {
  261. if (!this._interstitialAd) return;
  262. this._interstitialAd.show();
  263. } else {
  264. if (!this._interstitialAd) return;
  265. var timeNow = Date.now();
  266. if (this._showInterstitialAdTime == null) {
  267. this._showInterstitialAdTime = timeNow;
  268. return;
  269. }
  270. if (timeNow - this._showInterstitialAdTime > 120 * 1000) {
  271. this._interstitialAd.show();
  272. this._showInterstitialAdTime = timeNow;
  273. }
  274. }
  275. }
  276. showCustomAd(close) {
  277. if (!this._customAd) return;
  278. this._customAdCloseHandler = close;
  279. this._customAd.show().catch(e => {
  280. console.log('原生广告显示出错', e);
  281. });
  282. }
  283. hideCustomAd() {
  284. if (!this._customAd) return;
  285. this._customAd.hide().catch(e => {
  286. console.log('原生广告隐藏出错', e);
  287. });
  288. }
  289. showSigleCustomAd() {
  290. if (!this._sigleCustomAd || false) return;
  291. this._sigleCustomAd.show().catch(e => {
  292. console.log('原生当个格子广告显示出错', e);
  293. });
  294. }
  295. hideSigleCustomAd() {
  296. if (!this._sigleCustomAd || false) return;
  297. this._sigleCustomAd.hide().catch(e => {
  298. console.log('隐藏单个格子广告出错', e);
  299. });
  300. }
  301. /**单个格子广告*/
  302. __customSigleAdExist() {
  303. if (!this._sigleCustomAd) {
  304. this.__createSigleCustomAd();
  305. }
  306. this._sigleCustomAd.show().then(() => {
  307. if (this._sigleCustomAd.isShow()) {
  308. this.hideSigleCustomAd();
  309. }
  310. }).catch(res => {
  311. if (this._sigleCustomAd.isShow()) {
  312. this.hideSigleCustomAd();
  313. }
  314. });
  315. }
  316. /**多个格子广告*/
  317. __customAdExist() {
  318. if (!this._customAd) {
  319. this.__createCustomAd();
  320. }
  321. this._customAd.show().then(() => {
  322. if (this._customAd.isShow()) {
  323. this.hideCustomAd();
  324. }
  325. }).catch(res => {
  326. if (this._customAd.isShow()) {
  327. this.hideCustomAd();
  328. }
  329. });
  330. }
  331. exitGame() {
  332. wx.exitMiniProgram({});
  333. }
  334. __createVideoAd() {
  335. if (!WX_CONFIG.AD_ID.video) return;
  336. this._rewardVideo = wx.createRewardedVideoAd({
  337. adUnitId: WX_CONFIG.AD_ID.video
  338. }); // 注册视频的onClose事件
  339. this._rewardVideo.onClose(res => {
  340. if (res && res.isEnded || res === undefined) {
  341. var _this$_videoSuccessHa2;
  342. (_this$_videoSuccessHa2 = this._videoSuccessHandler) == null || _this$_videoSuccessHa2.call(this, true);
  343. } else {
  344. var _this$_videoSuccessHa3;
  345. this.showToast({
  346. title: "完整观看视频才有奖励哦"
  347. });
  348. (_this$_videoSuccessHa3 = this._videoSuccessHandler) == null || _this$_videoSuccessHa3.call(this, false);
  349. }
  350. this._videoSuccessHandler = null;
  351. }); // 注册视频的onError事件
  352. this._rewardVideo.onError(res => {
  353. var _this$_videoSuccessHa4;
  354. (_this$_videoSuccessHa4 = this._videoSuccessHandler) == null || _this$_videoSuccessHa4.call(this, false);
  355. this.showToast({
  356. title: "暂时没有可观看的视频"
  357. });
  358. this.shareShowReward(this._videoSuccessHandler);
  359. this._videoSuccessHandler = null;
  360. });
  361. }
  362. __createBannerAd() {
  363. if (!WX_CONFIG.AD_ID.banner) return;
  364. var info = wx.getSystemInfoSync();
  365. var f = (_crd && Adapter === void 0 ? (_reportPossibleCrUseOfAdapter({
  366. error: Error()
  367. }), Adapter) : Adapter).isNormalScreen();
  368. var w = f ? info.screenWidth * 0.85 : info.screenWidth * 0.85;
  369. this._bannerAd = wx.createBannerAd({
  370. adUnitId: WX_CONFIG.AD_ID.banner,
  371. adIntervals: 48,
  372. style: {
  373. left: 0,
  374. top: info.screenHeight,
  375. width: w,
  376. height: 70 //w * (f ? 0.48 : 0.5) //原始0
  377. }
  378. });
  379. this._bannerAd.onError(err => {
  380. switch (err.errCode) {
  381. case 1001:
  382. {
  383. break;
  384. }
  385. case 1004:
  386. {
  387. break;
  388. }
  389. }
  390. });
  391. this._bannerAd.onResize(() => {});
  392. }
  393. __createInterstitialAd() {
  394. if (!WX_CONFIG.AD_ID.interstitial) return;
  395. this._interstitialAd = wx.createInterstitialAd({
  396. adUnitId: WX_CONFIG.AD_ID.interstitial
  397. });
  398. }
  399. __createCustomAd() {
  400. if (!WX_CONFIG.AD_ID.multiGridCustom) return;
  401. var info = wx.getSystemInfoSync();
  402. this._customAd = wx.createCustomAd({
  403. adUnitId: WX_CONFIG.AD_ID.multiGridCustom,
  404. adIntervals: 60,
  405. style: {
  406. left: 0,
  407. top: info.screenHeight * 0.16,
  408. with: info.screenWidth * 0.9
  409. }
  410. });
  411. if (this._customAd) {
  412. this._customAd.onHide(res => {
  413. if (this._customAdCloseHandler) {
  414. this._customAdCloseHandler();
  415. }
  416. ;
  417. });
  418. this._customAd.onError(err => {
  419. switch (err.errCode) {
  420. case 1001:
  421. {
  422. break;
  423. }
  424. case 1004:
  425. {
  426. break;
  427. }
  428. }
  429. });
  430. }
  431. }
  432. __createSigleCustomAd() {
  433. if (!WX_CONFIG.AD_ID.sigleGridCustom) return;
  434. var info = wx.getSystemInfoSync();
  435. var f = (_crd && Adapter === void 0 ? (_reportPossibleCrUseOfAdapter({
  436. error: Error()
  437. }), Adapter) : Adapter).isNormalScreen();
  438. this._sigleCustomAd = wx.createCustomAd({
  439. adUnitId: WX_CONFIG.AD_ID.sigleGridCustom,
  440. adIntervals: 60,
  441. style: {
  442. left: info.screenWidth * 0.49,
  443. top: info.screenHeight * 0.038 + (f ? 20 : 35)
  444. }
  445. });
  446. this._sigleCustomAd.onError(err => {
  447. console.log('展示格子广告失败1');
  448. });
  449. }
  450. __turnVideoToShare(handler) {
  451. this.shareShowReward(handler);
  452. this._videoSuccessHandler = null;
  453. }
  454. };
  455. _export("default", new PlatformWX());
  456. _cclegacy._RF.pop();
  457. _crd = false;
  458. }
  459. };
  460. });
  461. //# sourceMappingURL=ef8fbfe139707974b3c4b369647c0d1d5047f681.js.map