sirius-common-utils 1.0.0
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.js +35 -0
- package/dist/utils/AppUtils.js +139 -0
- package/dist/utils/AxiosUtils.js +555 -0
- package/dist/utils/CfgUtils.js +25 -0
- package/dist/utils/DateUtils.js +193 -0
- package/dist/utils/DomUtils.js +50 -0
- package/dist/utils/ExplorerTypeUtils.js +48 -0
- package/dist/utils/FormUtils.js +128 -0
- package/dist/utils/JsonUtils.js +23 -0
- package/dist/utils/LoginUserUtils.js +169 -0
- package/dist/utils/NumberUtils.js +57 -0
- package/dist/utils/SignatureUtils.js +160 -0
- package/dist/utils/StringUtils.js +20 -0
- package/package.json +37 -0
- package/src/packages/index.js +29 -0
- package/src/packages/utils/AppUtils.js +155 -0
- package/src/packages/utils/AxiosUtils.js +433 -0
- package/src/packages/utils/CfgUtils.js +15 -0
- package/src/packages/utils/DateUtils.js +223 -0
- package/src/packages/utils/DomUtils.js +48 -0
- package/src/packages/utils/ExplorerTypeUtils.js +60 -0
- package/src/packages/utils/FormUtils.js +92 -0
- package/src/packages/utils/JsonUtils.js +21 -0
- package/src/packages/utils/LoginUserUtils.js +105 -0
- package/src/packages/utils/NumberUtils.js +60 -0
- package/src/packages/utils/SignatureUtils.js +132 -0
- package/src/packages/utils/StringUtils.js +17 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
var _CfgUtils = _interopRequireDefault(require("./CfgUtils"));
|
|
10
|
+
var _LoginUserUtils = _interopRequireDefault(require("./LoginUserUtils"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
13
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
14
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
|
+
var axios = null;
|
|
16
|
+
var urlContext = null; //URL路径前缀
|
|
17
|
+
|
|
18
|
+
var RESULT = {
|
|
19
|
+
SUCCESS: 200
|
|
20
|
+
};
|
|
21
|
+
var EXCEPTION_CODE = {
|
|
22
|
+
AUTHENTICATION_FAILED_COMMON: 901,
|
|
23
|
+
NETWORK_ISSUE_CLIENT: 911,
|
|
24
|
+
SYS_UNKNOWN_ISSUE: 999
|
|
25
|
+
};
|
|
26
|
+
var globalDialogUtilsInstance;
|
|
27
|
+
var globalSpinHandlerInstance;
|
|
28
|
+
var loginServiceInstance;
|
|
29
|
+
function init(pAxios, pSpinHandlerInstance, pDialogUtilsInstance, pLoginServiceInstance) {
|
|
30
|
+
axios = pAxios;
|
|
31
|
+
|
|
32
|
+
// axios.defaults.baseURL = getPath("/xms-test");
|
|
33
|
+
axios.defaults.baseURL = getPath(process.env.REACT_APP_AXIOS_CONTEXT);
|
|
34
|
+
axios.defaults.timeout = _CfgUtils["default"].ajax.timeout;
|
|
35
|
+
globalDialogUtilsInstance = pDialogUtilsInstance;
|
|
36
|
+
globalSpinHandlerInstance = pSpinHandlerInstance;
|
|
37
|
+
loginServiceInstance = pLoginServiceInstance;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
function loadParamFromLocationSearch(paramKey) {
|
|
44
|
+
var paramsStr = window.location.search;
|
|
45
|
+
if (paramsStr.indexOf('?') === 0) {
|
|
46
|
+
paramsStr = paramsStr.substring(1);
|
|
47
|
+
}
|
|
48
|
+
var entryParams = paramsStr.split('&');
|
|
49
|
+
var entryParamStr = _lodash["default"].find(entryParams, function (param) {
|
|
50
|
+
return param.indexOf(paramKey) === 0;
|
|
51
|
+
});
|
|
52
|
+
if (!entryParamStr) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
var param = entryParamStr.split('=');
|
|
56
|
+
if (!param[1]) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return param[1];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* get the entire url path
|
|
64
|
+
* @param path start with '/'
|
|
65
|
+
* @returns {string|*}
|
|
66
|
+
*/
|
|
67
|
+
function getPath(path) {
|
|
68
|
+
if (_lodash["default"].startsWith(path, "http")) {
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
if (urlContext == null) {
|
|
72
|
+
urlContext = window.document.location.href;
|
|
73
|
+
var lastIdx = urlContext.indexOf('.htm');
|
|
74
|
+
if (lastIdx > -1) {
|
|
75
|
+
urlContext = urlContext.substring(0, urlContext.lastIndexOf('/', lastIdx));
|
|
76
|
+
} else {
|
|
77
|
+
lastIdx = urlContext.indexOf('/#');
|
|
78
|
+
if (lastIdx > -1) {
|
|
79
|
+
urlContext = urlContext.substring(0, lastIdx);
|
|
80
|
+
} else {
|
|
81
|
+
lastIdx = urlContext.indexOf('#');
|
|
82
|
+
if (lastIdx > -1) {
|
|
83
|
+
urlContext = urlContext.substring(0, lastIdx);
|
|
84
|
+
} else {
|
|
85
|
+
console.log("Could not identify URL path ".concat(urlContext));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//http://localhost:3000/index.html/#/index/highTriggerWiggleRoomValue -> http://localhost:3000
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return urlContext + path;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Download excel from server
|
|
97
|
+
*/
|
|
98
|
+
function downloadExcelData(url, data, headers) {
|
|
99
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
100
|
+
return new Promise( /*#__PURE__*/function () {
|
|
101
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
|
|
102
|
+
var response, errorResult, link, blob, contentDisposition, _errorResult, temp, fileName, _errorResult2;
|
|
103
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
104
|
+
while (1) switch (_context.prev = _context.next) {
|
|
105
|
+
case 0:
|
|
106
|
+
headers = headers || {};
|
|
107
|
+
if (headers['Content-Type'] == null) {
|
|
108
|
+
headers['Content-Type'] = 'application/json';
|
|
109
|
+
}
|
|
110
|
+
_context.next = 4;
|
|
111
|
+
return buildUserAccessToken(headers);
|
|
112
|
+
case 4:
|
|
113
|
+
_context.prev = 4;
|
|
114
|
+
_context.next = 7;
|
|
115
|
+
return axios({
|
|
116
|
+
method: 'post',
|
|
117
|
+
url: url,
|
|
118
|
+
data: data,
|
|
119
|
+
headers: headers,
|
|
120
|
+
responseType: 'blob'
|
|
121
|
+
});
|
|
122
|
+
case 7:
|
|
123
|
+
response = _context.sent;
|
|
124
|
+
if (!response.data) {
|
|
125
|
+
_context.next = 15;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (!(response.data.errorCode && response.data.errorCode !== RESULT.SUCCESS)) {
|
|
129
|
+
_context.next = 15;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
_context.next = 12;
|
|
133
|
+
return handlerError(url, data, response);
|
|
134
|
+
case 12:
|
|
135
|
+
errorResult = _context.sent;
|
|
136
|
+
resolve(errorResult);
|
|
137
|
+
return _context.abrupt("return");
|
|
138
|
+
case 15:
|
|
139
|
+
link = document.createElement('a');
|
|
140
|
+
blob = new Blob([response.data], {
|
|
141
|
+
type: 'application/vnd.ms-excel'
|
|
142
|
+
});
|
|
143
|
+
contentDisposition = response.headers["content-disposition"];
|
|
144
|
+
if (!(contentDisposition == null)) {
|
|
145
|
+
_context.next = 24;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
_context.next = 21;
|
|
149
|
+
return handlerError(url, data, {
|
|
150
|
+
data: {
|
|
151
|
+
errorCode: EXCEPTION_CODE.SYS_UNKNOWN_ISSUE,
|
|
152
|
+
error: "System Error"
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
case 21:
|
|
156
|
+
_errorResult = _context.sent;
|
|
157
|
+
resolve(_errorResult);
|
|
158
|
+
return _context.abrupt("return");
|
|
159
|
+
case 24:
|
|
160
|
+
temp = contentDisposition.split(";")[1].split("ilename=")[1];
|
|
161
|
+
fileName = decodeURIComponent(temp);
|
|
162
|
+
console.log(fileName);
|
|
163
|
+
link.style.display = 'none';
|
|
164
|
+
link.href = URL.createObjectURL(blob);
|
|
165
|
+
link.setAttribute('download', fileName);
|
|
166
|
+
document.body.appendChild(link);
|
|
167
|
+
link.click();
|
|
168
|
+
document.body.removeChild(link);
|
|
169
|
+
resolve(true);
|
|
170
|
+
_context.next = 42;
|
|
171
|
+
break;
|
|
172
|
+
case 36:
|
|
173
|
+
_context.prev = 36;
|
|
174
|
+
_context.t0 = _context["catch"](4);
|
|
175
|
+
_context.next = 40;
|
|
176
|
+
return handlerError(url, {}, _context.t0);
|
|
177
|
+
case 40:
|
|
178
|
+
_errorResult2 = _context.sent;
|
|
179
|
+
resolve(_errorResult2);
|
|
180
|
+
case 42:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee, null, [[4, 36]]);
|
|
185
|
+
}));
|
|
186
|
+
return function (_x, _x2) {
|
|
187
|
+
return _ref.apply(this, arguments);
|
|
188
|
+
};
|
|
189
|
+
}());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
function downloadServerData(url) {
|
|
196
|
+
return new Promise(function (resolve, reject) {
|
|
197
|
+
var hyperlink = document.createElement('a');
|
|
198
|
+
hyperlink.style.display = 'none'; //隐藏,没必要展示出来
|
|
199
|
+
hyperlink.href = url;
|
|
200
|
+
hyperlink.target = "_blank";
|
|
201
|
+
document.body.appendChild(hyperlink);
|
|
202
|
+
hyperlink.click();
|
|
203
|
+
URL.revokeObjectURL(hyperlink.href); // 释放URL 对象
|
|
204
|
+
document.body.removeChild(hyperlink); //下载
|
|
205
|
+
|
|
206
|
+
resolve(true);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* upload file to server
|
|
212
|
+
* TODO Joey need check with FormData scenario
|
|
213
|
+
*/
|
|
214
|
+
function uploadFile(url, file, headers, onUploadProgress, customizedOptions) {
|
|
215
|
+
headers = headers || {};
|
|
216
|
+
var formdata = new FormData();
|
|
217
|
+
if (_lodash["default"].isArray(file)) {
|
|
218
|
+
formdata.append("files", file);
|
|
219
|
+
} else {
|
|
220
|
+
formdata.append("file", file);
|
|
221
|
+
}
|
|
222
|
+
customizedOptions = customizedOptions || {};
|
|
223
|
+
return execute("POST", url, formdata, headers, onUploadProgress, customizedOptions);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* getStaticTextFile
|
|
228
|
+
*/
|
|
229
|
+
function getStaticTextFile(url) {
|
|
230
|
+
return new Promise( /*#__PURE__*/function () {
|
|
231
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
|
|
232
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
233
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
axios.get(url).then(function (res) {
|
|
236
|
+
resolve(res);
|
|
237
|
+
}, function (error) {
|
|
238
|
+
resolve(null);
|
|
239
|
+
});
|
|
240
|
+
case 1:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context2.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee2);
|
|
245
|
+
}));
|
|
246
|
+
return function (_x3, _x4) {
|
|
247
|
+
return _ref2.apply(this, arguments);
|
|
248
|
+
};
|
|
249
|
+
}());
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* build form-data from param object
|
|
254
|
+
*/
|
|
255
|
+
function getUrlParam(params) {
|
|
256
|
+
if (params) {
|
|
257
|
+
var param = '';
|
|
258
|
+
_lodash["default"].each(params, function (i, val) {
|
|
259
|
+
if (i != null) {
|
|
260
|
+
param += val + '=' + encodeURIComponent(i) + '&';
|
|
261
|
+
} else {
|
|
262
|
+
param += val + '=&';
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
param = param.substring(0, param.length - 1);
|
|
266
|
+
return param;
|
|
267
|
+
} else {
|
|
268
|
+
return '';
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function getFormData(url, headers, customizedOptions) {
|
|
272
|
+
headers = headers || {};
|
|
273
|
+
if (headers['Content-Type'] == null) {
|
|
274
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
275
|
+
}
|
|
276
|
+
customizedOptions = customizedOptions || {};
|
|
277
|
+
return execute("GET", url, null, headers, null, customizedOptions);
|
|
278
|
+
}
|
|
279
|
+
function postFormData(url, dataObject, headers, customizedOptions) {
|
|
280
|
+
var formdata = null;
|
|
281
|
+
if (dataObject) {
|
|
282
|
+
formdata = getUrlParam(dataObject);
|
|
283
|
+
}
|
|
284
|
+
headers = headers || {};
|
|
285
|
+
if (headers['Content-Type'] == null) {
|
|
286
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
287
|
+
}
|
|
288
|
+
customizedOptions = customizedOptions || {};
|
|
289
|
+
return execute("POST", url, formdata, headers, null, customizedOptions);
|
|
290
|
+
}
|
|
291
|
+
function getJsonData(url, headers, customizedOptions) {
|
|
292
|
+
headers = headers || {};
|
|
293
|
+
if (headers['Content-Type'] == null) {
|
|
294
|
+
headers['Content-Type'] = 'application/json';
|
|
295
|
+
}
|
|
296
|
+
return execute("GET", url, null, headers, null, customizedOptions);
|
|
297
|
+
}
|
|
298
|
+
function postJsonData(url, dataObject, headers, customizedOptions) {
|
|
299
|
+
headers = headers || {};
|
|
300
|
+
if (headers['Content-Type'] == null) {
|
|
301
|
+
headers['Content-Type'] = 'application/json';
|
|
302
|
+
}
|
|
303
|
+
return execute("POST", url, dataObject, headers, null, customizedOptions);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* General Axios Data request
|
|
308
|
+
*
|
|
309
|
+
* @param method
|
|
310
|
+
* @param url
|
|
311
|
+
* @param data
|
|
312
|
+
* @param headers
|
|
313
|
+
* @param customizedOptions: { }customizedErrorHandlerFlag: false }
|
|
314
|
+
*/
|
|
315
|
+
function execute(method, url, data, headers, onUploadProgress) {
|
|
316
|
+
var customizedOptions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
317
|
+
return new Promise(function (resolve, reject) {
|
|
318
|
+
//check and set User AccessToken in the request header
|
|
319
|
+
buildUserAccessToken(headers).then(function () {
|
|
320
|
+
//AccessToken is valid
|
|
321
|
+
axios({
|
|
322
|
+
method: method,
|
|
323
|
+
url: url,
|
|
324
|
+
data: data,
|
|
325
|
+
headers: headers,
|
|
326
|
+
onUploadProgress: onUploadProgress
|
|
327
|
+
}).then(function (response) {
|
|
328
|
+
if (response.data) {
|
|
329
|
+
if (response.data.errorCode && response.data.errorCode !== RESULT.SUCCESS) {
|
|
330
|
+
if (customizedOptions.customizedErrorHandlerFlag) {
|
|
331
|
+
resolve(response.data);
|
|
332
|
+
} else {
|
|
333
|
+
handlerError(url, data, response).then(function (result) {
|
|
334
|
+
resolve(result);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
resolve(response.data);
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
resolve(response.data);
|
|
342
|
+
}
|
|
343
|
+
}, function (error) {
|
|
344
|
+
if (customizedOptions.customizedErrorHandlerFlag) {
|
|
345
|
+
resolve(error);
|
|
346
|
+
} else {
|
|
347
|
+
handlerError(url, data, error).then(function (result) {
|
|
348
|
+
resolve(result);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}, function (error) {
|
|
353
|
+
//AccessToken is invalid
|
|
354
|
+
handlerError(url, data, error).then(function (result) {
|
|
355
|
+
resolve(result);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function buildUserAccessToken(_x5) {
|
|
361
|
+
return _buildUserAccessToken.apply(this, arguments);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* build error message base on errorCode
|
|
365
|
+
*/
|
|
366
|
+
function _buildUserAccessToken() {
|
|
367
|
+
_buildUserAccessToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(headers) {
|
|
368
|
+
var currUserInfo;
|
|
369
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
370
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
371
|
+
case 0:
|
|
372
|
+
_context3.next = 2;
|
|
373
|
+
return _LoginUserUtils["default"].getCurrUserInfo();
|
|
374
|
+
case 2:
|
|
375
|
+
currUserInfo = _context3.sent;
|
|
376
|
+
if (currUserInfo && currUserInfo.accessToken) {
|
|
377
|
+
if (headers['ENOS_ACCESS_TOKEN'] == null) {
|
|
378
|
+
headers['ENOS_ACCESS_TOKEN'] = currUserInfo.accessToken;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
case 4:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context3.stop();
|
|
384
|
+
}
|
|
385
|
+
}, _callee3);
|
|
386
|
+
}));
|
|
387
|
+
return _buildUserAccessToken.apply(this, arguments);
|
|
388
|
+
}
|
|
389
|
+
function getErrorMsgByCode(errorCode, errorMsg) {
|
|
390
|
+
return errorMsg;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* request error handler
|
|
395
|
+
* if multiple ajax error happened. just process the first one.
|
|
396
|
+
*/
|
|
397
|
+
var reqErrorInProcessing = false;
|
|
398
|
+
function handlerError(_x6, _x7, _x8) {
|
|
399
|
+
return _handlerError.apply(this, arguments);
|
|
400
|
+
}
|
|
401
|
+
function _handlerError() {
|
|
402
|
+
_handlerError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(url, reqData, responseOrAxiosError) {
|
|
403
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
404
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
405
|
+
case 0:
|
|
406
|
+
if (!(reqErrorInProcessing === true)) {
|
|
407
|
+
_context4.next = 2;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
return _context4.abrupt("return");
|
|
411
|
+
case 2:
|
|
412
|
+
reqErrorInProcessing = true;
|
|
413
|
+
_context4.next = 5;
|
|
414
|
+
return handlerErrorLogic(url, reqData, responseOrAxiosError);
|
|
415
|
+
case 5:
|
|
416
|
+
reqErrorInProcessing = false;
|
|
417
|
+
case 6:
|
|
418
|
+
case "end":
|
|
419
|
+
return _context4.stop();
|
|
420
|
+
}
|
|
421
|
+
}, _callee4);
|
|
422
|
+
}));
|
|
423
|
+
return _handlerError.apply(this, arguments);
|
|
424
|
+
}
|
|
425
|
+
function showErrorMessage(_x9) {
|
|
426
|
+
return _showErrorMessage.apply(this, arguments);
|
|
427
|
+
}
|
|
428
|
+
function _showErrorMessage() {
|
|
429
|
+
_showErrorMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(errorCode) {
|
|
430
|
+
var heading,
|
|
431
|
+
message,
|
|
432
|
+
_args5 = arguments;
|
|
433
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
434
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
435
|
+
case 0:
|
|
436
|
+
heading = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : "System Error";
|
|
437
|
+
message = _args5.length > 2 ? _args5[2] : undefined;
|
|
438
|
+
globalSpinHandlerInstance.complete();
|
|
439
|
+
_context5.next = 5;
|
|
440
|
+
return globalDialogUtilsInstance.showAppErrorDialog(heading, message);
|
|
441
|
+
case 5:
|
|
442
|
+
case "end":
|
|
443
|
+
return _context5.stop();
|
|
444
|
+
}
|
|
445
|
+
}, _callee5);
|
|
446
|
+
}));
|
|
447
|
+
return _showErrorMessage.apply(this, arguments);
|
|
448
|
+
}
|
|
449
|
+
function handlerErrorLogic(_x10, _x11, _x12) {
|
|
450
|
+
return _handlerErrorLogic.apply(this, arguments);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* application exit handler
|
|
454
|
+
*/
|
|
455
|
+
function _handlerErrorLogic() {
|
|
456
|
+
_handlerErrorLogic = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(url, reqData, responseOrAxiosError) {
|
|
457
|
+
var errorCode, error, axiosErrorStatus, axiosErrorStatusText, sessionTimeoutErrorCodes;
|
|
458
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
459
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
460
|
+
case 0:
|
|
461
|
+
errorCode = _lodash["default"].get(responseOrAxiosError, 'data.errorCode');
|
|
462
|
+
error = _lodash["default"].get(responseOrAxiosError, 'data.error');
|
|
463
|
+
if (!errorCode && _lodash["default"].get(responseOrAxiosError, 'code')) {
|
|
464
|
+
axiosErrorStatus = _lodash["default"].get(responseOrAxiosError, 'response.status');
|
|
465
|
+
axiosErrorStatusText = _lodash["default"].get(responseOrAxiosError, 'response.statusText');
|
|
466
|
+
if (_lodash["default"].includes([502, 504], axiosErrorStatus)) {
|
|
467
|
+
errorCode = EXCEPTION_CODE.NETWORK_ISSUE_CLIENT;
|
|
468
|
+
error = axiosErrorStatusText;
|
|
469
|
+
} else if (_lodash["default"].includes([400], axiosErrorStatus)) {
|
|
470
|
+
errorCode = EXCEPTION_CODE.SYS_UNKNOWN_ISSUE;
|
|
471
|
+
error = axiosErrorStatusText;
|
|
472
|
+
} else if (_lodash["default"].includes([404], axiosErrorStatus)) {
|
|
473
|
+
errorCode = EXCEPTION_CODE.SYS_UNKNOWN_ISSUE;
|
|
474
|
+
error = axiosErrorStatusText;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
//session timeout
|
|
479
|
+
sessionTimeoutErrorCodes = [EXCEPTION_CODE.AUTHENTICATION_FAILED_COMMON];
|
|
480
|
+
if (!_lodash["default"].includes(sessionTimeoutErrorCodes, errorCode)) {
|
|
481
|
+
_context6.next = 8;
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
_context6.next = 7;
|
|
485
|
+
return appSessionExit(errorCode, true);
|
|
486
|
+
case 7:
|
|
487
|
+
return _context6.abrupt("return");
|
|
488
|
+
case 8:
|
|
489
|
+
if (!(EXCEPTION_CODE.NETWORK_ISSUE_CLIENT === errorCode)) {
|
|
490
|
+
_context6.next = 12;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
_context6.next = 11;
|
|
494
|
+
return showErrorMessage(errorCode, "Network issue", error);
|
|
495
|
+
case 11:
|
|
496
|
+
return _context6.abrupt("return");
|
|
497
|
+
case 12:
|
|
498
|
+
_context6.next = 14;
|
|
499
|
+
return showErrorMessage(errorCode, null, getErrorMsgByCode(errorCode, error));
|
|
500
|
+
case 14:
|
|
501
|
+
case "end":
|
|
502
|
+
return _context6.stop();
|
|
503
|
+
}
|
|
504
|
+
}, _callee6);
|
|
505
|
+
}));
|
|
506
|
+
return _handlerErrorLogic.apply(this, arguments);
|
|
507
|
+
}
|
|
508
|
+
function appSessionExit(_x13, _x14) {
|
|
509
|
+
return _appSessionExit.apply(this, arguments);
|
|
510
|
+
}
|
|
511
|
+
function _appSessionExit() {
|
|
512
|
+
_appSessionExit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(resultCode, forceCloseFlag) {
|
|
513
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
514
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
515
|
+
case 0:
|
|
516
|
+
if (!(loginServiceInstance && loginServiceInstance.logout)) {
|
|
517
|
+
_context7.next = 5;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
_context7.next = 3;
|
|
521
|
+
return loginServiceInstance.logout();
|
|
522
|
+
case 3:
|
|
523
|
+
_context7.next = 7;
|
|
524
|
+
break;
|
|
525
|
+
case 5:
|
|
526
|
+
_context7.next = 7;
|
|
527
|
+
return globalDialogUtilsInstance.showAppErrorDialog("Session Timeout", "Please login again");
|
|
528
|
+
case 7:
|
|
529
|
+
case "end":
|
|
530
|
+
return _context7.stop();
|
|
531
|
+
}
|
|
532
|
+
}, _callee7);
|
|
533
|
+
}));
|
|
534
|
+
return _appSessionExit.apply(this, arguments);
|
|
535
|
+
}
|
|
536
|
+
var AxiosUtils = {
|
|
537
|
+
init: init,
|
|
538
|
+
loadParamFromLocationSearch: loadParamFromLocationSearch,
|
|
539
|
+
getPath: getPath,
|
|
540
|
+
getUrlParam: getUrlParam,
|
|
541
|
+
getFormData: getFormData,
|
|
542
|
+
postFormData: postFormData,
|
|
543
|
+
getJsonData: getJsonData,
|
|
544
|
+
postJsonData: postJsonData,
|
|
545
|
+
downloadExcelData: downloadExcelData,
|
|
546
|
+
downloadServerData: downloadServerData,
|
|
547
|
+
uploadFile: uploadFile,
|
|
548
|
+
getStaticTextFile: getStaticTextFile,
|
|
549
|
+
appSessionExit: appSessionExit,
|
|
550
|
+
handlerError: handlerError,
|
|
551
|
+
getErrorMsgByCode: getErrorMsgByCode,
|
|
552
|
+
RESULT: RESULT
|
|
553
|
+
};
|
|
554
|
+
var _default = AxiosUtils;
|
|
555
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
//Application Configuration
|
|
9
|
+
appInfo: {
|
|
10
|
+
appName: 'XMS',
|
|
11
|
+
//application name
|
|
12
|
+
|
|
13
|
+
needFrontEndExceptionStatisticsFlag: true //need trace front-end logs
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
//Ajax Configuration
|
|
17
|
+
ajax: {
|
|
18
|
+
timeOut: 60000 //Timeout
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
sysCfg: {
|
|
22
|
+
ibmsEnabled: true
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports["default"] = _default;
|