autobots-commonlib 1.3.7 → 1.3.9
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/.idea/workspace.xml +73 -3
- package/README.md +6 -0
- package/app.js +3 -18
- package/lib/QCRNetworkModule.js +129 -0
- package/package.json +1 -1
- package/util/utils.js +53 -2
package/.idea/workspace.xml
CHANGED
|
@@ -322,7 +322,22 @@
|
|
|
322
322
|
<workItem from="1719543986343" duration="1315000" />
|
|
323
323
|
<workItem from="1719557850708" duration="158000" />
|
|
324
324
|
<workItem from="1720788061545" duration="659000" />
|
|
325
|
-
<workItem from="1723022063800" duration="
|
|
325
|
+
<workItem from="1723022063800" duration="1255000" />
|
|
326
|
+
<workItem from="1723445600579" duration="44000" />
|
|
327
|
+
<workItem from="1724206074117" duration="1956000" />
|
|
328
|
+
<workItem from="1728909453001" duration="438000" />
|
|
329
|
+
<workItem from="1734510585366" duration="7806000" />
|
|
330
|
+
<workItem from="1734574254811" duration="14608000" />
|
|
331
|
+
<workItem from="1734660084102" duration="1178000" />
|
|
332
|
+
<workItem from="1735107648089" duration="1649000" />
|
|
333
|
+
<workItem from="1735133340280" duration="453000" />
|
|
334
|
+
<workItem from="1735729650505" duration="747000" />
|
|
335
|
+
<workItem from="1735783516156" duration="6837000" />
|
|
336
|
+
<workItem from="1738999153812" duration="212000" />
|
|
337
|
+
<workItem from="1739254420113" duration="1284000" />
|
|
338
|
+
<workItem from="1739412050915" duration="155000" />
|
|
339
|
+
<workItem from="1739516604702" duration="755000" />
|
|
340
|
+
<workItem from="1741058434802" duration="1212000" />
|
|
326
341
|
</task>
|
|
327
342
|
<task id="LOCAL-00001" summary="1、增加新组件NewNavbar; 2、修改jump方法,增加一个参数;">
|
|
328
343
|
<created>1561551696357</created>
|
|
@@ -523,7 +538,15 @@
|
|
|
523
538
|
<option name="project" value="LOCAL" />
|
|
524
539
|
<updated>1716815699201</updated>
|
|
525
540
|
</task>
|
|
526
|
-
<
|
|
541
|
+
<task id="LOCAL-00027" summary="更新版本号到1.3.8">
|
|
542
|
+
<option name="closed" value="true" />
|
|
543
|
+
<created>1728909568868</created>
|
|
544
|
+
<option name="number" value="00027" />
|
|
545
|
+
<option name="presentableId" value="LOCAL-00027" />
|
|
546
|
+
<option name="project" value="LOCAL" />
|
|
547
|
+
<updated>1728909568868</updated>
|
|
548
|
+
</task>
|
|
549
|
+
<option name="localTasksCounter" value="28" />
|
|
527
550
|
<servers />
|
|
528
551
|
</component>
|
|
529
552
|
<component name="TimeTrackingManager">
|
|
@@ -571,6 +594,7 @@
|
|
|
571
594
|
<component name="Vcs.Log.Tabs.Properties">
|
|
572
595
|
<option name="OPEN_GENERIC_TABS">
|
|
573
596
|
<map>
|
|
597
|
+
<entry key="37b214ca-431b-4a81-bc9e-5fe3e91842d9" value="TOOL_WINDOW" />
|
|
574
598
|
<entry key="3c8b0b99-0aa6-41f7-ac7f-4cb445fce607" value="TOOL_WINDOW" />
|
|
575
599
|
<entry key="68016c0f-bd47-47ae-a11b-0f2068b8d124" value="TOOL_WINDOW" />
|
|
576
600
|
<entry key="af60ef88-1ce1-4b05-af70-286a8a22b0ce" value="TOOL_WINDOW" />
|
|
@@ -578,6 +602,31 @@
|
|
|
578
602
|
</option>
|
|
579
603
|
<option name="TAB_STATES">
|
|
580
604
|
<map>
|
|
605
|
+
<entry key="37b214ca-431b-4a81-bc9e-5fe3e91842d9">
|
|
606
|
+
<value>
|
|
607
|
+
<State>
|
|
608
|
+
<option name="FILTERS">
|
|
609
|
+
<map>
|
|
610
|
+
<entry key="branch">
|
|
611
|
+
<value>
|
|
612
|
+
<list>
|
|
613
|
+
<option value="HEAD" />
|
|
614
|
+
</list>
|
|
615
|
+
</value>
|
|
616
|
+
</entry>
|
|
617
|
+
<entry key="roots">
|
|
618
|
+
<value>
|
|
619
|
+
<list>
|
|
620
|
+
<option value="$PROJECT_DIR$" />
|
|
621
|
+
</list>
|
|
622
|
+
</value>
|
|
623
|
+
</entry>
|
|
624
|
+
</map>
|
|
625
|
+
</option>
|
|
626
|
+
<option name="SHOW_ONLY_AFFECTED_CHANGES" value="true" />
|
|
627
|
+
</State>
|
|
628
|
+
</value>
|
|
629
|
+
</entry>
|
|
581
630
|
<entry key="3c8b0b99-0aa6-41f7-ac7f-4cb445fce607">
|
|
582
631
|
<value>
|
|
583
632
|
<State>
|
|
@@ -628,6 +677,11 @@
|
|
|
628
677
|
</State>
|
|
629
678
|
</value>
|
|
630
679
|
</entry>
|
|
680
|
+
<entry key="MAIN">
|
|
681
|
+
<value>
|
|
682
|
+
<State />
|
|
683
|
+
</value>
|
|
684
|
+
</entry>
|
|
631
685
|
<entry key="af60ef88-1ce1-4b05-af70-286a8a22b0ce">
|
|
632
686
|
<value>
|
|
633
687
|
<State>
|
|
@@ -673,7 +727,23 @@
|
|
|
673
727
|
<MESSAGE value="更新版本号到1.3.3" />
|
|
674
728
|
<MESSAGE value="处理asyncFetch和asyncPostForm传递的参数为null的场景" />
|
|
675
729
|
<MESSAGE value="更新asyncFetch和asyncPostForm传递的参数,使用更严谨方式判断,防止非字符串型参数也传""的错误处理" />
|
|
676
|
-
<
|
|
730
|
+
<MESSAGE value="更新版本号到1.3.8" />
|
|
731
|
+
<option name="LAST_COMMIT_MESSAGE" value="更新版本号到1.3.8" />
|
|
732
|
+
</component>
|
|
733
|
+
<component name="XDebuggerManager">
|
|
734
|
+
<breakpoint-manager>
|
|
735
|
+
<breakpoints>
|
|
736
|
+
<line-breakpoint enabled="true" type="javascript">
|
|
737
|
+
<url>file://$PROJECT_DIR$/app.js</url>
|
|
738
|
+
<line>10</line>
|
|
739
|
+
<option name="timeStamp" value="1" />
|
|
740
|
+
</line-breakpoint>
|
|
741
|
+
<line-breakpoint enabled="true" type="javascript">
|
|
742
|
+
<url>file://$PROJECT_DIR$/native.js</url>
|
|
743
|
+
<option name="timeStamp" value="2" />
|
|
744
|
+
</line-breakpoint>
|
|
745
|
+
</breakpoints>
|
|
746
|
+
</breakpoint-manager>
|
|
677
747
|
</component>
|
|
678
748
|
<component name="editorHistoryManager">
|
|
679
749
|
<entry file="file://$PROJECT_DIR$/window.js">
|
package/README.md
CHANGED
package/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AppRegistry
|
|
1
|
+
import { AppRegistry } from 'react-native';
|
|
2
2
|
import RootController from './controller';
|
|
3
3
|
import config from './config';
|
|
4
|
-
|
|
4
|
+
import Utils from "./util/utils";
|
|
5
5
|
const app = {
|
|
6
6
|
Register: function(opt) {
|
|
7
7
|
config.set(opt);
|
|
@@ -10,21 +10,6 @@ const app = {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
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
|
-
}
|
|
13
|
+
Utils.consoleLogOutput();
|
|
27
14
|
|
|
28
15
|
module.exports = app;
|
|
29
|
-
|
|
30
|
-
|
package/lib/QCRNetworkModule.js
CHANGED
|
@@ -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
package/util/utils.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import DeviceInfo from "react-native-device-info";
|
|
2
|
-
import { Platform } from 'react-native';
|
|
2
|
+
import { Platform, NativeModules } from 'react-native';
|
|
3
|
+
import config from "../config";
|
|
4
|
+
|
|
5
|
+
let appCode = "";
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* 是否使用旧版网络接口
|
|
@@ -42,9 +45,57 @@ function compareVersion(version1, version2) {
|
|
|
42
45
|
return 0;
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
function newConsoleLog(type, msg) {
|
|
49
|
+
if (appCode === "") {
|
|
50
|
+
let data = config.get();
|
|
51
|
+
appCode = (data && data.name) ? data.name : '';
|
|
52
|
+
}
|
|
53
|
+
NativeModules.QCRLoganModule.writeLog({ tag: appCode, type: type, log: msg});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function consoleLogOutput() {
|
|
57
|
+
let disableLog = false;
|
|
58
|
+
if (NativeModules.RNDeviceInfo) {
|
|
59
|
+
console.log('isConsoleLogShow', NativeModules.RNDeviceInfo.isConsoleLogShow);
|
|
60
|
+
if (typeof NativeModules.RNDeviceInfo.isConsoleLogShow != 'undefined') {
|
|
61
|
+
let isConsoleLogShow = NativeModules.RNDeviceInfo.isConsoleLogShow;
|
|
62
|
+
if (!isConsoleLogShow) {
|
|
63
|
+
disableLog = true;
|
|
64
|
+
console.info = () => {};
|
|
65
|
+
console.log = () => {};
|
|
66
|
+
console.warn = () => {};
|
|
67
|
+
console.debug = () => {};
|
|
68
|
+
console.error = () => {};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log('disableLog=', disableLog);
|
|
73
|
+
console.log('writeLog=', NativeModules.QCRLoganModule && NativeModules.QCRLoganModule.writeLog);
|
|
74
|
+
|
|
75
|
+
if (!disableLog && NativeModules.QCRLoganModule && NativeModules.QCRLoganModule.writeLog) {
|
|
76
|
+
console.log('Console log redirect!');
|
|
77
|
+
console.log = (...args) => {
|
|
78
|
+
newConsoleLog(11, args.join(" "));
|
|
79
|
+
};
|
|
80
|
+
console.debug = (...args) => {
|
|
81
|
+
newConsoleLog(11, args.join(" "));
|
|
82
|
+
};
|
|
83
|
+
console.info = (...args) => {
|
|
84
|
+
newConsoleLog(12, args.join(" "));
|
|
85
|
+
};
|
|
86
|
+
console.warn = (...args) => {
|
|
87
|
+
newConsoleLog(13, args.join(" "));
|
|
88
|
+
};
|
|
89
|
+
console.error = (...args) => {
|
|
90
|
+
newConsoleLog(14, args.join(" "));
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
45
95
|
const Utils = {
|
|
46
96
|
isChooseOldNetApi,
|
|
47
|
-
compareVersion
|
|
97
|
+
compareVersion,
|
|
98
|
+
consoleLogOutput
|
|
48
99
|
};
|
|
49
100
|
|
|
50
101
|
export default Utils;
|