sirius-common-utils 1.0.0 → 1.0.1
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 +3 -4
- package/src/packages/index.js +0 -29
- package/src/packages/utils/AppUtils.js +0 -155
- package/src/packages/utils/AxiosUtils.js +0 -433
- package/src/packages/utils/CfgUtils.js +0 -15
- package/src/packages/utils/DateUtils.js +0 -223
- package/src/packages/utils/DomUtils.js +0 -48
- package/src/packages/utils/ExplorerTypeUtils.js +0 -60
- package/src/packages/utils/FormUtils.js +0 -92
- package/src/packages/utils/JsonUtils.js +0 -21
- package/src/packages/utils/LoginUserUtils.js +0 -105
- package/src/packages/utils/NumberUtils.js +0 -60
- package/src/packages/utils/SignatureUtils.js +0 -132
- package/src/packages/utils/StringUtils.js +0 -17
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
|
|
3
|
-
const FORMAT_DATE = "DD-MM-YYYY";
|
|
4
|
-
const FORMAT_DATETIME = "DD-MM-YYYY HH:mm:ss";
|
|
5
|
-
const FORMAT_YEARMONTH = "YYYY-MMMM";
|
|
6
|
-
const FORMAT_YEARWEEK = "YYYY-WW";
|
|
7
|
-
const FORMAT_DAYOFMONTH = "DD";
|
|
8
|
-
const FORMAT_YEAR = "YYYY";
|
|
9
|
-
const FORMAT_TIME = "HH:mm:ss";
|
|
10
|
-
|
|
11
|
-
function getCurrentMoment(){
|
|
12
|
-
return dayjs();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getCurrentDateText(){
|
|
16
|
-
return convertMomentToDateText(getCurrentMoment());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getCurrentDateTimeText(){
|
|
20
|
-
return convertMomentToDateTimeText(getCurrentMoment());
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getCurrentDate(){
|
|
24
|
-
return getCurrentMoment().toDate();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function convertMomentToTimestamp(moment) {
|
|
28
|
-
if (moment) {
|
|
29
|
-
return moment.toDate().getTime();
|
|
30
|
-
} else {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function convertMomentToDateText(moment) {
|
|
36
|
-
if (moment) {
|
|
37
|
-
return moment.format(FORMAT_DATE);
|
|
38
|
-
} else {
|
|
39
|
-
return '';
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function convertTimestampToMoment(timestamp) {
|
|
44
|
-
if (timestamp && timestamp > 0) {
|
|
45
|
-
return dayjs(timestamp);
|
|
46
|
-
} else {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function convertMomentToDateTimeText(moment) {
|
|
52
|
-
if (moment) {
|
|
53
|
-
return moment.format(FORMAT_DATETIME);
|
|
54
|
-
} else {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function convertMomentToYearText(moment) {
|
|
60
|
-
if (moment) {
|
|
61
|
-
return moment.format(FORMAT_YEAR);
|
|
62
|
-
} else {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function convertMomentToYearMonthText(moment) {
|
|
68
|
-
if (moment) {
|
|
69
|
-
return moment.format(FORMAT_YEARMONTH);
|
|
70
|
-
} else {
|
|
71
|
-
return "";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function convertMomentToDayOfMonthText(moment) {
|
|
76
|
-
if (moment) {
|
|
77
|
-
return moment.format(FORMAT_DAYOFMONTH);
|
|
78
|
-
} else {
|
|
79
|
-
return "";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function convertMomentToTimeText(moment) {
|
|
86
|
-
if (moment) {
|
|
87
|
-
return moment.format(FORMAT_TIME);
|
|
88
|
-
} else {
|
|
89
|
-
return "";
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function convertDateTimeTextToMoment(dateTimeText) {
|
|
94
|
-
if (dateTimeText) {
|
|
95
|
-
return dayjs(dateTimeText, FORMAT_DATETIME);
|
|
96
|
-
} else {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function convertYearMonthTextToMoment(yearMonthText) {
|
|
102
|
-
if (yearMonthText) {
|
|
103
|
-
return dayjs(yearMonthText, FORMAT_YEARMONTH);
|
|
104
|
-
} else {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function convertDateTextToMoment(dateText) {
|
|
110
|
-
if (dateText) {
|
|
111
|
-
return dayjs(dateText, FORMAT_DATE);
|
|
112
|
-
} else {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function convertTimeTextToMoment(dateTimeText) {
|
|
118
|
-
if (dateTimeText) {
|
|
119
|
-
return dayjs(dateTimeText, FORMAT_TIME);
|
|
120
|
-
} else {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function convertDateTextToDate(dateText) {
|
|
126
|
-
if (dateText) {
|
|
127
|
-
return dayjs(dateText, FORMAT_DATE).toDate();
|
|
128
|
-
} else {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function convertDateTimeTextToDate(dateTimeText) {
|
|
134
|
-
if (dateTimeText) {
|
|
135
|
-
let moment = dayjs(dateTimeText, FORMAT_DATETIME);
|
|
136
|
-
return dayjs(dateTimeText, FORMAT_DATETIME).toDate();
|
|
137
|
-
} else {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function convertTimestampToDateText(timestamp) {
|
|
143
|
-
let moments = convertTimestampToMoment(timestamp);
|
|
144
|
-
let text = convertMomentToDateText(moments);
|
|
145
|
-
return text;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function convertTimestampToDateTimeText(timestamp) {
|
|
149
|
-
let moments = convertTimestampToMoment(timestamp);
|
|
150
|
-
let text = convertMomentToDateTimeText(moments);
|
|
151
|
-
return text;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function convertDateToMoment(date) {
|
|
155
|
-
if(!date){
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
return dayjs(date);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function convertDateToDateText(date) {
|
|
162
|
-
let moments = convertDateToMoment(date);
|
|
163
|
-
let text = convertMomentToDateText(moments);
|
|
164
|
-
return text;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function convertDateToDateTimeText(date) {
|
|
168
|
-
let moments = convertDateToMoment(date);
|
|
169
|
-
let text = convertMomentToDateTimeText(moments);
|
|
170
|
-
return text;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
function buildDateRange(from, to){
|
|
175
|
-
return from+" ~ "+to;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function getFormatTextOfMMM(mthNumber){
|
|
179
|
-
let moment = getCurrentMoment();
|
|
180
|
-
moment = moment.month(mthNumber-1);
|
|
181
|
-
return moment.format('MMM');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export default {
|
|
185
|
-
FORMAT_DATE: FORMAT_DATE,
|
|
186
|
-
FORMAT_DATETIME: FORMAT_DATETIME,
|
|
187
|
-
FORMAT_YEARMONTH: FORMAT_YEARMONTH,
|
|
188
|
-
FORMAT_YEARWEEK: FORMAT_YEARWEEK,
|
|
189
|
-
FORMAT_TIME: FORMAT_TIME,
|
|
190
|
-
|
|
191
|
-
getCurrentMoment: getCurrentMoment,
|
|
192
|
-
getCurrentDateTimeText: getCurrentDateTimeText,
|
|
193
|
-
getCurrentDateText: getCurrentDateText,
|
|
194
|
-
getCurrentDate: getCurrentDate,
|
|
195
|
-
|
|
196
|
-
convertMomentToTimestamp: convertMomentToTimestamp,
|
|
197
|
-
convertMomentToDateText: convertMomentToDateText,
|
|
198
|
-
convertMomentToDateTimeText: convertMomentToDateTimeText,
|
|
199
|
-
convertMomentToYearText: convertMomentToYearText,
|
|
200
|
-
convertMomentToYearMonthText: convertMomentToYearMonthText,
|
|
201
|
-
convertMomentToDayOfMonthText: convertMomentToDayOfMonthText,
|
|
202
|
-
convertMomentToTimeText: convertMomentToTimeText,
|
|
203
|
-
|
|
204
|
-
convertTimestampToMoment: convertTimestampToMoment,
|
|
205
|
-
convertTimestampToDateText: convertTimestampToDateText,
|
|
206
|
-
convertTimestampToDateTimeText: convertTimestampToDateTimeText,
|
|
207
|
-
|
|
208
|
-
convertDateToMoment: convertDateToMoment,
|
|
209
|
-
convertDateToDateText: convertDateToDateText,
|
|
210
|
-
convertDateToDateTimeText: convertDateToDateTimeText,
|
|
211
|
-
|
|
212
|
-
convertYearMonthTextToMoment: convertYearMonthTextToMoment,
|
|
213
|
-
convertDateTextToMoment: convertDateTextToMoment,
|
|
214
|
-
convertDateTimeTextToMoment: convertDateTimeTextToMoment,
|
|
215
|
-
convertTimeTextToMoment: convertTimeTextToMoment,
|
|
216
|
-
|
|
217
|
-
convertDateTextToDate: convertDateTextToDate,
|
|
218
|
-
convertDateTimeTextToDate: convertDateTimeTextToDate,
|
|
219
|
-
|
|
220
|
-
buildDateRange:buildDateRange,
|
|
221
|
-
|
|
222
|
-
getFormatTextOfMMM: getFormatTextOfMMM,
|
|
223
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
|
|
3
|
-
function resetBodyScroll(){
|
|
4
|
-
document.querySelector("body").style.position="initial";
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function forbidBodyScroll(){
|
|
8
|
-
document.querySelector("body").style.position="fixed";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function syncDomAnimation() {
|
|
12
|
-
setTimeout(() => {
|
|
13
|
-
//sync all animation be the same
|
|
14
|
-
_.each(document.getAnimations(), (item) => {
|
|
15
|
-
item.startTime = 0;
|
|
16
|
-
});
|
|
17
|
-
}, 200);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* find the closet parent element by className
|
|
22
|
-
*
|
|
23
|
-
* @param elem
|
|
24
|
-
* @param className
|
|
25
|
-
*/
|
|
26
|
-
function closetByClassName(elem, classNameList) {
|
|
27
|
-
let classList = elem.classList;
|
|
28
|
-
if (classList) {
|
|
29
|
-
if (_.intersection(classList, classNameList).length > 0) {
|
|
30
|
-
return elem;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let parentElement = elem.parentElement;
|
|
35
|
-
if (parentElement) {
|
|
36
|
-
return closetByClassName(parentElement, classNameList);
|
|
37
|
-
} else {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default {
|
|
43
|
-
resetBodyScroll: resetBodyScroll,
|
|
44
|
-
forbidBodyScroll: forbidBodyScroll,
|
|
45
|
-
|
|
46
|
-
syncDomAnimation: syncDomAnimation,
|
|
47
|
-
closetByClassName: closetByClassName,
|
|
48
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
function isIOS() {
|
|
2
|
-
return [
|
|
3
|
-
'iPad Simulator',
|
|
4
|
-
'iPhone Simulator',
|
|
5
|
-
'iPod Simulator',
|
|
6
|
-
'iPad',
|
|
7
|
-
'iPhone',
|
|
8
|
-
'iPod'
|
|
9
|
-
].includes(navigator.platform) || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function isDesktopChrome() {
|
|
13
|
-
let result = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
|
14
|
-
if (!result) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (isMobileChrome()) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isMobileChrome() {
|
|
26
|
-
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isMobileDevice() {
|
|
30
|
-
return isIOS() || isMobileChrome();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function updateViewPort(pOptions = {}) {
|
|
34
|
-
let viewport = document.getElementsByName("viewport");
|
|
35
|
-
if (!viewport || viewport.length != 1) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let options = {};
|
|
40
|
-
_.merge(options, defaultOptions, pOptions);
|
|
41
|
-
|
|
42
|
-
let content = [];
|
|
43
|
-
_.each(options, (value, key) => {
|
|
44
|
-
content.push(key + "=" + value);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
viewport[0].content = _.join(content, ",");
|
|
48
|
-
|
|
49
|
-
console.debug("curr viewport is: " + viewport[0].content);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default {
|
|
53
|
-
isIOS: isIOS,
|
|
54
|
-
isDesktopChrome: isDesktopChrome,
|
|
55
|
-
isMobileChrome: isMobileChrome,
|
|
56
|
-
|
|
57
|
-
isMobileDevice: isMobileDevice,
|
|
58
|
-
|
|
59
|
-
updateViewPort: updateViewPort,
|
|
60
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React, {useEffect, useRef, useState, createContext, useContext} from 'react';
|
|
2
|
-
import _ from "lodash";
|
|
3
|
-
|
|
4
|
-
let globalDialogUtils;
|
|
5
|
-
|
|
6
|
-
function init(pDialogInstanceUtils) {
|
|
7
|
-
globalDialogUtils = pDialogInstanceUtils;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function toFormData(keyPrefix, model, ignoreKeys = [], formData = {}) {
|
|
11
|
-
if(model == null){
|
|
12
|
-
return {
|
|
13
|
-
keyPrefix: null
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
_.each(_.keys(model), (attr) => {
|
|
18
|
-
let value = model[attr];
|
|
19
|
-
let formKeyPath = keyPrefix ? keyPrefix + "#" + attr : attr;
|
|
20
|
-
|
|
21
|
-
if(_.includes(ignoreKeys, formKeyPath)){
|
|
22
|
-
formData[formKeyPath] = value;
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (_.isPlainObject(value)) {
|
|
27
|
-
toFormData(formKeyPath, value, ignoreKeys, formData);
|
|
28
|
-
} else {
|
|
29
|
-
formData[formKeyPath] = value;
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
return formData;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function toModel(formData, ignoreKeys = []) {
|
|
37
|
-
if(formData == null){
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let model = {};
|
|
42
|
-
_.each(_.keys(formData), (formKeyPath) => {
|
|
43
|
-
let value = formData[formKeyPath];
|
|
44
|
-
let path = formKeyPath.replaceAll("#", ".");
|
|
45
|
-
_.set(model, path, value);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return model;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function scrollToFirstError(ex){
|
|
52
|
-
const isError = document.getElementsByClassName('ant-form-item-has-error');
|
|
53
|
-
isError[0] && isError[0].scrollIntoView();
|
|
54
|
-
console.error(ex);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* show leave message when exit from a modified form page
|
|
59
|
-
* @param formOrCheckFormDirtyFunc AntDesignForm or checkFormDirtyFunction
|
|
60
|
-
* @returns {Promise<boolean>} true: can exit, or: abort exit
|
|
61
|
-
*/
|
|
62
|
-
async function confirmOfLeavingForm(formOrCheckFormDirtyFunc) {
|
|
63
|
-
if(formOrCheckFormDirtyFunc == null){
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
let formDirty = true;
|
|
67
|
-
if (typeof formOrCheckFormDirtyFunc === 'function') {
|
|
68
|
-
formDirty = await formOrCheckFormDirtyFunc();
|
|
69
|
-
}else{
|
|
70
|
-
formDirty = formOrCheckFormDirtyFunc.isFieldsTouched();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (formDirty) {
|
|
74
|
-
let result = await globalDialogUtils.showConfirmDialog(leaveMessage);
|
|
75
|
-
if (result !== true) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const leaveMessage = "Do you want to give up your modification?";
|
|
83
|
-
export default {
|
|
84
|
-
init: init,
|
|
85
|
-
|
|
86
|
-
toFormData: toFormData,
|
|
87
|
-
toModel: toModel,
|
|
88
|
-
scrollToFirstError: scrollToFirstError,
|
|
89
|
-
|
|
90
|
-
confirmOfLeavingForm: confirmOfLeavingForm,
|
|
91
|
-
leaveMessage: leaveMessage
|
|
92
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
|
|
3
|
-
function isJsonText(value) {
|
|
4
|
-
value = _.trim(value);
|
|
5
|
-
|
|
6
|
-
return (_.startsWith(value, "{") || _.startsWith(value, "["));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function formatJsonText(value) {
|
|
10
|
-
if (!isJsonText(value)) {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return JSON.stringify(JSON.parse(value), null, 4);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
isJsonText: isJsonText,
|
|
20
|
-
formatJsonText: formatJsonText,
|
|
21
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getCurrUserInfo
|
|
3
|
-
*/
|
|
4
|
-
import EnosAppPortalSdkUtils from "./EnosAppPortalSdkUtils";
|
|
5
|
-
import AxiosUtils from "./AxiosUtils";
|
|
6
|
-
import _ from "lodash";
|
|
7
|
-
import AppUtils from "./AppUtils";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function init(deviceType, pCurrUserInfoCache) {
|
|
11
|
-
if(pCurrUserInfoCache){
|
|
12
|
-
currUserInfoCache = pCurrUserInfoCache;
|
|
13
|
-
AppUtils.setLocalStorageObjItem("CURRENT_USER", currUserInfoCache);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
await getCurrUserModel();
|
|
17
|
-
|
|
18
|
-
setDeviceType(deviceType);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function clear(){
|
|
22
|
-
currUserInfoCache = null;
|
|
23
|
-
appUserModel = null;
|
|
24
|
-
AppUtils.setLocalStorageObjItem("CURRENT_USER", null);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function setDeviceType(deviceType) {
|
|
28
|
-
if(deviceType === 'MOBILE') {
|
|
29
|
-
AppUtils.setLocalStorageStringItem("DEVICE_TYPE", "MOBILE");
|
|
30
|
-
}else{
|
|
31
|
-
AppUtils.setLocalStorageStringItem("DEVICE_TYPE", "WEB");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isMobileDevice() {
|
|
36
|
-
let deviceType = AppUtils.getLocalStorageStringItem("DEVICE_TYPE");
|
|
37
|
-
return deviceType === 'MOBILE';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let currUserInfoCache = null;
|
|
41
|
-
async function getCurrUserInfo() {
|
|
42
|
-
if(isMobileDevice()){
|
|
43
|
-
return getCurrUserInfoCache();
|
|
44
|
-
}else{
|
|
45
|
-
let currUser = await EnosAppPortalSdkUtils.getUserInfo();
|
|
46
|
-
currUserInfoCache = currUser;
|
|
47
|
-
return currUser;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getCurrUserInfoCache(){
|
|
52
|
-
if(currUserInfoCache!=null){
|
|
53
|
-
return currUserInfoCache;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
currUserInfoCache = AppUtils.getLocalStorageObjItem("CURRENT_USER");
|
|
57
|
-
if(currUserInfoCache!=null){
|
|
58
|
-
return currUserInfoCache;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
console.debug("Please invoke getCurrUserInfo first");
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getCurrUserId(){
|
|
66
|
-
return getCurrUserInfoCache()?.id;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let appUserModel = null;
|
|
71
|
-
async function getCurrUserModel() {
|
|
72
|
-
if(appUserModel == null) {
|
|
73
|
-
let url = `/api/user/getCurrUserInfo`;
|
|
74
|
-
appUserModel = await AxiosUtils.getJsonData(url);
|
|
75
|
-
}
|
|
76
|
-
return appUserModel;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* check user role
|
|
81
|
-
*/
|
|
82
|
-
function userHasRole(roleCodeOrArray) {
|
|
83
|
-
if(appUserModel == null){
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if(_.isArray(roleCodeOrArray)){
|
|
88
|
-
return !_.isEmpty(_.intersection(appUserModel.roleList, roleCodeOrArray));
|
|
89
|
-
}else{
|
|
90
|
-
return _.includes(appUserModel.roleList, roleCodeOrArray);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default {
|
|
95
|
-
init: init,
|
|
96
|
-
clear: clear,
|
|
97
|
-
getCurrUserInfo: getCurrUserInfo,
|
|
98
|
-
getCurrUserInfoCache: getCurrUserInfoCache,
|
|
99
|
-
getCurrUserId: getCurrUserId,
|
|
100
|
-
getCurrUserModel: getCurrUserModel,
|
|
101
|
-
userHasRole: userHasRole,
|
|
102
|
-
|
|
103
|
-
isMobileDevice: isMobileDevice,
|
|
104
|
-
|
|
105
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
|
|
3
|
-
function formatNumberTextWithUnit(numberText, unitText) {
|
|
4
|
-
if (!unitText) {
|
|
5
|
-
return numberText;
|
|
6
|
-
}
|
|
7
|
-
return numberText + " " + unitText;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function formatPctWith2Digital(valuePct) {
|
|
11
|
-
let valuePctText = formatNumberWithDigital(valuePct, 2, false);
|
|
12
|
-
return valuePctText + "%";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function formatNumberWith2Digital(value) {
|
|
16
|
-
return formatNumberWithDigital(value, 2);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function formatNumberWith4Digital(value) {
|
|
20
|
-
return formatNumberWithDigital(value, 4);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function formatNumberWithDigital(value, digital) {
|
|
24
|
-
if (value === null) {
|
|
25
|
-
return "";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let dblValue = (_.toNumber(value));
|
|
29
|
-
if (isNaN(dblValue)) {
|
|
30
|
-
//the string value could not be convert to number, just return it;
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let valueText = value;
|
|
35
|
-
if (digital != null) {
|
|
36
|
-
let text = _.round(dblValue, digital) + "";
|
|
37
|
-
if (text.indexOf(".") === -1) {
|
|
38
|
-
text += '.';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let part1 = text.substring(0, text.indexOf("."));
|
|
42
|
-
let part2 = "";
|
|
43
|
-
|
|
44
|
-
if (digital > 0) {
|
|
45
|
-
part2 = text.substring(text.indexOf(".") + 1); //取到小数部分搜索
|
|
46
|
-
part2 = "." + _.padEnd(part2, digital, '0');
|
|
47
|
-
}
|
|
48
|
-
valueText = part1 + part2;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return valueText;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default {
|
|
55
|
-
formatPctWith2Digital: formatPctWith2Digital,
|
|
56
|
-
formatNumberWith2Digital: formatNumberWith2Digital,
|
|
57
|
-
formatNumberWith4Digital: formatNumberWith4Digital,
|
|
58
|
-
formatNumberWithDigital: formatNumberWithDigital,
|
|
59
|
-
formatNumberTextWithUnit: formatNumberTextWithUnit,
|
|
60
|
-
};
|