autobots-commonlib 1.3.6 → 1.3.8

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.
@@ -318,7 +318,13 @@
318
318
  <workItem from="1715841212364" duration="699000" />
319
319
  <workItem from="1716272524681" duration="9005000" />
320
320
  <workItem from="1716814998133" duration="2987000" />
321
- <workItem from="1717124536462" duration="598000" />
321
+ <workItem from="1717124536462" duration="1027000" />
322
+ <workItem from="1719543986343" duration="1315000" />
323
+ <workItem from="1719557850708" duration="158000" />
324
+ <workItem from="1720788061545" duration="659000" />
325
+ <workItem from="1723022063800" duration="1255000" />
326
+ <workItem from="1723445600579" duration="44000" />
327
+ <workItem from="1724206074117" duration="1956000" />
322
328
  </task>
323
329
  <task id="LOCAL-00001" summary="1、增加新组件NewNavbar;&#10;2、修改jump方法,增加一个参数;">
324
330
  <created>1561551696357</created>
@@ -567,12 +573,38 @@
567
573
  <component name="Vcs.Log.Tabs.Properties">
568
574
  <option name="OPEN_GENERIC_TABS">
569
575
  <map>
576
+ <entry key="3c8b0b99-0aa6-41f7-ac7f-4cb445fce607" value="TOOL_WINDOW" />
570
577
  <entry key="68016c0f-bd47-47ae-a11b-0f2068b8d124" value="TOOL_WINDOW" />
571
578
  <entry key="af60ef88-1ce1-4b05-af70-286a8a22b0ce" value="TOOL_WINDOW" />
572
579
  </map>
573
580
  </option>
574
581
  <option name="TAB_STATES">
575
582
  <map>
583
+ <entry key="3c8b0b99-0aa6-41f7-ac7f-4cb445fce607">
584
+ <value>
585
+ <State>
586
+ <option name="FILTERS">
587
+ <map>
588
+ <entry key="branch">
589
+ <value>
590
+ <list>
591
+ <option value="HEAD" />
592
+ </list>
593
+ </value>
594
+ </entry>
595
+ <entry key="roots">
596
+ <value>
597
+ <list>
598
+ <option value="$PROJECT_DIR$" />
599
+ </list>
600
+ </value>
601
+ </entry>
602
+ </map>
603
+ </option>
604
+ <option name="SHOW_ONLY_AFFECTED_CHANGES" value="true" />
605
+ </State>
606
+ </value>
607
+ </entry>
576
608
  <entry key="68016c0f-bd47-47ae-a11b-0f2068b8d124">
577
609
  <value>
578
610
  <State>
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  autobots commonlib
2
2
 
3
+ "1.3.8"
4
+ 添加写缓存接口支持和ios支持json数组数据
5
+
6
+ "1.3.7"
7
+ 实现console.log日志开关控制
8
+
3
9
  "1.3.6"
4
10
  解决Android下form类型post请求缓存获取不到的问题
5
11
 
package/app.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AppRegistry } from 'react-native';
1
+ import { AppRegistry, Platform, NativeModules } from 'react-native';
2
2
  import RootController from './controller';
3
3
  import config from './config';
4
4
 
@@ -10,6 +10,21 @@ const app = {
10
10
  }
11
11
  }
12
12
 
13
+ if (NativeModules.RNDeviceInfo) {
14
+ console.log('NativeModules.RNDeviceInfo.isConsoleLogShow', NativeModules.RNDeviceInfo.isConsoleLogShow);
15
+ if (typeof NativeModules.RNDeviceInfo.isConsoleLogShow != 'undefined') {
16
+ let isConsoleLogShow = NativeModules.RNDeviceInfo.isConsoleLogShow;
17
+ if (!isConsoleLogShow) {
18
+ console.log('console log switch is off');
19
+ console.info = () => {};
20
+ console.log = () => {};
21
+ console.warn = () => {};
22
+ console.debug = () => {};
23
+ console.error = () => {};
24
+ }
25
+ }
26
+ }
27
+
13
28
  module.exports = app;
14
29
 
15
30
 
@@ -5,6 +5,47 @@ import Utils from "../util/utils";
5
5
  var QCRRNNetworkModule = NativeModules.QCRRNNetworkModule;
6
6
 
7
7
  var NetworkModule = {
8
+
9
+ async getCacheData(cacheKey: String) {
10
+ if (QCRRNNetworkModule && QCRRNNetworkModule.getCacheData) {
11
+ try {
12
+ return await QCRRNNetworkModule.getCacheData(cacheKey, Platform.OS === 'android' ? null : {});
13
+ } catch (error) {
14
+ console.error('getCacheData发生了异常:' + error);
15
+ return '';
16
+ }
17
+ } else {
18
+ return '';
19
+ }
20
+ },
21
+
22
+ writeCacheData(cacheKey: String, params: Object, isAdd: boolean, expireTime: number) {
23
+ if (QCRRNNetworkModule && QCRRNNetworkModule.writeCache) {
24
+ const isAddNumber = Platform.OS === 'android' ? (isAdd ? 1 : 0) : isAdd;
25
+ if (Platform.OS === 'android' && typeof params === 'object') {
26
+ QCRRNNetworkModule.writeCache(cacheKey, JSON.stringify(params), isAddNumber, expireTime);
27
+ } else {
28
+ QCRRNNetworkModule.writeCache(cacheKey, params, isAddNumber, expireTime);
29
+ }
30
+ }
31
+ },
32
+
33
+ clearCacheData(cacheKey: String) {
34
+ if (QCRRNNetworkModule && QCRRNNetworkModule.clearCache) {
35
+ QCRRNNetworkModule.clearCache(cacheKey);
36
+ }
37
+ },
38
+
39
+ fetchList(url: String, config: Object, params: Object, cacheFunction: Function) {
40
+ return new Promise(function (resolve, reject) {
41
+ if (QCRRNNetworkModule && (!Utils.isChooseOldNetApi(params) || QCRRNNetworkModule.postList)) {
42
+ asyncListFetch(url, config, params, cacheFunction, resolve, reject);
43
+ } else {
44
+ asyncPostJsonFetch(url, config, params, resolve, reject);
45
+ }
46
+ });
47
+ },
48
+
8
49
  fetch(url: String, config: Object, params: Object, cacheFunction: Function) {
9
50
  return new Promise(function (resolve, reject) {
10
51
  if (QCRRNNetworkModule && !Utils.isChooseOldNetApi(params)) {
@@ -180,6 +221,94 @@ async function asyncFetch(url: String, config: Object, params: Object, cacheFunc
180
221
  }
181
222
  }
182
223
 
224
+ async function asyncListFetch(url: String, config: Object, params: Object, cacheFunction: Function, resolveCallback: Function, rejectCallback: Function) {
225
+ let needReadCache = (config && config.method && config.method.indexOf('cache') >= 0) ? true : false;
226
+ if (needReadCache && cacheFunction) {
227
+ try {
228
+ if (Platform.OS === 'android') {
229
+ //处理body为form类型要将param全部字段转为字条串类型,与请求网络接口写缓存时类型一致
230
+ if (params && config && config.headers) {
231
+ if (!(config.headers['Content-Type'] && config.headers['Content-Type'].indexOf('application/json') >= 0)) {
232
+ const stringFieldParams = {};
233
+ Object.keys(params).forEach(key => {
234
+ if (typeof params[key] !== 'undefined' && params[key] !== null) {
235
+ stringFieldParams[key] = String(params[key]);
236
+ }
237
+ });
238
+ params = stringFieldParams;
239
+ }
240
+ }
241
+ }
242
+ let response = await QCRRNNetworkModule.getCacheData(url, []);
243
+ if (typeof response === 'string') {
244
+ if (response.trim() != '') {
245
+ response = JSON.parse(response);
246
+ cacheFunction(response);
247
+ }
248
+ } else {
249
+ cacheFunction(response);
250
+ }
251
+ } catch (error) {
252
+ console.log('缓存结果出错:', error)
253
+ }
254
+ }
255
+
256
+ try {
257
+ var events;
258
+ if (Platform.OS === 'ios') {
259
+ events = await QCRRNNetworkModule.postList(url, config, params, needReadCache);
260
+ } else {//android
261
+ try {
262
+ //处理body为json类型
263
+ let isJsonPost = false;
264
+ if (config && config.headers) {
265
+ if (config.headers['Content-Type'] && config.headers['Content-Type'].indexOf('application/json') >= 0) {
266
+ //if(params && Object.keys(params).length !== 0){
267
+ let jsonparam = {};
268
+ jsonparam.json = params ? JSON.stringify(params) : {};
269
+ config.body = jsonparam;
270
+ isJsonPost = true;
271
+ }
272
+ }
273
+ config = config || {}
274
+ //处理body为form类型
275
+ if (!isJsonPost) {
276
+ config.headers = config.headers || {}
277
+ config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
278
+ // 将参数对象中的所有值转换为字符串类型,因为原生只按string类型来处理,否则有其它类型会报解析异常
279
+ const stringifiedParams = {};
280
+ if (params) {
281
+ Object.keys(params).forEach(key => {
282
+ if (typeof params[key] !== 'undefined' && params[key] !== null) {
283
+ stringifiedParams[key] = String(params[key]);
284
+ }
285
+ // else {
286
+ // stringifiedParams[key] = ""; // 将undefined值设为""
287
+ // }
288
+ });
289
+ }
290
+
291
+ let formparam = {};
292
+ formparam.form = JSON.stringify(stringifiedParams);
293
+ config.body = formparam;
294
+ }
295
+
296
+ console.log('asyncFetch 配置信息:', config);
297
+ events = await QCRRNNetworkModule.fetch(url, config);
298
+ if (typeof events === 'string') {
299
+ events = JSON.parse(events);
300
+ }
301
+ } catch (error) {
302
+ rejectCallback(error);
303
+ }
304
+ }
305
+ resolveCallback(events);
306
+ } catch (error) {
307
+ console.log('结果:', error)
308
+ rejectCallback(error);
309
+ }
310
+ }
311
+
183
312
  async function asyncFromFetch(url: String, config: Object, params: Object, resolveCallback: Function, rejectCallback: Function) {
184
313
  try {
185
314
  let isJsonPost = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobots-commonlib",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "autobots common lib",
5
5
  "main": "index.js",
6
6
  "scripts": {