pixuireactcomponents 1.3.79 → 1.3.81

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.79",
3
+ "version": "1.3.81",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,8 +6,15 @@ export declare namespace assetCache {
6
6
  * 缓存url资源到本地
7
7
  * @param url 资源url
8
8
  * @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
9
- * @returns 返回本地缓存文件路径
9
+ * @returns 返回本地缓存文件路径,成功后resolve资源的本地路径,失败后reject函数的url参数
10
10
  */
11
11
  const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
12
+ /**
13
+ *
14
+ * @param url 资源url
15
+ * @param responseType responseType
16
+ * @param retryTimes 重试次数
17
+ * @returns 下载成功是,返回xhr.response,否则返回空字符串
18
+ */
12
19
  const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
13
20
  }
@@ -37,29 +37,21 @@ 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
41
  var assetPrefix = 'cacheAsset';
41
42
  var isJssdkEnv = function () {
42
43
  return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
43
44
  };
44
45
  //动态导入lib_mgr
45
- var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
46
- var module_1, error_1;
47
- return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0:
50
- _a.trys.push([0, 2, , 3]);
51
- return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
52
- case 1:
53
- module_1 = _a.sent();
54
- return [2 /*return*/, module_1.LibMgr];
55
- case 2:
56
- error_1 = _a.sent();
57
- console.error('need puerts env');
58
- return [2 /*return*/, null];
59
- case 3: return [2 /*return*/];
60
- }
61
- });
62
- }); };
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
+ // };
63
55
  /**
64
56
  * 缓存资源到本地,仅jssdk环境可用
65
57
  */
@@ -70,7 +62,7 @@ export var assetCache;
70
62
  * 缓存url资源到本地
71
63
  * @param url 资源url
72
64
  * @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
73
- * @returns 返回本地缓存文件路径
65
+ * @returns 返回本地缓存文件路径,成功后resolve资源的本地路径,失败后reject函数的url参数
74
66
  */
75
67
  assetCache.cache = function (url, force, retryTimes) {
76
68
  if (retryTimes === void 0) { retryTimes = 3; }
@@ -79,32 +71,23 @@ export var assetCache;
79
71
  return __generator(this, function (_a) {
80
72
  console.log('cacheAsset---', url);
81
73
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
82
- var mgr, lib, localPath, xhr;
74
+ var lib, localPath, xhr;
83
75
  var _this = this;
84
76
  return __generator(this, function (_a) {
85
77
  switch (_a.label) {
86
78
  case 0:
87
79
  if (!isJssdkEnv()) {
88
80
  console.log('非jssdk环境');
89
- reject();
90
- return [2 /*return*/];
91
- }
92
- return [4 /*yield*/, getLibMgr()];
93
- case 1:
94
- mgr = _a.sent();
95
- if (!mgr) {
96
- reject();
97
- return [2 /*return*/];
81
+ reject(url);
98
82
  }
99
- lib = mgr.getInstance().getMainLib();
83
+ lib = LibMgr.getInstance().getMainLib();
100
84
  return [4 /*yield*/, getLocalPath(url)];
101
- case 2:
85
+ case 1:
102
86
  localPath = _a.sent();
103
87
  if (!force) {
104
88
  if (lib.fileExists(localPath)) {
105
89
  console.log('cacheAsset file exist', localPath);
106
90
  resolve(localPath);
107
- return [2 /*return*/];
108
91
  }
109
92
  }
110
93
  xhr = new XMLHttpRequest();
@@ -125,7 +108,7 @@ export var assetCache;
125
108
  assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
126
109
  }
127
110
  else {
128
- reject();
111
+ reject(url);
129
112
  }
130
113
  }
131
114
  return [2 /*return*/];
@@ -138,7 +121,7 @@ export var assetCache;
138
121
  assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
139
122
  }
140
123
  else {
141
- reject();
124
+ reject(url);
142
125
  }
143
126
  };
144
127
  xhr.send();
@@ -149,6 +132,13 @@ export var assetCache;
149
132
  });
150
133
  });
151
134
  };
135
+ /**
136
+ *
137
+ * @param url 资源url
138
+ * @param responseType responseType
139
+ * @param retryTimes 重试次数
140
+ * @returns 下载成功是,返回xhr.response,否则返回空字符串
141
+ */
152
142
  assetCache.download = function (url, responseType, retryTimes) {
153
143
  if (retryTimes === void 0) { retryTimes = 3; }
154
144
  console.log('download---', url);
@@ -168,7 +158,7 @@ export var assetCache;
168
158
  assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
169
159
  }
170
160
  else {
171
- reject();
161
+ reject('');
172
162
  }
173
163
  }
174
164
  return [2 /*return*/];
@@ -181,33 +171,24 @@ export var assetCache;
181
171
  assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
182
172
  }
183
173
  else {
184
- reject();
174
+ reject('');
185
175
  }
186
176
  };
187
177
  xhr.send();
188
178
  });
189
179
  };
190
180
  var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
191
- var mgr, lib, filePath, fileName;
181
+ var lib, filePath, fileName;
192
182
  return __generator(this, function (_a) {
193
- switch (_a.label) {
194
- case 0:
195
- console.log('getLocalPath', url);
196
- return [4 /*yield*/, getLibMgr()];
197
- case 1:
198
- mgr = _a.sent();
199
- if (!mgr) {
200
- return [2 /*return*/, ''];
201
- }
202
- lib = mgr.getInstance().getMainLib();
203
- filePath = path.join(lib.getCachePath(), 'assetcache');
204
- //检查assetcache文件夹
205
- if (!lib.dirExists(filePath)) {
206
- lib.makeDir(filePath);
207
- }
208
- fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
209
- return [2 /*return*/, path.join(filePath, fileName)];
183
+ console.log('getLocalPath', url);
184
+ lib = LibMgr.getInstance().getMainLib();
185
+ filePath = path.join(lib.getCachePath(), 'assetcache');
186
+ //检查assetcache文件夹
187
+ if (!lib.dirExists(filePath)) {
188
+ lib.makeDir(filePath);
210
189
  }
190
+ fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
191
+ return [2 /*return*/, path.join(filePath, fileName)];
211
192
  });
212
193
  }); };
213
194
  })(assetCache || (assetCache = {}));