1e163945-44c8-4233-85e3-d0605ec7be19.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. cc._RF.push(module, '1e163lFRMhCM4Xj0GBex74Z', 'GameBoxSlideItem');
  3. // common-plugin/Scripts/GameBoxSlideItem.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var Utils_1 = require("./Utils");
  26. var PlatUtils_1 = require("./PlatUtils");
  27. var CompatibleTool_1 = require("./CompatibleTool");
  28. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  29. /**
  30. * 游戏盒子顶部的幻灯片
  31. */
  32. var GameBoxSlideItem = /** @class */ (function (_super) {
  33. __extends(GameBoxSlideItem, _super);
  34. function GameBoxSlideItem() {
  35. var _this = _super !== null && _super.apply(this, arguments) || this;
  36. _this.data = null;
  37. _this.itemSprite = null;
  38. _this._dataDirty = false;
  39. _this.lastPostTime = 0; //最后一次上报时间
  40. return _this;
  41. // update (dt) {}
  42. }
  43. GameBoxSlideItem.prototype.onLoad = function () {
  44. this.itemSprite = this.node.getComponent(cc.Sprite);
  45. };
  46. // start() {
  47. // this.initUi();
  48. // this.initListener();
  49. // }
  50. /**
  51. * 初始化UI
  52. */
  53. GameBoxSlideItem.prototype.initUi = function () {
  54. };
  55. /**
  56. * 初始化监听事件
  57. */
  58. GameBoxSlideItem.prototype.initListener = function () {
  59. };
  60. /**
  61. * 初始化数据
  62. */
  63. GameBoxSlideItem.prototype.initData = function (data) {
  64. Utils_1.utils.showLog("#slideData=", data);
  65. this.data = data;
  66. this._dataDirty = true;
  67. };
  68. GameBoxSlideItem.prototype.update = function (dt) {
  69. if (this._dataDirty) {
  70. this._dataDirty = false;
  71. this.updateItem();
  72. }
  73. };
  74. GameBoxSlideItem.prototype.onEnable = function () {
  75. var _this = this;
  76. this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  77. _this._postData(_this.data.app_id);
  78. if (_this.data.app_id && Utils_1.utils.wechatTool.checkAppId(_this.data.app_id)) {
  79. Utils_1.utils.showLog("直接跳转!", _this.data.app_id);
  80. //@ts-ignore
  81. wx.navigateToMiniProgram({
  82. appId: _this.data.app_id,
  83. path: _this.data.app_path ? _this.data.app_path : "",
  84. success: function (res) {
  85. },
  86. fail: function (res) {
  87. // utils.showLog("跳转失败!", id);
  88. Utils_1.utils.showLog("\u8DF3\u8F6C\u5931\u8D25! res=" + JSON.stringify(res));
  89. }
  90. });
  91. }
  92. else if (_this.data.qr_code) {
  93. if (PlatUtils_1.default.IsWechat) {
  94. Utils_1.utils.showLog("二维码跳转!", _this.data.qr_code);
  95. Utils_1.utils.wechatTool.previewImage(_this.data.qr_code);
  96. // 上报数据
  97. // if (this.data && this.data.app_id) {
  98. // this._postData(this.data.app_id);
  99. // }
  100. }
  101. else {
  102. Utils_1.utils.showLog("不支持二维码跳转!");
  103. }
  104. }
  105. }, this);
  106. };
  107. GameBoxSlideItem.prototype.onDisable = function () {
  108. this.node.targetOff(this);
  109. };
  110. GameBoxSlideItem.prototype.updateItem = function () {
  111. var _this = this;
  112. if (this.data && this.data.banner) {
  113. CompatibleTool_1.default.LoadRes(this.data.banner, function (err, texture) {
  114. Utils_1.utils.showLog(err, "err");
  115. if (!err && cc.isValid(_this) && _this.itemSprite) {
  116. Utils_1.utils.showLog(_this.node.active, "node <<<");
  117. _this.itemSprite.spriteFrame = new cc.SpriteFrame(texture);
  118. }
  119. });
  120. }
  121. };
  122. GameBoxSlideItem.prototype._postData = function (appid) {
  123. // let curTime: number = new Date().getTime();
  124. // let interval: number = (curTime - this.lastPostTime) / 1000;
  125. // if (interval >= 3) {
  126. var url = "https://apps.youlesp.com/gbs?m=rclickV2&app_id=" + appid + "&game_id=" + Utils_1.utils.config.wechatconfig.appID;
  127. Utils_1.utils.showLog("上报数据, url=", url);
  128. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  129. if (ret) {
  130. // this.lastPostTime = curTime;
  131. Utils_1.utils.showLog("数据上报成功!");
  132. }
  133. else {
  134. Utils_1.utils.showLog("数据上报失败!");
  135. }
  136. });
  137. // } else {
  138. // cc.warn("上报的间隔时间小于3秒");
  139. // }
  140. };
  141. GameBoxSlideItem = __decorate([
  142. ccclass
  143. ], GameBoxSlideItem);
  144. return GameBoxSlideItem;
  145. }(cc.Component));
  146. exports.default = GameBoxSlideItem;
  147. cc._RF.pop();