@topthink/components 1.0.55 → 1.0.57

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.
@@ -0,0 +1,1352 @@
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 _defineProperty from '@babel/runtime/helpers/defineProperty';
11
+ import Notification from 'rc-notification';
12
+ import styled, { css } from 'styled-components';
13
+ import classNames from 'classnames';
14
+ import { useAsyncCallback } from 'react-async-hook';
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
+ class Unauthorized extends Error {
353
+ constructor(url) {
354
+ super('Unauthorized');
355
+ _defineProperty(this, "url", void 0);
356
+ this.url = url;
357
+ }
358
+ }
359
+
360
+ let noticeInstance;
361
+ const defaultOptions = {};
362
+ function getNoticeInstance(callback) {
363
+ if (noticeInstance) {
364
+ return callback(noticeInstance);
365
+ }
366
+ Notification.newInstance({
367
+ ...defaultOptions,
368
+ prefixCls: 'notification',
369
+ maxCount: 5,
370
+ style: {
371
+ top: 20,
372
+ right: 20
373
+ }
374
+ }, instance => {
375
+ if (noticeInstance) {
376
+ callback(noticeInstance);
377
+ return;
378
+ }
379
+ noticeInstance = instance;
380
+ callback(instance);
381
+ });
382
+ }
383
+ const notice = _ref => {
384
+ let {
385
+ type,
386
+ ...options
387
+ } = _ref;
388
+ getNoticeInstance(instance => {
389
+ options.duration = 3;
390
+ let variant = type;
391
+ switch (type) {
392
+ case 'error':
393
+ variant = 'danger';
394
+ options.duration = options.closable ? 0 : 5;
395
+ break;
396
+ }
397
+ options.content = jsx(Alert, {
398
+ variant: variant,
399
+ children: options.content
400
+ });
401
+ instance.notice(options);
402
+ });
403
+ };
404
+ const types = ['error', 'success', 'info'];
405
+ const Toast = types.reduce((toast, type) => {
406
+ toast[type] = (content, options) => {
407
+ notice({
408
+ ...options,
409
+ type,
410
+ content
411
+ });
412
+ };
413
+ return toast;
414
+ }, {});
415
+ Toast.defaults = defaultOptions;
416
+
417
+ rax.attach();
418
+ axios.defaults.raxConfig = {
419
+ retryDelay: 2000,
420
+ backoffType: 'static',
421
+ shouldRetry: _ref => {
422
+ let {
423
+ config,
424
+ response
425
+ } = _ref;
426
+ if (config.raxConfig?.retryDecider && !config.raxConfig.retryDecider()) {
427
+ return false;
428
+ }
429
+ return config.method?.toUpperCase() === 'GET' && response?.status === 449;
430
+ }
431
+ };
432
+ axios.defaults.maxContentLength = Infinity;
433
+ axios.defaults.maxBodyLength = Infinity;
434
+ axios.defaults.baseURL = '/api';
435
+ axios.defaults.authTokenName = 'authorization';
436
+ axios.interceptors.request.use(config => {
437
+ const key = config.authTokenName;
438
+ if (key) {
439
+ const token = localStorage.getItem(key);
440
+ if (token) {
441
+ config.headers = {
442
+ Authorization: `Bearer ${token}`,
443
+ ...config.headers
444
+ };
445
+ }
446
+ }
447
+ return config;
448
+ }, error => {
449
+ return Promise.reject(error);
450
+ });
451
+ const isRecord = data => {
452
+ return data && typeof data === 'object';
453
+ };
454
+ axios.interceptors.response.use(response => {
455
+ if (response.status === 201 && response.data.location) {
456
+ window.location.href = response.data.location;
457
+ response.data = undefined; //防止多次跳转
458
+ }
459
+
460
+ return response;
461
+ }, e => {
462
+ if (axios.isAxiosError(e)) {
463
+ if (e.response) {
464
+ const {
465
+ data,
466
+ status
467
+ } = e.response;
468
+ if (status === 401) {
469
+ e.errors = 'Unauthorized';
470
+ if (isRecord(data) && data.url) {
471
+ e = new Unauthorized(data.url);
472
+ }
473
+ Toast.error('Unauthorized');
474
+ } else {
475
+ if (isRecord(data)) {
476
+ if (status === 422) {
477
+ e.errors = data;
478
+ } else if ('message' in data) {
479
+ e.errors = data['message'];
480
+ }
481
+ } else {
482
+ e.errors = data;
483
+ }
484
+ }
485
+ }
486
+ }
487
+ return Promise.reject(e);
488
+ });
489
+ const isRequestError = axios.isAxiosError;
490
+ const showRequestError = e => {
491
+ if (axios.isAxiosError(e)) {
492
+ let errors = e.errors;
493
+ if (typeof e.errors !== 'string') {
494
+ errors = Object.values(e.errors).join('<br />');
495
+ }
496
+ Toast.error(errors);
497
+ } else {
498
+ throw e;
499
+ }
500
+ };
501
+ const request = async function (config) {
502
+ config = typeof config === 'string' ? {
503
+ url: config
504
+ } : config;
505
+ const {
506
+ data
507
+ } = await axios.request({
508
+ paramsSerializer: function (params) {
509
+ return queryString.stringify(params, {
510
+ sort: false,
511
+ skipNull: true,
512
+ skipEmptyString: true,
513
+ arrayFormat: 'bracket'
514
+ });
515
+ },
516
+ ...config
517
+ });
518
+ return data;
519
+ };
520
+ request.defaults = axios.defaults;
521
+ request.interceptors = axios.interceptors;
522
+
523
+ const useUnmountedRef = () => {
524
+ const unmountedRef = useRef(false);
525
+ useEffect(() => {
526
+ unmountedRef.current = false;
527
+ return () => {
528
+ unmountedRef.current = true;
529
+ };
530
+ }, []);
531
+ return unmountedRef;
532
+ };
533
+
534
+ function useSafeState(initialState) {
535
+ const unmountedRef = useUnmountedRef();
536
+ const [state, setState] = useState(initialState);
537
+ const setCurrentState = useCallback(currentState => {
538
+ /** if component is unmounted, stop update */
539
+ if (unmountedRef.current) return;
540
+ setState(currentState);
541
+ }, []);
542
+ return [state, setCurrentState];
543
+ }
544
+
545
+ const WaitModal = function (_ref) {
546
+ let {
547
+ state,
548
+ message,
549
+ resolve
550
+ } = _ref;
551
+ const open = useRef(true);
552
+ const {
553
+ result,
554
+ checkUrl,
555
+ onComplete
556
+ } = message;
557
+ const [checking, setChecking] = useSafeState(false);
558
+ useEffect(() => {
559
+ request({
560
+ url: checkUrl,
561
+ method: 'post',
562
+ data: {
563
+ order_no: result.order_no
564
+ },
565
+ raxConfig: {
566
+ shouldRetry(err) {
567
+ return open.current && err.response?.status === 449;
568
+ }
569
+ }
570
+ }).then(() => {
571
+ onComplete?.();
572
+ resolve();
573
+ }).catch(() => null);
574
+ }, []);
575
+ return jsx(Modal, {
576
+ ...state,
577
+ centered: true,
578
+ onHide: () => {
579
+ open.current = false;
580
+ state.onHide();
581
+ },
582
+ backdrop: 'static',
583
+ header: '\u652F\u4ED8\u7ED3\u679C',
584
+ okText: '\u5DF2\u5B8C\u6210\u652F\u4ED8',
585
+ okButtonProps: {
586
+ loading: checking
587
+ },
588
+ onOk: async e => {
589
+ e.preventDefault();
590
+ try {
591
+ setChecking(true);
592
+ await request({
593
+ url: checkUrl,
594
+ method: 'post',
595
+ data: {
596
+ order_no: result.order_no
597
+ },
598
+ raxConfig: {
599
+ shouldRetry() {
600
+ return false;
601
+ }
602
+ }
603
+ });
604
+ onComplete?.();
605
+ resolve();
606
+ } catch {
607
+ // ignore
608
+ } finally {
609
+ setChecking(false);
610
+ }
611
+ },
612
+ cancelText: '\u53D6\u6D88',
613
+ 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"
614
+ });
615
+ };
616
+ function waitPayComplete(options) {
617
+ const {
618
+ result
619
+ } = options;
620
+ window.open(result.pay_url);
621
+ show(WaitModal, options);
622
+ }
623
+
624
+ const Container$1 = styled.div`
625
+ padding: 48px 32px;
626
+ `;
627
+ const Icon = styled.div`
628
+ margin-bottom: 24px;
629
+ text-align: center;
630
+ font-size: 72px;
631
+ `;
632
+ const Title$1 = styled.div`
633
+ color: rgba(0, 0, 0, .85);
634
+ font-size: 24px;
635
+ line-height: 1.8;
636
+ text-align: center;
637
+ `;
638
+ const Extra = styled.div`
639
+ margin-top: 32px;
640
+ text-align: center;
641
+ `;
642
+ const IconMap = {
643
+ success: jsx("i", {
644
+ className: 'bi bi-check-circle-fill text-success'
645
+ }),
646
+ error: jsx("i", {
647
+ className: 'bi bi-exclamation-circle-fill text-danger'
648
+ }),
649
+ info: jsx("i", {
650
+ className: 'bi bi-info-circle-fill text-info'
651
+ }),
652
+ warning: jsx("i", {
653
+ className: 'bi bi-exclamation-triangle-fill text-warning'
654
+ })
655
+ };
656
+ function Result(_ref) {
657
+ let {
658
+ status,
659
+ title,
660
+ icon,
661
+ extra
662
+ } = _ref;
663
+ if (!icon && status) {
664
+ icon = IconMap[status];
665
+ }
666
+ return jsxs(Container$1, {
667
+ children: [icon && jsx(Icon, {
668
+ children: icon
669
+ }), title && jsx(Title$1, {
670
+ children: title
671
+ }), extra && jsx(Extra, {
672
+ children: extra
673
+ })]
674
+ });
675
+ }
676
+
677
+ styled.div`
678
+ position: relative;
679
+ `;
680
+ const Dimmer = styled.div`
681
+ display: ${props => props.active ? 'flex' : 'none'};
682
+ position: absolute;
683
+ top: 0 !important;
684
+ left: 0 !important;
685
+ width: 100%;
686
+ height: 100%;
687
+ text-align: center;
688
+ vertical-align: middle;
689
+ padding: 1em;
690
+ background-color: ${props => props.inverted ? 'rgba(255, 255, 255, .85)' : 'rgba(0, 0, 0, .85)'};
691
+ opacity: ${props => props.active ? 1 : 0};
692
+ line-height: 1;
693
+ animation-fill-mode: both;
694
+ animation-duration: .5s;
695
+ transition: background-color .5s linear;
696
+ flex-direction: column;
697
+ align-items: center;
698
+ justify-content: center;
699
+ user-select: none;
700
+ will-change: opacity;
701
+ z-index: 990;
702
+ `;
703
+
704
+ function Loader(_ref) {
705
+ let {
706
+ loading = true,
707
+ children,
708
+ variant = 'primary',
709
+ animation = 'border',
710
+ wrap,
711
+ ...props
712
+ } = _ref;
713
+ if (!loading) {
714
+ return null;
715
+ }
716
+ if (children) {
717
+ children = jsx("p", {
718
+ className: 'mt-3 text-secondary',
719
+ children: children
720
+ });
721
+ }
722
+ children = jsxs(Dimmer, {
723
+ inverted: true,
724
+ active: true,
725
+ children: [jsx(Spinner, {
726
+ animation: animation,
727
+ variant: variant,
728
+ ...props
729
+ }), children]
730
+ });
731
+ if (wrap) {
732
+ return jsx(Wrap, {
733
+ "$height": typeof wrap === 'number' ? wrap : 150,
734
+ children: children
735
+ });
736
+ }
737
+ return children;
738
+ }
739
+ const Wrap = styled.div`
740
+ position: relative;
741
+ height: ${props => `${props.$height}px`};
742
+ `;
743
+
744
+ function Card(_ref) {
745
+ let {
746
+ children,
747
+ title,
748
+ className,
749
+ ...props
750
+ } = _ref;
751
+ return jsx(Card$1, {
752
+ className: classNames('border-0 shadow-sm mb-3', className),
753
+ ...props,
754
+ children: jsxs("div", {
755
+ className: 'card-body',
756
+ children: [title && jsxs(Fragment$1, {
757
+ children: [jsx("h5", {
758
+ children: title
759
+ }), jsx("hr", {})]
760
+ }), children]
761
+ })
762
+ });
763
+ }
764
+
765
+ function Error$1(_ref) {
766
+ let {
767
+ errors
768
+ } = _ref;
769
+ if (!errors) {
770
+ return null;
771
+ }
772
+ return jsx(Alert, {
773
+ variant: 'danger',
774
+ children: jsx("ul", {
775
+ className: 'mb-0',
776
+ children: typeof errors === 'string' ? jsx("li", {
777
+ children: errors
778
+ }) : Object.entries(errors).map(_ref2 => {
779
+ let [name, error] = _ref2;
780
+ return jsx("li", {
781
+ children: error
782
+ }, name);
783
+ })
784
+ })
785
+ });
786
+ }
787
+
788
+ function Space(_ref) {
789
+ let {
790
+ children,
791
+ className,
792
+ size = 'small',
793
+ direction = 'horizontal'
794
+ } = _ref;
795
+ if (typeof size === 'string') {
796
+ size = {
797
+ small: 8,
798
+ middle: 16,
799
+ large: 24
800
+ }[size];
801
+ }
802
+ const items = Children.map(children, child => {
803
+ if (child) {
804
+ return jsx(Item, {
805
+ children: child
806
+ });
807
+ }
808
+ });
809
+ return jsx(Container, {
810
+ className: className,
811
+ "$direction": direction,
812
+ "$size": size,
813
+ children: items
814
+ });
815
+ }
816
+ const Container = styled.div`
817
+ display: inline-flex;
818
+ align-items: center;
819
+ gap: ${props => props.$size}px;
820
+
821
+ ${props => props.$direction === 'vertical' && css`
822
+ display: flex;
823
+ flex-direction: column;
824
+ align-items: inherit;
825
+ `}
826
+ `;
827
+ const Item = styled.div`
828
+
829
+ `;
830
+
831
+ const LazySteps = lazy(() => import('./steps-afba29a7.js'));
832
+ const LazyStep = lazy(() => import('./steps-afba29a7.js').then(_ref => {
833
+ let {
834
+ Step
835
+ } = _ref;
836
+ return {
837
+ default: Step
838
+ };
839
+ }));
840
+ function Steps(props) {
841
+ return jsx(Suspense, {
842
+ fallback: null,
843
+ children: jsx(LazySteps, {
844
+ ...props
845
+ })
846
+ });
847
+ }
848
+ const Step = function (props) {
849
+ return jsx(Suspense, {
850
+ fallback: null,
851
+ children: jsx(LazyStep, {
852
+ ...props
853
+ })
854
+ });
855
+ };
856
+ Steps.Step = Step;
857
+
858
+ function Statistic(_ref) {
859
+ let {
860
+ title,
861
+ content,
862
+ footer
863
+ } = _ref;
864
+ return jsxs(Card, {
865
+ children: [jsx(Title, {
866
+ children: title
867
+ }), jsx(Content, {
868
+ children: content
869
+ }), footer && jsx(Footer, {
870
+ children: footer
871
+ })]
872
+ });
873
+ }
874
+ const Footer = styled.div`
875
+ margin-top: 9px;
876
+ padding-top: 10px;
877
+ border-top: 1px solid #f0f0f0;
878
+ color: rgba(0, 0, 0, .65);
879
+ `;
880
+ const Content = styled.div`
881
+ color: rgba(0, 0, 0, .85);
882
+ font-size: 24px;
883
+ `;
884
+ const Title = styled.div`
885
+ margin-bottom: 4px;
886
+ color: rgba(0, 0, 0, .45);
887
+ font-size: 1.1rem;
888
+ `;
889
+
890
+ function noop() {}
891
+ function isInteger(value) {
892
+ return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
893
+ }
894
+ function Pagination(_ref) {
895
+ let {
896
+ total = 0,
897
+ onChange = noop,
898
+ defaultCurrent = 1,
899
+ defaultPageSize = 10,
900
+ className,
901
+ ...props
902
+ } = _ref;
903
+ const [current, setCurrent] = useState(defaultCurrent);
904
+ const [pageSize, setPageSize] = useState(defaultPageSize);
905
+ useEffect(() => {
906
+ if (isInteger(props.current)) {
907
+ setCurrent(props.current);
908
+ }
909
+ }, [props.current]);
910
+ useEffect(() => {
911
+ if (isInteger(props.pageSize)) {
912
+ setPageSize(props.pageSize);
913
+ }
914
+ }, [props.pageSize]);
915
+ const allPages = useMemo(() => {
916
+ return Math.floor((total - 1) / pageSize) + 1;
917
+ }, [total, pageSize]);
918
+ const handleChange = useCallback(p => {
919
+ return () => {
920
+ if (p !== current) {
921
+ setCurrent(p);
922
+ onChange(p, pageSize);
923
+ }
924
+ };
925
+ }, [onChange, current, pageSize]);
926
+ const pageBufferSize = 2;
927
+ const prevPage = current - 1 > 0 ? current - 1 : 0;
928
+ const nextPage = current + 1 < allPages ? current + 1 : allPages;
929
+ const pagerList = [];
930
+ let jumpPrev = null;
931
+ let jumpNext = null;
932
+ let firstPager = null;
933
+ let lastPager = null;
934
+ if (allPages <= 3 + pageBufferSize * 2) {
935
+ for (let i = 1; i <= allPages; i += 1) {
936
+ const active = current === i;
937
+ pagerList.push(jsx(Pagination$1.Item, {
938
+ active: active,
939
+ onClick: handleChange(i),
940
+ children: i
941
+ }, i));
942
+ }
943
+ } else {
944
+ lastPager = jsx(Pagination$1.Last, {
945
+ onClick: handleChange(allPages)
946
+ }, 'last');
947
+ firstPager = jsx(Pagination$1.First, {
948
+ onClick: handleChange(1)
949
+ }, 'first');
950
+ jumpPrev = jsx(Pagination$1.Prev, {
951
+ onClick: handleChange(prevPage)
952
+ }, 'prev');
953
+ jumpNext = jsx(Pagination$1.Next, {
954
+ onClick: handleChange(nextPage)
955
+ }, 'next');
956
+ let left = Math.max(1, current - pageBufferSize);
957
+ let right = Math.min(current + pageBufferSize, allPages);
958
+ if (current - 1 <= pageBufferSize) {
959
+ right = 1 + pageBufferSize * 2;
960
+ }
961
+ if (allPages - current <= pageBufferSize) {
962
+ left = allPages - pageBufferSize * 2;
963
+ }
964
+ for (let i = left; i <= right; i += 1) {
965
+ const active = current === i;
966
+ pagerList.push(jsx(Pagination$1.Item, {
967
+ active: active,
968
+ onClick: handleChange(i),
969
+ children: i
970
+ }, i));
971
+ }
972
+ if (current - 1 >= pageBufferSize * 2 && current !== 1 + 2) {
973
+ pagerList.unshift(jumpPrev);
974
+ }
975
+ if (allPages - current >= pageBufferSize * 2 && current !== allPages - 2) {
976
+ pagerList.push(jumpNext);
977
+ }
978
+ if (left !== 1) {
979
+ pagerList.unshift(firstPager);
980
+ }
981
+ if (right !== allPages) {
982
+ pagerList.push(lastPager);
983
+ }
984
+ }
985
+ return jsx(Pagination$1, {
986
+ className: className,
987
+ children: pagerList
988
+ });
989
+ }
990
+
991
+ function NumberFormat(_ref) {
992
+ let {
993
+ className,
994
+ value,
995
+ locale = 'zh-CN',
996
+ currency = true,
997
+ options = {}
998
+ } = _ref;
999
+ const formatter = useMemo(() => {
1000
+ let opt;
1001
+ if (currency) {
1002
+ opt = {
1003
+ style: 'currency',
1004
+ currency: 'CNY'
1005
+ };
1006
+ } else {
1007
+ opt = {
1008
+ minimumFractionDigits: 2
1009
+ };
1010
+ }
1011
+ return new Intl.NumberFormat(locale, {
1012
+ ...opt,
1013
+ ...options
1014
+ });
1015
+ }, [currency, locale, options]);
1016
+ if (className) {
1017
+ return jsx("span", {
1018
+ className: className,
1019
+ children: formatter.format(value)
1020
+ });
1021
+ }
1022
+ return jsx(Fragment$1, {
1023
+ children: formatter.format(value)
1024
+ });
1025
+ }
1026
+
1027
+ function LoadingButton(_ref) {
1028
+ let {
1029
+ loading,
1030
+ disabled,
1031
+ children,
1032
+ ...props
1033
+ } = _ref;
1034
+ return jsx(Button$1, {
1035
+ ...props,
1036
+ disabled: loading || disabled,
1037
+ children: loading ? 'Loading…' : children
1038
+ });
1039
+ }
1040
+
1041
+ const LazyImageZoom = lazy(() => import('./image-zoom-912e2b3b.js'));
1042
+ function ImageZoom(props) {
1043
+ return jsx(Suspense, {
1044
+ fallback: null,
1045
+ children: jsx(LazyImageZoom, {
1046
+ ...props
1047
+ })
1048
+ });
1049
+ }
1050
+
1051
+ function RequestButton(_ref) {
1052
+ let {
1053
+ url,
1054
+ method,
1055
+ confirm,
1056
+ onSuccess,
1057
+ children,
1058
+ disabled,
1059
+ as = Button,
1060
+ ...props
1061
+ } = _ref;
1062
+ const [fetching, setFetching] = useSafeState(false);
1063
+ const handleClick = useCallback(async e => {
1064
+ e.preventDefault();
1065
+ try {
1066
+ setFetching(true);
1067
+ if (confirm) {
1068
+ if (!(await Modal.confirm({
1069
+ message: confirm
1070
+ }))) {
1071
+ return;
1072
+ }
1073
+ }
1074
+ const config = typeof url === 'string' ? {
1075
+ url,
1076
+ method
1077
+ } : {
1078
+ method,
1079
+ ...url
1080
+ };
1081
+ const result = await request(config);
1082
+ if (onSuccess) {
1083
+ onSuccess(result);
1084
+ }
1085
+ } catch (e) {
1086
+ showRequestError(e);
1087
+ } finally {
1088
+ setFetching(false);
1089
+ }
1090
+ }, [url, method, setFetching]);
1091
+ return createElement(as, {
1092
+ ...props,
1093
+ disabled: disabled || fetching,
1094
+ onClick: handleClick
1095
+ }, children);
1096
+ }
1097
+
1098
+ const LazyForm = lazy(() => import('./form-9c0e638a.js'));
1099
+ const Form = forwardRef((props, ref) => {
1100
+ return jsx(Suspense, {
1101
+ fallback: null,
1102
+ children: jsx(LazyForm, {
1103
+ ...props,
1104
+ ref: ref
1105
+ })
1106
+ });
1107
+ });
1108
+
1109
+ const LazyTable = lazy(() => import('./index-d964165a.js'));
1110
+ const Table = forwardRef((props, ref) => {
1111
+ return jsx(Suspense, {
1112
+ fallback: null,
1113
+ children: jsx(LazyTable, {
1114
+ ...props,
1115
+ ref: ref
1116
+ })
1117
+ });
1118
+ });
1119
+
1120
+ let id = 0;
1121
+ function useOverlayState() {
1122
+ let {
1123
+ onHide,
1124
+ onShow
1125
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1126
+ const [visible, setVisible] = useState(false);
1127
+ const [key, setKey] = useState(`visible-${id}`);
1128
+ const hide = useCallback(() => {
1129
+ setVisible(false);
1130
+ if (onHide) {
1131
+ onHide();
1132
+ }
1133
+ }, [setVisible, onHide]);
1134
+ const exit = useCallback(() => {
1135
+ setKey(`visible-${++id}`);
1136
+ }, [setKey, id]);
1137
+ const show = useCallback(() => {
1138
+ setVisible(true);
1139
+ if (onShow) {
1140
+ onShow();
1141
+ }
1142
+ }, [setVisible, onShow]);
1143
+ const state = {
1144
+ show: visible,
1145
+ onHide: hide,
1146
+ onExited: exit,
1147
+ key
1148
+ };
1149
+ return {
1150
+ visible,
1151
+ show,
1152
+ hide,
1153
+ state
1154
+ };
1155
+ }
1156
+
1157
+ const ModalButton = forwardRef((_ref, ref) => {
1158
+ let {
1159
+ text,
1160
+ onOk,
1161
+ modalProps,
1162
+ children,
1163
+ onShow,
1164
+ confirmLoading,
1165
+ as = Button,
1166
+ ...props
1167
+ } = _ref;
1168
+ const {
1169
+ state,
1170
+ show,
1171
+ hide
1172
+ } = useOverlayState({
1173
+ onShow
1174
+ });
1175
+ useImperativeHandle(ref, () => ({
1176
+ close: hide
1177
+ }));
1178
+ const handleOk = async e => {
1179
+ if (onOk) {
1180
+ const result = await onOk();
1181
+ if (result === false) {
1182
+ e.preventDefault();
1183
+ }
1184
+ }
1185
+ };
1186
+ const button = createElement(as, {
1187
+ ...props,
1188
+ onClick: show
1189
+ }, text);
1190
+ return jsxs(Fragment$1, {
1191
+ children: [button, jsx(Modal, {
1192
+ header: text,
1193
+ ...modalProps,
1194
+ ...state,
1195
+ confirmLoading: confirmLoading,
1196
+ onOk: handleOk,
1197
+ children: children
1198
+ })]
1199
+ });
1200
+ });
1201
+
1202
+ function ModalForm(_ref) {
1203
+ let {
1204
+ text,
1205
+ onSuccess,
1206
+ buttonProps,
1207
+ modalProps,
1208
+ children,
1209
+ ...props
1210
+ } = _ref;
1211
+ const [loading, setLoading] = useState(false);
1212
+ const ref = useRef(null);
1213
+ const form = useRef(null);
1214
+ const handleOk = useCallback(() => {
1215
+ form.current?.submit();
1216
+ return false;
1217
+ }, []);
1218
+ const handleSuccess = useCallback(data => {
1219
+ if (onSuccess) {
1220
+ onSuccess(data);
1221
+ }
1222
+ ref.current?.close();
1223
+ }, [onSuccess]);
1224
+ return jsx(ModalButton, {
1225
+ ref: ref,
1226
+ text: text,
1227
+ ...buttonProps,
1228
+ modalProps: modalProps,
1229
+ onOk: handleOk,
1230
+ confirmLoading: loading,
1231
+ children: jsxs(Form, {
1232
+ ...props,
1233
+ onSubmitting: setLoading,
1234
+ ref: form,
1235
+ onSuccess: handleSuccess,
1236
+ children: [children, jsx("input", {
1237
+ type: 'submit',
1238
+ hidden: true
1239
+ })]
1240
+ })
1241
+ });
1242
+ }
1243
+
1244
+ function useRequest(config) {
1245
+ let {
1246
+ manual,
1247
+ refreshDeps,
1248
+ ...options
1249
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1250
+ let {
1251
+ execute,
1252
+ currentParams,
1253
+ error,
1254
+ ...others
1255
+ } = useAsyncCallback(async params => {
1256
+ config = typeof config === 'string' ? {
1257
+ url: config
1258
+ } : config;
1259
+ return await request({
1260
+ ...config,
1261
+ ...params
1262
+ });
1263
+ }, options);
1264
+ useEffect(() => {
1265
+ if (!manual && !refreshDeps) {
1266
+ try {
1267
+ execute();
1268
+ } catch {}
1269
+ }
1270
+ }, []);
1271
+ useEffect(() => {
1272
+ if (refreshDeps) {
1273
+ refresh();
1274
+ }
1275
+ }, refreshDeps);
1276
+ const refresh = useCallback(async () => {
1277
+ try {
1278
+ if (currentParams) {
1279
+ await execute(...currentParams);
1280
+ } else {
1281
+ await execute();
1282
+ }
1283
+ } catch {}
1284
+ }, [execute, currentParams]);
1285
+ if (error && isRequestError(error)) {
1286
+ const errors = error.errors;
1287
+ error = new Error(typeof errors === 'string' ? errors : values(errors).join(''));
1288
+ }
1289
+ return {
1290
+ refresh,
1291
+ execute,
1292
+ error,
1293
+ ...others
1294
+ };
1295
+ }
1296
+
1297
+ function useCallbackRef(callback) {
1298
+ let deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1299
+ const callbackRef = useRef(callback);
1300
+ useEffect(() => {
1301
+ callbackRef.current = callback;
1302
+ });
1303
+ return useCallback(function () {
1304
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1305
+ args[_key] = arguments[_key];
1306
+ }
1307
+ return callbackRef.current?.(...args);
1308
+ }, deps);
1309
+ }
1310
+
1311
+ function useControllableState(props) {
1312
+ const {
1313
+ value: valueProp,
1314
+ defaultValue,
1315
+ onChange,
1316
+ shouldUpdate = (prev, next) => prev !== next
1317
+ } = props;
1318
+ const onChangeProp = useCallbackRef(onChange);
1319
+ const shouldUpdateProp = useCallbackRef(shouldUpdate);
1320
+ const [uncontrolledState, setUncontrolledState] = useState(defaultValue);
1321
+ const controlled = valueProp !== undefined;
1322
+ const value = controlled ? valueProp : uncontrolledState;
1323
+ const setValue = useCallbackRef(next => {
1324
+ const setter = next;
1325
+ const nextValue = typeof next === 'function' ? setter(value) : next;
1326
+ if (!shouldUpdateProp(value, nextValue)) {
1327
+ return;
1328
+ }
1329
+ if (!controlled) {
1330
+ setUncontrolledState(nextValue);
1331
+ }
1332
+ onChangeProp(nextValue);
1333
+ }, [controlled, onChangeProp, value, shouldUpdateProp]);
1334
+ return [value, setValue];
1335
+ }
1336
+
1337
+ function useDebounce(callback, wait, options) {
1338
+ const callbackRef = useRef(callback);
1339
+ const debouncedCallbackRef = useRef(debounce(callback, wait, options));
1340
+ useEffect(() => {
1341
+ callbackRef.current = callback;
1342
+ });
1343
+ useEffect(() => {
1344
+ debouncedCallbackRef.current = debounce(function () {
1345
+ callbackRef.current(...arguments);
1346
+ }, wait, options);
1347
+ }, [wait, options]);
1348
+ return debouncedCallbackRef.current;
1349
+ }
1350
+
1351
+ 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 };
1352
+ //# sourceMappingURL=index-4f51cece.js.map