@tmsfe/tms-core 0.0.86 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.86",
3
+ "version": "0.0.87",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
- };