@tmsfe/tms-core 0.0.94 → 0.0.96
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 +45 -4
- package/src/env.js +43 -14
- package/src/eventDispatcher.js +12 -5
- package/src/index-proxy.js +5 -2
- package/src/index.js +49 -13
- package/src/ipxHelper.js +7 -4
- package/src/location/base.ts +26 -4
- 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 +5 -4
- 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 +34 -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 +39 -15
- package/src/rpx.js +7 -3
- package/src/runtime/car.js +4 -0
- package/src/runtime/index.js +41 -22
- package/src/runtime/login.ts +24 -3
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tms-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.96",
|
|
4
4
|
"description": "tms运行时框架",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "rimraf dist && rollup -wc --environment TARGET:tms-core,INTER_ENV:public",
|
|
11
|
-
"build": "rimraf dist && rollup -c --environment TARGET:tms-core,INTER_ENV:public"
|
|
11
|
+
"build": "rimraf dist && rollup -c --environment TARGET:tms-core,INTER_ENV:public",
|
|
12
|
+
"tsc": "npx tsc",
|
|
13
|
+
"docs": "npx tsc && npx jsdocmd exec -c ./tmsdoc.config.js"
|
|
12
14
|
},
|
|
13
15
|
"main": "src/index",
|
|
14
16
|
"miniprogram": "src",
|
|
@@ -35,7 +37,9 @@
|
|
|
35
37
|
"rollup": "^2.6.1",
|
|
36
38
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
37
39
|
"rollup-plugin-terser": "^6.1.0",
|
|
38
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
40
|
+
"rollup-plugin-typescript2": "0.27.0",
|
|
41
|
+
"typescript": "^4.5.4",
|
|
42
|
+
"@tmsfe/jsdocmd": "0.0.2"
|
|
39
43
|
},
|
|
40
44
|
"author": "tms·web",
|
|
41
45
|
"gitHead": "72bf52451594b49a1c9f78edbad5956d414a66ca"
|
package/src/cloudService.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 小程序调用云函数相关方法
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { getEnvInfo, getAuthInfo } from './env';
|
|
2
6
|
|
|
3
7
|
/**
|
|
@@ -6,6 +10,9 @@ import { getEnvInfo, getAuthInfo } from './env';
|
|
|
6
10
|
* @param {Object} data 需要传给云函数的参数
|
|
7
11
|
* @param {Boolean} withAuth 是否需要补充userId,token参数,当云函数需要调用SinanServer时,需要这些参数来完成鉴权
|
|
8
12
|
* @returns {viod} 云函数
|
|
13
|
+
* @example
|
|
14
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
15
|
+
* tms.callCloudFunc('user', { $url: 'user/getState', ...param }, true).then(({ result }) => result)
|
|
9
16
|
*/
|
|
10
17
|
export const callCloudFunc = async (name = '', data = {}, withAuth = true) => {
|
|
11
18
|
const { cloudEnvId, appVersion } = getEnvInfo();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本比较函数
|
|
3
|
+
* @param {String} sourceVersion 作为基准版本号
|
|
4
|
+
* @param {String} targetVersion 目标比较版本号
|
|
5
|
+
* @returns {Number} 比较结果
|
|
6
|
+
* 返回值说明:
|
|
7
|
+
* 1 : 大于基准版本号
|
|
8
|
+
* 0 : 等于基准版本号
|
|
9
|
+
* -1: 小于基准版本号
|
|
10
|
+
*/
|
|
11
|
+
export const compareVersion = (sourceVersion, targetVersion) => {
|
|
12
|
+
if (typeof sourceVersion !== 'string' || typeof targetVersion !== 'string') {
|
|
13
|
+
throw new Error('版本比较参数类型有误');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const toInt = n => parseInt(n, 10); // eslint-disable-line require-jsdoc
|
|
17
|
+
const sourceArray = sourceVersion.split('.').map(toInt);
|
|
18
|
+
const targetArray = targetVersion.split('.').map(toInt);
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < sourceArray.length; i += 1) {
|
|
21
|
+
if (sourceArray[i] > targetArray[i]) {
|
|
22
|
+
return 1;
|
|
23
|
+
} if (sourceArray[i] < targetArray[i]) {
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 0;
|
|
29
|
+
};
|
package/src/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @desc: 小程获取配置相关接口
|
|
3
3
|
*/
|
|
4
4
|
import Request from './request';
|
|
5
5
|
import { getEnvInfo } from './env';
|
|
@@ -27,12 +27,13 @@ const formatConfigPaths = (configPath) => {
|
|
|
27
27
|
/**
|
|
28
28
|
* getConfig 批量拉取配置
|
|
29
29
|
* @description 拉取运营平台上的配置内容。关于运营平台的具体用法,参见{@link https://iwiki.woa.com/pages/viewpage.action?pageId=527948584}
|
|
30
|
-
* @category 配置相关
|
|
31
30
|
* @example <caption>拉取单个配置</caption>
|
|
32
|
-
* const
|
|
31
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
32
|
+
* const cfg = await tms.getConfig('/${client}/violation/subscribe', {}, { title: '当前城市不支持订阅'})
|
|
33
33
|
* console.log(cfg); // 成功则返回服务端存储的配置,失败返回默认值
|
|
34
34
|
* @example <caption>批量拉取配置</caption>
|
|
35
|
-
const
|
|
35
|
+
const { tms } = getApp({ allowDefault: true });
|
|
36
|
+
const cfgs = await tms.getConfig([
|
|
36
37
|
'/${client}/home/service',
|
|
37
38
|
'/${client}/home/navbar',
|
|
38
39
|
], {}, [
|
|
@@ -86,6 +87,46 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/**
|
|
91
|
+
* getApolloConfig 获取阿波罗平台配置
|
|
92
|
+
* @description 拉取阿波罗的配置内容。参见{@link http://mapollo.woa.com/#/26fdbf3}
|
|
93
|
+
* @example <caption>拉取单个配置</caption>
|
|
94
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
95
|
+
* const cfg = await tms.getApolloConfig('sinan_me_faq', {}, { name: '默认配置'})
|
|
96
|
+
* console.log(cfg); // 成功则返回服务端存储的配置,失败返回默认值
|
|
97
|
+
* @param {String|Array} configPath 配置路径,单个路径或配置路径数组,支持替换${client}为当前小程序。例如在出行小程序,${client}会变替换为sinan
|
|
98
|
+
* @param {Object} extendAttr 扩展属性,用于自定义的过滤条件,保留字段 businessKey、moduleKey。
|
|
99
|
+
* @param {Object} [defaultCfg] 默认配置,请求失败返回默认值。
|
|
100
|
+
* @returns {Promise<Object|Array<Object>>}
|
|
101
|
+
* 有默认值时,请求失败返回默认值。无默认值时,请求失败返回Promise.reject
|
|
102
|
+
*/
|
|
103
|
+
function getApolloConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
104
|
+
const configPaths = formatConfigPaths(configPath);
|
|
105
|
+
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
106
|
+
const { businessKey, moduleKey, ...extendAttrs } = extendAttr;
|
|
107
|
+
const api = new Request();
|
|
108
|
+
return api.post('marketing/apollo/config', {
|
|
109
|
+
businessKey,
|
|
110
|
+
moduleKey,
|
|
111
|
+
configPaths,
|
|
112
|
+
extendAttrs: JSON.stringify(extendAttrs),
|
|
113
|
+
})
|
|
114
|
+
.then((res) => {
|
|
115
|
+
const { errCode, resData = {} } = res || {};
|
|
116
|
+
const { status, msg, data } = resData;
|
|
117
|
+
if (errCode === 0 && status === 0) {
|
|
118
|
+
return data.map(item => item.content);
|
|
119
|
+
}
|
|
120
|
+
throw new Error(msg);
|
|
121
|
+
})
|
|
122
|
+
.catch((e) => {
|
|
123
|
+
if (defaultCfgs) return Promise.resolve(defaultCfgs);
|
|
124
|
+
return Promise.reject({ err: e, msg: `获取${configPaths.join(',')}配置失败` });
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
89
128
|
export {
|
|
90
129
|
getConfig,
|
|
130
|
+
getApolloConfig,
|
|
91
131
|
};
|
|
132
|
+
|
package/src/env.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 小程序运行环境相关接口
|
|
3
|
+
*/
|
|
1
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @description 公共对象-环境变量env
|
|
7
|
+
* @namespace Env
|
|
8
|
+
* @param {String} wxAppId 当前运行时小程序的appId
|
|
9
|
+
* @param {String} appVersion 当前运行时所在项目的版本号
|
|
10
|
+
* @param {String} appEnv 运行环境 test - 测试、production - 正式
|
|
11
|
+
* @param {String} client 运行时项目名,sinan - 腾讯出行服务;
|
|
12
|
+
* @param {String} cloudEnvId 运行云函数的环境id
|
|
13
|
+
*/
|
|
2
14
|
const env = {
|
|
3
|
-
wxAppId: '',
|
|
4
|
-
appVersion: '',
|
|
5
|
-
appEnv: '',
|
|
6
|
-
client: '',
|
|
7
|
-
cloudEnvId: '',
|
|
15
|
+
wxAppId: '',
|
|
16
|
+
appVersion: '',
|
|
17
|
+
appEnv: '',
|
|
18
|
+
client: '',
|
|
19
|
+
cloudEnvId: '',
|
|
8
20
|
};
|
|
9
21
|
|
|
10
22
|
let baseAuthInfo = undefined;
|
|
@@ -12,9 +24,17 @@ const getAuthInfoQueue = [];
|
|
|
12
24
|
|
|
13
25
|
/**
|
|
14
26
|
* @description 设置用户信息
|
|
15
|
-
* @param {Object} authInfo
|
|
16
|
-
* @param {Object} err
|
|
27
|
+
* @param {Object} authInfo 用户登录状态信息
|
|
28
|
+
* @param {Object} err 当获取用户信息失败时,设置错误信息
|
|
17
29
|
* @returns {Void} 无返回值
|
|
30
|
+
* @example
|
|
31
|
+
* setAuthInfo({
|
|
32
|
+
firstLogin: 0
|
|
33
|
+
openId: "ou8xs5Uo4MHCETZ_P7IUwOAxvr-M"
|
|
34
|
+
token: "d8ffecd9317376bd1de3b49e1fa0e3bb"
|
|
35
|
+
uid: "407210826"
|
|
36
|
+
unionId: "oFghpwpqGK18ixIlNGy34Y28gCb0"
|
|
37
|
+
* })
|
|
18
38
|
*/
|
|
19
39
|
export const setAuthInfo = (authInfo, err) => {
|
|
20
40
|
baseAuthInfo = authInfo;
|
|
@@ -28,25 +48,34 @@ export const setAuthInfo = (authInfo, err) => {
|
|
|
28
48
|
}
|
|
29
49
|
};
|
|
30
50
|
/**
|
|
31
|
-
* 获取登录状态信息
|
|
32
|
-
* @returns {Object}
|
|
51
|
+
* @description 获取登录状态信息
|
|
52
|
+
* @returns {Object} 获取当前用户登录状态参数(见上)
|
|
53
|
+
* @example
|
|
54
|
+
* const data = await getAuthInfo()
|
|
55
|
+
{
|
|
56
|
+
firstLogin: 0 // 是否第一次登录
|
|
57
|
+
openId: "ou8xs5Uo4MHCETZ_P7IUwOAxvr-M"
|
|
58
|
+
token: "d8ffecd9317376bd1de3b49e1fa0e3bb"
|
|
59
|
+
uid: "407210826"
|
|
60
|
+
unionId: "oFghpwpqGK18ixIlNGy34Y28gCb0"
|
|
61
|
+
}
|
|
33
62
|
*/
|
|
34
63
|
export const getAuthInfo = async () => {
|
|
35
|
-
if (baseAuthInfo !== undefined)
|
|
64
|
+
if (baseAuthInfo !== undefined) {
|
|
36
65
|
return baseAuthInfo;
|
|
37
66
|
}
|
|
38
67
|
return new Promise((resolve, reject) => getAuthInfoQueue.push({ resolve, reject }));
|
|
39
68
|
};
|
|
40
69
|
|
|
41
70
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @returns {
|
|
71
|
+
* @description 用于获取运行时所在的环境信息
|
|
72
|
+
* @returns {Object} 运行时环境信息 (返回值见上Env:namepace)
|
|
44
73
|
*/
|
|
45
74
|
export const getEnvInfo = () => env;
|
|
46
75
|
/**
|
|
47
76
|
* 设置环境变量
|
|
48
|
-
* @param {
|
|
49
|
-
* @returns {
|
|
77
|
+
* @param {Object} 运行时环境信息 (入参见上Env:namepace)
|
|
78
|
+
* @returns {Void} 无.
|
|
50
79
|
*/
|
|
51
80
|
export const setEnvInfo = (envInfo) => {
|
|
52
81
|
const { wxAppId, appVersion, appEnv, client, cloudEnvId } = envInfo;
|
package/src/eventDispatcher.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/* eslint-disable require-jsdoc */
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* @desc: 自定义事件机制
|
|
3
|
+
* @desc: EventDispatcher 类 事件监听器
|
|
7
4
|
* @author: kexinwu@tencent.com
|
|
8
|
-
*
|
|
9
5
|
*/
|
|
10
6
|
|
|
11
7
|
/**
|
|
@@ -93,3 +89,14 @@ export default class EventDispatcher {
|
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @description 获取EventDispatcher的实例
|
|
95
|
+
* @returns {Object} [EventDispatcher实例](#class-eventdispatcher)
|
|
96
|
+
* @example
|
|
97
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
98
|
+
* const events = tms.getEventDispatcher();
|
|
99
|
+
* events.bind('xxx', () => {})
|
|
100
|
+
* events.dispatch({type: 'xxx'})
|
|
101
|
+
*/
|
|
102
|
+
export const getEventDispatcher = () => new EventDispatcher();
|
package/src/index-proxy.js
CHANGED
|
@@ -10,7 +10,8 @@ import AutoReport from './report/proxy/index';
|
|
|
10
10
|
import md5 from './md5';
|
|
11
11
|
import { serialize } from './objUtils';
|
|
12
12
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
13
|
-
import { getNavBarConfigData
|
|
13
|
+
import { getNavBarConfigData } from './navbarUtils';
|
|
14
|
+
import { compareVersion } from './compareVersion';
|
|
14
15
|
import * as uiUtil from './tmsuiUtils';
|
|
15
16
|
import * as rpxUtil from './rpx';
|
|
16
17
|
import * as stringUtils from './stringUtils';
|
|
@@ -67,7 +68,7 @@ const asyncFuncNames = [
|
|
|
67
68
|
// 这行是runtime的
|
|
68
69
|
'getPhone', 'registerPhone', 'login', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
|
|
69
70
|
// tms-core
|
|
70
|
-
'setAuthInfo', 'getConfig', 'navigateToWebview', 'callCloudFunc', 'getEncryptUserInfo',
|
|
71
|
+
'setAuthInfo', 'getConfig', 'getApolloConfig', 'navigateToWebview', 'callCloudFunc', 'getEncryptUserInfo',
|
|
71
72
|
'setUserLocation', 'getUserLocation', 'getMpOpenId', 'getOuterOpenId',
|
|
72
73
|
];
|
|
73
74
|
asyncFuncNames.forEach((funcName) => {
|
|
@@ -147,6 +148,8 @@ function getLocationManager() {
|
|
|
147
148
|
cityName: '深圳市',
|
|
148
149
|
latitude: 22.54286,
|
|
149
150
|
longitude: 114.05956,
|
|
151
|
+
title: '深圳市民中心',
|
|
152
|
+
address: '广东省深圳市福田区福中三路',
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
155
|
return function (...args) {
|
package/src/index.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module: index
|
|
3
|
+
* @desc: tms-core入口文件
|
|
4
|
+
*/
|
|
1
5
|
import runtime from './runtime/index';
|
|
2
6
|
import Request from './request';
|
|
3
7
|
import AutoReport from './report/proxy/index';
|
|
4
8
|
import Reporter from './report/index';
|
|
5
|
-
import { getConfig } from './config';
|
|
9
|
+
import { getConfig, getApolloConfig } from './config';
|
|
6
10
|
import syncApi from './syncfnmanager';
|
|
7
11
|
import nav from './navigator';
|
|
8
12
|
import { getLogManager, getRealtimeLogManager } from './log';
|
|
9
13
|
import { setEnvInfo, getEnvInfo, setAuthInfo, setAppPagePaths, isAppPageExist, getHomePage } from './env';
|
|
10
14
|
import md5 from './md5';
|
|
11
15
|
import { callCloudFunc } from './cloudService';
|
|
12
|
-
import
|
|
16
|
+
import { getEventDispatcher } from './eventDispatcher';
|
|
13
17
|
import { serialize } from './objUtils';
|
|
14
18
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
15
19
|
import { rpxToPx, pxToRpx } from './rpx';
|
|
16
|
-
import { getNavBarConfigData
|
|
20
|
+
import { getNavBarConfigData } from './navbarUtils';
|
|
21
|
+
import { compareVersion } from './compareVersion';
|
|
17
22
|
import {
|
|
18
23
|
formatPlate,
|
|
19
24
|
subStr,
|
|
@@ -72,16 +77,10 @@ const createRequest = (config = {}) => new Request(config);
|
|
|
72
77
|
* @description 埋点上报
|
|
73
78
|
* @returns {Object} 包含[report方法](#report)的对象
|
|
74
79
|
* @example
|
|
75
|
-
* getReporter().
|
|
80
|
+
* getReporter().report2('当前页面|组件的唯一标志', {});
|
|
76
81
|
*/
|
|
77
82
|
const getReporter = () => Reporter;
|
|
78
83
|
|
|
79
|
-
/**
|
|
80
|
-
* @description 自定义事件机制
|
|
81
|
-
* @returns {Object} [EventDispatcher实例](#class-eventdispatcher)
|
|
82
|
-
*/
|
|
83
|
-
const getEventDispatcher = () => new EventDispatcher();
|
|
84
|
-
|
|
85
84
|
/**
|
|
86
85
|
* @description 获取地理位置方法的集合
|
|
87
86
|
* @returns {Class} [Location类](#class-location)
|
|
@@ -97,7 +96,15 @@ const getLocationBaseClass = () => LocationBase;
|
|
|
97
96
|
/**
|
|
98
97
|
* @description init core包初始化, 小程序已在app.js中对齐初始化
|
|
99
98
|
* @param {Object} options 初始化
|
|
100
|
-
* @
|
|
99
|
+
* @param {String} options.appVersion 小程序本次发版的版本号
|
|
100
|
+
* @param {String} options.wxAppId appId
|
|
101
|
+
* @param {String} options.client 小程序名
|
|
102
|
+
* @param {String} options.appEnv 环境名称 production、development、test、predist
|
|
103
|
+
* @param {Array} options.appPagePaths 小程序包含的所有页面路径
|
|
104
|
+
* @param {String} options.homePage 首页的相关配置 { path: "/page/**", isTab: false }
|
|
105
|
+
* @param {String} options.cloudEnvId 云函数的环境id
|
|
106
|
+
* @param {String} options.defaultHost 小程序请求调用接口的域名,所有请求都会走腾讯出行网关服务,腾讯出行网关在转发到相关服务
|
|
107
|
+
* @returns {void} 无返回值.
|
|
101
108
|
*/
|
|
102
109
|
const init = (options = {}) => {
|
|
103
110
|
const { appVersion, wxAppId, client, defaultHost, cloudEnvId, appEnv, appPagePaths, homePage } = options;
|
|
@@ -129,6 +136,36 @@ const getUserLocation = () => {
|
|
|
129
136
|
return getLocInstance().getLocationDetail(false);
|
|
130
137
|
};
|
|
131
138
|
|
|
139
|
+
/**
|
|
140
|
+
* @namespace api
|
|
141
|
+
* @description 对外暴露的api
|
|
142
|
+
* @param {Function} init 初始化方法
|
|
143
|
+
* @param {Function} createRequest 创建Request的实例的方法
|
|
144
|
+
* @param {Function} getReporter 获取上报管理器
|
|
145
|
+
* @param {Function} getLocationManager 获取地理位置管理器
|
|
146
|
+
* @param {Function} setUserLocation 设置用户位置信息
|
|
147
|
+
* @param {Function} getUserLocation 获取用户位置信息
|
|
148
|
+
* @param {Function} cloudService... 云函数相关处理查看 [cloudService](#clouddservice)
|
|
149
|
+
* @param {Function} compareVersion... 版本比较查看 [compareVersion](#compareversion)
|
|
150
|
+
* @param {Function} config... 配置相关函数查看 [config](#config)
|
|
151
|
+
* @param {Function} env... 环境相关处理查看 [env](#env)
|
|
152
|
+
* @param {Function} eventdispatcher... 事件管理相关处理 [eventdispatcher](#eventdispatcher)
|
|
153
|
+
* @param {Function} ipxHelper... iphonex相关方法查看 [ipxHelper](#ipxhelper)
|
|
154
|
+
* @param {Function} log... 上报相关方法查看 [log](#log)
|
|
155
|
+
* @param {Function} md5... md5加密查看 [md5](#md5)
|
|
156
|
+
* @param {Function} mpInfo... 服务接入相关接口查看 [mpInfo](#mpinfo)
|
|
157
|
+
* @param {Function} navbarUtils... 获取导航高度的相关函数查看 [navbarUtils](#navbarutils)
|
|
158
|
+
* @param {Function} navigator... 小程序跳转相关方法 [navigator](#navigator)
|
|
159
|
+
* @param {Function} numUtils... 数字相关处理查看 [numUtils](#numutils)
|
|
160
|
+
* @param {Function} objUtils... 对象相关处理查看[objUtils](#objutils)
|
|
161
|
+
* @param {Function} request... 请求相关处理查看 [request](#request)
|
|
162
|
+
* @param {Function} rpx... px与rpx的相互转化查看 [rpx](#rpx)
|
|
163
|
+
* @param {Function} runtime... 集成业务通用接口查看 [runtime-index](#runtime-index)
|
|
164
|
+
* @param {Function} storage... 本地缓存查看 [storage](#storage)
|
|
165
|
+
* @param {Function} stringUtils... 字符串相关处理查看 [stringUtils](#stringutils)
|
|
166
|
+
* @param {Function} syncfnmanager... 小程序调用wx同步方法的管理查看 [syncfnmanager](#syncfnmanager)
|
|
167
|
+
* @param {Function} timeUtils... 数字相关处理查看 [timeUtils](#timeutils)
|
|
168
|
+
*/
|
|
132
169
|
const api = {
|
|
133
170
|
init,
|
|
134
171
|
createRequest,
|
|
@@ -142,6 +179,7 @@ const api = {
|
|
|
142
179
|
getEventDispatcher,
|
|
143
180
|
getEnvInfo,
|
|
144
181
|
getConfig,
|
|
182
|
+
getApolloConfig,
|
|
145
183
|
navigateToWebview: nav.navigateToWebview,
|
|
146
184
|
isAppPageExist,
|
|
147
185
|
getHomePage,
|
|
@@ -193,11 +231,9 @@ const api = {
|
|
|
193
231
|
/* 获取加密的用户信息 */
|
|
194
232
|
getEncryptUserInfo,
|
|
195
233
|
|
|
196
|
-
/** rpx转px */
|
|
197
234
|
rpxToPx,
|
|
198
235
|
pxToRpx,
|
|
199
236
|
|
|
200
|
-
/** 版本比较 */
|
|
201
237
|
compareVersion,
|
|
202
238
|
getNavBarConfigData,
|
|
203
239
|
|
package/src/ipxHelper.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @desc: iPhoneX相关交接接口
|
|
3
3
|
* @author: petegao@tencent.com
|
|
4
4
|
* Created: 2019-01-14.
|
|
5
5
|
*
|
|
@@ -12,7 +12,8 @@ let isIPXSign = false;
|
|
|
12
12
|
let ipxClass = '';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @
|
|
15
|
+
* @private
|
|
16
|
+
* @returns {Void}
|
|
16
17
|
*/
|
|
17
18
|
function init() {
|
|
18
19
|
if (isInit) {
|
|
@@ -31,7 +32,8 @@ function init() {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
* @
|
|
35
|
+
* @description 判断是否是 iPhoneX
|
|
36
|
+
* @returns {Boolean}
|
|
35
37
|
*/
|
|
36
38
|
function isIPX() {
|
|
37
39
|
init();
|
|
@@ -39,7 +41,8 @@ function isIPX() {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
|
-
* @
|
|
44
|
+
* @description 返回 ipxClass
|
|
45
|
+
* @returns {String}
|
|
43
46
|
*/
|
|
44
47
|
function getIpxClass() {
|
|
45
48
|
init();
|
package/src/location/base.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
|
|
1
2
|
import { getSetting, updateLocStatus, getSystemInfo, getTextByReason, openSetting } from './utils';// eslint-disable-line
|
|
2
3
|
import EventDispatcher from '../eventDispatcher';
|
|
3
4
|
import { WxPostionType } from '../types/object'; // eslint-disable-line
|
|
4
5
|
|
|
6
|
+
const logger = wx.getLogManager({});
|
|
7
|
+
logger.log('location模块代码被装载');
|
|
8
|
+
|
|
5
9
|
const event = new EventDispatcher();
|
|
6
10
|
|
|
7
11
|
let getLocPromise: null | Promise<any> = null;
|
|
@@ -12,6 +16,19 @@ const defaultLocationType = 'gcj02';
|
|
|
12
16
|
// 派发事件的名称
|
|
13
17
|
const EventName = 'loc_status_changed';
|
|
14
18
|
|
|
19
|
+
// 小程序切换到前台|后台之后清除缓存,使后续能重新定位获取到最新位置
|
|
20
|
+
function cleanCache(type: string) {
|
|
21
|
+
if (getLocPromise || userLocationCache) {
|
|
22
|
+
getLocPromise = null;
|
|
23
|
+
userLocationCache = undefined;
|
|
24
|
+
logger.log(type, '清除location缓存');
|
|
25
|
+
} else {
|
|
26
|
+
logger.log(type, 'location无缓存需要清理');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
wx.onAppShow(() => cleanCache('wx.onAppShow'));
|
|
30
|
+
wx.onAppHide(() => cleanCache('wx.onAppHide'));
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* @private 将wx.getLocation获取位置方法用promise封装
|
|
17
34
|
* @param { string } type 获取位置类型
|
|
@@ -22,9 +39,13 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
|
|
|
22
39
|
wx.getLocation({
|
|
23
40
|
type,
|
|
24
41
|
success: (res: WxPostionType) => {
|
|
42
|
+
logger.log(`wx.getLocation('${type}') 成功:\n`, JSON.stringify(res, null, ' '));
|
|
25
43
|
resolve(res);
|
|
26
44
|
},
|
|
27
|
-
fail:
|
|
45
|
+
fail: (err) => {
|
|
46
|
+
logger.warn(`wx.getLocation('${type}') 失败:\n`, JSON.stringify(err, null, ' '));
|
|
47
|
+
reject(err);
|
|
48
|
+
},
|
|
28
49
|
});
|
|
29
50
|
});
|
|
30
51
|
}
|
|
@@ -34,6 +55,7 @@ let isListenerLocation = false;
|
|
|
34
55
|
|
|
35
56
|
/**
|
|
36
57
|
* @class Location
|
|
58
|
+
* @private
|
|
37
59
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
38
60
|
* 获取位置授权等等。业务无关
|
|
39
61
|
*/
|
|
@@ -44,8 +66,8 @@ class LocationBase {
|
|
|
44
66
|
listenerLocation() {
|
|
45
67
|
if (!isListenerLocation) {
|
|
46
68
|
isListenerLocation = true;
|
|
47
|
-
wx.onLocationChange(this.
|
|
48
|
-
wx.startLocationUpdate({});
|
|
69
|
+
wx.onLocationChange(this.subscribeLocationChange);
|
|
70
|
+
wx.startLocationUpdate({}).then();
|
|
49
71
|
}
|
|
50
72
|
}
|
|
51
73
|
|
|
@@ -182,7 +204,7 @@ class LocationBase {
|
|
|
182
204
|
* @param { object } res 用户位置信息对象
|
|
183
205
|
* @returns { undefined } no retrurn
|
|
184
206
|
*/
|
|
185
|
-
public
|
|
207
|
+
public subscribeLocationChange(res: WxPostionType) {
|
|
186
208
|
userLocationCache = res;
|
|
187
209
|
}
|
|
188
210
|
|
package/src/location/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module: location
|
|
3
|
+
* @desc: 封装业务侧位置的接口。 将用户经纬度转化为城市等展示信息
|
|
4
|
+
*/
|
|
1
5
|
import Request from '../request';
|
|
2
6
|
import EventDispatcher from '../eventDispatcher';
|
|
3
7
|
import LocationBase from './base'; // eslint-disable-line
|
|
@@ -48,10 +52,22 @@ let ipLocationPromise: null | Promise<IpLocationType> = null; // ip定位请求
|
|
|
48
52
|
|
|
49
53
|
/**
|
|
50
54
|
* @class Location
|
|
51
|
-
* @classdesc 基于LocationBase,封装业务侧位置的接口。 将用户经纬度转化为城市等展示信息
|
|
52
55
|
*/
|
|
53
56
|
class Location extends LocationBase {
|
|
54
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @desc 默认位置信息
|
|
59
|
+
* @property {object} locForNoAuth 默认的位置信息
|
|
60
|
+
* @property {string} locForNoAuth.privince 省份信息
|
|
61
|
+
* @property {string} locForNoAuth.cityCode 城市编码
|
|
62
|
+
* @property {string} locForNoAuth.cityName 城市名称
|
|
63
|
+
* @property {string} locForNoAuth.district 地区名称
|
|
64
|
+
* @property {string} locForNoAuth.latitude 维度
|
|
65
|
+
* @property {string} locForNoAuth.longitude 经度
|
|
66
|
+
* @example
|
|
67
|
+
* const app = getApp({ allowDefault: true });
|
|
68
|
+
* const locationManager = app.tms.getLocationManager(); // 获取位置管理器
|
|
69
|
+
* console.log(locationManager.locForNoAuth) // 获取默认位置
|
|
70
|
+
*/
|
|
55
71
|
public locForNoAuth = {
|
|
56
72
|
province: '广东省',
|
|
57
73
|
cityCode: '440300',
|
|
@@ -69,11 +85,15 @@ class Location extends LocationBase {
|
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
/**
|
|
72
|
-
*
|
|
88
|
+
* @description 根据经纬度获取地理位置信息, 比如城市信息
|
|
73
89
|
* @param { number } lat 用户纬度信息
|
|
74
90
|
* @param { number } lng 用户经度信息
|
|
75
|
-
* @param { number } getPoi 位置
|
|
91
|
+
* @param { number } getPoi 位置 0 - 不获取(不返回poi字段), 1 - 获取(返回poi字段)
|
|
76
92
|
* @returns { Promise<PostionType | void> } 获取位置信息的promise
|
|
93
|
+
* @example
|
|
94
|
+
* const app = getApp({ allowDefault: true });
|
|
95
|
+
* const locationManager = app.tms.getLocationManager(); // 获取位置管理器
|
|
96
|
+
* await locationManager.getPoiInfo('xxx', 'xxx', 1)
|
|
77
97
|
*/
|
|
78
98
|
getPoiInfo(lat: number, lng: number, getPoi: number): Promise<PostionType | void> {
|
|
79
99
|
// 优先查询缓存中是否有位置信息,如果有直接返回
|
|
@@ -128,7 +148,10 @@ class Location extends LocationBase {
|
|
|
128
148
|
* @param {Number} getPoi 是否获取详细poi信息, 0 - 不获取(不返回poi字段), 1 - 获取(返回poi字段)
|
|
129
149
|
* @returns {Promise<POI|ERR>} 返回对象
|
|
130
150
|
* @example
|
|
131
|
-
*
|
|
151
|
+
* const app = getApp({ allowDefault: true });
|
|
152
|
+
* const locationManager = app.tms.getLocationManager(); // 获取位置管理器
|
|
153
|
+
* const res = await locationManager.getLocationDetail(false, 'gcj02', '', 1);
|
|
154
|
+
* <caption>res-POI类型示例</caption>
|
|
132
155
|
* {
|
|
133
156
|
* cityName: '北京市',
|
|
134
157
|
* cityCode: '100100',
|
|
@@ -143,7 +166,7 @@ class Location extends LocationBase {
|
|
|
143
166
|
* }
|
|
144
167
|
* }
|
|
145
168
|
* @example
|
|
146
|
-
* <caption>ERR类型示例</caption>
|
|
169
|
+
* <caption>res-ERR类型示例</caption>
|
|
147
170
|
* {
|
|
148
171
|
* err,
|
|
149
172
|
* unAuthed: true,
|
|
@@ -248,7 +271,7 @@ class Location extends LocationBase {
|
|
|
248
271
|
}
|
|
249
272
|
|
|
250
273
|
/**
|
|
251
|
-
* @description
|
|
274
|
+
* @description 先获取用户手动设置的位置信息,获取不到则定位授权获取用户位置信息
|
|
252
275
|
* @memberof Location
|
|
253
276
|
* @param {Boolean} showModalWhenCloseAuth 没有授权时是否展示授权弹窗
|
|
254
277
|
* @returns {Promise} 用户位置信息
|
package/src/location/utils.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private: true
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import EventDispatcher from '../eventDispatcher';
|
|
2
6
|
|
|
3
7
|
const event = new EventDispatcher();
|
|
@@ -123,7 +127,7 @@ export function getTextByReason(locationEnabled: boolean, isSysAndWechatAllowedG
|
|
|
123
127
|
export function getSystemInfo(): WechatMiniprogram.SystemInfo | undefined {
|
|
124
128
|
try {
|
|
125
129
|
const sys: WechatMiniprogram.SystemInfo = wx.getSystemInfoSync();
|
|
126
|
-
// 方便开发时调试
|
|
130
|
+
// @ts-ignore 方便开发时调试
|
|
127
131
|
if (sys.platform === 'devtools') {
|
|
128
132
|
sys.locationEnabled = true;
|
|
129
133
|
sys.locationAuthorized = true;
|
package/src/log.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 本文件主要负责在小程序中日志打印功能,包含本地日志及实时日志.
|
|
2
|
+
* @desc: 本文件主要负责在小程序中日志打印功能,包含本地日志及实时日志.
|
|
3
|
+
* 主要做了两件事:
|
|
3
4
|
* 1、参数序列化处理;支持传递任意多个参数,并对类型为对象的参数进行字符串序列化处理(避免打印出来是'[Object Object]'的格式);
|
|
4
5
|
* 2、低版本兼容;
|
|
5
6
|
*/
|
|
@@ -19,6 +20,9 @@ const ManagerForLowerVersionLib = {
|
|
|
19
20
|
let logInstance = null;
|
|
20
21
|
let rtLogInstance = null;
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
22
26
|
function getLogInstance() {
|
|
23
27
|
if (logInstance === null) {
|
|
24
28
|
logInstance = wx.getLogManager ? wx.getLogManager() : ManagerForLowerVersionLib;
|
|
@@ -26,6 +30,9 @@ function getLogInstance() {
|
|
|
26
30
|
return logInstance;
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
29
36
|
function getRTLogInstance() {
|
|
30
37
|
if (rtLogInstance === null) {
|
|
31
38
|
rtLogInstance = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : ManagerForLowerVersionLib;
|
|
@@ -34,6 +41,7 @@ function getRTLogInstance() {
|
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
/**
|
|
44
|
+
* @private
|
|
37
45
|
* 参数中有对象类型的,将其转换为字符串类型,以便查看
|
|
38
46
|
* @param {Array<Any>} params 需要格式化的数据
|
|
39
47
|
* @returns {Array<String>} 字符串序列化后的数据
|
|
@@ -146,7 +154,8 @@ const RTLOG = {
|
|
|
146
154
|
* @description 获取日志管理器对象,该对象提供的方法同wx.getLogManager()提供的方法,详见微信文档
|
|
147
155
|
* @returns {Object} [LOG](#namespace-log)
|
|
148
156
|
* @example
|
|
149
|
-
* const
|
|
157
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
158
|
+
* const logger = tms.getLogManager();
|
|
150
159
|
* logger.log(1, 'str', { a: 1 }, ...);
|
|
151
160
|
* logger.info(1, 'str', { a: 1 }, ...);
|
|
152
161
|
* logger.debug(1, 'str', { a: 1 }, ...);
|
|
@@ -158,7 +167,8 @@ const getLogManager = () => LOG;
|
|
|
158
167
|
* @description 获取实时日志管理器对象,该对象提供的方法同wx.getRealtimeLogManager()提供的方法,详见微信文档
|
|
159
168
|
* @returns {Object} [RTLOG](#namespace-rtlog)
|
|
160
169
|
* @example
|
|
161
|
-
* const
|
|
170
|
+
* const { tms } = getApp({ allowDefault: true });
|
|
171
|
+
* const logger = tms.getRealtimeLogManager();
|
|
162
172
|
* logger.info(1, 'str', { a: 1 }, ...);
|
|
163
173
|
* logger.warn(1, 'str', { a: 1 }, ...);
|
|
164
174
|
* logger.error(1, 'str', { a: 1 }, ...);
|