@topthink/components 1.0.56 → 1.0.58
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/es/editor-widget-ebec8493.js +356 -0
- package/es/editor-widget-ebec8493.js.map +1 -0
- package/es/form-74ef0417.js +2 -0
- package/es/form-74ef0417.js.map +1 -0
- package/es/form-8925a750.js +231 -0
- package/es/form-8925a750.js.map +1 -0
- package/es/form-9c0e638a.js +230 -1
- package/es/form-9c0e638a.js.map +1 -1
- package/es/index-2b97b70d.js +2 -0
- package/es/index-2b97b70d.js.map +1 -0
- package/es/index-303e1845.js +560 -0
- package/es/index-303e1845.js.map +1 -0
- package/es/index-4f51cece.js +1304 -19
- package/es/index-4f51cece.js.map +1 -1
- package/es/index-563b11c6.js +67 -0
- package/es/index-563b11c6.js.map +1 -0
- package/es/index-6ae8237d.js +67 -0
- package/es/index-6ae8237d.js.map +1 -0
- package/es/index-7a7c06a9.js +40 -0
- package/es/index-7a7c06a9.js.map +1 -0
- package/es/index-9869b1c6.js +1350 -0
- package/es/index-9869b1c6.js.map +1 -0
- package/es/index-a214613e.js +40 -0
- package/es/index-a214613e.js.map +1 -0
- package/es/index-d964165a.js +529 -9
- package/es/index-d964165a.js.map +1 -1
- package/es/index.js +1 -1
- package/package.json +7 -5
- package/types/components/lazy/form/widgets/editor-widget.d.ts +5 -0
- package/types/index.d.ts +1 -1
- package/types/utils/is-record.d.ts +1 -0
- package/types/errors/unauthorized.d.ts +0 -4
- /package/types/components/lazy/{form.d.ts → form/index.d.ts} +0 -0
|
@@ -0,0 +1,1350 @@
|
|
|
1
|
+
import Swal from 'sweetalert2/dist/sweetalert2.js';
|
|
2
|
+
import withReactContent from 'sweetalert2-react-content';
|
|
3
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
4
|
+
import { useRef, useState, useEffect, createContext, Fragment, useContext, useCallback, useMemo, forwardRef, Children, lazy, Suspense, createElement, useImperativeHandle } from 'react';
|
|
5
|
+
import { OverlayTrigger, Tooltip as Tooltip$1, Spinner, Button as Button$1, Modal as Modal$1, Alert, Card as Card$1, Pagination as Pagination$1 } from 'react-bootstrap';
|
|
6
|
+
import { uniqueId, values, debounce } from 'lodash';
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import queryString from 'query-string';
|
|
9
|
+
import * as rax from 'retry-axios';
|
|
10
|
+
import Notification from 'rc-notification';
|
|
11
|
+
import styled, { css } from 'styled-components';
|
|
12
|
+
import classNames from 'classnames';
|
|
13
|
+
import { useAsyncCallback } from 'react-async-hook';
|
|
14
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
15
|
+
|
|
16
|
+
const CustomSwal = withReactContent(Swal);
|
|
17
|
+
const defaultOptions$1 = {
|
|
18
|
+
confirmButtonText: '确定',
|
|
19
|
+
cancelButtonText: '取消'
|
|
20
|
+
};
|
|
21
|
+
const Message$1 = {
|
|
22
|
+
confirm: async options => {
|
|
23
|
+
const {
|
|
24
|
+
isConfirmed
|
|
25
|
+
} = await CustomSwal.fire({
|
|
26
|
+
...defaultOptions$1,
|
|
27
|
+
icon: 'warning',
|
|
28
|
+
showCancelButton: true,
|
|
29
|
+
...options,
|
|
30
|
+
async preConfirm(data) {
|
|
31
|
+
if (options.preConfirm) {
|
|
32
|
+
try {
|
|
33
|
+
return await options.preConfirm(data);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e instanceof Error) {
|
|
36
|
+
CustomSwal.showValidationMessage(e.message);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return isConfirmed;
|
|
45
|
+
},
|
|
46
|
+
success: options => {
|
|
47
|
+
CustomSwal.fire({
|
|
48
|
+
...defaultOptions$1,
|
|
49
|
+
toast: true,
|
|
50
|
+
position: 'top',
|
|
51
|
+
icon: 'success',
|
|
52
|
+
timer: 2000,
|
|
53
|
+
showConfirmButton: false,
|
|
54
|
+
...options
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
error: options => {
|
|
58
|
+
CustomSwal.fire({
|
|
59
|
+
...defaultOptions$1,
|
|
60
|
+
toast: true,
|
|
61
|
+
position: 'top',
|
|
62
|
+
icon: 'error',
|
|
63
|
+
timer: 5000,
|
|
64
|
+
showConfirmButton: false,
|
|
65
|
+
...options
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
close: result => {
|
|
69
|
+
CustomSwal.close(result);
|
|
70
|
+
},
|
|
71
|
+
defaults: defaultOptions$1
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function useStateWithCallback(initState) {
|
|
75
|
+
const callbackRef = useRef(null);
|
|
76
|
+
const [state, setState] = useState(initState);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (callbackRef.current) {
|
|
79
|
+
callbackRef.current();
|
|
80
|
+
callbackRef.current = null;
|
|
81
|
+
}
|
|
82
|
+
}, [state]);
|
|
83
|
+
const setCallbackState = (value, callback) => {
|
|
84
|
+
callbackRef.current = typeof callback === 'function' ? callback : null;
|
|
85
|
+
setState(value);
|
|
86
|
+
};
|
|
87
|
+
return [state, setCallbackState];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const MessageContext = createContext({});
|
|
91
|
+
function wrapMessage(Component) {
|
|
92
|
+
return _ref => {
|
|
93
|
+
let {
|
|
94
|
+
resolve,
|
|
95
|
+
destroy,
|
|
96
|
+
message
|
|
97
|
+
} = _ref;
|
|
98
|
+
const [show, setShow] = useStateWithCallback(true);
|
|
99
|
+
const context = useContext(MessageContext);
|
|
100
|
+
const handleResolve = useCallback(value => {
|
|
101
|
+
setShow(false, () => {
|
|
102
|
+
resolve(value);
|
|
103
|
+
});
|
|
104
|
+
}, [setShow, resolve]);
|
|
105
|
+
const state = useMemo(() => {
|
|
106
|
+
return {
|
|
107
|
+
show,
|
|
108
|
+
onHide: () => handleResolve(),
|
|
109
|
+
onExited: () => destroy(),
|
|
110
|
+
container: context.container
|
|
111
|
+
};
|
|
112
|
+
}, [show, handleResolve, destroy]);
|
|
113
|
+
return jsx(Component, {
|
|
114
|
+
resolve: handleResolve,
|
|
115
|
+
state: state,
|
|
116
|
+
message: message
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function createMessage(Component) {
|
|
121
|
+
return message => {
|
|
122
|
+
return new Promise(resolve => {
|
|
123
|
+
const component = jsx(Component, {
|
|
124
|
+
resolve: resolve,
|
|
125
|
+
destroy: () => {
|
|
126
|
+
hide(component);
|
|
127
|
+
},
|
|
128
|
+
message: message
|
|
129
|
+
});
|
|
130
|
+
show$1(component);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
let listener = () => void 0;
|
|
135
|
+
let memoryState = new Set();
|
|
136
|
+
const show$1 = modal => {
|
|
137
|
+
memoryState = new Set(memoryState);
|
|
138
|
+
memoryState.add(modal);
|
|
139
|
+
listener(memoryState);
|
|
140
|
+
};
|
|
141
|
+
const hide = modal => {
|
|
142
|
+
memoryState = new Set(memoryState);
|
|
143
|
+
memoryState.delete(modal);
|
|
144
|
+
listener(memoryState);
|
|
145
|
+
};
|
|
146
|
+
function Message(props) {
|
|
147
|
+
const [state, setState] = useState(memoryState);
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
listener = setState;
|
|
150
|
+
}, []);
|
|
151
|
+
return jsx(MessageContext.Provider, {
|
|
152
|
+
value: props,
|
|
153
|
+
children: Array.from(state).map((message, index) => jsx(Fragment, {
|
|
154
|
+
children: message
|
|
155
|
+
}, `message-${index}`))
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function show(Component, options) {
|
|
160
|
+
return createMessage(wrapMessage(Component))(options);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function Tooltip(_ref) {
|
|
164
|
+
let {
|
|
165
|
+
tooltip,
|
|
166
|
+
children,
|
|
167
|
+
placement = 'bottom'
|
|
168
|
+
} = _ref;
|
|
169
|
+
return jsx(OverlayTrigger, {
|
|
170
|
+
placement: placement,
|
|
171
|
+
overlay: jsx(Tooltip$1, {
|
|
172
|
+
id: uniqueId(),
|
|
173
|
+
children: tooltip
|
|
174
|
+
}),
|
|
175
|
+
children: children
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const TableContext = createContext(false);
|
|
180
|
+
|
|
181
|
+
const Button = forwardRef((_ref, ref) => {
|
|
182
|
+
let {
|
|
183
|
+
loading,
|
|
184
|
+
percent,
|
|
185
|
+
disabled,
|
|
186
|
+
children,
|
|
187
|
+
tooltip,
|
|
188
|
+
variant,
|
|
189
|
+
...props
|
|
190
|
+
} = _ref;
|
|
191
|
+
const inTable = useContext(TableContext);
|
|
192
|
+
if (inTable && !variant) {
|
|
193
|
+
variant = 'link';
|
|
194
|
+
}
|
|
195
|
+
if (loading) {
|
|
196
|
+
disabled = true;
|
|
197
|
+
children = jsxs(Fragment$1, {
|
|
198
|
+
children: [jsx(Spinner, {
|
|
199
|
+
ref: ref,
|
|
200
|
+
as: 'span',
|
|
201
|
+
size: 'sm',
|
|
202
|
+
role: 'status',
|
|
203
|
+
"aria-hidden": 'true',
|
|
204
|
+
animation: 'border'
|
|
205
|
+
}), percent ? jsxs("span", {
|
|
206
|
+
className: 'ms-2',
|
|
207
|
+
children: [percent, "%"]
|
|
208
|
+
}) : null]
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const button = jsx(Button$1, {
|
|
212
|
+
ref: ref,
|
|
213
|
+
...props,
|
|
214
|
+
variant: variant,
|
|
215
|
+
disabled: disabled,
|
|
216
|
+
children: children
|
|
217
|
+
});
|
|
218
|
+
if (tooltip) {
|
|
219
|
+
return jsx(Tooltip, {
|
|
220
|
+
tooltip: tooltip,
|
|
221
|
+
children: jsx("span", {
|
|
222
|
+
className: 'd-inline-block',
|
|
223
|
+
children: button
|
|
224
|
+
})
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return button;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const Confirm = function (_ref) {
|
|
231
|
+
let {
|
|
232
|
+
state,
|
|
233
|
+
message: {
|
|
234
|
+
title,
|
|
235
|
+
message,
|
|
236
|
+
okText,
|
|
237
|
+
cancelText
|
|
238
|
+
},
|
|
239
|
+
resolve
|
|
240
|
+
} = _ref;
|
|
241
|
+
return jsxs(Modal$1, {
|
|
242
|
+
centered: true,
|
|
243
|
+
...state,
|
|
244
|
+
children: [jsx(Modal$1.Header, {
|
|
245
|
+
children: jsx(Modal$1.Title, {
|
|
246
|
+
as: 'h5',
|
|
247
|
+
children: title || '确认'
|
|
248
|
+
})
|
|
249
|
+
}), jsx(Modal$1.Body, {
|
|
250
|
+
children: message
|
|
251
|
+
}), jsxs(Modal$1.Footer, {
|
|
252
|
+
children: [jsx(Button, {
|
|
253
|
+
variant: 'secondary',
|
|
254
|
+
onClick: () => resolve(),
|
|
255
|
+
children: cancelText || '取消'
|
|
256
|
+
}), jsx(Button, {
|
|
257
|
+
onClick: () => resolve(true),
|
|
258
|
+
children: okText || '确定'
|
|
259
|
+
})]
|
|
260
|
+
})]
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
function confirm(options) {
|
|
264
|
+
return createMessage(wrapMessage(Confirm))(options);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const Modal = _ref => {
|
|
268
|
+
let {
|
|
269
|
+
header,
|
|
270
|
+
children,
|
|
271
|
+
footer,
|
|
272
|
+
closable = true,
|
|
273
|
+
show,
|
|
274
|
+
cancelText = '取消',
|
|
275
|
+
okText = '确定',
|
|
276
|
+
onOk,
|
|
277
|
+
onCancel,
|
|
278
|
+
onHide,
|
|
279
|
+
okButtonProps,
|
|
280
|
+
bodyAs,
|
|
281
|
+
headerAs = 'h5',
|
|
282
|
+
confirmLoading = false,
|
|
283
|
+
...rest
|
|
284
|
+
} = _ref;
|
|
285
|
+
const [loading, setLoading] = useState(false);
|
|
286
|
+
const okButton = useMemo(() => {
|
|
287
|
+
return jsx(Button, {
|
|
288
|
+
loading: loading || confirmLoading,
|
|
289
|
+
variant: 'primary',
|
|
290
|
+
onClick: async e => {
|
|
291
|
+
setLoading(true);
|
|
292
|
+
try {
|
|
293
|
+
await onOk?.(e);
|
|
294
|
+
if (!e.defaultPrevented) {
|
|
295
|
+
onHide?.();
|
|
296
|
+
}
|
|
297
|
+
} finally {
|
|
298
|
+
setLoading(false);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
...okButtonProps,
|
|
302
|
+
children: okText
|
|
303
|
+
});
|
|
304
|
+
}, [okButtonProps, okText, onOk, onHide, loading, confirmLoading]);
|
|
305
|
+
const cancelButton = useMemo(() => {
|
|
306
|
+
return jsx(Button, {
|
|
307
|
+
variant: 'secondary',
|
|
308
|
+
onClick: e => {
|
|
309
|
+
onCancel?.(e);
|
|
310
|
+
if (!e.defaultPrevented) {
|
|
311
|
+
onHide?.();
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
children: cancelText
|
|
315
|
+
});
|
|
316
|
+
}, [onCancel, onHide, cancelText]);
|
|
317
|
+
switch (typeof footer) {
|
|
318
|
+
case 'undefined':
|
|
319
|
+
footer = jsxs(Fragment$1, {
|
|
320
|
+
children: [cancelButton, okButton]
|
|
321
|
+
});
|
|
322
|
+
break;
|
|
323
|
+
case 'function':
|
|
324
|
+
footer = footer({
|
|
325
|
+
okButton,
|
|
326
|
+
cancelButton
|
|
327
|
+
});
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
return jsxs(Modal$1, {
|
|
331
|
+
...rest,
|
|
332
|
+
onHide: onHide,
|
|
333
|
+
show: show,
|
|
334
|
+
children: [header && jsx(Modal$1.Header, {
|
|
335
|
+
closeButton: closable,
|
|
336
|
+
children: jsx(Modal$1.Title, {
|
|
337
|
+
as: headerAs,
|
|
338
|
+
children: header
|
|
339
|
+
})
|
|
340
|
+
}), jsx(Modal$1.Body, {
|
|
341
|
+
as: bodyAs,
|
|
342
|
+
children: children
|
|
343
|
+
}), footer && jsx(Modal$1.Footer, {
|
|
344
|
+
children: footer
|
|
345
|
+
})]
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
Modal.Message = Message;
|
|
349
|
+
Modal.confirm = confirm;
|
|
350
|
+
Modal.show = show;
|
|
351
|
+
|
|
352
|
+
let noticeInstance;
|
|
353
|
+
const defaultOptions = {};
|
|
354
|
+
function getNoticeInstance(callback) {
|
|
355
|
+
if (noticeInstance) {
|
|
356
|
+
return callback(noticeInstance);
|
|
357
|
+
}
|
|
358
|
+
Notification.newInstance({
|
|
359
|
+
...defaultOptions,
|
|
360
|
+
prefixCls: 'notification',
|
|
361
|
+
maxCount: 5,
|
|
362
|
+
style: {
|
|
363
|
+
top: 20,
|
|
364
|
+
right: 20
|
|
365
|
+
}
|
|
366
|
+
}, instance => {
|
|
367
|
+
if (noticeInstance) {
|
|
368
|
+
callback(noticeInstance);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
noticeInstance = instance;
|
|
372
|
+
callback(instance);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const notice = _ref => {
|
|
376
|
+
let {
|
|
377
|
+
type,
|
|
378
|
+
...options
|
|
379
|
+
} = _ref;
|
|
380
|
+
getNoticeInstance(instance => {
|
|
381
|
+
options.duration = 3;
|
|
382
|
+
let variant = type;
|
|
383
|
+
switch (type) {
|
|
384
|
+
case 'error':
|
|
385
|
+
variant = 'danger';
|
|
386
|
+
options.duration = options.closable ? 0 : 5;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
options.content = jsx(Alert, {
|
|
390
|
+
variant: variant,
|
|
391
|
+
children: options.content
|
|
392
|
+
});
|
|
393
|
+
instance.notice(options);
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
const types = ['error', 'success', 'info'];
|
|
397
|
+
const Toast = types.reduce((toast, type) => {
|
|
398
|
+
toast[type] = (content, options) => {
|
|
399
|
+
notice({
|
|
400
|
+
...options,
|
|
401
|
+
type,
|
|
402
|
+
content
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
return toast;
|
|
406
|
+
}, {});
|
|
407
|
+
Toast.defaults = defaultOptions;
|
|
408
|
+
|
|
409
|
+
function isRecord(data) {
|
|
410
|
+
return data && typeof data === 'object';
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
rax.attach();
|
|
414
|
+
axios.defaults.raxConfig = {
|
|
415
|
+
retryDelay: 2000,
|
|
416
|
+
backoffType: 'static',
|
|
417
|
+
shouldRetry: _ref => {
|
|
418
|
+
let {
|
|
419
|
+
config,
|
|
420
|
+
response
|
|
421
|
+
} = _ref;
|
|
422
|
+
if (config.raxConfig?.retryDecider && !config.raxConfig.retryDecider()) {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
return config.method?.toUpperCase() === 'GET' && response?.status === 449;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
axios.defaults.maxContentLength = Infinity;
|
|
429
|
+
axios.defaults.maxBodyLength = Infinity;
|
|
430
|
+
axios.defaults.baseURL = '/api';
|
|
431
|
+
axios.defaults.authTokenName = 'authorization';
|
|
432
|
+
axios.interceptors.request.use(config => {
|
|
433
|
+
const key = config.authTokenName;
|
|
434
|
+
if (key) {
|
|
435
|
+
const token = localStorage.getItem(key);
|
|
436
|
+
if (token) {
|
|
437
|
+
config.headers = {
|
|
438
|
+
Authorization: `Bearer ${token}`,
|
|
439
|
+
...config.headers
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return config;
|
|
444
|
+
}, error => {
|
|
445
|
+
return Promise.reject(error);
|
|
446
|
+
});
|
|
447
|
+
axios.interceptors.response.use(response => {
|
|
448
|
+
if (response.status === 201 && response.data.location) {
|
|
449
|
+
window.location.href = response.data.location;
|
|
450
|
+
response.data = undefined; //防止多次跳转
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return response;
|
|
454
|
+
}, e => {
|
|
455
|
+
if (axios.isAxiosError(e)) {
|
|
456
|
+
if (e.response) {
|
|
457
|
+
const {
|
|
458
|
+
data,
|
|
459
|
+
status
|
|
460
|
+
} = e.response;
|
|
461
|
+
if (status === 401) {
|
|
462
|
+
e.errors = 'Unauthorized';
|
|
463
|
+
Toast.error('Unauthorized');
|
|
464
|
+
} else {
|
|
465
|
+
if (isRecord(data)) {
|
|
466
|
+
if (status === 422) {
|
|
467
|
+
e.errors = data;
|
|
468
|
+
} else if ('message' in data) {
|
|
469
|
+
e.errors = data['message'];
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
e.errors = data;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return Promise.reject(e);
|
|
478
|
+
});
|
|
479
|
+
const isRequestError = axios.isAxiosError;
|
|
480
|
+
const showRequestError = e => {
|
|
481
|
+
if (axios.isAxiosError(e)) {
|
|
482
|
+
let errors = e.errors;
|
|
483
|
+
if (typeof e.errors !== 'string') {
|
|
484
|
+
errors = Object.values(e.errors).join('<br />');
|
|
485
|
+
}
|
|
486
|
+
Toast.error(errors);
|
|
487
|
+
} else {
|
|
488
|
+
throw e;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const request = async function (config) {
|
|
492
|
+
config = typeof config === 'string' ? {
|
|
493
|
+
url: config
|
|
494
|
+
} : config;
|
|
495
|
+
const {
|
|
496
|
+
data
|
|
497
|
+
} = await axios.request({
|
|
498
|
+
paramsSerializer: function (params) {
|
|
499
|
+
return queryString.stringify(params, {
|
|
500
|
+
sort: false,
|
|
501
|
+
skipNull: true,
|
|
502
|
+
skipEmptyString: true,
|
|
503
|
+
arrayFormat: 'bracket'
|
|
504
|
+
});
|
|
505
|
+
},
|
|
506
|
+
...config
|
|
507
|
+
});
|
|
508
|
+
return data;
|
|
509
|
+
};
|
|
510
|
+
request.defaults = axios.defaults;
|
|
511
|
+
request.interceptors = axios.interceptors;
|
|
512
|
+
|
|
513
|
+
const useUnmountedRef = () => {
|
|
514
|
+
const unmountedRef = useRef(false);
|
|
515
|
+
useEffect(() => {
|
|
516
|
+
unmountedRef.current = false;
|
|
517
|
+
return () => {
|
|
518
|
+
unmountedRef.current = true;
|
|
519
|
+
};
|
|
520
|
+
}, []);
|
|
521
|
+
return unmountedRef;
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
function useSafeState(initialState) {
|
|
525
|
+
const unmountedRef = useUnmountedRef();
|
|
526
|
+
const [state, setState] = useState(initialState);
|
|
527
|
+
const setCurrentState = useCallback(currentState => {
|
|
528
|
+
/** if component is unmounted, stop update */
|
|
529
|
+
if (unmountedRef.current) return;
|
|
530
|
+
setState(currentState);
|
|
531
|
+
}, []);
|
|
532
|
+
return [state, setCurrentState];
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const WaitModal = function (_ref) {
|
|
536
|
+
let {
|
|
537
|
+
state,
|
|
538
|
+
message,
|
|
539
|
+
resolve
|
|
540
|
+
} = _ref;
|
|
541
|
+
const open = useRef(true);
|
|
542
|
+
const {
|
|
543
|
+
result,
|
|
544
|
+
checkUrl,
|
|
545
|
+
onComplete
|
|
546
|
+
} = message;
|
|
547
|
+
const [checking, setChecking] = useSafeState(false);
|
|
548
|
+
useEffect(() => {
|
|
549
|
+
request({
|
|
550
|
+
url: checkUrl,
|
|
551
|
+
method: 'post',
|
|
552
|
+
data: {
|
|
553
|
+
order_no: result.order_no
|
|
554
|
+
},
|
|
555
|
+
raxConfig: {
|
|
556
|
+
shouldRetry(err) {
|
|
557
|
+
return open.current && err.response?.status === 449;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}).then(() => {
|
|
561
|
+
onComplete?.();
|
|
562
|
+
resolve();
|
|
563
|
+
}).catch(() => null);
|
|
564
|
+
}, []);
|
|
565
|
+
return jsx(Modal, {
|
|
566
|
+
...state,
|
|
567
|
+
centered: true,
|
|
568
|
+
onHide: () => {
|
|
569
|
+
open.current = false;
|
|
570
|
+
state.onHide();
|
|
571
|
+
},
|
|
572
|
+
backdrop: 'static',
|
|
573
|
+
header: '\u652F\u4ED8\u7ED3\u679C',
|
|
574
|
+
okText: '\u5DF2\u5B8C\u6210\u652F\u4ED8',
|
|
575
|
+
okButtonProps: {
|
|
576
|
+
loading: checking
|
|
577
|
+
},
|
|
578
|
+
onOk: async e => {
|
|
579
|
+
e.preventDefault();
|
|
580
|
+
try {
|
|
581
|
+
setChecking(true);
|
|
582
|
+
await request({
|
|
583
|
+
url: checkUrl,
|
|
584
|
+
method: 'post',
|
|
585
|
+
data: {
|
|
586
|
+
order_no: result.order_no
|
|
587
|
+
},
|
|
588
|
+
raxConfig: {
|
|
589
|
+
shouldRetry() {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
onComplete?.();
|
|
595
|
+
resolve();
|
|
596
|
+
} catch {
|
|
597
|
+
// ignore
|
|
598
|
+
} finally {
|
|
599
|
+
setChecking(false);
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
cancelText: '\u53D6\u6D88',
|
|
603
|
+
children: "\u8BF7\u5728\u65B0\u6253\u5F00\u7684\u9875\u9762\u4E0A\u8FDB\u884C\u652F\u4ED8\uFF0C\u652F\u4ED8\u5B8C\u6210\u540E\u518D\u5173\u95ED\u6B64\u7A97\u53E3"
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
function waitPayComplete(options) {
|
|
607
|
+
const {
|
|
608
|
+
result
|
|
609
|
+
} = options;
|
|
610
|
+
window.open(result.pay_url);
|
|
611
|
+
show(WaitModal, options);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const Container$1 = styled.div`
|
|
615
|
+
padding: 48px 32px;
|
|
616
|
+
`;
|
|
617
|
+
const Icon = styled.div`
|
|
618
|
+
margin-bottom: 24px;
|
|
619
|
+
text-align: center;
|
|
620
|
+
font-size: 72px;
|
|
621
|
+
`;
|
|
622
|
+
const Title$1 = styled.div`
|
|
623
|
+
color: rgba(0, 0, 0, .85);
|
|
624
|
+
font-size: 24px;
|
|
625
|
+
line-height: 1.8;
|
|
626
|
+
text-align: center;
|
|
627
|
+
`;
|
|
628
|
+
const Extra = styled.div`
|
|
629
|
+
margin-top: 32px;
|
|
630
|
+
text-align: center;
|
|
631
|
+
`;
|
|
632
|
+
const IconMap = {
|
|
633
|
+
success: jsx("i", {
|
|
634
|
+
className: 'bi bi-check-circle-fill text-success'
|
|
635
|
+
}),
|
|
636
|
+
error: jsx("i", {
|
|
637
|
+
className: 'bi bi-exclamation-circle-fill text-danger'
|
|
638
|
+
}),
|
|
639
|
+
info: jsx("i", {
|
|
640
|
+
className: 'bi bi-info-circle-fill text-info'
|
|
641
|
+
}),
|
|
642
|
+
warning: jsx("i", {
|
|
643
|
+
className: 'bi bi-exclamation-triangle-fill text-warning'
|
|
644
|
+
})
|
|
645
|
+
};
|
|
646
|
+
function Result(_ref) {
|
|
647
|
+
let {
|
|
648
|
+
status,
|
|
649
|
+
title,
|
|
650
|
+
icon,
|
|
651
|
+
extra
|
|
652
|
+
} = _ref;
|
|
653
|
+
if (!icon && status) {
|
|
654
|
+
icon = IconMap[status];
|
|
655
|
+
}
|
|
656
|
+
return jsxs(Container$1, {
|
|
657
|
+
children: [icon && jsx(Icon, {
|
|
658
|
+
children: icon
|
|
659
|
+
}), title && jsx(Title$1, {
|
|
660
|
+
children: title
|
|
661
|
+
}), extra && jsx(Extra, {
|
|
662
|
+
children: extra
|
|
663
|
+
})]
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
styled.div`
|
|
668
|
+
position: relative;
|
|
669
|
+
`;
|
|
670
|
+
const Dimmer = styled.div`
|
|
671
|
+
display: ${props => props.active ? 'flex' : 'none'};
|
|
672
|
+
position: absolute;
|
|
673
|
+
top: 0 !important;
|
|
674
|
+
left: 0 !important;
|
|
675
|
+
width: 100%;
|
|
676
|
+
height: 100%;
|
|
677
|
+
text-align: center;
|
|
678
|
+
vertical-align: middle;
|
|
679
|
+
padding: 1em;
|
|
680
|
+
background-color: ${props => props.inverted ? 'rgba(255, 255, 255, .85)' : 'rgba(0, 0, 0, .85)'};
|
|
681
|
+
opacity: ${props => props.active ? 1 : 0};
|
|
682
|
+
line-height: 1;
|
|
683
|
+
animation-fill-mode: both;
|
|
684
|
+
animation-duration: .5s;
|
|
685
|
+
transition: background-color .5s linear;
|
|
686
|
+
flex-direction: column;
|
|
687
|
+
align-items: center;
|
|
688
|
+
justify-content: center;
|
|
689
|
+
user-select: none;
|
|
690
|
+
will-change: opacity;
|
|
691
|
+
z-index: 990;
|
|
692
|
+
`;
|
|
693
|
+
|
|
694
|
+
function Loader(_ref) {
|
|
695
|
+
let {
|
|
696
|
+
loading = true,
|
|
697
|
+
children,
|
|
698
|
+
variant = 'primary',
|
|
699
|
+
animation = 'border',
|
|
700
|
+
wrap,
|
|
701
|
+
...props
|
|
702
|
+
} = _ref;
|
|
703
|
+
if (!loading) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
if (children) {
|
|
707
|
+
children = jsx("p", {
|
|
708
|
+
className: 'mt-3 text-secondary',
|
|
709
|
+
children: children
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
children = jsxs(Dimmer, {
|
|
713
|
+
inverted: true,
|
|
714
|
+
active: true,
|
|
715
|
+
children: [jsx(Spinner, {
|
|
716
|
+
animation: animation,
|
|
717
|
+
variant: variant,
|
|
718
|
+
...props
|
|
719
|
+
}), children]
|
|
720
|
+
});
|
|
721
|
+
if (wrap) {
|
|
722
|
+
return jsx(Wrap, {
|
|
723
|
+
"$height": typeof wrap === 'number' ? wrap : 150,
|
|
724
|
+
children: children
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
return children;
|
|
728
|
+
}
|
|
729
|
+
const Wrap = styled.div`
|
|
730
|
+
position: relative;
|
|
731
|
+
height: ${props => `${props.$height}px`};
|
|
732
|
+
`;
|
|
733
|
+
|
|
734
|
+
function Card(_ref) {
|
|
735
|
+
let {
|
|
736
|
+
children,
|
|
737
|
+
title,
|
|
738
|
+
className,
|
|
739
|
+
...props
|
|
740
|
+
} = _ref;
|
|
741
|
+
return jsx(Card$1, {
|
|
742
|
+
className: classNames('border-0 shadow-sm mb-3', className),
|
|
743
|
+
...props,
|
|
744
|
+
children: jsxs("div", {
|
|
745
|
+
className: 'card-body',
|
|
746
|
+
children: [title && jsxs(Fragment$1, {
|
|
747
|
+
children: [jsx("h5", {
|
|
748
|
+
children: title
|
|
749
|
+
}), jsx("hr", {})]
|
|
750
|
+
}), children]
|
|
751
|
+
})
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function Error$1(_ref) {
|
|
756
|
+
let {
|
|
757
|
+
errors
|
|
758
|
+
} = _ref;
|
|
759
|
+
if (!errors) {
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
return jsx(Alert, {
|
|
763
|
+
variant: 'danger',
|
|
764
|
+
children: jsx("ul", {
|
|
765
|
+
className: 'mb-0',
|
|
766
|
+
children: typeof errors === 'string' ? jsx("li", {
|
|
767
|
+
children: errors
|
|
768
|
+
}) : Object.entries(errors).map(_ref2 => {
|
|
769
|
+
let [name, error] = _ref2;
|
|
770
|
+
return jsx("li", {
|
|
771
|
+
children: error
|
|
772
|
+
}, name);
|
|
773
|
+
})
|
|
774
|
+
})
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function Space(_ref) {
|
|
779
|
+
let {
|
|
780
|
+
children,
|
|
781
|
+
className,
|
|
782
|
+
size = 'small',
|
|
783
|
+
direction = 'horizontal'
|
|
784
|
+
} = _ref;
|
|
785
|
+
if (typeof size === 'string') {
|
|
786
|
+
size = {
|
|
787
|
+
small: 8,
|
|
788
|
+
middle: 16,
|
|
789
|
+
large: 24
|
|
790
|
+
}[size];
|
|
791
|
+
}
|
|
792
|
+
const items = Children.map(children, child => {
|
|
793
|
+
if (child) {
|
|
794
|
+
return jsx(Item, {
|
|
795
|
+
children: child
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
return jsx(Container, {
|
|
800
|
+
className: className,
|
|
801
|
+
"$direction": direction,
|
|
802
|
+
"$size": size,
|
|
803
|
+
children: items
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
const Container = styled.div`
|
|
807
|
+
display: inline-flex;
|
|
808
|
+
align-items: center;
|
|
809
|
+
gap: ${props => props.$size}px;
|
|
810
|
+
|
|
811
|
+
${props => props.$direction === 'vertical' && css`
|
|
812
|
+
display: flex;
|
|
813
|
+
flex-direction: column;
|
|
814
|
+
align-items: inherit;
|
|
815
|
+
`}
|
|
816
|
+
`;
|
|
817
|
+
const Item = styled.div`
|
|
818
|
+
|
|
819
|
+
`;
|
|
820
|
+
|
|
821
|
+
const LazySteps = lazy(() => import('./steps-afba29a7.js'));
|
|
822
|
+
const LazyStep = lazy(() => import('./steps-afba29a7.js').then(_ref => {
|
|
823
|
+
let {
|
|
824
|
+
Step
|
|
825
|
+
} = _ref;
|
|
826
|
+
return {
|
|
827
|
+
default: Step
|
|
828
|
+
};
|
|
829
|
+
}));
|
|
830
|
+
function Steps(props) {
|
|
831
|
+
return jsx(Suspense, {
|
|
832
|
+
fallback: null,
|
|
833
|
+
children: jsx(LazySteps, {
|
|
834
|
+
...props
|
|
835
|
+
})
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
const Step = function (props) {
|
|
839
|
+
return jsx(Suspense, {
|
|
840
|
+
fallback: null,
|
|
841
|
+
children: jsx(LazyStep, {
|
|
842
|
+
...props
|
|
843
|
+
})
|
|
844
|
+
});
|
|
845
|
+
};
|
|
846
|
+
Steps.Step = Step;
|
|
847
|
+
|
|
848
|
+
function Statistic(_ref) {
|
|
849
|
+
let {
|
|
850
|
+
title,
|
|
851
|
+
content,
|
|
852
|
+
footer
|
|
853
|
+
} = _ref;
|
|
854
|
+
return jsxs(Card, {
|
|
855
|
+
children: [jsx(Title, {
|
|
856
|
+
children: title
|
|
857
|
+
}), jsx(Content, {
|
|
858
|
+
children: content
|
|
859
|
+
}), footer && jsx(Footer, {
|
|
860
|
+
children: footer
|
|
861
|
+
})]
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
const Footer = styled.div`
|
|
865
|
+
margin-top: 9px;
|
|
866
|
+
padding-top: 10px;
|
|
867
|
+
border-top: 1px solid #f0f0f0;
|
|
868
|
+
color: rgba(0, 0, 0, .65);
|
|
869
|
+
`;
|
|
870
|
+
const Content = styled.div`
|
|
871
|
+
color: rgba(0, 0, 0, .85);
|
|
872
|
+
font-size: 24px;
|
|
873
|
+
`;
|
|
874
|
+
const Title = styled.div`
|
|
875
|
+
margin-bottom: 4px;
|
|
876
|
+
color: rgba(0, 0, 0, .45);
|
|
877
|
+
font-size: 1.1rem;
|
|
878
|
+
`;
|
|
879
|
+
|
|
880
|
+
function noop() {}
|
|
881
|
+
function isInteger(value) {
|
|
882
|
+
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
|
|
883
|
+
}
|
|
884
|
+
function Pagination(_ref) {
|
|
885
|
+
let {
|
|
886
|
+
total = 0,
|
|
887
|
+
onChange = noop,
|
|
888
|
+
defaultCurrent = 1,
|
|
889
|
+
defaultPageSize = 10,
|
|
890
|
+
className,
|
|
891
|
+
...props
|
|
892
|
+
} = _ref;
|
|
893
|
+
const [current, setCurrent] = useState(defaultCurrent);
|
|
894
|
+
const [pageSize, setPageSize] = useState(defaultPageSize);
|
|
895
|
+
useEffect(() => {
|
|
896
|
+
if (isInteger(props.current)) {
|
|
897
|
+
setCurrent(props.current);
|
|
898
|
+
}
|
|
899
|
+
}, [props.current]);
|
|
900
|
+
useEffect(() => {
|
|
901
|
+
if (isInteger(props.pageSize)) {
|
|
902
|
+
setPageSize(props.pageSize);
|
|
903
|
+
}
|
|
904
|
+
}, [props.pageSize]);
|
|
905
|
+
const allPages = useMemo(() => {
|
|
906
|
+
return Math.floor((total - 1) / pageSize) + 1;
|
|
907
|
+
}, [total, pageSize]);
|
|
908
|
+
const handleChange = useCallback(p => {
|
|
909
|
+
return () => {
|
|
910
|
+
if (p !== current) {
|
|
911
|
+
setCurrent(p);
|
|
912
|
+
onChange(p, pageSize);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
}, [onChange, current, pageSize]);
|
|
916
|
+
const pageBufferSize = 2;
|
|
917
|
+
const prevPage = current - 1 > 0 ? current - 1 : 0;
|
|
918
|
+
const nextPage = current + 1 < allPages ? current + 1 : allPages;
|
|
919
|
+
const pagerList = [];
|
|
920
|
+
let jumpPrev = null;
|
|
921
|
+
let jumpNext = null;
|
|
922
|
+
let firstPager = null;
|
|
923
|
+
let lastPager = null;
|
|
924
|
+
if (allPages <= 3 + pageBufferSize * 2) {
|
|
925
|
+
for (let i = 1; i <= allPages; i += 1) {
|
|
926
|
+
const active = current === i;
|
|
927
|
+
pagerList.push(jsx(Pagination$1.Item, {
|
|
928
|
+
active: active,
|
|
929
|
+
onClick: handleChange(i),
|
|
930
|
+
children: i
|
|
931
|
+
}, i));
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
lastPager = jsx(Pagination$1.Last, {
|
|
935
|
+
onClick: handleChange(allPages)
|
|
936
|
+
}, 'last');
|
|
937
|
+
firstPager = jsx(Pagination$1.First, {
|
|
938
|
+
onClick: handleChange(1)
|
|
939
|
+
}, 'first');
|
|
940
|
+
jumpPrev = jsx(Pagination$1.Prev, {
|
|
941
|
+
onClick: handleChange(prevPage)
|
|
942
|
+
}, 'prev');
|
|
943
|
+
jumpNext = jsx(Pagination$1.Next, {
|
|
944
|
+
onClick: handleChange(nextPage)
|
|
945
|
+
}, 'next');
|
|
946
|
+
let left = Math.max(1, current - pageBufferSize);
|
|
947
|
+
let right = Math.min(current + pageBufferSize, allPages);
|
|
948
|
+
if (current - 1 <= pageBufferSize) {
|
|
949
|
+
right = 1 + pageBufferSize * 2;
|
|
950
|
+
}
|
|
951
|
+
if (allPages - current <= pageBufferSize) {
|
|
952
|
+
left = allPages - pageBufferSize * 2;
|
|
953
|
+
}
|
|
954
|
+
for (let i = left; i <= right; i += 1) {
|
|
955
|
+
const active = current === i;
|
|
956
|
+
pagerList.push(jsx(Pagination$1.Item, {
|
|
957
|
+
active: active,
|
|
958
|
+
onClick: handleChange(i),
|
|
959
|
+
children: i
|
|
960
|
+
}, i));
|
|
961
|
+
}
|
|
962
|
+
if (current - 1 >= pageBufferSize * 2 && current !== 1 + 2) {
|
|
963
|
+
pagerList.unshift(jumpPrev);
|
|
964
|
+
}
|
|
965
|
+
if (allPages - current >= pageBufferSize * 2 && current !== allPages - 2) {
|
|
966
|
+
pagerList.push(jumpNext);
|
|
967
|
+
}
|
|
968
|
+
if (left !== 1) {
|
|
969
|
+
pagerList.unshift(firstPager);
|
|
970
|
+
}
|
|
971
|
+
if (right !== allPages) {
|
|
972
|
+
pagerList.push(lastPager);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return jsx(Pagination$1, {
|
|
976
|
+
className: className,
|
|
977
|
+
children: pagerList
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function NumberFormat(_ref) {
|
|
982
|
+
let {
|
|
983
|
+
className,
|
|
984
|
+
value,
|
|
985
|
+
locale = 'zh-CN',
|
|
986
|
+
currency = true,
|
|
987
|
+
options = {}
|
|
988
|
+
} = _ref;
|
|
989
|
+
const formatter = useMemo(() => {
|
|
990
|
+
let opt;
|
|
991
|
+
if (currency) {
|
|
992
|
+
opt = {
|
|
993
|
+
style: 'currency',
|
|
994
|
+
currency: 'CNY'
|
|
995
|
+
};
|
|
996
|
+
} else {
|
|
997
|
+
opt = {
|
|
998
|
+
minimumFractionDigits: 2
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
return new Intl.NumberFormat(locale, {
|
|
1002
|
+
...opt,
|
|
1003
|
+
...options
|
|
1004
|
+
});
|
|
1005
|
+
}, [currency, locale, options]);
|
|
1006
|
+
if (className) {
|
|
1007
|
+
return jsx("span", {
|
|
1008
|
+
className: className,
|
|
1009
|
+
children: formatter.format(value)
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
return jsx(Fragment$1, {
|
|
1013
|
+
children: formatter.format(value)
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function LoadingButton(_ref) {
|
|
1018
|
+
let {
|
|
1019
|
+
loading,
|
|
1020
|
+
disabled,
|
|
1021
|
+
children,
|
|
1022
|
+
...props
|
|
1023
|
+
} = _ref;
|
|
1024
|
+
return jsx(Button$1, {
|
|
1025
|
+
...props,
|
|
1026
|
+
disabled: loading || disabled,
|
|
1027
|
+
children: loading ? 'Loading…' : children
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
const LazyImageZoom = lazy(() => import('./image-zoom-912e2b3b.js'));
|
|
1032
|
+
function ImageZoom(props) {
|
|
1033
|
+
return jsx(Suspense, {
|
|
1034
|
+
fallback: null,
|
|
1035
|
+
children: jsx(LazyImageZoom, {
|
|
1036
|
+
...props
|
|
1037
|
+
})
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
function RequestButton(_ref) {
|
|
1042
|
+
let {
|
|
1043
|
+
url,
|
|
1044
|
+
method,
|
|
1045
|
+
confirm,
|
|
1046
|
+
onSuccess,
|
|
1047
|
+
children,
|
|
1048
|
+
disabled,
|
|
1049
|
+
as = Button,
|
|
1050
|
+
...props
|
|
1051
|
+
} = _ref;
|
|
1052
|
+
const [fetching, setFetching] = useSafeState(false);
|
|
1053
|
+
const handleClick = useCallback(async e => {
|
|
1054
|
+
e.preventDefault();
|
|
1055
|
+
try {
|
|
1056
|
+
setFetching(true);
|
|
1057
|
+
if (confirm) {
|
|
1058
|
+
if (!(await Modal.confirm({
|
|
1059
|
+
message: confirm
|
|
1060
|
+
}))) {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
const config = typeof url === 'string' ? {
|
|
1065
|
+
url,
|
|
1066
|
+
method
|
|
1067
|
+
} : {
|
|
1068
|
+
method,
|
|
1069
|
+
...url
|
|
1070
|
+
};
|
|
1071
|
+
const result = await request(config);
|
|
1072
|
+
if (onSuccess) {
|
|
1073
|
+
onSuccess(result);
|
|
1074
|
+
}
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
showRequestError(e);
|
|
1077
|
+
} finally {
|
|
1078
|
+
setFetching(false);
|
|
1079
|
+
}
|
|
1080
|
+
}, [url, method, setFetching]);
|
|
1081
|
+
return createElement(as, {
|
|
1082
|
+
...props,
|
|
1083
|
+
disabled: disabled || fetching,
|
|
1084
|
+
onClick: handleClick
|
|
1085
|
+
}, children);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
const LazyForm = lazy(() => import('./form-8925a750.js'));
|
|
1089
|
+
const Form = forwardRef((props, ref) => {
|
|
1090
|
+
return jsx(Suspense, {
|
|
1091
|
+
fallback: null,
|
|
1092
|
+
children: jsx(LazyForm, {
|
|
1093
|
+
...props,
|
|
1094
|
+
ref: ref
|
|
1095
|
+
})
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
const LazyTable = lazy(() => import('./index-303e1845.js'));
|
|
1100
|
+
const Table = forwardRef((props, ref) => {
|
|
1101
|
+
return jsx(Suspense, {
|
|
1102
|
+
fallback: null,
|
|
1103
|
+
children: jsx(LazyTable, {
|
|
1104
|
+
...props,
|
|
1105
|
+
ref: ref
|
|
1106
|
+
})
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
let id = 0;
|
|
1111
|
+
function useOverlayState() {
|
|
1112
|
+
let {
|
|
1113
|
+
onHide,
|
|
1114
|
+
onShow
|
|
1115
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1116
|
+
const [visible, setVisible] = useState(false);
|
|
1117
|
+
const [key, setKey] = useState(`visible-${id}`);
|
|
1118
|
+
const hide = useCallback(() => {
|
|
1119
|
+
setVisible(false);
|
|
1120
|
+
if (onHide) {
|
|
1121
|
+
onHide();
|
|
1122
|
+
}
|
|
1123
|
+
}, [setVisible, onHide]);
|
|
1124
|
+
const exit = useCallback(() => {
|
|
1125
|
+
setKey(`visible-${++id}`);
|
|
1126
|
+
}, [setKey, id]);
|
|
1127
|
+
const show = useCallback(() => {
|
|
1128
|
+
setVisible(true);
|
|
1129
|
+
if (onShow) {
|
|
1130
|
+
onShow();
|
|
1131
|
+
}
|
|
1132
|
+
}, [setVisible, onShow]);
|
|
1133
|
+
const state = {
|
|
1134
|
+
show: visible,
|
|
1135
|
+
onHide: hide,
|
|
1136
|
+
onExited: exit,
|
|
1137
|
+
key
|
|
1138
|
+
};
|
|
1139
|
+
return {
|
|
1140
|
+
visible,
|
|
1141
|
+
show,
|
|
1142
|
+
hide,
|
|
1143
|
+
state
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const ModalButton = forwardRef((_ref, ref) => {
|
|
1148
|
+
let {
|
|
1149
|
+
text,
|
|
1150
|
+
onOk,
|
|
1151
|
+
modalProps,
|
|
1152
|
+
children,
|
|
1153
|
+
onShow,
|
|
1154
|
+
confirmLoading,
|
|
1155
|
+
as = Button,
|
|
1156
|
+
...props
|
|
1157
|
+
} = _ref;
|
|
1158
|
+
const {
|
|
1159
|
+
state,
|
|
1160
|
+
show,
|
|
1161
|
+
hide
|
|
1162
|
+
} = useOverlayState({
|
|
1163
|
+
onShow
|
|
1164
|
+
});
|
|
1165
|
+
useImperativeHandle(ref, () => ({
|
|
1166
|
+
close: hide
|
|
1167
|
+
}));
|
|
1168
|
+
const handleOk = async e => {
|
|
1169
|
+
if (onOk) {
|
|
1170
|
+
const result = await onOk();
|
|
1171
|
+
if (result === false) {
|
|
1172
|
+
e.preventDefault();
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
const button = createElement(as, {
|
|
1177
|
+
...props,
|
|
1178
|
+
onClick: show
|
|
1179
|
+
}, text);
|
|
1180
|
+
return jsxs(Fragment$1, {
|
|
1181
|
+
children: [button, jsx(Modal, {
|
|
1182
|
+
header: text,
|
|
1183
|
+
...modalProps,
|
|
1184
|
+
...state,
|
|
1185
|
+
confirmLoading: confirmLoading,
|
|
1186
|
+
onOk: handleOk,
|
|
1187
|
+
children: children
|
|
1188
|
+
})]
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
function ModalForm(_ref) {
|
|
1193
|
+
let {
|
|
1194
|
+
text,
|
|
1195
|
+
onSuccess,
|
|
1196
|
+
buttonProps,
|
|
1197
|
+
modalProps,
|
|
1198
|
+
children,
|
|
1199
|
+
...props
|
|
1200
|
+
} = _ref;
|
|
1201
|
+
const [loading, setLoading] = useState(false);
|
|
1202
|
+
const ref = useRef(null);
|
|
1203
|
+
const form = useRef(null);
|
|
1204
|
+
const handleOk = useCallback(() => {
|
|
1205
|
+
form.current?.submit();
|
|
1206
|
+
return false;
|
|
1207
|
+
}, []);
|
|
1208
|
+
const handleSuccess = useCallback(data => {
|
|
1209
|
+
if (onSuccess) {
|
|
1210
|
+
onSuccess(data);
|
|
1211
|
+
}
|
|
1212
|
+
ref.current?.close();
|
|
1213
|
+
}, [onSuccess]);
|
|
1214
|
+
return jsx(ModalButton, {
|
|
1215
|
+
ref: ref,
|
|
1216
|
+
text: text,
|
|
1217
|
+
...buttonProps,
|
|
1218
|
+
modalProps: modalProps,
|
|
1219
|
+
onOk: handleOk,
|
|
1220
|
+
confirmLoading: loading,
|
|
1221
|
+
children: jsxs(Form, {
|
|
1222
|
+
...props,
|
|
1223
|
+
onSubmitting: setLoading,
|
|
1224
|
+
ref: form,
|
|
1225
|
+
onSuccess: handleSuccess,
|
|
1226
|
+
children: [children, jsx("input", {
|
|
1227
|
+
type: 'submit',
|
|
1228
|
+
hidden: true
|
|
1229
|
+
})]
|
|
1230
|
+
})
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
function useRequest(config) {
|
|
1235
|
+
let {
|
|
1236
|
+
manual,
|
|
1237
|
+
refreshDeps,
|
|
1238
|
+
...options
|
|
1239
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1240
|
+
let {
|
|
1241
|
+
execute,
|
|
1242
|
+
currentParams,
|
|
1243
|
+
error,
|
|
1244
|
+
...others
|
|
1245
|
+
} = useAsyncCallback(async params => {
|
|
1246
|
+
config = typeof config === 'string' ? {
|
|
1247
|
+
url: config
|
|
1248
|
+
} : config;
|
|
1249
|
+
return await request({
|
|
1250
|
+
...config,
|
|
1251
|
+
...params
|
|
1252
|
+
});
|
|
1253
|
+
}, options);
|
|
1254
|
+
useEffect(() => {
|
|
1255
|
+
if (!manual && !refreshDeps) {
|
|
1256
|
+
try {
|
|
1257
|
+
execute();
|
|
1258
|
+
} catch {}
|
|
1259
|
+
}
|
|
1260
|
+
}, []);
|
|
1261
|
+
useEffect(() => {
|
|
1262
|
+
if (refreshDeps) {
|
|
1263
|
+
refresh();
|
|
1264
|
+
}
|
|
1265
|
+
}, refreshDeps);
|
|
1266
|
+
const refresh = useCallback(async () => {
|
|
1267
|
+
try {
|
|
1268
|
+
if (currentParams) {
|
|
1269
|
+
await execute(...currentParams);
|
|
1270
|
+
} else {
|
|
1271
|
+
await execute();
|
|
1272
|
+
}
|
|
1273
|
+
} catch {}
|
|
1274
|
+
}, [execute, currentParams]);
|
|
1275
|
+
if (error && isRequestError(error)) {
|
|
1276
|
+
const errors = error.errors;
|
|
1277
|
+
error = new Error(typeof errors === 'string' ? errors : values(errors).join(''));
|
|
1278
|
+
}
|
|
1279
|
+
return {
|
|
1280
|
+
refresh,
|
|
1281
|
+
execute,
|
|
1282
|
+
error,
|
|
1283
|
+
...others
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function useCallbackRef(callback) {
|
|
1288
|
+
let deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
1289
|
+
const callbackRef = useRef(callback);
|
|
1290
|
+
useEffect(() => {
|
|
1291
|
+
callbackRef.current = callback;
|
|
1292
|
+
});
|
|
1293
|
+
return useCallback(function () {
|
|
1294
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1295
|
+
args[_key] = arguments[_key];
|
|
1296
|
+
}
|
|
1297
|
+
return callbackRef.current?.(...args);
|
|
1298
|
+
}, deps);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function useControllableState(props) {
|
|
1302
|
+
const {
|
|
1303
|
+
value: valueProp,
|
|
1304
|
+
defaultValue,
|
|
1305
|
+
onChange,
|
|
1306
|
+
shouldUpdate = (prev, next) => prev !== next
|
|
1307
|
+
} = props;
|
|
1308
|
+
const onChangeProp = useCallbackRef(onChange);
|
|
1309
|
+
const shouldUpdateProp = useCallbackRef(shouldUpdate);
|
|
1310
|
+
const [uncontrolledState, setUncontrolledState] = useState(defaultValue);
|
|
1311
|
+
const controlled = valueProp !== undefined;
|
|
1312
|
+
const value = controlled ? valueProp : uncontrolledState;
|
|
1313
|
+
const setValue = useCallbackRef(next => {
|
|
1314
|
+
const setter = next;
|
|
1315
|
+
const nextValue = typeof next === 'function' ? setter(value) : next;
|
|
1316
|
+
if (!shouldUpdateProp(value, nextValue)) {
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
if (!controlled) {
|
|
1320
|
+
setUncontrolledState(nextValue);
|
|
1321
|
+
}
|
|
1322
|
+
onChangeProp(nextValue);
|
|
1323
|
+
}, [controlled, onChangeProp, value, shouldUpdateProp]);
|
|
1324
|
+
return [value, setValue];
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
function useDebounce(callback, wait, options) {
|
|
1328
|
+
const callbackRef = useRef(callback);
|
|
1329
|
+
const debouncedCallbackRef = useRef(debounce(callback, wait, options));
|
|
1330
|
+
useEffect(() => {
|
|
1331
|
+
callbackRef.current = callback;
|
|
1332
|
+
});
|
|
1333
|
+
useEffect(() => {
|
|
1334
|
+
debouncedCallbackRef.current = debounce(function () {
|
|
1335
|
+
callbackRef.current(...arguments);
|
|
1336
|
+
}, wait, options);
|
|
1337
|
+
}, [wait, options]);
|
|
1338
|
+
return debouncedCallbackRef.current;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
class Unauthorized extends Error {
|
|
1342
|
+
constructor(url) {
|
|
1343
|
+
super('Unauthorized');
|
|
1344
|
+
_defineProperty(this, "url", void 0);
|
|
1345
|
+
this.url = url;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
export { Button as B, Card as C, Error$1 as E, Form as F, ImageZoom as I, Loader as L, Message$1 as M, NumberFormat as N, Pagination as P, Result as R, Space as S, TableContext as T, Unauthorized as U, useDebounce as a, useControllableState as b, Toast as c, Steps as d, Step as e, Statistic as f, LoadingButton as g, RequestButton as h, Table as i, ModalForm as j, ModalButton as k, Modal as l, Tooltip as m, useRequest as n, useOverlayState as o, isRequestError as p, request as r, showRequestError as s, useSafeState as u, waitPayComplete as w };
|
|
1350
|
+
//# sourceMappingURL=index-9869b1c6.js.map
|