@tmsfe/tms-core 0.0.14 → 0.0.15
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/dist/index-proxy.js +10 -0
- package/dist/index.js +32 -15
- package/package.json +1 -1
- package/src/config.js +10 -5
- package/src/fastreport.js +8 -4
- package/src/index-proxy.js +9 -0
- package/src/location/base.ts +11 -4
package/dist/index-proxy.js
CHANGED
|
@@ -131,6 +131,16 @@ function getLocationManager() {
|
|
|
131
131
|
return setUserLocation;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
if (name === 'locForNoAuth') {
|
|
135
|
+
return {
|
|
136
|
+
province: '广东省',
|
|
137
|
+
cityCode: '440300',
|
|
138
|
+
cityName: '深圳市',
|
|
139
|
+
latitude: 22.54286,
|
|
140
|
+
longitude: 114.05956
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
134
144
|
return function (...args) {
|
|
135
145
|
return ps.then(() => invoke(manager, name, args));
|
|
136
146
|
};
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,8 @@ const handleParamOfDifferentType = param => {
|
|
|
37
37
|
});
|
|
38
38
|
return data;
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
const defAssign = (value, defaultValue) => value || defaultValue;
|
|
40
42
|
/**
|
|
41
43
|
* @class FastReport
|
|
42
44
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -54,16 +56,20 @@ class FastReport {
|
|
|
54
56
|
* @param {Boolean} appVer 是否上报小程序版本
|
|
55
57
|
* @returns {Promsie} 返回上报结果
|
|
56
58
|
*/
|
|
57
|
-
static report(param, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
59
|
+
static report(param = {}, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
58
60
|
var _data$;
|
|
59
61
|
|
|
60
|
-
if (!
|
|
62
|
+
if (!param[27]) return Promise.reject('invalid report param');
|
|
61
63
|
const env = getEnvInfo();
|
|
62
64
|
const data = handleParamOfDifferentType(param);
|
|
63
65
|
data[9] = '2';
|
|
64
66
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo$1()));
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
+
|
|
68
|
+
if (appVer) {
|
|
69
|
+
data[10] = defAssign(data[10], env.appVersion);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
data[26] = defAssign(data[26], (_data$ = data[27]) === null || _data$ === void 0 ? void 0 : _data$[0]);
|
|
67
73
|
data[28] = env.client;
|
|
68
74
|
|
|
69
75
|
if (reportShowScene && !data[29]) {
|
|
@@ -122,6 +128,17 @@ const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((pat
|
|
|
122
128
|
|
|
123
129
|
return {}; // 没找到配置,返回一个空对象
|
|
124
130
|
});
|
|
131
|
+
|
|
132
|
+
const formatConfigPaths = configPath => {
|
|
133
|
+
const configPaths = Array.isArray(configPath) ? configPath : [configPath];
|
|
134
|
+
const {
|
|
135
|
+
client
|
|
136
|
+
} = getEnvInfo();
|
|
137
|
+
configPaths.forEach((path, index) => {
|
|
138
|
+
configPaths[index] = path.replace(/\$\{client\}/, client);
|
|
139
|
+
});
|
|
140
|
+
return configPaths;
|
|
141
|
+
};
|
|
125
142
|
/**
|
|
126
143
|
* getConfig 批量拉取配置
|
|
127
144
|
* @description 拉取运营平台上的配置内容。关于运营平台的具体用法,参见{@link https://iwiki.woa.com/pages/viewpage.action?pageId=527948584}
|
|
@@ -159,14 +176,8 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
|
|
162
|
-
const configPaths =
|
|
179
|
+
const configPaths = formatConfigPaths(configPath);
|
|
163
180
|
const defaultCfgs = defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg]) || null;
|
|
164
|
-
const {
|
|
165
|
-
client
|
|
166
|
-
} = getEnvInfo();
|
|
167
|
-
configPaths.forEach((path, index) => {
|
|
168
|
-
configPaths[index] = path.replace(/\$\{client\}/, client);
|
|
169
|
-
});
|
|
170
181
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
171
182
|
const api = new Request();
|
|
172
183
|
return api.post('marketing/config', {
|
|
@@ -548,6 +559,8 @@ function getWxLocation(type = defaultLocationType) {
|
|
|
548
559
|
});
|
|
549
560
|
});
|
|
550
561
|
}
|
|
562
|
+
// 是否开启监听位置变更
|
|
563
|
+
let isListenerLocation = false;
|
|
551
564
|
/**
|
|
552
565
|
* @class Location
|
|
553
566
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
@@ -555,11 +568,14 @@ function getWxLocation(type = defaultLocationType) {
|
|
|
555
568
|
*/
|
|
556
569
|
class LocationBase {
|
|
557
570
|
/**
|
|
558
|
-
* @private
|
|
571
|
+
* @private 开启监听位置变更,要在授权之后才能开启
|
|
559
572
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
573
|
+
listenerLocation() {
|
|
574
|
+
if (!isListenerLocation) {
|
|
575
|
+
isListenerLocation = true;
|
|
576
|
+
wx.onLocationChange(this.subscribeLocationChnage);
|
|
577
|
+
wx.startLocationUpdate({});
|
|
578
|
+
}
|
|
563
579
|
}
|
|
564
580
|
/**
|
|
565
581
|
* 获取用户当前位置(经纬度)
|
|
@@ -609,6 +625,7 @@ class LocationBase {
|
|
|
609
625
|
getWxLocationPromise(showModalWhenCloseAuth, type, content = '', showCancel = true) {
|
|
610
626
|
return new Promise((resolve, reject) => {
|
|
611
627
|
getWxLocation(type).then((res) => {
|
|
628
|
+
this.listenerLocation();
|
|
612
629
|
userLocationCache$1 = res;
|
|
613
630
|
// 更新用户状态 -- todo
|
|
614
631
|
updateLocStatus(true);
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -15,6 +15,15 @@ const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((pat
|
|
|
15
15
|
return {}; // 没找到配置,返回一个空对象
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
const formatConfigPaths = (configPath) => {
|
|
19
|
+
const configPaths = Array.isArray(configPath) ? configPath : [configPath];
|
|
20
|
+
const { client } = getEnvInfo();
|
|
21
|
+
configPaths.forEach((path, index) => {
|
|
22
|
+
configPaths[index] = path.replace(/\$\{client\}/, client);
|
|
23
|
+
});
|
|
24
|
+
return configPaths;
|
|
25
|
+
};
|
|
26
|
+
|
|
18
27
|
/**
|
|
19
28
|
* getConfig 批量拉取配置
|
|
20
29
|
* @description 拉取运营平台上的配置内容。关于运营平台的具体用法,参见{@link https://iwiki.woa.com/pages/viewpage.action?pageId=527948584}
|
|
@@ -47,12 +56,8 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
const configPaths =
|
|
59
|
+
const configPaths = formatConfigPaths(configPath);
|
|
51
60
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
52
|
-
const { client } = getEnvInfo();
|
|
53
|
-
configPaths.forEach((path, index) => {
|
|
54
|
-
configPaths[index] = path.replace(/\$\{client\}/, client);
|
|
55
|
-
});
|
|
56
61
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
57
62
|
const api = new Request();
|
|
58
63
|
return api.post('marketing/config', {
|
package/src/fastreport.js
CHANGED
|
@@ -28,6 +28,8 @@ const handleParamOfDifferentType = (param) => {
|
|
|
28
28
|
return data;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
const defAssign = (value, defaultValue) => (value || defaultValue);
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* @class FastReport
|
|
33
35
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -43,14 +45,16 @@ export default class FastReport {
|
|
|
43
45
|
* @param {Boolean} appVer 是否上报小程序版本
|
|
44
46
|
* @returns {Promsie} 返回上报结果
|
|
45
47
|
*/
|
|
46
|
-
static report(param, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
47
|
-
if (!param
|
|
48
|
+
static report(param = {}, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
49
|
+
if (!param[27]) return Promise.reject('invalid report param');
|
|
48
50
|
const env = getEnvInfo();
|
|
49
51
|
const data = handleParamOfDifferentType(param);
|
|
50
52
|
data[9] = '2';
|
|
51
53
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo()));
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
if (appVer) {
|
|
55
|
+
data[10] = defAssign(data[10], env.appVersion);
|
|
56
|
+
}
|
|
57
|
+
data[26] = defAssign(data[26], data[27]?.[0]);
|
|
54
58
|
data[28] = env.client;
|
|
55
59
|
if (reportShowScene && !data[29]) {
|
|
56
60
|
const appShowScene = wx.getStorageSync('appShowScene');
|
package/src/index-proxy.js
CHANGED
|
@@ -134,6 +134,15 @@ function getLocationManager() {
|
|
|
134
134
|
if (name === 'setUserLocation') {
|
|
135
135
|
return setUserLocation;
|
|
136
136
|
}
|
|
137
|
+
if (name === 'locForNoAuth') {
|
|
138
|
+
return {
|
|
139
|
+
province: '广东省',
|
|
140
|
+
cityCode: '440300',
|
|
141
|
+
cityName: '深圳市',
|
|
142
|
+
latitude: 22.54286,
|
|
143
|
+
longitude: 114.05956,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
137
146
|
return function (...args) {
|
|
138
147
|
return ps.then(() => invoke(manager, name, args));
|
|
139
148
|
};
|
package/src/location/base.ts
CHANGED
|
@@ -29,6 +29,9 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// 是否开启监听位置变更
|
|
33
|
+
let isListenerLocation = false;
|
|
34
|
+
|
|
32
35
|
/**
|
|
33
36
|
* @class Location
|
|
34
37
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
@@ -36,11 +39,14 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
|
|
|
36
39
|
*/
|
|
37
40
|
class LocationBase {
|
|
38
41
|
/**
|
|
39
|
-
* @private
|
|
42
|
+
* @private 开启监听位置变更,要在授权之后才能开启
|
|
40
43
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
listenerLocation() {
|
|
45
|
+
if (!isListenerLocation) {
|
|
46
|
+
isListenerLocation = true;
|
|
47
|
+
wx.onLocationChange(this.subscribeLocationChnage);
|
|
48
|
+
wx.startLocationUpdate({});
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
/**
|
|
@@ -95,6 +101,7 @@ class LocationBase {
|
|
|
95
101
|
public getWxLocationPromise(showModalWhenCloseAuth: boolean, type: string, content = '', showCancel = true) {
|
|
96
102
|
return new Promise((resolve, reject) => {
|
|
97
103
|
getWxLocation(type).then((res: WxPostionType) => {
|
|
104
|
+
this.listenerLocation();
|
|
98
105
|
userLocationCache = res;
|
|
99
106
|
// 更新用户状态 -- todo
|
|
100
107
|
updateLocStatus(true);
|