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