@tmsfe/tms-core 0.0.84 → 0.0.87
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
package/src/index-proxy.js
CHANGED
|
@@ -10,7 +10,7 @@ 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 } from './navbarUtils';
|
|
13
|
+
import { getNavBarConfigData, compareVersion } from './navbarUtils';
|
|
14
14
|
import * as uiUtil from './tmsuiUtils';
|
|
15
15
|
import * as rpxUtil from './rpx';
|
|
16
16
|
import * as stringUtils from './stringUtils';
|
|
@@ -216,6 +216,7 @@ const api = {
|
|
|
216
216
|
calCoordinateDistance,
|
|
217
217
|
formatDistance,
|
|
218
218
|
getNavBarConfigData,
|
|
219
|
+
compareVersion,
|
|
219
220
|
createRequest,
|
|
220
221
|
getEnvInfo,
|
|
221
222
|
isAppPageExist,
|
package/src/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import EventDispatcher from './eventDispatcher';
|
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
13
|
import { calCoordinateDistance, formatDistance } from './distanceUtils';
|
|
14
14
|
import { rpxToPx, pxToRpx } from './rpx';
|
|
15
|
-
import { getNavBarConfigData } from './navbarUtils';
|
|
15
|
+
import { getNavBarConfigData, compareVersion } from './navbarUtils';
|
|
16
16
|
import {
|
|
17
17
|
formatPlate,
|
|
18
18
|
subStr,
|
|
@@ -196,6 +196,8 @@ const api = {
|
|
|
196
196
|
rpxToPx,
|
|
197
197
|
pxToRpx,
|
|
198
198
|
|
|
199
|
+
/** 版本比较 */
|
|
200
|
+
compareVersion,
|
|
199
201
|
getNavBarConfigData,
|
|
200
202
|
|
|
201
203
|
storage,
|
package/src/navbarUtils.js
CHANGED
|
@@ -125,14 +125,15 @@ class CanvasDrawer {
|
|
|
125
125
|
* @memberof Wxml2Poster
|
|
126
126
|
*/
|
|
127
127
|
drawText(text, x, y, size, color, align = 'left', bold = 'normal', baseLine = 'middle', calWidth = false) {
|
|
128
|
+
const str = `${text}`; // 避免某些环境下字体宽度计算异常(如手图),这里统一将绘制文本转为字符串
|
|
128
129
|
this.ctx.save();
|
|
129
130
|
this.ctx.fillStyle = color;
|
|
130
131
|
this.ctx.font = `normal ${bold} ${~~(this.toPx(size))}px sans-serif`;
|
|
131
132
|
let width = 0;
|
|
132
|
-
if (calWidth) width = this.ctx.measureText(
|
|
133
|
+
if (calWidth) width = this.ctx.measureText(str).width; // 必须在设置字体属性后未绘制前计算才能拿到准确值; 无需计算时避免耗费性能
|
|
133
134
|
this.ctx.textAlign = align;
|
|
134
135
|
this.ctx.textBaseline = baseLine;
|
|
135
|
-
this.ctx.fillText(
|
|
136
|
+
this.ctx.fillText(str, this.toPx(x), this.toPx(y));
|
|
136
137
|
this.ctx.restore();
|
|
137
138
|
return width;
|
|
138
139
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
class Common {
|
|
2
|
-
// 获取本月开始时间
|
|
3
|
-
static getMonthStart() {
|
|
4
|
-
const now = new Date(); // 获取当前时间
|
|
5
|
-
const beginTimes = now.getFullYear(); // 开始计算
|
|
6
|
-
let month = now.getMonth() + 1 ; // getMonth()是以0开始的月份
|
|
7
|
-
if (month < 10) {
|
|
8
|
-
month = `0${month}`;
|
|
9
|
-
}
|
|
10
|
-
const startTimes = `${beginTimes}-${month}-01`; // 格式 Y-m-d
|
|
11
|
-
return startTimes;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static pointToYuan(num) {
|
|
15
|
-
if (!num || num <= 0) {
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
const { tms } = getApp({ allowDefault: true });
|
|
19
|
-
return tms.roundStr(num / 100, 0);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static handleApiRes(res) {
|
|
23
|
-
let { errCode, errMsg, resData } = res;
|
|
24
|
-
// 兼容后端返回err、info作为字段的情况
|
|
25
|
-
// eslint-disable-next-line
|
|
26
|
-
if (resData?.data?.hasOwnProperty('err')) {
|
|
27
|
-
errCode = resData.data.err;
|
|
28
|
-
errMsg = resData.data.info;
|
|
29
|
-
resData = resData.data;
|
|
30
|
-
if (errCode !== 0) {
|
|
31
|
-
return Promise.reject({ errCode, errMsg, resData });
|
|
32
|
-
}
|
|
33
|
-
return Promise.resolve(resData);
|
|
34
|
-
}
|
|
35
|
-
if (errCode !== 0) {
|
|
36
|
-
return Promise.reject(res);
|
|
37
|
-
}
|
|
38
|
-
return Promise.resolve(resData);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static handleConditionValue(item, value) {
|
|
42
|
-
if (isNaN(value)) {
|
|
43
|
-
return { value, units: item.units };
|
|
44
|
-
}
|
|
45
|
-
let newValue = value;
|
|
46
|
-
let { units } = item;
|
|
47
|
-
// 小数点处理
|
|
48
|
-
if (item.point === 0) {
|
|
49
|
-
newValue = Math.round(newValue);
|
|
50
|
-
}
|
|
51
|
-
if (item.point) {
|
|
52
|
-
newValue = parseFloat(newValue.toFixed(item.point));
|
|
53
|
-
}
|
|
54
|
-
if (newValue > 9999) {
|
|
55
|
-
newValue = `${(newValue / 10000).toFixed(1)}`;
|
|
56
|
-
units = `万${item.units}`;
|
|
57
|
-
}
|
|
58
|
-
return { value: newValue, units };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export default Common;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import m from './Model';
|
|
2
|
-
import Comm from './Comm';
|
|
3
|
-
|
|
4
|
-
export default class Controller {
|
|
5
|
-
static report = m.report;
|
|
6
|
-
static carManager = m.carManager;
|
|
7
|
-
static getConfig = m.getConfig;
|
|
8
|
-
static locManager = m.locManager;
|
|
9
|
-
static rtLog = m.rtLog;
|
|
10
|
-
static dateToString = m.dateToString;
|
|
11
|
-
static log = m.log;
|
|
12
|
-
|
|
13
|
-
// 通用的埋点方法
|
|
14
|
-
// wecarId seriesId modelId必传
|
|
15
|
-
static commReport(currentCar = {}, param = {}) {
|
|
16
|
-
const { wecarId = '', seriesId = 0, modelId = 0 } = currentCar;
|
|
17
|
-
// console.log('我要埋点了', param['27'], { 4: wecarId, 39: seriesId, 30: modelId, ...param });
|
|
18
|
-
return Controller.report({ 4: wecarId, 39: seriesId, 30: modelId, ...param });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 车辆本月etc账单
|
|
22
|
-
static async getETCAmount(currentCar) {
|
|
23
|
-
const { plate, wecarId, userId, plateColor } = currentCar;
|
|
24
|
-
const param = { userId, plateNum: plate, wecarId };
|
|
25
|
-
let result = { etcData: {} };
|
|
26
|
-
try {
|
|
27
|
-
const { data } = await m.queryEtcBindStatus(param) || {};
|
|
28
|
-
if (!data || data.etcStatus !== 1) {
|
|
29
|
-
result.isBindEtc = false;
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
} catch (error) {
|
|
33
|
-
result.isBindEtc = false;
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const param2 = { plateColor, dateBegin: Comm.getMonthStart(), dateEnd: Controller.dateToString() };
|
|
39
|
-
Object.assign(param, param2);
|
|
40
|
-
const res = await m.queryEtcMount(param) || {};
|
|
41
|
-
result = {
|
|
42
|
-
isBindEtc: true,
|
|
43
|
-
getEtcDataError: false,
|
|
44
|
-
};
|
|
45
|
-
if (res.totalAmount > 0) {
|
|
46
|
-
result.etcData = { ...res, totalAmount: Comm.pointToYuan(res.totalAmount) };
|
|
47
|
-
} else {
|
|
48
|
-
result.etcData = { };
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
result = {
|
|
52
|
-
isBindEtc: true,
|
|
53
|
-
getEtcDataError: true,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 获取车况配置
|
|
60
|
-
static async getCarConditionConfig(param) {
|
|
61
|
-
let data = {};
|
|
62
|
-
try {
|
|
63
|
-
data = await m.getCarConditionConfig(param);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
m.log({ name: 'getCarConditionConfig', param, err });
|
|
66
|
-
}
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 获取车控配置
|
|
71
|
-
static async getCarControlConfig(param) {
|
|
72
|
-
let data = {};
|
|
73
|
-
try {
|
|
74
|
-
data = await m.getCarControlConfig(param);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
m.log({ name: 'getCarControlConfig', param, err });
|
|
77
|
-
}
|
|
78
|
-
return data;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 获取车况
|
|
82
|
-
static async getGactoyotaCondition(param) {
|
|
83
|
-
let data = {};
|
|
84
|
-
try {
|
|
85
|
-
data = await m.getGactoyotaCondition(param);
|
|
86
|
-
} catch (err) {
|
|
87
|
-
m.log({ name: 'getGactoyotaCondition', param, err });
|
|
88
|
-
}
|
|
89
|
-
return data;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Comm from './Comm';
|
|
2
|
-
const app = getApp({ allowDefault: true });
|
|
3
|
-
|
|
4
|
-
export default class Model {
|
|
5
|
-
static report = app.tms.getReporter().report;
|
|
6
|
-
static carManager = app.tms.getCarManager();
|
|
7
|
-
static getConfig = app.tms.getConfig;
|
|
8
|
-
static locManager = app.tms.getLocationManager();
|
|
9
|
-
static rtLog = app.tms.getRealtimeLogManager();
|
|
10
|
-
static dateToString = app.tms.dateToString;
|
|
11
|
-
|
|
12
|
-
static doRequest(path, param, method = 'POST', header) {
|
|
13
|
-
return app.tms.createRequest().doRequest(path, { ...param }, method, header)
|
|
14
|
-
.then(res => Comm.handleApiRes(res))
|
|
15
|
-
.catch(err => Promise.reject(err));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static log(...args) {
|
|
19
|
-
console.error(...args);
|
|
20
|
-
Model.rtLog.info(args[0]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 获取车况数据
|
|
24
|
-
// static getGactoyotaCondition(param) {
|
|
25
|
-
// return Model.doRequest('gactoyota/condition', { ...param }, 'POST');
|
|
26
|
-
// }
|
|
27
|
-
static getGactoyotaCondition(param) {
|
|
28
|
-
return Model.doRequest('carcardvinfosvc/get_car_condition', { ...param }, 'POST', {
|
|
29
|
-
'X-TAI-Module': 'carcardvinfosvc',
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// 获取车况配置
|
|
34
|
-
static getCarConditionConfig() {
|
|
35
|
-
const app = getApp({ allowDefault: true });
|
|
36
|
-
return app.tms.getConfig('/sinan/carcondition/config');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 获取车控配置
|
|
40
|
-
static getCarControlConfig() {
|
|
41
|
-
const app = getApp({ allowDefault: true });
|
|
42
|
-
return app.tms.getConfig('/sinan/carcontrol/config');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static queryEtcMount(param) {
|
|
46
|
-
return Model.doRequest('etc/totalamount', { ...param }, 'post');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static queryEtcBindStatus(param) {
|
|
50
|
-
return Model.doRequest('etc/querybindstatus', { ...param }, 'post');
|
|
51
|
-
}
|
|
52
|
-
};
|