@tmsfe/tms-core 0.0.92 → 0.0.95
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 +7 -3
- package/src/cloudService.js +7 -0
- package/src/compareVersion.js +29 -0
- package/src/config.js +5 -4
- package/src/env.js +43 -14
- package/src/eventDispatcher.js +12 -5
- package/src/index-proxy.js +5 -2
- package/src/index.js +47 -12
- package/src/ipxHelper.js +7 -4
- package/src/location/base.ts +2 -0
- package/src/location/index.ts +30 -7
- package/src/location/utils.ts +5 -1
- package/src/log.js +13 -3
- package/src/md5.js +1 -4
- package/src/mpInfo.js +7 -1
- package/src/navbarUtils.js +9 -35
- package/src/navigator.js +2 -4
- package/src/numUtils.js +9 -6
- package/src/objUtils.js +3 -2
- package/src/report/clone.ts +3 -5
- package/src/report/formatV1.ts +1 -0
- package/src/report/formatV2.ts +1 -0
- package/src/report/helper.ts +2 -1
- package/src/report/index.ts +27 -4
- package/src/report/proxy/app.ts +1 -0
- package/src/report/proxy/component.ts +1 -0
- package/src/report/proxy/helper.ts +3 -2
- package/src/report/proxy/index.ts +1 -0
- package/src/report/proxy/page.ts +1 -0
- package/src/report/proxy/types.ts +1 -0
- package/src/report/sender.ts +1 -0
- package/src/request.js +1 -1
- package/src/rpx.js +7 -3
- package/src/runtime/car.js +4 -0
- package/src/runtime/index.js +43 -23
- package/src/runtime/{login.js → login.ts} +57 -2
- package/src/storage.js +13 -9
- package/src/stringUtils.js +8 -5
- package/src/syncfnmanager.js +3 -3
- package/src/timeUtils.js +25 -31
- package/tmsdoc.config.js +12 -0
- package/tsconfig.json +29 -27
package/src/navbarUtils.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 获取导航高度的相关函数
|
|
3
|
+
*/
|
|
4
|
+
import { compareVersion } from './compareVersion';
|
|
1
5
|
let systemInfo = null;
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
|
-
*
|
|
5
|
-
* 返回数据同wx.getSystemInfoSync
|
|
8
|
+
* 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
|
|
6
9
|
* @returns {Object} 系统信息
|
|
7
10
|
*/
|
|
8
11
|
const getSystemInfoSync = () => {
|
|
@@ -18,7 +21,7 @@ const getSystemInfoSync = () => {
|
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
24
|
+
* 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
|
|
22
25
|
* @returns {Object} 系统信息
|
|
23
26
|
*/
|
|
24
27
|
const getSysInfo = () => {
|
|
@@ -34,7 +37,7 @@ const getSysInfo = () => {
|
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
40
|
+
* 获取胶囊位置信息,返回数据同wx.getMenuButtonBoundingClientRect {@link https://developers.weixin.qq.com/miniprogram/dev/api/ui/menu/wx.getMenuButtonBoundingClientRect.html}
|
|
38
41
|
* @returns {Object} 胶囊位置信息
|
|
39
42
|
*/
|
|
40
43
|
const getMenuButtonRectInfo = () => {
|
|
@@ -51,38 +54,9 @@ const getMenuButtonRectInfo = () => {
|
|
|
51
54
|
return menuButtonRectInfo;
|
|
52
55
|
};
|
|
53
56
|
|
|
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
57
|
/**
|
|
85
58
|
* 胶囊高度适配,以兼容获取到的胶囊高度值非法的情况
|
|
59
|
+
* @private
|
|
86
60
|
* @param {Number} height 胶囊高度
|
|
87
61
|
* @param {Boolean} isIOS 是否是ios系统
|
|
88
62
|
* @returns {Number} 胶囊高度
|
|
@@ -97,6 +71,7 @@ const formatMenuHeight = (height, isIOS) => {
|
|
|
97
71
|
|
|
98
72
|
/**
|
|
99
73
|
* 计算自定义导航栏布局信息
|
|
74
|
+
* @private
|
|
100
75
|
* @param {Boolean} isIOS 是否是ios平台
|
|
101
76
|
* @param {Number} statusBarHeight 状态栏高度
|
|
102
77
|
* @param {String} apiCategory API类别
|
|
@@ -194,5 +169,4 @@ const getEnterOptions = () => {
|
|
|
194
169
|
|
|
195
170
|
export {
|
|
196
171
|
getNavBarConfigData,
|
|
197
|
-
compareVersion,
|
|
198
172
|
};
|
package/src/navigator.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* @
|
|
3
|
+
* @desc: 小程序跳转相关方法
|
|
4
4
|
* @author Davislu <davislu@tencent.com>
|
|
5
|
-
* @brief navigator provides some function to navigate pages in miniprogram.
|
|
6
|
-
*
|
|
7
5
|
*/
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -26,7 +24,7 @@ const DEFN = () => {};
|
|
|
26
24
|
* @param {object} setting.navbar 页面导航栏设置
|
|
27
25
|
* @param {string} setting.navbar.frontColor 导航栏字体颜色
|
|
28
26
|
* @param {string} setting.navbar.backgroundColor 导航栏背景颜色
|
|
29
|
-
* @returns {
|
|
27
|
+
* @returns {void} 无返回值
|
|
30
28
|
*/
|
|
31
29
|
const navigateToWebview = ({ url: webUrl, complete = DEFN, message = DEFN, share = {}, navbar = {} }) => {
|
|
32
30
|
const page = '/modules/x/webcontainer/webcontainer';
|
package/src/numUtils.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 数字处理相关函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { roundStr } from './stringUtils';
|
|
2
6
|
/**
|
|
3
7
|
* 四舍五入(支持保留n位小数,n>=0)
|
|
4
|
-
* @param {any} x
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* 如果n的值包含小数部分,round处理时只关注n的整数部分值
|
|
8
|
+
* @param {any} x 原数字, 如果n不是合法数字或者无法转换为合法数字,round结果返回NaN
|
|
9
|
+
* @param {any} n 保留几位小数,默认0;
|
|
10
|
+
1. 如果n不是合法数字或者无法转换为合法数字,round结果返回NaN;
|
|
11
|
+
2. 如果n小于0,round结果返回NaN;
|
|
12
|
+
3. 如果n的值包含小数部分,round处理时只关注n的整数部分值
|
|
10
13
|
* @return {number} 返回一个保留n位小数的数字,异常情况下可能是NaN
|
|
11
14
|
*/
|
|
12
15
|
const round = (x, n = 0) => parseFloat(roundStr(x, n, false));
|
package/src/objUtils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Description: Some Functions for Obejct.
|
|
2
|
+
* @desc: 对象处理相关函数
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -32,6 +31,8 @@ export class JsonParseError extends Error {
|
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* 安全的JSON.parse
|
|
34
|
+
* @param {object} data JSON.parse的对象
|
|
35
|
+
* @param {boolean} throwErrIfParseFail 如果解析失败,是否抛出错误
|
|
35
36
|
*/
|
|
36
37
|
export function safeJsonParse(data, throwErrIfParseFail = false) {
|
|
37
38
|
try {
|
package/src/report/clone.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 负责对象的克隆
|
|
3
|
+
* @private: true
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
const maxArrLen = 10;
|
|
@@ -13,8 +14,8 @@ const fieldWhiteList = [
|
|
|
13
14
|
|
|
14
15
|
function isBasicsType(obj: any, isConstraintLen = true): { isBasics: boolean, value: any } {
|
|
15
16
|
const type = typeof obj;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const arr1 = ['number', 'boolean', 'bigint'];
|
|
18
|
+
if (obj === null || obj === undefined || arr1.includes(type)) {
|
|
18
19
|
return { isBasics: true, value: obj };
|
|
19
20
|
}
|
|
20
21
|
if (type === 'string') {
|
|
@@ -67,9 +68,6 @@ function deepClone(obj: any, depth = 0, maxDepth = 5): any {
|
|
|
67
68
|
}
|
|
68
69
|
const value = obj[name];
|
|
69
70
|
const isConstraintLen = !fieldWhiteList.includes(name);
|
|
70
|
-
if (!isConstraintLen) {
|
|
71
|
-
debugger
|
|
72
|
-
}
|
|
73
71
|
const res1 = isBasicsType(value, isConstraintLen);
|
|
74
72
|
if (res1.isBasics) {
|
|
75
73
|
// @ts-ignore
|
package/src/report/formatV1.ts
CHANGED
package/src/report/formatV2.ts
CHANGED
package/src/report/helper.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 埋点辅助函数
|
|
3
|
+
* @private: true
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
// / <reference path='./types.ts'/>
|
|
@@ -8,7 +9,7 @@ import clone from './clone';
|
|
|
8
9
|
|
|
9
10
|
function getTms(): any {
|
|
10
11
|
// 如果是在app.js的onLaunch中调用,则没有getApp().tms为空
|
|
11
|
-
return getApp()?.tms || wx.tms;
|
|
12
|
+
return getApp()?.tms || (wx as any).tms;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
let initOptions: IInitOptions;
|
package/src/report/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @desc: 埋点上报
|
|
3
|
+
* @module: report
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
// / <reference path='./types.ts'/>
|
|
@@ -10,6 +11,7 @@ import formatV2 from './formatV2';
|
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* 初始化
|
|
14
|
+
* @private
|
|
13
15
|
*/
|
|
14
16
|
function init(options: IInitOptions): void {
|
|
15
17
|
helper.init(options);
|
|
@@ -17,7 +19,9 @@ function init(options: IInitOptions): void {
|
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* 旧埋点
|
|
20
|
-
* @param
|
|
22
|
+
* @param { object } data 上报对象
|
|
23
|
+
* @example
|
|
24
|
+
* report({ 27: xxxx, 34: xxx })
|
|
21
25
|
*/
|
|
22
26
|
function report(data: IOldParams = {}): void {
|
|
23
27
|
if (helper.canReport()) {
|
|
@@ -27,7 +31,9 @@ function report(data: IOldParams = {}): void {
|
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* 旧埋点,快速上报,不依赖用户位置
|
|
30
|
-
* @param
|
|
34
|
+
* @param { object } data 上报对象
|
|
35
|
+
* @example
|
|
36
|
+
* fastReport({ 27: xxxx, 34: xxx })
|
|
31
37
|
*/
|
|
32
38
|
function fastReport(data: IOldParams = {}): void {
|
|
33
39
|
if (helper.canReport()) {
|
|
@@ -38,6 +44,14 @@ function fastReport(data: IOldParams = {}): void {
|
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* 新埋点
|
|
47
|
+
* @param {string} 参数1 页面|组件的唯一标志
|
|
48
|
+
* @param {any} 参数2 埋点属性(会埋在埋点31个字段)
|
|
49
|
+
* @param {any} 参数3 埋点属性(会埋在埋点32个字段) 依次类推参数4、参数5,最多10个参数
|
|
50
|
+
* @returns {void}
|
|
51
|
+
* @example
|
|
52
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
53
|
+
* const reporter = tms.getReporter();
|
|
54
|
+
* reporter.report2('user_security_level', {}, {});
|
|
41
55
|
*/
|
|
42
56
|
function report2(...data: any[]): void {
|
|
43
57
|
if (helper.canReport()) {
|
|
@@ -46,7 +60,16 @@ function report2(...data: any[]): void {
|
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
/**
|
|
49
|
-
*
|
|
63
|
+
* 新埋点,埋点需要立即上报,不依赖用户位置,
|
|
64
|
+
* fastReport2()上报时携带的"省"、"市"等需要异步请求的基础字段会从缓存中读取,如果无缓存则为空,report2()则一定会携带这些字段
|
|
65
|
+
* @param {string} 参数1 页面|组件的唯一标志
|
|
66
|
+
* @param {any} 参数2 埋点属性(会埋在埋点31个字段)
|
|
67
|
+
* @param {any} 参数3 埋点属性(会埋在埋点32个字段) 依次类推参数4、参数5,最多10个参数
|
|
68
|
+
* @returns {void}
|
|
69
|
+
* @example
|
|
70
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
71
|
+
* const reporter = tms.getReporter();
|
|
72
|
+
* reporter.fastReport2('user_security_level', {}, {});
|
|
50
73
|
*/
|
|
51
74
|
function fastReport2(...data: any[]): void {
|
|
52
75
|
if (helper.canReport()) {
|
package/src/report/proxy/app.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 全埋点辅助类
|
|
3
|
+
* @private: true
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
// / <reference path='./types.ts'/>
|
|
6
7
|
|
|
7
8
|
function getReporter(): any {
|
|
8
9
|
// 如果是在app.js的onLaunch中调用,则没有getApp().tms为空
|
|
9
|
-
const tms = getApp()?.tms || wx.tms;
|
|
10
|
+
const tms = getApp()?.tms || (wx as any).tms;
|
|
10
11
|
return tms.getReporter();
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -56,7 +57,7 @@ function setLastBindEvent(info: IBindEvent): void {
|
|
|
56
57
|
const pages = getCurrentPages().reverse();
|
|
57
58
|
const page = pages.find((t: any) => t) || {};
|
|
58
59
|
// eslint-disable-next-line
|
|
59
|
-
info.pageUrl = page.route;
|
|
60
|
+
info.pageUrl = (page as any).route;
|
|
60
61
|
lastBindEvent = info;
|
|
61
62
|
}
|
|
62
63
|
|
package/src/report/proxy/page.ts
CHANGED
package/src/report/sender.ts
CHANGED
package/src/request.js
CHANGED
package/src/rpx.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: pr\rpx互相转化
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import syncApi from './syncfnmanager';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* @description rpx to px
|
|
5
9
|
* @param {Number} rpx 需要转换的rpx数值
|
|
6
|
-
* @returns {Number} 转换后的
|
|
10
|
+
* @returns {Number} 转换后的px数值
|
|
7
11
|
*/
|
|
8
12
|
const rpxToPx = (rpx) => {
|
|
9
13
|
const sys = syncApi.getSystemInfoSync();
|
|
@@ -14,8 +18,8 @@ const rpxToPx = (rpx) => {
|
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* @description px to rpx
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
21
|
+
* @param {Number} px 需要转换的px数值
|
|
22
|
+
* @returns {Number} 转换后的rpx数值
|
|
19
23
|
*/
|
|
20
24
|
const pxToRpx = (px) => {
|
|
21
25
|
const sys = syncApi.getSystemInfoSync();
|
package/src/runtime/car.js
CHANGED
package/src/runtime/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @copyright 2021-present, Tencent, Inc. All rights reserved.
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
5
|
+
* @module: runtime-index
|
|
6
|
+
* @desc: 集成业务通用接口(登录、车辆、微信支付分)
|
|
7
7
|
*/
|
|
8
8
|
import Login from './login';
|
|
9
9
|
import Car from './car';
|
|
10
10
|
import getOpenAppTrafficData from './getopenapptrafficdata';
|
|
11
11
|
|
|
12
|
-
const { loginFn, getOpenId, getMycarPubOpenId, getSinanPubOpenId, getPhone } = Login;
|
|
12
|
+
const { loginFn, getOpenId, getMycarPubOpenId, getSinanPubOpenId, getPhone, registerPhone } = Login;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* __resolver__ 用于维护 app.tms.fn 中数据的填充
|
|
@@ -74,14 +74,15 @@ const login = async () => {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param {
|
|
79
|
-
* @param {
|
|
80
|
-
* @param { param.
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {
|
|
77
|
+
* 设置微信支付分授权
|
|
78
|
+
* @param {Object} params对象类型 以下是params的解释
|
|
79
|
+
* @param {Number}params.traceSource 请求来源: 1-订单 2-支付网关 3-车机网关 4-开放平台 6-分账
|
|
80
|
+
* @param {String } param.subMchId 商户id
|
|
81
|
+
* @param {Number} params.bussClassify 请求来源: 1-洗车 2-停车 12-代驾 24-租车 13-保养 3-加油
|
|
82
|
+
* @param {Number} params.payChannel 请求来源: 1-小程序 2-车机 3-小场景 4-开放平台 5-H5
|
|
83
|
+
* @param {String} params.wechaId 公众号id,支付分授权相关一般都用我的车的车公众号
|
|
84
|
+
* @param {String} params.subAppId 小程序的id,支付分授权相关一般都用我的车小程序id
|
|
85
|
+
* @param {String} params.openId 用户在我的车公众号下面的id
|
|
85
86
|
* @returns { object } { state: 1, errMsg: 200, errMsg: '', errData: '' }
|
|
86
87
|
*/
|
|
87
88
|
async function setPaypointAuth(param = {}) {
|
|
@@ -130,8 +131,9 @@ function getRequestInstnce() {
|
|
|
130
131
|
|
|
131
132
|
/**
|
|
132
133
|
* 获取微信支付分授权
|
|
133
|
-
* @param {
|
|
134
|
-
* @param {
|
|
134
|
+
* @param {Object} params对象类型 以下是params的解释
|
|
135
|
+
* @param {Number} params.traceSource 请求来源: 1-订单 2-支付网关 3-车机网关 4-开放平台 6-分账
|
|
136
|
+
* @param {Number} param.payChannel 请求来源: 1-小程序 2-车机 3-小场景 4-开放平台 5-H5
|
|
135
137
|
* @returns { object } { errMsg: 200, errMsg: '', errData: '' }
|
|
136
138
|
*/
|
|
137
139
|
async function getPermissionList(param = {}) {
|
|
@@ -150,13 +152,14 @@ async function getPermissionList(param = {}) {
|
|
|
150
152
|
|
|
151
153
|
/**
|
|
152
154
|
* 获取微信支付分授权
|
|
153
|
-
* @param {
|
|
154
|
-
* @param {
|
|
155
|
-
* @param {
|
|
156
|
-
* @param {
|
|
157
|
-
* @param {
|
|
158
|
-
* @param {
|
|
159
|
-
* @param {
|
|
155
|
+
* @param {Object} params对象类型 以下是params的解释
|
|
156
|
+
* @param {Number} params.traceSource 请求来源: 1-订单 2-支付网关 3-车机网关 4-开放平台 6-分账
|
|
157
|
+
* @param {String} params.subMchId 商户id
|
|
158
|
+
* @param {Number} params.bussClassify请求来源: 1-洗车 2-停车 12-代驾 24-租车 13-保养 3-加油
|
|
159
|
+
* @param {Number} params.payChannel请求来源: 1-小程序 2-车机 3-小场景 4-开放平台 5-H5
|
|
160
|
+
* @param {String} params.wechaId 公众号id,支付分授权相关一般都用我的车的车公众号
|
|
161
|
+
* @param {String} params.subAppId小程序的id,支付分授权相关一般都用我的车小程序id
|
|
162
|
+
* @param {String} params.openId用户在我的车公众号下面的id
|
|
160
163
|
* @returns { object } { state: 1, errMsg: 200, errMsg: '', errData: '' }
|
|
161
164
|
*/
|
|
162
165
|
async function terminatePaypointPermisson(param = {}) {
|
|
@@ -183,9 +186,10 @@ async function terminatePaypointPermisson(param = {}) {
|
|
|
183
186
|
|
|
184
187
|
/**
|
|
185
188
|
* 获取用户在某个业务中是否授权
|
|
186
|
-
* @param {
|
|
187
|
-
* @param {
|
|
188
|
-
* @param {
|
|
189
|
+
* @param {Object} params对象类型 以下是params的解释
|
|
190
|
+
* @param {Number} params.traceSource 请求来源: 1-订单 2-支付网关 3-车机网关 4-开放平台 6-分账
|
|
191
|
+
* @param {Number} params.bussClassify 请求来源: 1-洗车 2-停车 12-代驾 24-租车 13-保养 3-加油
|
|
192
|
+
* @param {Number} params.payChannel 请求来源: 1-小程序 2-车机 3-小场景 4-开放平台 5-H5
|
|
189
193
|
* @returns { object } { state: 1, errMsg: 200, errMsg: '', errData: '' }
|
|
190
194
|
*/
|
|
191
195
|
async function queryServicePermissions(param = {}) {
|
|
@@ -203,8 +207,24 @@ async function queryServicePermissions(param = {}) {
|
|
|
203
207
|
return res;
|
|
204
208
|
}
|
|
205
209
|
|
|
210
|
+
/**
|
|
211
|
+
* @namespace runtimeapi
|
|
212
|
+
* @description 对外暴露的api
|
|
213
|
+
* @param {Function} getPhone 获取手机号
|
|
214
|
+
* @param {Function} login... 详见跳转[runtime-login](#runtime-login)
|
|
215
|
+
* @param {Function} getLoginInfo 返回 loginInfoPromise
|
|
216
|
+
* @param {Function} getOpenId 获取openId 详见跳转[runtime-login](#runtime-login)
|
|
217
|
+
* @param {Function} getMycarPubOpenId 获取用户在我的车公众号下的openId 详见跳转[runtime-login](#runtime-login)
|
|
218
|
+
* @param {Function} getSinanPubOpenId 获取用户在出行服务公众号下的openId 详见跳转[runtime-login](#runtime-login)
|
|
219
|
+
* @param {Function} getCarManager 用户获取小程序统一维护的车信息管理器,详见跳转 [runtimt-car](#runtime-car)
|
|
220
|
+
* @param {Function} setPaypointAuth 设置微信支付分授权
|
|
221
|
+
* @param {Function} getPermissionList 获取微信支付分授权
|
|
222
|
+
* @param {Function} terminatePaypointPermisson 获取微信支付分授权
|
|
223
|
+
* @param {Function} queryServicePermissions 获取用户在某个业务中是否授权
|
|
224
|
+
*/
|
|
206
225
|
const api = {
|
|
207
226
|
getPhone,
|
|
227
|
+
registerPhone,
|
|
208
228
|
login,
|
|
209
229
|
getLoginInfo,
|
|
210
230
|
getOpenId,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable valid-jsdoc */
|
|
2
2
|
/**
|
|
3
3
|
* @copyright 2021-present, Tencent, Inc. All rights reserved.
|
|
4
|
+
* @module: runtime-login
|
|
5
|
+
* @desc: 登录相关
|
|
4
6
|
* @brief login.js 用于维护 runtime 框架的用户登录流程,获取用户的登录的可信凭证.
|
|
5
7
|
* runtime初始化时,会调用登录流程,基于runtime的后续业务代码,不必关注用户的登录状态,
|
|
6
8
|
* 当前,登录流程仅支持【腾讯出行服务小程序】,我们计划支持出行服务公众号的H5开发,基于runtime的
|
|
@@ -18,6 +20,12 @@
|
|
|
18
20
|
|
|
19
21
|
import getOpenAppTrafficData from './getopenapptrafficdata';
|
|
20
22
|
|
|
23
|
+
interface PhoneRegisterResult {
|
|
24
|
+
success: boolean,
|
|
25
|
+
phone: string,
|
|
26
|
+
errMsg: string,
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
/**
|
|
22
30
|
* 调用wx.login获取登录code
|
|
23
31
|
* @private
|
|
@@ -63,11 +71,15 @@ const loginFn = async () => {
|
|
|
63
71
|
* @returns { object } resData 用户信息
|
|
64
72
|
*/
|
|
65
73
|
async function login() {
|
|
66
|
-
let userData
|
|
74
|
+
let userData: {
|
|
75
|
+
errCode?: any,
|
|
76
|
+
resData?: any
|
|
77
|
+
} = {};
|
|
67
78
|
|
|
68
79
|
try {
|
|
69
80
|
const code = await getCode();
|
|
70
81
|
|
|
82
|
+
// @ts-ignore
|
|
71
83
|
const { trafficEntrence: registerSource, scene: sceneId } = getOpenAppTrafficData();
|
|
72
84
|
|
|
73
85
|
userData = await getApp().tms.createRequest({ withAuth: false }).post('user/login', { code, registerSource, sceneId });
|
|
@@ -93,6 +105,7 @@ const getOpenId = async () => {
|
|
|
93
105
|
return getOpenIdProm;
|
|
94
106
|
}
|
|
95
107
|
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
96
109
|
getOpenIdProm = new Promise(async (resolve, reject) => {
|
|
97
110
|
getApp().tms.callCloudFunc('user', { $url: 'user/getOpenId' })
|
|
98
111
|
.then((res) => {
|
|
@@ -192,15 +205,57 @@ const getSinanPubOpenId = () => {
|
|
|
192
205
|
const getPhone = () => getApp().tms.createRequest({ withAuth: true }).post('user/phone/fetch')
|
|
193
206
|
.then((res) => {
|
|
194
207
|
if (res && res.errCode === 0) {
|
|
195
|
-
return (res.resData
|
|
208
|
+
return (res.resData?.phoneno) || '';
|
|
196
209
|
}
|
|
197
210
|
return Promise.reject(res);
|
|
198
211
|
});
|
|
199
212
|
|
|
213
|
+
/**
|
|
214
|
+
* @description 绑定手机号
|
|
215
|
+
* @param {Object} data params 加密数据对象
|
|
216
|
+
* @param {string} data.encryptedData button组件bindgetphonenumber事件返回的encryptedData字段
|
|
217
|
+
* @param {string} data.iv button组件bindgetphonenumber事件返回的iv字段
|
|
218
|
+
* @returns {Object} data 绑定结果回调
|
|
219
|
+
* @returns {number} data.success 是否绑定成功 boolean类型
|
|
220
|
+
* @returns {number} data.phone 绑定成功时的手机号,失败则为空
|
|
221
|
+
* @returns {number} data.errMsg 绑定结果描述信息
|
|
222
|
+
* @example
|
|
223
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
224
|
+
* const res = await tms.registerPhone({ encryptedData, iv })
|
|
225
|
+
* if(res.success) {
|
|
226
|
+
* console.log('phone', res.phone)
|
|
227
|
+
* } else {
|
|
228
|
+
* // 注册失败处理逻辑
|
|
229
|
+
* console.log(res.errMsg)
|
|
230
|
+
* }
|
|
231
|
+
*/
|
|
232
|
+
async function registerPhone({ encryptedData, iv }: {encryptedData: string, iv: string}): Promise<PhoneRegisterResult> {
|
|
233
|
+
try {
|
|
234
|
+
const result = await getApp().tms.createRequest().post('user/phone/regist', {
|
|
235
|
+
iv,
|
|
236
|
+
isCipher: 1,
|
|
237
|
+
phoneno: encryptedData,
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
success: result.errCode === 0,
|
|
241
|
+
phone: result.errCode === 0 ? result.resData.phoneno : '',
|
|
242
|
+
errMsg: result.errMsg,
|
|
243
|
+
};
|
|
244
|
+
} catch (error: any) {
|
|
245
|
+
console.error(error);
|
|
246
|
+
return {
|
|
247
|
+
success: false,
|
|
248
|
+
phone: '',
|
|
249
|
+
errMsg: '绑定失败',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
200
254
|
const runtimeObj = {
|
|
201
255
|
loginFn,
|
|
202
256
|
getOpenId,
|
|
203
257
|
getPhone,
|
|
258
|
+
registerPhone,
|
|
204
259
|
getMycarPubOpenId,
|
|
205
260
|
getSinanPubOpenId,
|
|
206
261
|
};
|
package/src/storage.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 处理localstorage相关函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* 保存数据到localstorage
|
|
3
7
|
* @param key
|
|
@@ -17,7 +21,7 @@ function setItem(key, data) {
|
|
|
17
21
|
* 从localstorage取数据
|
|
18
22
|
* @param key
|
|
19
23
|
* @param defaultValue wx接口报错时返回默认值
|
|
20
|
-
* @returns {
|
|
24
|
+
* @returns {any}
|
|
21
25
|
*/
|
|
22
26
|
function getItem(key, defaultValue = null) {
|
|
23
27
|
try {
|
|
@@ -60,10 +64,10 @@ function cleanTask() {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/**
|
|
63
|
-
* 缓存组件或页面的缓存data
|
|
64
|
-
* @param key
|
|
65
|
-
* @param version
|
|
66
|
-
* @param data
|
|
67
|
+
* 缓存组件或页面的缓存data,会缓存到localStorage里
|
|
68
|
+
* @param {string} key localStorage的唯一标志
|
|
69
|
+
* @param {string} version 版本号,低于该版本号的缓存会被异步清除
|
|
70
|
+
* @param {object} data 页面缓存的数据
|
|
67
71
|
* @returns {boolean}
|
|
68
72
|
*/
|
|
69
73
|
function setCacheData(key, version, data) {
|
|
@@ -81,10 +85,10 @@ function setCacheData(key, version, data) {
|
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
87
|
* 获取组件或页面的缓存data
|
|
84
|
-
* @param key
|
|
85
|
-
* @param version
|
|
86
|
-
* @param defaultData
|
|
87
|
-
* @returns {
|
|
88
|
+
* @param {string} key localStorage的唯一标志
|
|
89
|
+
* @param {string} version 版本号
|
|
90
|
+
* @param {object} defaultData 接口报错时返回默认值
|
|
91
|
+
* @returns {any}
|
|
88
92
|
*/
|
|
89
93
|
function getCacheData(key, version, defaultData = null) {
|
|
90
94
|
const str = `${key}_v${version}`;
|