orion-design 0.1.0 → 0.1.2
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/components/Flex/Col.d.ts +25 -0
- package/dist/components/Flex/Item.d.ts +25 -0
- package/dist/components/Flex/Row.d.ts +25 -0
- package/dist/components/Flex/index.d.ts +10 -0
- package/dist/components/Flex/index.js +151 -0
- package/dist/components/Modal/Modal.d.ts +2 -0
- package/dist/components/Space/index.d.ts +76 -0
- package/dist/components/_util/classNames.d.ts +2 -0
- package/dist/components/_util/classNames.js +31 -0
- package/dist/components/_util/isValid.d.ts +2 -0
- package/dist/components/_util/isValid.js +5 -0
- package/dist/components/_util/props-util/index.d.ts +6 -0
- package/dist/components/_util/props-util/index.js +53 -0
- package/dist/components/_util/props-util/initDefaultProps.d.ts +6 -0
- package/dist/components/_util/props-util/initDefaultProps.js +25 -0
- package/dist/components/_util/type.d.ts +62 -0
- package/dist/components/_util/type.js +66 -0
- package/dist/components/_util/util.d.ts +18 -0
- package/dist/components/_util/util.js +83 -0
- package/dist/components/_util/vue-types/index.d.ts +12 -0
- package/dist/components/_util/vue-types/index.js +473 -0
- package/dist/components/components.d.ts +4 -0
- package/dist/components/components.js +10 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +23 -0
- package/dist/components-O4L3qYfM.js +61 -0
- package/dist/error/OrionError.js +9 -7
- package/dist/index.css +44 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +12 -3
- package/dist/print/LodopFuncs.js +109 -140
- package/dist/print/index.js +204 -199
- package/dist/request/ErrorHandlerChain.js +13 -13
- package/dist/request/RequestFilterChain.js +13 -13
- package/dist/request/ResponseParserChain.js +13 -13
- package/dist/request/disivion/DateSerializer.js +44 -53
- package/dist/request/disivion/DivisionErrorHandler.js +42 -42
- package/dist/request/disivion/DivisionResponseParser.js +22 -18
- package/dist/request/disivion/index.d.ts +21 -1
- package/dist/request/disivion/index.js +493 -24
- package/dist/request/error/BizExceptionResponseError.js +10 -10
- package/dist/request/error/ExceptionResponseError.js +10 -10
- package/dist/request/error/ResponseError.js +11 -9
- package/dist/request/error/SessionExceptionResponseError.js +10 -10
- package/dist/request/index.d.ts +3 -0
- package/dist/request/index.js +9 -20
- package/dist/style/index.d.ts +3 -0
- package/dist/style/index.js +1 -0
- package/dist/utils/DateUtil.js +47 -52
- package/dist/utils/NumberUtil.js +5 -5
- package/dist/utils/cloneDeep.js +1 -2255
- package/dist/utils/delay.js +1 -1
- package/dist/utils/index.js +3 -4
- package/dist/utils/md5.js +218 -272
- package/dist/version/index.d.ts +2 -0
- package/dist/version/index.js +6 -0
- package/dist/version/version.d.ts +2 -0
- package/dist/version/version.js +3 -0
- package/global.d.ts +9 -0
- package/package.json +28 -10
- package/dist/_commonjsHelpers-BFTU3MAI.js +0 -7
- package/dist/bignumber-upqAL281.js +0 -2907
- package/dist/dayjs.min-CYqA_arp.js +0 -12
- package/dist/request/disivion/request.d.ts +0 -21
- package/dist/request/disivion/request.js +0 -19345
- package/dist/request/postByOpenNewWindow.d.ts +0 -1
- package/dist/request/postByOpenNewWindow.js +0 -41
@@ -7,53 +7,53 @@ import SessionExceptionResponseError from '../error/SessionExceptionResponseErro
|
|
7
7
|
// import SobekThrone from '../../throne/SobekThrone'
|
8
8
|
// import SobekMsgBox from '../../msgbox/SobekMsgBox'
|
9
9
|
function readBlob(blob) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
});
|
15
|
-
reader.readAsText(blob);
|
10
|
+
return new Promise(resolve => {
|
11
|
+
const reader = new FileReader();
|
12
|
+
reader.addEventListener('loadend', () => {
|
13
|
+
resolve(reader.result);
|
16
14
|
});
|
15
|
+
reader.readAsText(blob);
|
16
|
+
});
|
17
17
|
}
|
18
18
|
class DivisionErrorHandler {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
jsonData = rawData;
|
35
|
-
}
|
36
|
-
const { success, errorcode, data, errortext } = jsonData;
|
37
|
-
if (errorcode === '-1') {
|
38
|
-
throw new ExceptionResponseError(errortext, error, response, jsonData);
|
39
|
-
}
|
40
|
-
else if (errorcode === '-2') {
|
41
|
-
throw new BizExceptionResponseError(errortext, error, response, jsonData);
|
42
|
-
}
|
43
|
-
else if (errorcode === '-3') {
|
44
|
-
throw new SessionExceptionResponseError(errortext, error, response, jsonData);
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
throw new ExceptionResponseError(errortext, error, response, jsonData);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
let errortext = "'" + response.config.url + "' " + response.status + ' ' + response.statusText;
|
52
|
-
throw new ExceptionResponseError(errortext, error, response, null);
|
53
|
-
}
|
19
|
+
constructor() {}
|
20
|
+
async handle(error, chain) {
|
21
|
+
if (error instanceof ResponseError) {
|
22
|
+
const response = error.response;
|
23
|
+
if (response.status == 200) {
|
24
|
+
const rawData = response.data;
|
25
|
+
let jsonData;
|
26
|
+
if (rawData instanceof Blob) {
|
27
|
+
// 文件下载抛异常JSON,在Blob里面
|
28
|
+
jsonData = await readBlob(rawData);
|
29
|
+
jsonData = JSON.parse(jsonData);
|
30
|
+
jsonData = JSON.parse(jsonData);
|
31
|
+
} else {
|
32
|
+
// 普通请求的异常JSON
|
33
|
+
jsonData = rawData;
|
54
34
|
}
|
55
|
-
|
35
|
+
const {
|
36
|
+
success,
|
37
|
+
errorcode,
|
38
|
+
data,
|
39
|
+
errortext
|
40
|
+
} = jsonData;
|
41
|
+
if (errorcode === '-1') {
|
42
|
+
throw new ExceptionResponseError(errortext, error, response, jsonData);
|
43
|
+
} else if (errorcode === '-2') {
|
44
|
+
throw new BizExceptionResponseError(errortext, error, response, jsonData);
|
45
|
+
} else if (errorcode === '-3') {
|
46
|
+
throw new SessionExceptionResponseError(errortext, error, response, jsonData);
|
47
|
+
} else {
|
48
|
+
throw new ExceptionResponseError(errortext, error, response, jsonData);
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
let errortext = "'" + response.config.url + "' " + response.status + ' ' + response.statusText;
|
52
|
+
throw new ExceptionResponseError(errortext, error, response, null);
|
53
|
+
}
|
56
54
|
}
|
55
|
+
throw error;
|
56
|
+
}
|
57
57
|
}
|
58
58
|
|
59
59
|
export { DivisionErrorHandler as default, readBlob };
|
@@ -1,23 +1,27 @@
|
|
1
1
|
class DivisionResponseParser {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
// server 端响应的不是 application/json 协议
|
9
|
-
if (contentType.indexOf('application/json') === -1) {
|
10
|
-
return chain.doParse(response, chain);
|
11
|
-
}
|
12
|
-
// data为string时,兼容ie
|
13
|
-
const { success, errorcode, data, errortext } = window.ActiveXObject || 'ActiveXObject' in window ? (typeof response.data === 'string' ? JSON.parse(response.data) : response.data) : response.data;
|
14
|
-
if (success === true) {
|
15
|
-
return chain.doParse(data, chain);
|
16
|
-
}
|
17
|
-
else {
|
18
|
-
throw new Error(errortext);
|
19
|
-
}
|
2
|
+
parse(response, chain) {
|
3
|
+
// server 端不响应内容
|
4
|
+
const contentType = response.headers['content-type'];
|
5
|
+
if (!contentType) {
|
6
|
+
return chain.doParse(response, chain);
|
20
7
|
}
|
8
|
+
// server 端响应的不是 application/json 协议
|
9
|
+
if (contentType.indexOf('application/json') === -1) {
|
10
|
+
return chain.doParse(response, chain);
|
11
|
+
}
|
12
|
+
// data为string时,兼容ie
|
13
|
+
const {
|
14
|
+
success,
|
15
|
+
errorcode,
|
16
|
+
data,
|
17
|
+
errortext
|
18
|
+
} = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
|
19
|
+
if (success === true) {
|
20
|
+
return chain.doParse(data, chain);
|
21
|
+
} else {
|
22
|
+
throw new Error(errortext);
|
23
|
+
}
|
24
|
+
}
|
21
25
|
}
|
22
26
|
|
23
27
|
export { DivisionResponseParser as default };
|
@@ -1 +1,21 @@
|
|
1
|
-
|
1
|
+
import { type ResponseParser } from '../ResponseParserChain';
|
2
|
+
import { type ErrorHandler } from '../ErrorHandlerChain';
|
3
|
+
import { type RequestFilter } from '../RequestFilterChain';
|
4
|
+
export type RequestParams = Record<string, unknown>;
|
5
|
+
export interface RequestOptionsI {
|
6
|
+
loading?: boolean;
|
7
|
+
mask?: boolean;
|
8
|
+
timeout?: number;
|
9
|
+
}
|
10
|
+
declare function request<T>(url: string, data?: RequestParams | FormData, options?: RequestOptionsI): Promise<T>;
|
11
|
+
declare namespace request {
|
12
|
+
var download: (url: string, data?: RequestParams, options?: RequestOptionsI) => Promise<void>;
|
13
|
+
var upload: (url: string, params: RequestParams, options: RequestOptionsI) => Promise<unknown>;
|
14
|
+
var setBaseUrl: (pBaseUrl: string) => void;
|
15
|
+
var setRequestTimeout: (pTimeout: number) => void;
|
16
|
+
var setRequestHeaders: (pRequestHeaders: () => Record<string, string | null>) => void;
|
17
|
+
var setRequestFilters: (...filters: RequestFilter[]) => void;
|
18
|
+
var setResponseParsers: (...parsers: ResponseParser[]) => void;
|
19
|
+
var setErrorHandlers: (...handlers: ErrorHandler[]) => void;
|
20
|
+
}
|
21
|
+
export default request;
|
@@ -1,28 +1,497 @@
|
|
1
|
-
|
2
|
-
import '
|
3
|
-
import '
|
4
|
-
import 'stream';
|
5
|
-
import 'path';
|
6
|
-
import 'http';
|
7
|
-
import 'https';
|
8
|
-
import 'url';
|
9
|
-
import 'fs';
|
10
|
-
import 'assert';
|
11
|
-
import 'tty';
|
12
|
-
import 'os';
|
13
|
-
import 'zlib';
|
14
|
-
import 'events';
|
15
|
-
import '../../dayjs.min-CYqA_arp.js';
|
1
|
+
import axios from 'axios';
|
2
|
+
import { cloneDeep } from 'lodash-es';
|
3
|
+
import 'dayjs';
|
16
4
|
import '../../utils/md5.js';
|
17
|
-
import '
|
18
|
-
import '../ResponseParserChain.js';
|
19
|
-
import '../ErrorHandlerChain.js';
|
20
|
-
import '../RequestFilterChain.js';
|
21
|
-
import './DateSerializer.js';
|
22
|
-
import './DivisionResponseParser.js';
|
23
|
-
import './DivisionErrorHandler.js';
|
24
|
-
import '
|
5
|
+
import 'decimal.js';
|
6
|
+
import ResponseParserChain from '../ResponseParserChain.js';
|
7
|
+
import ErrorHandlerChain from '../ErrorHandlerChain.js';
|
8
|
+
import RequestFilterChain from '../RequestFilterChain.js';
|
9
|
+
import DateSerializer from './DateSerializer.js';
|
10
|
+
import DivisionResponseParser from './DivisionResponseParser.js';
|
11
|
+
import DivisionErrorHandler from './DivisionErrorHandler.js';
|
12
|
+
import { ElLoading } from 'element-plus';
|
13
|
+
import ResponseError from '../error/ResponseError.js';
|
25
14
|
import '../error/ExceptionResponseError.js';
|
26
15
|
import '../error/BizExceptionResponseError.js';
|
27
16
|
import '../error/SessionExceptionResponseError.js';
|
28
|
-
|
17
|
+
|
18
|
+
/**
|
19
|
+
* base64.ts
|
20
|
+
*
|
21
|
+
* Licensed under the BSD 3-Clause License.
|
22
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
23
|
+
*
|
24
|
+
* References:
|
25
|
+
* http://en.wikipedia.org/wiki/Base64
|
26
|
+
*
|
27
|
+
* @author Dan Kogai (https://github.com/dankogai)
|
28
|
+
*/
|
29
|
+
const version = '3.7.7';
|
30
|
+
/**
|
31
|
+
* @deprecated use lowercase `version`.
|
32
|
+
*/
|
33
|
+
const VERSION = version;
|
34
|
+
const _hasBuffer = typeof Buffer === 'function';
|
35
|
+
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
36
|
+
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
37
|
+
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
38
|
+
const b64chs = Array.prototype.slice.call(b64ch);
|
39
|
+
const b64tab = ((a) => {
|
40
|
+
let tab = {};
|
41
|
+
a.forEach((c, i) => tab[c] = i);
|
42
|
+
return tab;
|
43
|
+
})(b64chs);
|
44
|
+
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
45
|
+
const _fromCC = String.fromCharCode.bind(String);
|
46
|
+
const _U8Afrom = typeof Uint8Array.from === 'function'
|
47
|
+
? Uint8Array.from.bind(Uint8Array)
|
48
|
+
: (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
|
49
|
+
const _mkUriSafe = (src) => src
|
50
|
+
.replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_');
|
51
|
+
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
|
52
|
+
/**
|
53
|
+
* polyfill version of `btoa`
|
54
|
+
*/
|
55
|
+
const btoaPolyfill = (bin) => {
|
56
|
+
// console.log('polyfilled');
|
57
|
+
let u32, c0, c1, c2, asc = '';
|
58
|
+
const pad = bin.length % 3;
|
59
|
+
for (let i = 0; i < bin.length;) {
|
60
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 ||
|
61
|
+
(c1 = bin.charCodeAt(i++)) > 255 ||
|
62
|
+
(c2 = bin.charCodeAt(i++)) > 255)
|
63
|
+
throw new TypeError('invalid character found');
|
64
|
+
u32 = (c0 << 16) | (c1 << 8) | c2;
|
65
|
+
asc += b64chs[u32 >> 18 & 63]
|
66
|
+
+ b64chs[u32 >> 12 & 63]
|
67
|
+
+ b64chs[u32 >> 6 & 63]
|
68
|
+
+ b64chs[u32 & 63];
|
69
|
+
}
|
70
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
71
|
+
};
|
72
|
+
/**
|
73
|
+
* does what `window.btoa` of web browsers do.
|
74
|
+
* @param {String} bin binary string
|
75
|
+
* @returns {string} Base64-encoded string
|
76
|
+
*/
|
77
|
+
const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
|
78
|
+
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
|
79
|
+
: btoaPolyfill;
|
80
|
+
const _fromUint8Array = _hasBuffer
|
81
|
+
? (u8a) => Buffer.from(u8a).toString('base64')
|
82
|
+
: (u8a) => {
|
83
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
84
|
+
const maxargs = 0x1000;
|
85
|
+
let strs = [];
|
86
|
+
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
87
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
88
|
+
}
|
89
|
+
return _btoa(strs.join(''));
|
90
|
+
};
|
91
|
+
/**
|
92
|
+
* converts a Uint8Array to a Base64 string.
|
93
|
+
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
|
94
|
+
* @returns {string} Base64 string
|
95
|
+
*/
|
96
|
+
const fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
97
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
98
|
+
// const utob = (src: string) => unescape(encodeURIComponent(src));
|
99
|
+
// reverting good old fationed regexp
|
100
|
+
const cb_utob = (c) => {
|
101
|
+
if (c.length < 2) {
|
102
|
+
var cc = c.charCodeAt(0);
|
103
|
+
return cc < 0x80 ? c
|
104
|
+
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
|
105
|
+
+ _fromCC(0x80 | (cc & 0x3f)))
|
106
|
+
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
|
107
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
108
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
var cc = 0x10000
|
112
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
113
|
+
+ (c.charCodeAt(1) - 0xDC00);
|
114
|
+
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
|
115
|
+
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
|
116
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
117
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
118
|
+
}
|
119
|
+
};
|
120
|
+
const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
121
|
+
/**
|
122
|
+
* @deprecated should have been internal use only.
|
123
|
+
* @param {string} src UTF-8 string
|
124
|
+
* @returns {string} UTF-16 string
|
125
|
+
*/
|
126
|
+
const utob = (u) => u.replace(re_utob, cb_utob);
|
127
|
+
//
|
128
|
+
const _encode = _hasBuffer
|
129
|
+
? (s) => Buffer.from(s, 'utf8').toString('base64')
|
130
|
+
: _TE
|
131
|
+
? (s) => _fromUint8Array(_TE.encode(s))
|
132
|
+
: (s) => _btoa(utob(s));
|
133
|
+
/**
|
134
|
+
* converts a UTF-8-encoded string to a Base64 string.
|
135
|
+
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
136
|
+
* @returns {string} Base64 string
|
137
|
+
*/
|
138
|
+
const encode = (src, urlsafe = false) => urlsafe
|
139
|
+
? _mkUriSafe(_encode(src))
|
140
|
+
: _encode(src);
|
141
|
+
/**
|
142
|
+
* converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
|
143
|
+
* @returns {string} Base64 string
|
144
|
+
*/
|
145
|
+
const encodeURI = (src) => encode(src, true);
|
146
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
147
|
+
// const btou = (src: string) => decodeURIComponent(escape(src));
|
148
|
+
// reverting good old fationed regexp
|
149
|
+
const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
150
|
+
const cb_btou = (cccc) => {
|
151
|
+
switch (cccc.length) {
|
152
|
+
case 4:
|
153
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
154
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
155
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
156
|
+
| (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
|
157
|
+
return (_fromCC((offset >>> 10) + 0xD800)
|
158
|
+
+ _fromCC((offset & 0x3FF) + 0xDC00));
|
159
|
+
case 3:
|
160
|
+
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
|
161
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
162
|
+
| (0x3f & cccc.charCodeAt(2)));
|
163
|
+
default:
|
164
|
+
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
|
165
|
+
| (0x3f & cccc.charCodeAt(1)));
|
166
|
+
}
|
167
|
+
};
|
168
|
+
/**
|
169
|
+
* @deprecated should have been internal use only.
|
170
|
+
* @param {string} src UTF-16 string
|
171
|
+
* @returns {string} UTF-8 string
|
172
|
+
*/
|
173
|
+
const btou = (b) => b.replace(re_btou, cb_btou);
|
174
|
+
/**
|
175
|
+
* polyfill version of `atob`
|
176
|
+
*/
|
177
|
+
const atobPolyfill = (asc) => {
|
178
|
+
// console.log('polyfilled');
|
179
|
+
asc = asc.replace(/\s+/g, '');
|
180
|
+
if (!b64re.test(asc))
|
181
|
+
throw new TypeError('malformed base64.');
|
182
|
+
asc += '=='.slice(2 - (asc.length & 3));
|
183
|
+
let u24, bin = '', r1, r2;
|
184
|
+
for (let i = 0; i < asc.length;) {
|
185
|
+
u24 = b64tab[asc.charAt(i++)] << 18
|
186
|
+
| b64tab[asc.charAt(i++)] << 12
|
187
|
+
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
188
|
+
| (r2 = b64tab[asc.charAt(i++)]);
|
189
|
+
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
|
190
|
+
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
|
191
|
+
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
192
|
+
}
|
193
|
+
return bin;
|
194
|
+
};
|
195
|
+
/**
|
196
|
+
* does what `window.atob` of web browsers do.
|
197
|
+
* @param {String} asc Base64-encoded string
|
198
|
+
* @returns {string} binary string
|
199
|
+
*/
|
200
|
+
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
|
201
|
+
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
|
202
|
+
: atobPolyfill;
|
203
|
+
//
|
204
|
+
const _toUint8Array = _hasBuffer
|
205
|
+
? (a) => _U8Afrom(Buffer.from(a, 'base64'))
|
206
|
+
: (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
207
|
+
/**
|
208
|
+
* converts a Base64 string to a Uint8Array.
|
209
|
+
*/
|
210
|
+
const toUint8Array = (a) => _toUint8Array(_unURI(a));
|
211
|
+
//
|
212
|
+
const _decode = _hasBuffer
|
213
|
+
? (a) => Buffer.from(a, 'base64').toString('utf8')
|
214
|
+
: _TD
|
215
|
+
? (a) => _TD.decode(_toUint8Array(a))
|
216
|
+
: (a) => btou(_atob(a));
|
217
|
+
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
|
218
|
+
/**
|
219
|
+
* converts a Base64 string to a UTF-8 string.
|
220
|
+
* @param {String} src Base64 string. Both normal and URL-safe are supported
|
221
|
+
* @returns {string} UTF-8 string
|
222
|
+
*/
|
223
|
+
const decode = (src) => _decode(_unURI(src));
|
224
|
+
/**
|
225
|
+
* check if a value is a valid Base64 string
|
226
|
+
* @param {String} src a value to check
|
227
|
+
*/
|
228
|
+
const isValid = (src) => {
|
229
|
+
if (typeof src !== 'string')
|
230
|
+
return false;
|
231
|
+
const s = src.replace(/\s+/g, '').replace(/={0,2}$/, '');
|
232
|
+
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
233
|
+
};
|
234
|
+
//
|
235
|
+
const _noEnum = (v) => {
|
236
|
+
return {
|
237
|
+
value: v, enumerable: false, writable: true, configurable: true
|
238
|
+
};
|
239
|
+
};
|
240
|
+
/**
|
241
|
+
* extend String.prototype with relevant methods
|
242
|
+
*/
|
243
|
+
const extendString = function () {
|
244
|
+
const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));
|
245
|
+
_add('fromBase64', function () { return decode(this); });
|
246
|
+
_add('toBase64', function (urlsafe) { return encode(this, urlsafe); });
|
247
|
+
_add('toBase64URI', function () { return encode(this, true); });
|
248
|
+
_add('toBase64URL', function () { return encode(this, true); });
|
249
|
+
_add('toUint8Array', function () { return toUint8Array(this); });
|
250
|
+
};
|
251
|
+
/**
|
252
|
+
* extend Uint8Array.prototype with relevant methods
|
253
|
+
*/
|
254
|
+
const extendUint8Array = function () {
|
255
|
+
const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
|
256
|
+
_add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });
|
257
|
+
_add('toBase64URI', function () { return fromUint8Array(this, true); });
|
258
|
+
_add('toBase64URL', function () { return fromUint8Array(this, true); });
|
259
|
+
};
|
260
|
+
/**
|
261
|
+
* extend Builtin prototypes with relevant methods
|
262
|
+
*/
|
263
|
+
const extendBuiltins = () => {
|
264
|
+
extendString();
|
265
|
+
extendUint8Array();
|
266
|
+
};
|
267
|
+
const gBase64 = {
|
268
|
+
version: version,
|
269
|
+
VERSION: VERSION,
|
270
|
+
atob: _atob,
|
271
|
+
atobPolyfill: atobPolyfill,
|
272
|
+
btoa: _btoa,
|
273
|
+
btoaPolyfill: btoaPolyfill,
|
274
|
+
fromBase64: decode,
|
275
|
+
toBase64: encode,
|
276
|
+
encode: encode,
|
277
|
+
encodeURI: encodeURI,
|
278
|
+
encodeURL: encodeURI,
|
279
|
+
utob: utob,
|
280
|
+
btou: btou,
|
281
|
+
decode: decode,
|
282
|
+
isValid: isValid,
|
283
|
+
fromUint8Array: fromUint8Array,
|
284
|
+
toUint8Array: toUint8Array,
|
285
|
+
extendString: extendString,
|
286
|
+
extendUint8Array: extendUint8Array,
|
287
|
+
extendBuiltins: extendBuiltins
|
288
|
+
};
|
289
|
+
|
290
|
+
//////////////////////////////////// Chain
|
291
|
+
let gRequestHeaders = () => ({});
|
292
|
+
let gResponseParsers = [new DivisionResponseParser()];
|
293
|
+
let gErrorHandlers = [new DivisionErrorHandler()];
|
294
|
+
let gRequestFilters = [{
|
295
|
+
doFilter: (request, chain) => {
|
296
|
+
const headers = gRequestHeaders();
|
297
|
+
Object.keys(headers).forEach(function (key) {
|
298
|
+
request.headers[key] = headers[key];
|
299
|
+
});
|
300
|
+
chain.doFilter(request, chain);
|
301
|
+
}
|
302
|
+
}, {
|
303
|
+
doFilter: request => {
|
304
|
+
new DateSerializer('YYYYMMDDHHmmss').serialize(request.data);
|
305
|
+
}
|
306
|
+
}];
|
307
|
+
//////////////////////////////////// GLOBAL VARS
|
308
|
+
let BASE_URL = '/';
|
309
|
+
let REQUEST_TIMEOUT = 1000 * 30;
|
310
|
+
//////////////////////////////////// AXIOS
|
311
|
+
const g_AxiosInstance = axios.create();
|
312
|
+
g_AxiosInstance.interceptors.request.use(function (config) {
|
313
|
+
const chain = new RequestFilterChain(gRequestFilters);
|
314
|
+
chain.doFilter(config, chain);
|
315
|
+
return config;
|
316
|
+
});
|
317
|
+
g_AxiosInstance.interceptors.response.use(function (response) {
|
318
|
+
try {
|
319
|
+
const chain = new ResponseParserChain(gResponseParsers);
|
320
|
+
return chain.doParse(response, chain);
|
321
|
+
} catch (e) {
|
322
|
+
throw new ResponseError(e.message, {
|
323
|
+
cause: e
|
324
|
+
}, response);
|
325
|
+
}
|
326
|
+
});
|
327
|
+
function request(url, data = {}, options = {
|
328
|
+
loading: true,
|
329
|
+
mask: false,
|
330
|
+
timeout: REQUEST_TIMEOUT
|
331
|
+
}) {
|
332
|
+
let newData = data;
|
333
|
+
if (!(data instanceof FormData)) {
|
334
|
+
newData = cloneDeep(data);
|
335
|
+
}
|
336
|
+
// loading
|
337
|
+
let loading;
|
338
|
+
if (options.loading === true) {
|
339
|
+
loading = ElLoading.service({
|
340
|
+
fullscreen: true,
|
341
|
+
background: 'transparent'
|
342
|
+
});
|
343
|
+
}
|
344
|
+
return g_AxiosInstance.request({
|
345
|
+
baseURL: BASE_URL,
|
346
|
+
method: 'POST',
|
347
|
+
timeout: REQUEST_TIMEOUT,
|
348
|
+
withCredentials: true,
|
349
|
+
url,
|
350
|
+
data: newData,
|
351
|
+
responseType: 'json',
|
352
|
+
...options
|
353
|
+
}).then(data => {
|
354
|
+
if (loading) {
|
355
|
+
loading.close();
|
356
|
+
}
|
357
|
+
return data;
|
358
|
+
}).catch(function (error) {
|
359
|
+
if (loading) {
|
360
|
+
loading.close();
|
361
|
+
}
|
362
|
+
const chain = new ErrorHandlerChain(gErrorHandlers);
|
363
|
+
return chain.handle(error, chain);
|
364
|
+
});
|
365
|
+
}
|
366
|
+
function download(url, data = {}, options = {
|
367
|
+
loading: true,
|
368
|
+
mask: false,
|
369
|
+
timeout: REQUEST_TIMEOUT
|
370
|
+
}) {
|
371
|
+
let loading;
|
372
|
+
if (options.loading === true) {
|
373
|
+
loading = ElLoading.service({
|
374
|
+
fullscreen: true,
|
375
|
+
background: 'transparent'
|
376
|
+
});
|
377
|
+
}
|
378
|
+
return g_AxiosInstance.request({
|
379
|
+
baseURL: BASE_URL,
|
380
|
+
method: 'POST',
|
381
|
+
timeout: REQUEST_TIMEOUT,
|
382
|
+
withCredentials: true,
|
383
|
+
url,
|
384
|
+
data,
|
385
|
+
responseType: 'blob',
|
386
|
+
...options
|
387
|
+
}).then(data => {
|
388
|
+
if (loading) {
|
389
|
+
loading.close();
|
390
|
+
}
|
391
|
+
return data;
|
392
|
+
}).then(response => {
|
393
|
+
const contentDisposition = response.headers['content-disposition'];
|
394
|
+
const blob = response.data;
|
395
|
+
const base64FileName = contentDisposition.match(/attachment; filename=\"(.*?)\"/)[1];
|
396
|
+
const decodedFileName = gBase64.decode(base64FileName);
|
397
|
+
// for IE
|
398
|
+
//@ts-ignore
|
399
|
+
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
400
|
+
//@ts-ignore
|
401
|
+
window.navigator.msSaveOrOpenBlob(blob, decodedFileName);
|
402
|
+
} else {
|
403
|
+
const a = document.createElement('a');
|
404
|
+
const url = URL.createObjectURL(blob);
|
405
|
+
a.href = url;
|
406
|
+
a.download = decodedFileName;
|
407
|
+
document.body.appendChild(a);
|
408
|
+
a.click();
|
409
|
+
document.body.removeChild(a);
|
410
|
+
URL.revokeObjectURL(url);
|
411
|
+
}
|
412
|
+
}).catch(function (error) {
|
413
|
+
if (loading) {
|
414
|
+
loading.close();
|
415
|
+
}
|
416
|
+
const chain = new ErrorHandlerChain(gErrorHandlers);
|
417
|
+
return chain.handle(error, chain);
|
418
|
+
});
|
419
|
+
}
|
420
|
+
function upload(url, params, options) {
|
421
|
+
const formdata = new FormData();
|
422
|
+
if (params) {
|
423
|
+
const keys = Object.keys(params);
|
424
|
+
const normalParams = {};
|
425
|
+
for (let i = 0; i < keys.length; i++) {
|
426
|
+
const key = keys[i];
|
427
|
+
const itemValue = params[key];
|
428
|
+
if (itemValue instanceof File) {
|
429
|
+
formdata.append(key, itemValue);
|
430
|
+
} else if (itemValue instanceof Array) {
|
431
|
+
let isFile = false;
|
432
|
+
for (let j = 0; j < itemValue.length; j++) {
|
433
|
+
if (itemValue[j] instanceof File) {
|
434
|
+
isFile = true;
|
435
|
+
break;
|
436
|
+
}
|
437
|
+
}
|
438
|
+
if (isFile) {
|
439
|
+
for (let j = 0; j < itemValue.length; j++) {
|
440
|
+
formdata.append(key, itemValue[j]);
|
441
|
+
}
|
442
|
+
} else {
|
443
|
+
// formdata.append(key, JSON.stringify(itemValue));
|
444
|
+
normalParams[key] = itemValue;
|
445
|
+
}
|
446
|
+
} else {
|
447
|
+
// formdata.append(key, itemValue);
|
448
|
+
normalParams[key] = itemValue;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
formdata.append('ibayJson', JSON.stringify(normalParams));
|
452
|
+
}
|
453
|
+
return request(url, formdata, options);
|
454
|
+
}
|
455
|
+
//////////////////////////////////// Exports
|
456
|
+
// api
|
457
|
+
request.download = download;
|
458
|
+
request.upload = upload;
|
459
|
+
// setters
|
460
|
+
request.setBaseUrl = pBaseUrl => {
|
461
|
+
if (!pBaseUrl) {
|
462
|
+
throw new Error(`pBaseUrl is null!`);
|
463
|
+
}
|
464
|
+
BASE_URL = pBaseUrl;
|
465
|
+
};
|
466
|
+
request.setRequestTimeout = pTimeout => {
|
467
|
+
REQUEST_TIMEOUT = pTimeout;
|
468
|
+
};
|
469
|
+
request.setRequestHeaders = pRequestHeaders => {
|
470
|
+
if (!pRequestHeaders) {
|
471
|
+
throw new Error(`pRequestHeaders is null!`);
|
472
|
+
}
|
473
|
+
if (!(pRequestHeaders instanceof Function)) {
|
474
|
+
throw new Error(`pRequestHeaders is not a function!`);
|
475
|
+
}
|
476
|
+
gRequestHeaders = pRequestHeaders;
|
477
|
+
};
|
478
|
+
request.setRequestFilters = (...filters) => {
|
479
|
+
if (filters == null) {
|
480
|
+
throw new Error(`filters is null!`);
|
481
|
+
}
|
482
|
+
gRequestFilters = filters;
|
483
|
+
};
|
484
|
+
request.setResponseParsers = (...parsers) => {
|
485
|
+
if (parsers == null) {
|
486
|
+
throw new Error(`parsers is null!`);
|
487
|
+
}
|
488
|
+
gResponseParsers = parsers;
|
489
|
+
};
|
490
|
+
request.setErrorHandlers = (...handlers) => {
|
491
|
+
if (handlers == null) {
|
492
|
+
throw new Error(`handlers should not null!`);
|
493
|
+
}
|
494
|
+
gErrorHandlers = handlers;
|
495
|
+
};
|
496
|
+
|
497
|
+
export { request as default };
|