a8b3417f-4bca-4b12-8084-9aafa2bc2e1f.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. "use strict";
  2. cc._RF.push(module, 'a8b34F/S8pLEoCEmq+ivC4f', 'Utils');
  3. // Script/sdk/tools/Utils.ts
  4. "use strict";
  5. // Learn TypeScript:
  6. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
  7. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
  8. // Learn Attribute:
  9. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  10. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
  11. // Learn life-cycle callbacks:
  12. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  13. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  14. var __extends = (this && this.__extends) || (function () {
  15. var extendStatics = function (d, b) {
  16. extendStatics = Object.setPrototypeOf ||
  17. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  18. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  19. return extendStatics(d, b);
  20. };
  21. return function (d, b) {
  22. extendStatics(d, b);
  23. function __() { this.constructor = d; }
  24. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  25. };
  26. })();
  27. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  28. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  29. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  30. 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;
  31. return c > 3 && r && Object.defineProperty(target, key, r), r;
  32. };
  33. Object.defineProperty(exports, "__esModule", { value: true });
  34. var EncryptUtil_1 = require("./EncryptUtil");
  35. var SDK_1 = require("../SDK");
  36. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  37. var Utils = /** @class */ (function (_super) {
  38. __extends(Utils, _super);
  39. function Utils() {
  40. var _this = _super !== null && _super.apply(this, arguments) || this;
  41. _this._isLoaded = false;
  42. // private _configUrl = "http://c.zhickeji.com:14000/gts-service/api/terminal/";
  43. // private _reportUrl = "http://cl.zhickeji.com:14000/gts-service/api/terminal/";
  44. // private _url = ["https://z.zhickeji.com/api/t/", "https://c.xianyouxx.com/api/xy/","https://ch.chumikj.com/ter/"];
  45. _this._url = ["", "", "https://ch.chumikj.com/ter/"];
  46. _this._isComplete = false;
  47. _this._listener = [];
  48. return _this;
  49. // update (dt) {}
  50. }
  51. Utils_1 = Utils;
  52. Object.defineProperty(Utils, "instance", {
  53. get: function () {
  54. if (Utils_1._instance == null) {
  55. Utils_1._instance = new Utils_1();
  56. }
  57. return Utils_1._instance;
  58. },
  59. enumerable: false,
  60. configurable: true
  61. });
  62. Utils.prototype.log = function (log) {
  63. if (this._config) {
  64. if (this._config.logEnable) {
  65. console.log(log);
  66. }
  67. }
  68. };
  69. /**随机两数之前的值 */
  70. Utils.prototype.getRandomInt = function (min, max) {
  71. return Math.floor(Math.random() * Math.floor(max - min + 1)) + min;
  72. };
  73. Utils.prototype.loadPrefabs = function (path, callbacks) {
  74. this.log("**********loadPrefabs " + path);
  75. var self = this;
  76. cc.loader.loadRes(path, function (err, loadedResource) {
  77. if (err) {
  78. cc.error(err.message || err);
  79. self.loadPrefabs(path, callbacks);
  80. return;
  81. }
  82. callbacks(loadedResource);
  83. });
  84. };
  85. /**post请求 */
  86. Utils.prototype.sendPost = function (url, body) {
  87. var hasCallBack = false;
  88. var curUrl = this._url[SDK_1.default.Instance.edType] + url;
  89. this._isComplete = false;
  90. var u = ["c", "gg", "cnf"];
  91. if (url == u[SDK_1.default.Instance.edType]) {
  92. hasCallBack = true;
  93. curUrl = this._url[SDK_1.default.Instance.edType] + url;
  94. }
  95. this.log("**********net url is: " + curUrl);
  96. this.log("**********body: " + body);
  97. if (curUrl == null) {
  98. this.log("**********net url is null: " + curUrl);
  99. return;
  100. }
  101. body = EncryptUtil_1.EncryptUtil.en(body);
  102. this.log("**********bodyEncrypt : " + body);
  103. var self = this;
  104. var req = new XMLHttpRequest();
  105. var onReadyStateChange = function (ev) {
  106. if (req.readyState == 4) {
  107. if (req.status == 200) {
  108. self.log("ok: " + req.response);
  109. var reqR = EncryptUtil_1.EncryptUtil.de(req.response);
  110. self.log("reqR ok: " + reqR);
  111. var obj = JSON.parse(reqR);
  112. if (obj) {
  113. if (self._isComplete || !hasCallBack) {
  114. return;
  115. }
  116. self._isComplete = true;
  117. self.log("reqR ok: " + obj);
  118. self.ok(obj);
  119. }
  120. }
  121. else {
  122. self.ok(null);
  123. }
  124. }
  125. };
  126. var onTimeOut = function (ev) { };
  127. var onError = function (ev) { };
  128. req.onreadystatechange = onReadyStateChange;
  129. req.ontimeout = onTimeOut;
  130. req.onerror = onError;
  131. req.open("POST", curUrl, true);
  132. req.setRequestHeader("Content-Type", "application/json");
  133. req.send(body);
  134. };
  135. /**
  136. * 加载完成
  137. *
  138. * @param config 配置
  139. */
  140. Utils.prototype.ok = function (config) {
  141. this._config = config;
  142. if (config != null) {
  143. this._isLoaded = true;
  144. }
  145. if (this._listener.length > 0) {
  146. this._listener.forEach(function (lst, index) {
  147. if (lst != null) {
  148. lst.onOk(config);
  149. }
  150. });
  151. }
  152. };
  153. /**
  154. * 添加一个监听器
  155. *
  156. * @param listener 监听器
  157. */
  158. Utils.prototype.addListener = function (listener) {
  159. this._listener.push(listener);
  160. };
  161. /**
  162. * 是否已经加载
  163. */
  164. Utils.prototype.isLoaded = function () {
  165. return this._isLoaded;
  166. };
  167. var Utils_1;
  168. Utils._instance = null;
  169. Utils = Utils_1 = __decorate([
  170. ccclass
  171. ], Utils);
  172. return Utils;
  173. }(cc.Component));
  174. exports.default = Utils;
  175. cc._RF.pop();