pixuireactcomponents 1.3.85 → 1.3.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.85",
3
+ "version": "1.3.87",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,21 +37,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import { GameletAPI } from 'gamelet-pixui-frame';
38
38
  import path from 'path';
39
39
  import { tools } from './tools';
40
- import { LibMgr } from '../../../lib/loadlib/lib_mgr';
40
+ // import { LibMgr } from '../../../lib/loadlib/lib_mgr';
41
41
  var assetPrefix = 'cacheAsset';
42
42
  var isJssdkEnv = function () {
43
43
  return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
44
44
  };
45
45
  //动态导入lib_mgr
46
- // const getLibMgr = async () => {
47
- // try {
48
- // const module = await import('../../../lib/loadlib/lib_mgr');
49
- // return module.LibMgr;
50
- // } catch (error) {
51
- // console.error('need puerts env');
52
- // return null;
53
- // }
54
- // };
46
+ var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
47
+ var module_1, error_1;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0:
51
+ _a.trys.push([0, 2, , 3]);
52
+ return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
53
+ case 1:
54
+ module_1 = _a.sent();
55
+ return [2 /*return*/, module_1.LibMgr];
56
+ case 2:
57
+ error_1 = _a.sent();
58
+ console.error('need puerts env');
59
+ return [2 /*return*/, null];
60
+ case 3: return [2 /*return*/];
61
+ }
62
+ });
63
+ }); };
55
64
  /**
56
65
  * 缓存资源到本地,仅jssdk环境可用
57
66
  */
@@ -71,7 +80,7 @@ export var assetCache;
71
80
  return __generator(this, function (_a) {
72
81
  console.log('cacheAsset---', url);
73
82
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
74
- var urlWithoutParams, lib, localPath, xhr;
83
+ var urlWithoutParams, LibMgr, lib, localPath, xhr;
75
84
  var _this = this;
76
85
  return __generator(this, function (_a) {
77
86
  switch (_a.label) {
@@ -81,26 +90,46 @@ export var assetCache;
81
90
  reject(url);
82
91
  }
83
92
  urlWithoutParams = url.split('?')[0];
93
+ return [4 /*yield*/, getLibMgr()];
94
+ case 1:
95
+ LibMgr = _a.sent();
96
+ if (!LibMgr) {
97
+ console.log('getLibMgr failed');
98
+ reject();
99
+ return [2 /*return*/];
100
+ }
84
101
  lib = LibMgr.getInstance().getMainLib();
85
102
  return [4 /*yield*/, getLocalPath(urlWithoutParams)];
86
- case 1:
103
+ case 2:
87
104
  localPath = _a.sent();
105
+ if (!localPath) {
106
+ console.log('getLocalPath failed');
107
+ reject();
108
+ return [2 /*return*/];
109
+ }
110
+ console.log('cacheAsset getlocalPath', localPath);
88
111
  if (!force) {
89
112
  if (lib.fileExists(localPath)) {
90
113
  console.log('cacheAsset file exist', localPath);
91
114
  resolve(localPath);
92
115
  }
93
116
  }
117
+ console.log('cacheAsset file not exist or not force', url, localPath);
94
118
  xhr = new XMLHttpRequest();
95
119
  xhr.open('GET', url, true);
96
120
  xhr.responseType = 'arraybuffer';
97
121
  xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
98
- var buf;
99
122
  return __generator(this, function (_a) {
100
123
  if (xhr.status === 200) {
101
- buf = Buffer.from(xhr.response, 'binary').buffer;
102
- lib.saveToFile(localPath, buf);
103
- resolve(localPath);
124
+ console.log('cacheAsset xhr statue=200', url, localPath);
125
+ // let buf = Buffer.from(xhr.response, 'binary').buffer;
126
+ if (localPath) {
127
+ lib.saveToFile(localPath, xhr.response);
128
+ resolve(localPath);
129
+ }
130
+ else {
131
+ reject(url);
132
+ }
104
133
  }
105
134
  else {
106
135
  console.warn('cacheAsset xhr statue!=200', xhr.status);
@@ -179,17 +208,27 @@ export var assetCache;
179
208
  });
180
209
  };
181
210
  var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
182
- var lib, filePath, fileName;
211
+ var LibMgr, lib, filePath, fileName;
183
212
  return __generator(this, function (_a) {
184
- console.log('getLocalPath', url);
185
- lib = LibMgr.getInstance().getMainLib();
186
- filePath = path.join(lib.getCachePath(), 'assetcache');
187
- //检查assetcache文件夹
188
- if (!lib.dirExists(filePath)) {
189
- lib.makeDir(filePath);
213
+ switch (_a.label) {
214
+ case 0:
215
+ console.log('getLocalPath', url);
216
+ return [4 /*yield*/, getLibMgr()];
217
+ case 1:
218
+ LibMgr = _a.sent();
219
+ if (!LibMgr) {
220
+ console.log('getLibMgr failed');
221
+ return [2 /*return*/];
222
+ }
223
+ lib = LibMgr.getInstance().getMainLib();
224
+ filePath = path.join(lib.getCachePath(), 'assetcache');
225
+ //检查assetcache文件夹
226
+ if (!lib.dirExists(filePath)) {
227
+ lib.makeDir(filePath);
228
+ }
229
+ fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
230
+ return [2 /*return*/, path.join(filePath, fileName)];
190
231
  }
191
- fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
192
- return [2 /*return*/, path.join(filePath, fileName)];
193
232
  });
194
233
  }); };
195
234
  })(assetCache || (assetCache = {}));