@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.92",
3
+ "version": "0.0.95",
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"
@@ -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 cfg = await app.tms.getConfig('/${client}/violation/subscribe', {}, { title: '当前城市不支持订阅'})
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 cfgs = await app.tms.getConfig([
35
+ const { tms } = getApp({ allowDefault: true });
36
+ const cfgs = await tms.getConfig([
36
37
  '/${client}/home/service',
37
38
  '/${client}/home/navbar',
38
39
  ], {}, [
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: '', // 当前运行时小程序的appId
4
- appVersion: '', // 当前运行时所在项目的版本号
5
- appEnv: '', // 运行环境 test - 测试、production - 正式
6
- client: '', // 运行时项目名,sinan - 腾讯出行服务; mycar - 我的车小程序
7
- cloudEnvId: '', // 运行云函数的环境id
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 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
- * tms.getEnvInfo 用于获取运行时所在的环境信息
43
- * @returns {object} 运行时环境信息.
71
+ * @description 用于获取运行时所在的环境信息
72
+ * @returns {Object} 运行时环境信息 (返回值见上Env:namepace)
44
73
  */
45
74
  export const getEnvInfo = () => env;
46
75
  /**
47
76
  * 设置环境变量
48
- * @param {object} envInfo 环境变量
49
- * @returns {undefined} 无.
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;
@@ -1,11 +1,7 @@
1
1
  /* eslint-disable require-jsdoc */
2
2
  /**
3
- * Copyright 2017-present, Tencent, Inc.
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();
@@ -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, compareVersion } from './navbarUtils';
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';
@@ -65,7 +66,7 @@ const asyncFuncNames = [
65
66
  // 这行是tms-ui的
66
67
  'showDrawer', 'hideDrawer', 'showModal', 'hideModal',
67
68
  // 这行是runtime的
68
- 'getPhone', 'login', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
69
+ 'getPhone', 'registerPhone', 'login', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
69
70
  // tms-core
70
71
  'setAuthInfo', 'getConfig', 'navigateToWebview', 'callCloudFunc', 'getEncryptUserInfo',
71
72
  'setUserLocation', 'getUserLocation', 'getMpOpenId', 'getOuterOpenId',
@@ -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,3 +1,7 @@
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';
@@ -9,11 +13,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 EventDispatcher from './eventDispatcher';
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, compareVersion } from './navbarUtils';
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().report(reportData, reportNow);
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
- * @returns {undefined} 无返回值.
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,
@@ -193,11 +230,9 @@ const api = {
193
230
  /* 获取加密的用户信息 */
194
231
  getEncryptUserInfo,
195
232
 
196
- /** rpx转px */
197
233
  rpxToPx,
198
234
  pxToRpx,
199
235
 
200
- /** 版本比较 */
201
236
  compareVersion,
202
237
  getNavBarConfigData,
203
238
 
package/src/ipxHelper.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Tencent Inc. All Rights Reserved.
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
- * @returns {undefined}
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
- * @returns {Boolean} 判断是否是 iPhoneX
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
- * @returns {String} 返回 ipxClass
44
+ * @description 返回 ipxClass
45
+ * @returns {String}
43
46
  */
44
47
  function getIpxClass() {
45
48
  init();
@@ -1,3 +1,4 @@
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
@@ -34,6 +35,7 @@ let isListenerLocation = false;
34
35
 
35
36
  /**
36
37
  * @class Location
38
+ * @private
37
39
  * @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
38
40
  * 获取位置授权等等。业务无关
39
41
  */
@@ -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
- * <caption>POI类型示例</caption>
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} 用户位置信息
@@ -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 logger = getLogManager();
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 logger = getRealtimeLogManager();
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 }, ...);
package/src/md5.js CHANGED
@@ -1,9 +1,6 @@
1
1
  /**
2
- * @copyright 2017-present, Tencent, Inc. All rights reserved.
3
2
  * @author Davis.Lu <davislu@tencent.com>
4
- *
5
- * @file crypto tools.
6
- *
3
+ * @desc: 基于md5算法对源字符串进行hash,生成hash字符串
7
4
  **/
8
5
 
9
6
  /**
package/src/mpInfo.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 支持服务接入相关接口
2
+ * @desc: 支持服务接入相关接口
3
3
  */
4
4
  import Request from './request';
5
5
 
@@ -11,6 +11,9 @@ import Request from './request';
11
11
  * @param {String} mpId 接入服务商渠道标识
12
12
  * @param {String} userId 出行用户标识
13
13
  * @returns {Promise<String>} 返回 openId,失败时返回空
14
+ * @example
15
+ * const { tms } = getApp({ allowDefault: true });
16
+ * tms.getMpOpenId('xxx', '111')
14
17
  */
15
18
  async function getMpOpenId(mpId, userId) {
16
19
  const { resData } = await new Request().post('user/mpinfo', { userId, mpId });
@@ -25,6 +28,9 @@ async function getMpOpenId(mpId, userId) {
25
28
  * @category 服务接入
26
29
  * @param {String} apiKey 服务接入方渠道标识
27
30
  * @returns {Promise<String>} 返回 openId,失败时返回空
31
+ * @example
32
+ * const { tms } = getApp({ allowDefault: true });
33
+ * tms.getMpOpenId('xxx', '111')
28
34
  */
29
35
  async function getOuterOpenId(apiKey) {
30
36
  const { resData } = await new Request().post('user/mpinfo', { mpId: apiKey });