@tmsfe/tms-core 0.0.74 → 0.0.77
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/mpInfo.js +10 -3
- package/src/navbarUtils.js +187 -18
package/package.json
CHANGED
package/src/mpInfo.js
CHANGED
|
@@ -32,10 +32,17 @@ async function getOuterOpenId(apiKey) {
|
|
|
32
32
|
return openId;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* 获取用户加密数据
|
|
37
|
+
* @param {String} mpId 服务接入方渠道标识,spId 或 apiKey。注意:如果使用 apiKey,需要在后台增加 apiKey 和 spId 的映射
|
|
38
|
+
* @param {String} queryTypes 要加密的用户信息类型集合,多个种类型用','连接;支持的类型见下文“用户信息类型标识” |
|
|
39
|
+
* @param {Object} propNameMap 加密数据对象中信息字段名映射
|
|
40
|
+
* @returns {Promise<{ encrStr: String }>} 加密字符串
|
|
41
|
+
*/
|
|
42
|
+
async function getEncryptUserInfo(mpId = '', queryTypes = '', propNameMap = {}) {
|
|
36
43
|
if (!mpId) return Promise.reject('缺少服务标志mpId');
|
|
37
44
|
if (!queryTypes) return Promise.reject('缺少需要加密的用户信息字段描述');
|
|
38
|
-
return new Request().get('user/info/encrypt', { mpId, queryTypes })
|
|
45
|
+
return new Request().get('user/info/encrypt', { mpId, queryTypes, propNameMap })
|
|
39
46
|
.then((res) => {
|
|
40
47
|
const { resData, errCode, errMsg } = res || {};
|
|
41
48
|
if (errCode === 0) {
|
|
@@ -44,7 +51,7 @@ async function getEncryptUserInfo(mpId = '', queryTypes = '') {
|
|
|
44
51
|
}
|
|
45
52
|
return Promise.reject(errMsg);
|
|
46
53
|
})
|
|
47
|
-
.catch(
|
|
54
|
+
.catch(() => Promise.reject('请求发生错误,请重试'));
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
export {
|
package/src/navbarUtils.js
CHANGED
|
@@ -1,26 +1,195 @@
|
|
|
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
|
+
|
|
1
150
|
/**
|
|
2
151
|
* 获取导航栏相关信息
|
|
3
152
|
* @returns {Object} data 导航栏布局信息
|
|
4
153
|
* @returns {Number} data.enable 是否支持自定义导航栏
|
|
5
|
-
* @returns {Number} data.statusBarHeight 状态栏高度,单位
|
|
6
|
-
* @returns {Number} data.navBarHeight 导航栏高度(不含状态栏),单位
|
|
7
|
-
* @returns {Number} data.menuTop 菜单按钮上边距,单位
|
|
8
|
-
* @returns {Number} data.menuRight 菜单按钮右边缘距离屏幕左边缘的距离,单位
|
|
9
|
-
* @returns {Number} data.menuWidth 菜单按钮宽度,单位
|
|
10
|
-
* @returns {Number} data.menuHeight 菜单按钮高度,单位
|
|
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也有不同)
|
|
11
162
|
*/
|
|
12
|
-
const getNavBarConfigData = () => {
|
|
13
|
-
const
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 };
|
|
24
193
|
};
|
|
25
194
|
|
|
26
195
|
export {
|