@tmsfe/tms-core 0.0.202 → 0.0.204
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 +1 -1
- package/src/navbarUtils.js +1 -17
- package/src/report/helper.ts +2 -1
- package/src/report/proxy/helper.ts +2 -6
- package/src/syncfnmanager.js +4 -7
- package/src/utils/canvas/canvasDrawer.js +3 -1
- package/src/wxApi.ts +35 -1
package/package.json
CHANGED
package/src/navbarUtils.js
CHANGED
|
@@ -2,23 +2,7 @@
|
|
|
2
2
|
* @desc: 获取导航高度的相关函数
|
|
3
3
|
*/
|
|
4
4
|
import { compareVersion } from './compareVersion';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
|
|
9
|
-
* @returns {Object} 系统信息
|
|
10
|
-
*/
|
|
11
|
-
const getSystemInfoSync = () => {
|
|
12
|
-
if (systemInfo) return systemInfo;
|
|
13
|
-
let res;
|
|
14
|
-
try {
|
|
15
|
-
systemInfo = wx.getSystemInfoSync();
|
|
16
|
-
res = systemInfo;
|
|
17
|
-
} catch (_) {
|
|
18
|
-
res = {};
|
|
19
|
-
}
|
|
20
|
-
return res;
|
|
21
|
-
};
|
|
5
|
+
import { getSystemInfoSync } from './wxApi';
|
|
22
6
|
|
|
23
7
|
/**
|
|
24
8
|
* 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
|
package/src/report/helper.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import clone from './clone';
|
|
7
|
+
import { getSystemInfoSync } from '../wxApi';
|
|
7
8
|
import {
|
|
8
9
|
IPage,
|
|
9
10
|
DataItem,
|
|
@@ -42,7 +43,7 @@ let systemInfo: ISystemInfo;
|
|
|
42
43
|
*/
|
|
43
44
|
function getSystemInfo(): ISystemInfo {
|
|
44
45
|
if (!systemInfo) {
|
|
45
|
-
const currentSystemInfo =
|
|
46
|
+
const currentSystemInfo = getSystemInfoSync() as any;
|
|
46
47
|
// eslint-disable-next-line
|
|
47
48
|
const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host } = currentSystemInfo;
|
|
48
49
|
systemInfo = { model, wxVersion, platform, SDKVersion, host };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import clone from '../clone';
|
|
7
7
|
import helper from '../helper';
|
|
8
|
+
import { getSystemInfoSync } from '../../wxApi';
|
|
8
9
|
import { IInitOptions, IBindEvent } from './types';
|
|
9
10
|
|
|
10
11
|
let initOptions: IInitOptions;
|
|
@@ -30,16 +31,11 @@ function fastReportData(...args: any[]): any {
|
|
|
30
31
|
initOptions.fastReport(...args);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
let systemInfo: WechatMiniprogram.SystemInfo;
|
|
34
|
-
|
|
35
34
|
/**
|
|
36
35
|
* 获取wx.getSystemInfoSync()
|
|
37
36
|
*/
|
|
38
37
|
function getSystemInfo(): any {
|
|
39
|
-
|
|
40
|
-
systemInfo = wx.getSystemInfoSync();
|
|
41
|
-
}
|
|
42
|
-
return systemInfo;
|
|
38
|
+
return getSystemInfoSync();
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
let lastBindEvent: IBindEvent;
|
package/src/syncfnmanager.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getSystemInfoSync as getSystemInfoSyncFunc } from './wxApi';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @desc: 本文件负责对小程序调用wx同步方法的管理
|
|
3
5
|
*/
|
|
@@ -14,13 +16,8 @@ const getSystemInfoSync = () => {
|
|
|
14
16
|
return systemInfo;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return systemInfo;
|
|
21
|
-
} catch (_) {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
19
|
+
systemInfo = getSystemInfoSyncFunc();
|
|
20
|
+
return systemInfo;
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getSystemInfoSync } from '../../wxApi';
|
|
2
|
+
|
|
1
3
|
class CanvasDrawer {
|
|
2
4
|
constructor(canvasId, container, instance = '', designWindowWidth = 750) {
|
|
3
5
|
this.canvasId = canvasId; // canvasId
|
|
@@ -16,7 +18,7 @@ class CanvasDrawer {
|
|
|
16
18
|
const canvas = res[0].node;
|
|
17
19
|
this.canvas = canvas;
|
|
18
20
|
this.ctx = canvas.getContext('2d');
|
|
19
|
-
const { pixelRatio: dpr, windowWidth } =
|
|
21
|
+
const { pixelRatio: dpr, windowWidth } = getSystemInfoSync();
|
|
20
22
|
canvas.width = res[0].width * dpr;
|
|
21
23
|
canvas.height = res[0].height * dpr;
|
|
22
24
|
this.ratio = windowWidth / this.designWindowWidth;
|
package/src/wxApi.ts
CHANGED
|
@@ -35,4 +35,38 @@ async function getWxSetting(forceRefresh = false): Promise<{
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* 获取系统信息
|
|
40
|
+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html
|
|
41
|
+
* !!! 注意事项 !!!
|
|
42
|
+
* 1. 小程序常规打开和被半屏时屏幕尺寸不一样,获取屏幕高度、顶部栏胶囊位置的不要使用该缓存,会导致样式异常,如:navBar组件
|
|
43
|
+
* 2. 获取系统授权信息的不要使用该缓存,会导致授权信息更新不及时,如:系统位置定位开关打开 | 允许微信使用位置定位能力开关打开
|
|
44
|
+
*/
|
|
45
|
+
function getSystemInfoSync(): WechatMiniprogram.SystemInfo {
|
|
46
|
+
if (wx.tmsSystemInfo) {
|
|
47
|
+
return wx.tmsSystemInfo;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// 可以安全缓存的key,其它key缓存可能会因为更新不及时出现异常
|
|
52
|
+
const canCacheKeys = [
|
|
53
|
+
'brand', 'model', 'pixelRatio', 'screenWidth', 'windowWidth', 'language',
|
|
54
|
+
'version', 'system', 'platform', 'SDKVersion', 'benchmarkLevel', 'host',
|
|
55
|
+
];
|
|
56
|
+
const systemInfo = wx.getSystemInfoSync();
|
|
57
|
+
const safeSystemInfo = {};
|
|
58
|
+
canCacheKeys.forEach((key) => {
|
|
59
|
+
safeSystemInfo[key] = systemInfo[key];
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
wx.tmsSystemInfo = safeSystemInfo;
|
|
63
|
+
return wx.tmsSystemInfo;
|
|
64
|
+
} catch (_) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
getWxSetting,
|
|
71
|
+
getSystemInfoSync,
|
|
72
|
+
};
|