@tmsfe/tms-core 0.0.76 → 0.0.79
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 +2 -0
- package/src/index.js +2 -0
- package/src/mpInfo.js +10 -3
- package/src/report/proxy/page.ts +32 -0
- package/src/tmsuiUtils.js +68 -0
package/package.json
CHANGED
package/src/index-proxy.js
CHANGED
|
@@ -11,6 +11,7 @@ import md5 from './md5';
|
|
|
11
11
|
import { serialize } from './objUtils';
|
|
12
12
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
13
13
|
import { getNavBarConfigData } from './navbarUtils';
|
|
14
|
+
import * as uiUtil from './tmsuiUtils';
|
|
14
15
|
import * as rpxUtil from './rpx';
|
|
15
16
|
import * as stringUtils from './stringUtils';
|
|
16
17
|
import * as timeUtils from './timeUtils';
|
|
@@ -221,6 +222,7 @@ const api = {
|
|
|
221
222
|
getHomePage,
|
|
222
223
|
storage,
|
|
223
224
|
...rpxUtil,
|
|
225
|
+
...uiUtil,
|
|
224
226
|
...asyncFuncs,
|
|
225
227
|
...objFuncs,
|
|
226
228
|
...syncApi,
|
package/src/index.js
CHANGED
|
@@ -45,6 +45,7 @@ import getLocInstance from './location/index';
|
|
|
45
45
|
import LocationBase from './location/base';
|
|
46
46
|
import { getMpOpenId, getOuterOpenId, getEncryptUserInfo } from './mpInfo';
|
|
47
47
|
import * as storage from './storage';
|
|
48
|
+
import * as uiUtil from './tmsuiUtils';
|
|
48
49
|
import { throttle, debounce } from './funcUtils';
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -200,6 +201,7 @@ const api = {
|
|
|
200
201
|
storage,
|
|
201
202
|
|
|
202
203
|
...syncApi,
|
|
204
|
+
...uiUtil,
|
|
203
205
|
throttle,
|
|
204
206
|
debounce,
|
|
205
207
|
};
|
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/report/proxy/page.ts
CHANGED
|
@@ -139,9 +139,41 @@ function proxyNavigateApi(api: string): void {
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// 劫持消息订阅接口
|
|
143
|
+
function proxySubscribeMessage(): void {
|
|
144
|
+
const originalApi = wx.requestSubscribeMessage;
|
|
145
|
+
Object.defineProperty(wx, 'requestSubscribeMessage', {
|
|
146
|
+
writable: true,
|
|
147
|
+
enumerable: true,
|
|
148
|
+
configurable: true,
|
|
149
|
+
value(options: any) {
|
|
150
|
+
const { tmplIds } = options;
|
|
151
|
+
const originalSuccess = options.success || helper.emptyFunc;
|
|
152
|
+
const originalFail = options.fail || helper.emptyFunc;
|
|
153
|
+
// eslint-disable-next-line
|
|
154
|
+
options.success = function(res: any) {
|
|
155
|
+
for (const tmplId of tmplIds) {
|
|
156
|
+
const result = res[tmplId];
|
|
157
|
+
if (result) {
|
|
158
|
+
helper.reportData('wx_requestSubscribeMessage_result', tmplId, result);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
originalSuccess.call(this, res);
|
|
162
|
+
};
|
|
163
|
+
// eslint-disable-next-line
|
|
164
|
+
options.fail = function(err: any) {
|
|
165
|
+
helper.reportData('wx_requestSubscribeMessage_fail', tmplIds, err.errMsg);
|
|
166
|
+
originalFail.fail(this, err);
|
|
167
|
+
};
|
|
168
|
+
originalApi.call(this, options);
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
142
173
|
// 劫持Page
|
|
143
174
|
function init(): void {
|
|
144
175
|
proxyPage();
|
|
176
|
+
proxySubscribeMessage();
|
|
145
177
|
proxyNavigateApi('navigateTo');
|
|
146
178
|
proxyNavigateApi('redirectTo');
|
|
147
179
|
proxyNavigateApi('reLaunch');
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* 从当前页面中选定组件
|
|
4
|
+
* @param {String} selector 元素选择器
|
|
5
|
+
* @returns {Element} 组件
|
|
6
|
+
*/
|
|
7
|
+
const selectCompFromCurPage = (selector) => {
|
|
8
|
+
const pages = getCurrentPages();
|
|
9
|
+
if (pages.length === 0) {
|
|
10
|
+
throw new Error('Empty page container found');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const context = pages[pages.length - 1];
|
|
14
|
+
const comp = context.selectComponent(selector);
|
|
15
|
+
if (!comp) {
|
|
16
|
+
throw new Error(`No component found with selector <${selector}>`);
|
|
17
|
+
}
|
|
18
|
+
return comp;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/* eslint-disable */
|
|
22
|
+
const showDrawer = (options = {}, selectComp = selectCompFromCurPage) => {
|
|
23
|
+
const { selector = '#drawer' } = options;
|
|
24
|
+
const comp = selectComp(selector);
|
|
25
|
+
comp?.show(options);
|
|
26
|
+
};
|
|
27
|
+
const hideDrawer = (options = {}, selectComp = selectCompFromCurPage) => {
|
|
28
|
+
const { selector = '#drawer' } = options;
|
|
29
|
+
const comp = selectComp(selector);
|
|
30
|
+
comp?.hide(options);
|
|
31
|
+
};
|
|
32
|
+
/* eslint-disable */
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 显示或隐藏Modal
|
|
36
|
+
* @param {Boolean} display 展示/隐藏
|
|
37
|
+
* @param {Object} options Modal参数
|
|
38
|
+
* @param {Function} selectComp 选择组件的方法
|
|
39
|
+
* @returns {void}
|
|
40
|
+
*/
|
|
41
|
+
const toggleModal = (display = true, options = {}, selectComp) => {
|
|
42
|
+
const { selector = '#modal' } = options;
|
|
43
|
+
try {
|
|
44
|
+
const comp = selectComp(selector);
|
|
45
|
+
if (display) {
|
|
46
|
+
comp.show(options);
|
|
47
|
+
} else {
|
|
48
|
+
comp.hide(options);
|
|
49
|
+
}
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (typeof options.fail === 'function') {
|
|
52
|
+
options.fail({ errMsg: e.toString() });
|
|
53
|
+
} else {
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
if (typeof options.complete === 'function') {
|
|
57
|
+
options.complete({ success: false, errMsg: e.toString() });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const showModal = (options, selectComp = selectCompFromCurPage) => toggleModal(true, options, selectComp);
|
|
63
|
+
const hideModal = (options, selectComp = selectCompFromCurPage) => toggleModal(false,options, selectComp);
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
showDrawer, hideDrawer,
|
|
67
|
+
showModal, hideModal,
|
|
68
|
+
};
|