@tmsfe/tms-core 0.0.11 → 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 +51 -24
- package/package.json +3 -7
- package/rollup.config.js +1 -1
- package/src/config.js +10 -5
- package/src/fastreport.js +21 -11
- package/src/index-proxy.js +9 -0
- package/src/location/base.ts +11 -4
- package/src/report.js +9 -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
|
@@ -28,6 +28,17 @@ const getSystemInfo$1 = () => {
|
|
|
28
28
|
host
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
|
|
32
|
+
const handleParamOfDifferentType = param => {
|
|
33
|
+
const data = new Array(41);
|
|
34
|
+
Object.keys(param).forEach(key => {
|
|
35
|
+
const valType = typeof param[key];
|
|
36
|
+
if (valType === 'string') data[key] = param[key];else if (valType === 'object') data[key] = JSON.stringify(param[key]);else data[key] = String(param[key]);
|
|
37
|
+
});
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const defAssign = (value, defaultValue) => value || defaultValue;
|
|
31
42
|
/**
|
|
32
43
|
* @class FastReport
|
|
33
44
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -45,20 +56,20 @@ class FastReport {
|
|
|
45
56
|
* @param {Boolean} appVer 是否上报小程序版本
|
|
46
57
|
* @returns {Promsie} 返回上报结果
|
|
47
58
|
*/
|
|
48
|
-
static report(param, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
59
|
+
static report(param = {}, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
49
60
|
var _data$;
|
|
50
61
|
|
|
51
|
-
if (!
|
|
52
|
-
const data = new Array(41);
|
|
62
|
+
if (!param[27]) return Promise.reject('invalid report param');
|
|
53
63
|
const env = getEnvInfo();
|
|
54
|
-
|
|
55
|
-
const valType = typeof param[key];
|
|
56
|
-
if (valType === 'string') data[key] = param[key];else if (valType === 'object') data[key] = JSON.stringify(param[key]);else data[key] = String(param[key]);
|
|
57
|
-
});
|
|
64
|
+
const data = handleParamOfDifferentType(param);
|
|
58
65
|
data[9] = '2';
|
|
59
66
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo$1()));
|
|
60
|
-
|
|
61
|
-
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]);
|
|
62
73
|
data[28] = env.client;
|
|
63
74
|
|
|
64
75
|
if (reportShowScene && !data[29]) {
|
|
@@ -117,6 +128,17 @@ const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((pat
|
|
|
117
128
|
|
|
118
129
|
return {}; // 没找到配置,返回一个空对象
|
|
119
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
|
+
};
|
|
120
142
|
/**
|
|
121
143
|
* getConfig 批量拉取配置
|
|
122
144
|
* @description 拉取运营平台上的配置内容。关于运营平台的具体用法,参见{@link https://iwiki.woa.com/pages/viewpage.action?pageId=527948584}
|
|
@@ -154,14 +176,8 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
154
176
|
}
|
|
155
177
|
}
|
|
156
178
|
|
|
157
|
-
const configPaths =
|
|
179
|
+
const configPaths = formatConfigPaths(configPath);
|
|
158
180
|
const defaultCfgs = defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg]) || null;
|
|
159
|
-
const {
|
|
160
|
-
client
|
|
161
|
-
} = getEnvInfo();
|
|
162
|
-
configPaths.forEach((path, index) => {
|
|
163
|
-
configPaths[index] = path.replace(/\$\{client\}/, client);
|
|
164
|
-
});
|
|
165
181
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
166
182
|
const api = new Request();
|
|
167
183
|
return api.post('marketing/config', {
|
|
@@ -543,6 +559,8 @@ function getWxLocation(type = defaultLocationType) {
|
|
|
543
559
|
});
|
|
544
560
|
});
|
|
545
561
|
}
|
|
562
|
+
// 是否开启监听位置变更
|
|
563
|
+
let isListenerLocation = false;
|
|
546
564
|
/**
|
|
547
565
|
* @class Location
|
|
548
566
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
@@ -550,11 +568,14 @@ function getWxLocation(type = defaultLocationType) {
|
|
|
550
568
|
*/
|
|
551
569
|
class LocationBase {
|
|
552
570
|
/**
|
|
553
|
-
* @private
|
|
571
|
+
* @private 开启监听位置变更,要在授权之后才能开启
|
|
554
572
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
573
|
+
listenerLocation() {
|
|
574
|
+
if (!isListenerLocation) {
|
|
575
|
+
isListenerLocation = true;
|
|
576
|
+
wx.onLocationChange(this.subscribeLocationChnage);
|
|
577
|
+
wx.startLocationUpdate({});
|
|
578
|
+
}
|
|
558
579
|
}
|
|
559
580
|
/**
|
|
560
581
|
* 获取用户当前位置(经纬度)
|
|
@@ -604,6 +625,7 @@ class LocationBase {
|
|
|
604
625
|
getWxLocationPromise(showModalWhenCloseAuth, type, content = '', showCancel = true) {
|
|
605
626
|
return new Promise((resolve, reject) => {
|
|
606
627
|
getWxLocation(type).then((res) => {
|
|
628
|
+
this.listenerLocation();
|
|
607
629
|
userLocationCache$1 = res;
|
|
608
630
|
// 更新用户状态 -- todo
|
|
609
631
|
updateLocStatus(true);
|
|
@@ -1248,16 +1270,21 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
1248
1270
|
|
|
1249
1271
|
}; // 对部分空数据使用默认数据填充
|
|
1250
1272
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1273
|
+
const handleDefaultData = (paramItem, defaultData) => {
|
|
1274
|
+
const arr = [paramItem, paramItem === 0, paramItem === false];
|
|
1275
|
+
return arr.some(item => !!item) ? paramItem : defaultData || '';
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
Object.keys(defaultReportData).forEach(index => {
|
|
1279
|
+
const paramItem = param[index];
|
|
1280
|
+
param[index] = handleDefaultData(paramItem, defaultReportData[index]);
|
|
1253
1281
|
}); // 所有上报数据都转换为字符串
|
|
1254
1282
|
|
|
1255
1283
|
param.forEach((reportItem, index) => {
|
|
1256
1284
|
if (reportItem && typeof reportItem !== 'string') {
|
|
1257
1285
|
param[index] = `${JSON.stringify(reportItem)}`;
|
|
1258
1286
|
} else {
|
|
1259
|
-
|
|
1260
|
-
param[index] = paramItem || paramItem === 0 ? `${paramItem}` : '';
|
|
1287
|
+
param[index] = handleDefaultData(reportItem, '');
|
|
1261
1288
|
}
|
|
1262
1289
|
});
|
|
1263
1290
|
return param.map(item => item !== null ? encodeURIComponent(item) : item);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tms-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "tms运行时框架",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,12 +34,8 @@
|
|
|
34
34
|
"rollup": "^2.6.1",
|
|
35
35
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
36
36
|
"rollup-plugin-terser": "^6.1.0",
|
|
37
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
38
|
-
"typescript": "^4.5.2"
|
|
37
|
+
"rollup-plugin-typescript2": "0.27.0"
|
|
39
38
|
},
|
|
40
39
|
"author": "tms·web",
|
|
41
|
-
"gitHead": "72bf52451594b49a1c9f78edbad5956d414a66ca"
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"rollup-plugin-replace": "^2.2.0"
|
|
44
|
-
}
|
|
40
|
+
"gitHead": "72bf52451594b49a1c9f78edbad5956d414a66ca"
|
|
45
41
|
}
|
package/rollup.config.js
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
|
@@ -16,6 +16,20 @@ const getSystemInfo = () => {
|
|
|
16
16
|
return { model, wxVersion, platform, SDKVersion, host };
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
const handleParamOfDifferentType = (param) => {
|
|
20
|
+
const data = new Array(41);
|
|
21
|
+
Object.keys(param).forEach((key) => {
|
|
22
|
+
const valType = typeof param[key];
|
|
23
|
+
if (valType === 'string') data[key] = param[key];
|
|
24
|
+
else if (valType === 'object') data[key] = JSON.stringify(param[key]);
|
|
25
|
+
else data[key] = String(param[key]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const defAssign = (value, defaultValue) => (value || defaultValue);
|
|
32
|
+
|
|
19
33
|
/**
|
|
20
34
|
* @class FastReport
|
|
21
35
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -31,20 +45,16 @@ export default class FastReport {
|
|
|
31
45
|
* @param {Boolean} appVer 是否上报小程序版本
|
|
32
46
|
* @returns {Promsie} 返回上报结果
|
|
33
47
|
*/
|
|
34
|
-
static report(param, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
35
|
-
if (!param
|
|
36
|
-
const data = new Array(41);
|
|
48
|
+
static report(param = {}, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
49
|
+
if (!param[27]) return Promise.reject('invalid report param');
|
|
37
50
|
const env = getEnvInfo();
|
|
38
|
-
|
|
39
|
-
const valType = typeof param[key];
|
|
40
|
-
if (valType === 'string') data[key] = param[key];
|
|
41
|
-
else if (valType === 'object') data[key] = JSON.stringify(param[key]);
|
|
42
|
-
else data[key] = String(param[key]);
|
|
43
|
-
});
|
|
51
|
+
const data = handleParamOfDifferentType(param);
|
|
44
52
|
data[9] = '2';
|
|
45
53
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo()));
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
if (appVer) {
|
|
55
|
+
data[10] = defAssign(data[10], env.appVersion);
|
|
56
|
+
}
|
|
57
|
+
data[26] = defAssign(data[26], data[27]?.[0]);
|
|
48
58
|
data[28] = env.client;
|
|
49
59
|
if (reportShowScene && !data[29]) {
|
|
50
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);
|
package/src/report.js
CHANGED
|
@@ -212,8 +212,14 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
212
212
|
36: getAppShowOptions(), // 打开小程序的场景值及参数
|
|
213
213
|
};
|
|
214
214
|
// 对部分空数据使用默认数据填充
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
const handleDefaultData = (paramItem, defaultData) => {
|
|
216
|
+
const arr = [paramItem, paramItem === 0, paramItem === false];
|
|
217
|
+
return (arr.some(item => !!item)) ? paramItem : (defaultData || '');
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
Object.keys(defaultReportData).forEach((index) => {
|
|
221
|
+
const paramItem = param[index];
|
|
222
|
+
param[index] = handleDefaultData(paramItem, defaultReportData[index]);
|
|
217
223
|
});
|
|
218
224
|
|
|
219
225
|
// 所有上报数据都转换为字符串
|
|
@@ -221,8 +227,7 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
221
227
|
if (reportItem && typeof reportItem !== 'string') {
|
|
222
228
|
param[index] = `${JSON.stringify(reportItem)}`;
|
|
223
229
|
} else {
|
|
224
|
-
|
|
225
|
-
param[index] = (paramItem || paramItem === 0) ? `${paramItem}` : '';
|
|
230
|
+
param[index] = handleDefaultData(reportItem, '');
|
|
226
231
|
}
|
|
227
232
|
});
|
|
228
233
|
|