8d127def-ab30-4efd-857a-c0ef2fef6445.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. cc._RF.push(module, '8d1273vqzBO/YV6wO8v72RF', 'GameBoxListGameItem');
  3. // common-plugin/Scripts/GameBoxListGameItem.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. var GameBoxListGameItem = /** @class */ (function (_super) {
  30. __extends(GameBoxListGameItem, _super);
  31. function GameBoxListGameItem() {
  32. var _this = _super !== null && _super.apply(this, arguments) || this;
  33. /*
  34. {
  35. "id": 274,
  36. "icon": "http://ff.td68x.com/xcx/ylyxhz/44r4.png",
  37. "app_path": "pages/index/index?ald_media_id=5778&ald_link_key=21c462bc56b283b3",
  38. "name": "快乐游戏盒子",
  39. "qr_code": "http://ff.td68x.com/xcx/ylyxhz/44xp.png",
  40. "home_type": 4,
  41. "home_name": "休闲精选",
  42. "app_id": ""
  43. */
  44. _this.data = null;
  45. _this.icon = null;
  46. _this.labelName = null;
  47. _this.labelShadow = null;
  48. _this._dataDirty = false;
  49. _this.lastPostTime = 0; //最后一次上报时间
  50. return _this;
  51. }
  52. GameBoxListGameItem.prototype.onLoad = function () {
  53. var mask = this.node.getChildByName("Mask");
  54. this.icon = mask.getChildByName("Icon").getComponent(cc.Sprite);
  55. this.labelName = this.node.getChildByName("Label").getComponent(cc.Label);
  56. this.labelShadow = this.node.getChildByName("LabelShadow").getComponent(cc.Label);
  57. };
  58. GameBoxListGameItem.prototype.init = function (data) {
  59. this.data = data;
  60. this._dataDirty = true;
  61. };
  62. GameBoxListGameItem.prototype.update = function (dt) {
  63. if (this._dataDirty) {
  64. this._dataDirty = false;
  65. this.updateItem();
  66. }
  67. };
  68. GameBoxListGameItem.prototype.onEnable = function () {
  69. var _this = this;
  70. this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  71. _this._postData(_this.data.app_id);
  72. if (_this.data.app_id && Utils_1.utils.wechatTool.checkAppId(_this.data.app_id)) {
  73. Utils_1.utils.showLog("直接跳转!", _this.data.app_id);
  74. //@ts-ignore
  75. wx.navigateToMiniProgram({
  76. appId: _this.data.app_id,
  77. path: _this.data.app_path ? _this.data.app_path : "",
  78. success: function (res) {
  79. },
  80. fail: function (res) {
  81. // utils.showLog("跳转失败!", id);
  82. Utils_1.utils.showLog("\u8DF3\u8F6C\u5931\u8D25! ; res=" + JSON.stringify(res));
  83. }
  84. });
  85. }
  86. else if (_this.data.qr_code) {
  87. if (PlatUtils_1.default.IsWechat) {
  88. Utils_1.utils.showLog("二维码跳转!", _this.data.qr_code);
  89. Utils_1.utils.wechatTool.previewImage(_this.data.qr_code);
  90. }
  91. else {
  92. Utils_1.utils.showLog("不支持二维码跳转!");
  93. }
  94. }
  95. }, this);
  96. };
  97. GameBoxListGameItem.prototype.onDisable = function () {
  98. this.node.targetOff(this);
  99. };
  100. GameBoxListGameItem.prototype.updateItem = function () {
  101. var _this = this;
  102. if (this.data) {
  103. if (this.data.name) {
  104. var gameName = this.data.name;
  105. if (this.data.name.length > 4) {
  106. gameName = gameName.slice(0, 4);
  107. gameName += "...";
  108. }
  109. this.labelName.string = gameName;
  110. this.labelShadow.string = gameName;
  111. }
  112. if (this.data.icon) {
  113. CompatibleTool_1.default.LoadRes(this.data.icon, function (err, texture) {
  114. if (!err && cc.isValid(_this) && _this.icon && _this.icon.spriteFrame) {
  115. _this.icon.spriteFrame = new cc.SpriteFrame(texture);
  116. }
  117. });
  118. }
  119. }
  120. };
  121. GameBoxListGameItem.prototype._postData = function (appid) {
  122. // let curTime: number = new Date().getTime();
  123. // let interval: number = (curTime - this.lastPostTime) / 1000;
  124. // if (interval >= 3) {
  125. var url = "https://apps.youlesp.com/gbs?m=rclickV2&app_id=" + appid + "&game_id=" + Utils_1.utils.config.wechatconfig.appID;
  126. Utils_1.utils.showLog("上报数据, url=", url);
  127. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  128. if (ret) {
  129. // this.lastPostTime = curTime;
  130. Utils_1.utils.showLog("数据上报成功!");
  131. }
  132. else {
  133. Utils_1.utils.showLog("数据上报失败!");
  134. }
  135. });
  136. // } else {
  137. // cc.warn("上报的间隔时间小于3秒");
  138. // }
  139. };
  140. GameBoxListGameItem = __decorate([
  141. ccclass
  142. ], GameBoxListGameItem);
  143. return GameBoxListGameItem;
  144. }(cc.Component));
  145. exports.default = GameBoxListGameItem;
  146. cc._RF.pop();