@tmsfe/tms-core 0.0.73 → 0.0.76
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/index-proxy.js +4 -2
- package/src/index.js +5 -1
- package/src/navbarUtils.js +197 -0
- package/src/report/README.md +2 -2
- package/src/report/proxy/helper.ts +1 -1
- package/src/rpx.js +13 -0
package/package.json
CHANGED
package/src/index-proxy.js
CHANGED
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
import syncApi from './syncfnmanager';
|
|
9
9
|
import AutoReport from './report/proxy/index';
|
|
10
10
|
import md5 from './md5';
|
|
11
|
-
import { rpxToPx } from './rpx';
|
|
12
11
|
import { serialize } from './objUtils';
|
|
13
12
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
13
|
+
import { getNavBarConfigData } from './navbarUtils';
|
|
14
|
+
import * as rpxUtil from './rpx';
|
|
14
15
|
import * as stringUtils from './stringUtils';
|
|
15
16
|
import * as timeUtils from './timeUtils';
|
|
16
17
|
import * as ipxHelper from './ipxHelper';
|
|
@@ -210,15 +211,16 @@ const api = {
|
|
|
210
211
|
md5,
|
|
211
212
|
getCarManager,
|
|
212
213
|
getLocationManager,
|
|
213
|
-
rpxToPx,
|
|
214
214
|
serialize,
|
|
215
215
|
calCoordinateDistance,
|
|
216
216
|
formatDistance,
|
|
217
|
+
getNavBarConfigData,
|
|
217
218
|
createRequest,
|
|
218
219
|
getEnvInfo,
|
|
219
220
|
isAppPageExist,
|
|
220
221
|
getHomePage,
|
|
221
222
|
storage,
|
|
223
|
+
...rpxUtil,
|
|
222
224
|
...asyncFuncs,
|
|
223
225
|
...objFuncs,
|
|
224
226
|
...syncApi,
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,8 @@ import { callCloudFunc } from './cloudService';
|
|
|
11
11
|
import EventDispatcher from './eventDispatcher';
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
13
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
14
|
-
import { rpxToPx } from './rpx';
|
|
14
|
+
import { rpxToPx, pxToRpx } from './rpx';
|
|
15
|
+
import { getNavBarConfigData } from './navbarUtils';
|
|
15
16
|
import {
|
|
16
17
|
formatPlate,
|
|
17
18
|
subStr,
|
|
@@ -192,6 +193,9 @@ const api = {
|
|
|
192
193
|
|
|
193
194
|
/** rpx转px */
|
|
194
195
|
rpxToPx,
|
|
196
|
+
pxToRpx,
|
|
197
|
+
|
|
198
|
+
getNavBarConfigData,
|
|
195
199
|
|
|
196
200
|
storage,
|
|
197
201
|
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
let systemInfo = null;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 获取系统信息,有缓存
|
|
5
|
+
* 返回数据同wx.getSystemInfoSync
|
|
6
|
+
* @returns {Object} 系统信息
|
|
7
|
+
*/
|
|
8
|
+
const getSystemInfoSync = () => {
|
|
9
|
+
if (systemInfo) return systemInfo;
|
|
10
|
+
let res;
|
|
11
|
+
try {
|
|
12
|
+
systemInfo = wx.getSystemInfoSync();
|
|
13
|
+
res = systemInfo;
|
|
14
|
+
} catch (_) {
|
|
15
|
+
res = {};
|
|
16
|
+
}
|
|
17
|
+
return res;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取系统信息
|
|
22
|
+
* @returns {Object} 系统信息
|
|
23
|
+
*/
|
|
24
|
+
const getSysInfo = () => {
|
|
25
|
+
let sysInfo = {};
|
|
26
|
+
try {
|
|
27
|
+
sysInfo = getSystemInfoSync();
|
|
28
|
+
sysInfo.getSystemInfoSuccess = true;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
// 获取系统信息失败时,使用默认数据
|
|
31
|
+
sysInfo = { getSystemInfoSuccess: false, statusBarHeight: 0, windowWidth: 0 };
|
|
32
|
+
}
|
|
33
|
+
return sysInfo;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取胶囊位置信息
|
|
38
|
+
* @returns {Object} 胶囊位置信息
|
|
39
|
+
*/
|
|
40
|
+
const getMenuButtonRectInfo = () => {
|
|
41
|
+
let menuButtonRectInfo = {};
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
menuButtonRectInfo = wx.getMenuButtonBoundingClientRect();
|
|
45
|
+
menuButtonRectInfo.getMenuRectInfoSuccess = true;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// 获取胶囊位置信息失败,使用默认值
|
|
48
|
+
menuButtonRectInfo = { getMenuRectInfoSuccess: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return menuButtonRectInfo;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 版本比较函数
|
|
56
|
+
* @param {String} sourceVersion 作为基准版本号
|
|
57
|
+
* @param {String} targetVersion 目标比较版本号
|
|
58
|
+
* @returns {Number} 比较结果
|
|
59
|
+
* 返回值说明:
|
|
60
|
+
* 1 : 大于基准版本号
|
|
61
|
+
* 0 : 等于基准版本号
|
|
62
|
+
* -1: 小于基准版本号
|
|
63
|
+
*/
|
|
64
|
+
const compareVersion = (sourceVersion, targetVersion) => {
|
|
65
|
+
if (typeof sourceVersion !== 'string' || typeof targetVersion !== 'string') {
|
|
66
|
+
throw new Error('版本比较参数类型有误');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const toInt = n => parseInt(n, 10); // eslint-disable-line require-jsdoc
|
|
70
|
+
const sourceArray = sourceVersion.split('.').map(toInt);
|
|
71
|
+
const targetArray = targetVersion.split('.').map(toInt);
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < sourceArray.length; i += 1) {
|
|
74
|
+
if (sourceArray[i] > targetArray[i]) {
|
|
75
|
+
return 1;
|
|
76
|
+
} if (sourceArray[i] < targetArray[i]) {
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return 0;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 胶囊高度适配,以兼容获取到的胶囊高度值非法的情况
|
|
86
|
+
* @param {Number} height 胶囊高度
|
|
87
|
+
* @param {Boolean} isIOS 是否是ios系统
|
|
88
|
+
* @returns {Number} 胶囊高度
|
|
89
|
+
*/
|
|
90
|
+
const formatMenuHeight = (height, isIOS) => {
|
|
91
|
+
if (height > 0) {
|
|
92
|
+
return height;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return isIOS ? 32 : 34;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 计算自定义导航栏布局信息
|
|
100
|
+
* @param {Boolean} isIOS 是否是ios平台
|
|
101
|
+
* @param {Number} statusBarHeight 状态栏高度
|
|
102
|
+
* @param {String} apiCategory API类别
|
|
103
|
+
* @returns {Object} data 导航栏布局信息
|
|
104
|
+
* @returns {Number} data.statusBarHeight 状态栏高度,单位rpx
|
|
105
|
+
* @returns {Number} data.navBarHeight 导航栏高度(不含状态栏),单位rpx
|
|
106
|
+
* @returns {Number} data.menuTop 菜单按钮上边距,单位rpx
|
|
107
|
+
* @returns {Number} data.menuRight 菜单按钮右边缘距离屏幕左边缘的距离,单位rpx
|
|
108
|
+
* @returns {Number} data.menuWidth 菜单按钮宽度,单位rpx
|
|
109
|
+
* @returns {Number} data.menuHeight 菜单按钮高度,单位rpx
|
|
110
|
+
*/
|
|
111
|
+
const calculateNavBarLayout = (isIOS, statusBarHeight, apiCategory) => {
|
|
112
|
+
const data = {};
|
|
113
|
+
const menuTopOnIos = statusBarHeight + 4;
|
|
114
|
+
const menuTopOnAndroid = statusBarHeight + 8; // statusBarHeight高度,不同机型差距较大,不适合写死
|
|
115
|
+
const menuRectInfo = getMenuButtonRectInfo(); // 插件下基础库2.15.0起支持
|
|
116
|
+
let { right, width, height = 0, top } = menuRectInfo;
|
|
117
|
+
// 数据有异常时使用默认值
|
|
118
|
+
if (top <= 0) {
|
|
119
|
+
top = isIOS ? menuTopOnIos : menuTopOnAndroid;
|
|
120
|
+
}
|
|
121
|
+
if (right <= 0) {
|
|
122
|
+
right = isIOS ? 368 : 383;
|
|
123
|
+
}
|
|
124
|
+
if (width < 0) {
|
|
125
|
+
width = isIOS ? 87 : 94;
|
|
126
|
+
}
|
|
127
|
+
height = formatMenuHeight(height, isIOS);
|
|
128
|
+
|
|
129
|
+
data.statusBarHeight = calStatusBarHeight(statusBarHeight, apiCategory); // 顶部状态栏高度
|
|
130
|
+
data.navBarHeight = calNavBarHeight(top, height, statusBarHeight, apiCategory); // 小程序导航栏高度
|
|
131
|
+
data.menuTop = top; // 菜单按钮上边距
|
|
132
|
+
data.menuRight = right; // 菜单按钮右边距离屏幕左边缘的距离
|
|
133
|
+
data.menuWidth = width; // 菜单按钮宽度
|
|
134
|
+
data.menuHeight = height; // 菜单按钮高度
|
|
135
|
+
return data;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const calStatusBarHeight = (statusBarHeight, apiCategory) => {
|
|
139
|
+
if (apiCategory !== 'embedded') return statusBarHeight;
|
|
140
|
+
return 0;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const calNavBarHeight = (menuTop, menuHeight, statusBarHeight, apiCategory) => {
|
|
144
|
+
if (apiCategory !== 'embedded') {
|
|
145
|
+
return menuHeight + ((menuTop - statusBarHeight) * 2);
|
|
146
|
+
}
|
|
147
|
+
return menuHeight + (7 * 2);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 获取导航栏相关信息
|
|
152
|
+
* @returns {Object} data 导航栏布局信息
|
|
153
|
+
* @returns {Number} data.enable 是否支持自定义导航栏
|
|
154
|
+
* @returns {Number} data.statusBarHeight 状态栏高度,单位rpx
|
|
155
|
+
* @returns {Number} data.navBarHeight 导航栏高度(不含状态栏),单位rpx
|
|
156
|
+
* @returns {Number} data.menuTop 菜单按钮上边距,单位rpx
|
|
157
|
+
* @returns {Number} data.menuRight 菜单按钮右边缘距离屏幕左边缘的距离,单位rpx
|
|
158
|
+
* @returns {Number} data.menuWidth 菜单按钮宽度,单位rpx
|
|
159
|
+
* @returns {Number} data.menuHeight 菜单按钮高度,单位rpx
|
|
160
|
+
* @returns {Object} data.enterOptions 启动参数
|
|
161
|
+
* @returns {Object} data.enterOptions.apiCategory API 类别(不同apiCategory场景下的API有不同限制,UI也有不同)
|
|
162
|
+
*/
|
|
163
|
+
const getNavBarConfigData = () => { // eslint-disable-line require-jsdoc
|
|
164
|
+
const systemInfo = getSysInfo();
|
|
165
|
+
const { brand, getSystemInfoSuccess, platform } = systemInfo;
|
|
166
|
+
const isIOS = platform === 'ios';
|
|
167
|
+
const StatusBarHeightOnIOS = 44;
|
|
168
|
+
const StatusBarHeightOnAndroid = 24;
|
|
169
|
+
let { statusBarHeight, version } = systemInfo;
|
|
170
|
+
// 获取系统信息失败,给设置一个默认版本
|
|
171
|
+
if (!getSystemInfoSuccess || !version) {
|
|
172
|
+
version = '7.0.1';
|
|
173
|
+
}
|
|
174
|
+
// 获取状态栏高度失败 | 接口调用成功,但数据为0时,使用默认值
|
|
175
|
+
if (!getSystemInfoSuccess || (getSystemInfoSuccess && statusBarHeight <= 0)) {
|
|
176
|
+
statusBarHeight = isIOS ? StatusBarHeightOnIOS : StatusBarHeightOnAndroid;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const enable = compareVersion(version, '7.0.0') >= 0 || brand === 'devtools'; // 微信版本是否支持自定义顶栏,不支持时自动隐藏
|
|
180
|
+
const enterOptions = getEnterOptions();
|
|
181
|
+
if (enable) {
|
|
182
|
+
return { enable, ...calculateNavBarLayout(isIOS, statusBarHeight, enterOptions.apiCategory) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return { enable };
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// 获取需要对外暴露的启动参数
|
|
189
|
+
const getEnterOptions = () => {
|
|
190
|
+
const options = wx.getEnterOptionsSync();
|
|
191
|
+
const { apiCategory = 'default' } = options || {};
|
|
192
|
+
return { apiCategory };
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export {
|
|
196
|
+
getNavBarConfigData,
|
|
197
|
+
};
|
package/src/report/README.md
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
#### 页面自动上报事件
|
|
49
49
|
##### 一、必须上报的生命周期事件:
|
|
50
50
|
1. onLoad: 页面加载
|
|
51
|
-
2. onShow: 页面显示
|
|
51
|
+
2. onShow: 页面显示(曝光)
|
|
52
52
|
3. onReady: 页面初次渲染完成
|
|
53
53
|
4. onHide: 页面隐藏
|
|
54
54
|
5. onUnload: 页面卸载
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
##### 二、可能会上报的生命周期事件(取决于页面是否实现该函数):
|
|
57
57
|
1. onPullDownRefresh: 用户下拉动作
|
|
58
58
|
2. onReachBottom: 页面上拉触底
|
|
59
|
-
3. onShareAppMessage: 用户点击右上角转发
|
|
59
|
+
3. onShareAppMessage: 用户点击右上角转发(分享)
|
|
60
60
|
4. onShareTimeline: 用户点击右上角转发到朋友圈
|
|
61
61
|
5. onAddToFavorites: 用户点击右上角收藏
|
|
62
62
|
6. onReportPageTouch: 用户触摸页面 - 如果页面wxml有view节点则会注入该事件
|
package/src/rpx.js
CHANGED
|
@@ -12,6 +12,19 @@ const rpxToPx = (rpx) => {
|
|
|
12
12
|
return rpx * ratio;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @description px to rpx
|
|
17
|
+
* @returns {Number} 转换后的rpx数值
|
|
18
|
+
* @param px
|
|
19
|
+
*/
|
|
20
|
+
const pxToRpx = (px) => {
|
|
21
|
+
const sys = syncApi.getSystemInfoSync();
|
|
22
|
+
const ww = sys.windowWidth;
|
|
23
|
+
const ratio = 750 / ww;
|
|
24
|
+
return px * ratio;
|
|
25
|
+
};
|
|
26
|
+
|
|
15
27
|
export {
|
|
16
28
|
rpxToPx,
|
|
29
|
+
pxToRpx,
|
|
17
30
|
};
|