@tmsfe/tms-core 0.0.44 → 0.0.47
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 +1 -1
- package/src/distanceUtils.ts +37 -0
- package/src/index-proxy.js +2 -0
- package/src/index.js +3 -0
- package/src/report/formatV1.ts +1 -1
- package/src/report/formatV2.ts +1 -1
- package/src/report/helper.ts +20 -0
- package/src/report/proxy/helper.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 经纬度距离计算
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// 将角度换算为弧度
|
|
7
|
+
function convertDegreesToRadians(degrees: number): number {
|
|
8
|
+
return (degrees * Math.PI) / 180;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function haverSin(theta: number): number {
|
|
12
|
+
const val = Math.sin(theta / 2);
|
|
13
|
+
return val * val;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 计算两点间距离,单位 m
|
|
17
|
+
function calCoordinateDistance(
|
|
18
|
+
a: { latitude: number, longitude: number },
|
|
19
|
+
b: { latitude: number, longitude: number },
|
|
20
|
+
): number {
|
|
21
|
+
// 地球半径 平均值,千米
|
|
22
|
+
const earthRadius = 6371;
|
|
23
|
+
const lat1 = convertDegreesToRadians(a.latitude);
|
|
24
|
+
const lon1 = convertDegreesToRadians(a.longitude);
|
|
25
|
+
const lat2 = convertDegreesToRadians(b.latitude);
|
|
26
|
+
const lon2 = convertDegreesToRadians(b.longitude);
|
|
27
|
+
// 差值
|
|
28
|
+
const vLon = Math.abs(lon1 - lon2);
|
|
29
|
+
const vLat = Math.abs(lat1 - lat2);
|
|
30
|
+
const h = haverSin(vLat) + (Math.cos(lat1) * Math.cos(lat2) * haverSin(vLon));
|
|
31
|
+
const distance = 2 * earthRadius * Math.asin(Math.sqrt(h));
|
|
32
|
+
return distance * 1000;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
calCoordinateDistance,
|
|
37
|
+
};
|
package/src/index-proxy.js
CHANGED
|
@@ -10,6 +10,7 @@ import AutoReport from './report/proxy/index';
|
|
|
10
10
|
import md5 from './md5';
|
|
11
11
|
import { rpxToPx } from './rpx';
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
|
+
import { calCoordinateDistance } from './distanceUtils';
|
|
13
14
|
import * as stringUtils from './stringUtils';
|
|
14
15
|
import * as timeUtils from './timeUtils';
|
|
15
16
|
import * as ipxHelper from './ipxHelper';
|
|
@@ -210,6 +211,7 @@ const api = {
|
|
|
210
211
|
getLocationManager,
|
|
211
212
|
rpxToPx,
|
|
212
213
|
serialize,
|
|
214
|
+
calCoordinateDistance,
|
|
213
215
|
createRequest,
|
|
214
216
|
getEnvInfo,
|
|
215
217
|
isAppPageExist,
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import md5 from './md5';
|
|
|
10
10
|
import { callCloudFunc } from './cloudService';
|
|
11
11
|
import EventDispatcher from './eventDispatcher';
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
|
+
import { calCoordinateDistance } from './distanceUtils';
|
|
13
14
|
import { rpxToPx } from './rpx';
|
|
14
15
|
import {
|
|
15
16
|
formatPlate,
|
|
@@ -169,6 +170,8 @@ const api = {
|
|
|
169
170
|
/* 处理对象方法 */
|
|
170
171
|
serialize,
|
|
171
172
|
|
|
173
|
+
calCoordinateDistance,
|
|
174
|
+
|
|
172
175
|
/* 获取外部合作商openid */
|
|
173
176
|
getMpOpenId, // 变更为 getOuterOpenId
|
|
174
177
|
getOuterOpenId,
|
package/src/report/formatV1.ts
CHANGED
|
@@ -17,7 +17,7 @@ function getBaseData(deviceData: IDeviceData): DataItem[] {
|
|
|
17
17
|
// ++++++++++++++++++++++++++字段列表++++++++++++++++++++++++++
|
|
18
18
|
// 0: log_time,日志入库时间
|
|
19
19
|
// 1: access_time,埋点触发时间
|
|
20
|
-
arr[1] =
|
|
20
|
+
arr[1] = helper.getNowString();
|
|
21
21
|
// 2: user_ip,前端无需赋值
|
|
22
22
|
// 3: qimei,灯塔中的用户ID
|
|
23
23
|
// 4: imei,Android手机的imei IOS系统中的idfv 车联网中的wecarid
|
package/src/report/formatV2.ts
CHANGED
|
@@ -17,7 +17,7 @@ function getBaseData(deviceData: IDeviceData): { arr: DataItem[], nextIndex: num
|
|
|
17
17
|
// ++++++++++++++++++++++++++字段列表++++++++++++++++++++++++++
|
|
18
18
|
// 0: log_time,日志入库时间
|
|
19
19
|
// 1: access_time,埋点触发时间
|
|
20
|
-
arr[1] =
|
|
20
|
+
arr[1] = helper.getNowString();
|
|
21
21
|
// 2: user_ip,前端无需赋值
|
|
22
22
|
// 3: qimei,灯塔中的用户ID
|
|
23
23
|
// 4: imei,Android手机的imei IOS系统中的idfv 车联网中的wecarid
|
package/src/report/helper.ts
CHANGED
|
@@ -83,6 +83,25 @@ function convert2String(value: any): string {
|
|
|
83
83
|
return String(value);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function num2Str(num: number, maxLength = 2): string {
|
|
87
|
+
return num.toString().padStart(maxLength, '0');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 获取当前时间格式化后的字符串
|
|
92
|
+
*/
|
|
93
|
+
function getNowString(): string {
|
|
94
|
+
const date = new Date();
|
|
95
|
+
const year = date.getFullYear().toString();
|
|
96
|
+
const month = num2Str(date.getMonth() + 1);
|
|
97
|
+
const day = num2Str(date.getDate());
|
|
98
|
+
const hours = num2Str(date.getHours());
|
|
99
|
+
const minutes = num2Str(date.getMinutes());
|
|
100
|
+
const seconds = num2Str(date.getSeconds());
|
|
101
|
+
const ms = num2Str(date.getMilliseconds(), 3);
|
|
102
|
+
return `${year}${month}${day}${hours}${minutes}${seconds}${ms}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
/**
|
|
87
106
|
* 获取当前页面信息
|
|
88
107
|
*/
|
|
@@ -203,6 +222,7 @@ export default {
|
|
|
203
222
|
getSystemInfo,
|
|
204
223
|
getSystemInfoString,
|
|
205
224
|
convert2String,
|
|
225
|
+
getNowString,
|
|
206
226
|
getPageInfo,
|
|
207
227
|
getLaunchOptionsString,
|
|
208
228
|
getLaunchFrom,
|