@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.
@@ -1,21 +1,684 @@
1
- import e from"sweetalert2/dist/sweetalert2.js";import t from"sweetalert2-react-content";import{jsx as n,jsxs as r,Fragment as o}from"react/jsx-runtime";import{useRef as i,useState as a,useEffect as s,createContext as c,Fragment as l,useContext as d,useCallback as u,useMemo as f,forwardRef as h,Children as m,lazy as p,Suspense as g,createElement as y,useImperativeHandle as b}from"react";import{OverlayTrigger as x,Tooltip as v,Spinner as w,Button as k,Modal as C,Alert as N,Card as z,Pagination as S}from"react-bootstrap";import{uniqueId as P,values as j,debounce as B}from"lodash";import T from"axios";import $ from"query-string";import*as E from"retry-axios";import L from"@babel/runtime/helpers/defineProperty";import F from"rc-notification";import H,{css as A}from"styled-components";import D from"classnames";import{useAsyncCallback as M}from"react-async-hook";const U=t(e),O={confirmButtonText:"确定",cancelButtonText:"取消"},I={confirm:async e=>{const{isConfirmed:t}=await U.fire({...O,icon:"warning",showCancelButton:!0,...e,async preConfirm(t){if(e.preConfirm)try{return await e.preConfirm(t)}catch(e){return e instanceof Error&&U.showValidationMessage(e.message),!1}return!0}});return t},success:e=>{U.fire({...O,toast:!0,position:"top",icon:"success",timer:2e3,showConfirmButton:!1,...e})},error:e=>{U.fire({...O,toast:!0,position:"top",icon:"error",timer:5e3,showConfirmButton:!1,...e})},close:e=>{U.close(e)},defaults:O};const R=c({});function _(e){return t=>{let{resolve:r,destroy:o,message:c}=t;const[l,h]=function(e){const t=i(null),[n,r]=a(e);return s((()=>{t.current&&(t.current(),t.current=null)}),[n]),[n,(e,n)=>{t.current="function"==typeof n?n:null,r(e)}]}(!0),m=d(R),p=u((e=>{h(!1,(()=>{r(e)}))}),[h,r]),g=f((()=>({show:l,onHide:()=>p(),onExited:()=>o(),container:m.container})),[l,p,o]);return n(e,{resolve:p,state:g,message:c})}}function q(e){return t=>new Promise((r=>{const o=n(e,{resolve:r,destroy:()=>{J(o)},message:t});Y(o)}))}let V=()=>{},G=new Set;const Y=e=>{G=new Set(G),G.add(e),V(G)},J=e=>{G=new Set(G),G.delete(e),V(G)};function K(e,t){return q(_(e))(t)}function Q(e){let{tooltip:t,children:r,placement:o="bottom"}=e;return n(x,{placement:o,overlay:n(v,{id:P(),children:t}),children:r})}const W=c(!1),X=h(((e,t)=>{let{loading:i,percent:a,disabled:s,children:c,tooltip:l,variant:u,...f}=e;d(W)&&!u&&(u="link"),i&&(s=!0,c=r(o,{children:[n(w,{ref:t,as:"span",size:"sm",role:"status","aria-hidden":"true",animation:"border"}),a?r("span",{className:"ms-2",children:[a,"%"]}):null]}));const h=n(k,{ref:t,...f,variant:u,disabled:s,children:c});return l?n(Q,{tooltip:l,children:n("span",{className:"d-inline-block",children:h})}):h})),Z=function(e){let{state:t,message:{title:o,message:i,okText:a,cancelText:s},resolve:c}=e;return r(C,{centered:!0,...t,children:[n(C.Header,{children:n(C.Title,{as:"h5",children:o||"确认"})}),n(C.Body,{children:i}),r(C.Footer,{children:[n(X,{variant:"secondary",onClick:()=>c(),children:s||"取消"}),n(X,{onClick:()=>c(!0),children:a||"确定"})]})]})};const ee=e=>{let{header:t,children:i,footer:s,closable:c=!0,show:l,cancelText:d="取消",okText:u="确定",onOk:h,onCancel:m,onHide:p,okButtonProps:g,bodyAs:y,headerAs:b="h5",confirmLoading:x=!1,...v}=e;const[w,k]=a(!1),N=f((()=>n(X,{loading:w||x,variant:"primary",onClick:async e=>{k(!0);try{await(h?.(e)),e.defaultPrevented||p?.()}finally{k(!1)}},...g,children:u})),[g,u,h,p,w,x]),z=f((()=>n(X,{variant:"secondary",onClick:e=>{m?.(e),e.defaultPrevented||p?.()},children:d})),[m,p,d]);switch(typeof s){case"undefined":s=r(o,{children:[z,N]});break;case"function":s=s({okButton:N,cancelButton:z})}return r(C,{...v,onHide:p,show:l,children:[t&&n(C.Header,{closeButton:c,children:n(C.Title,{as:b,children:t})}),n(C.Body,{as:y,children:i}),s&&n(C.Footer,{children:s})]})};ee.Message=function(e){const[t,r]=a(G);return s((()=>{V=r}),[]),n(R.Provider,{value:e,children:Array.from(t).map(((e,t)=>n(l,{children:e},`message-${t}`)))})},ee.confirm=function(e){return q(_(Z))(e)},ee.show=K;class te extends Error{constructor(e){super("Unauthorized"),L(this,"url",void 0),this.url=e}}let ne;const re={};const oe=e=>{let{type:t,...r}=e;!function(e){if(ne)return e(ne);F.newInstance({...re,prefixCls:"notification",maxCount:5,style:{top:20,right:20}},(t=>{ne?e(ne):(ne=t,e(t))}))}((e=>{r.duration=3;let o=t;if("error"===t)o="danger",r.duration=r.closable?0:5;r.content=n(N,{variant:o,children:r.content}),e.notice(r)}))},ie=["error","success","info"].reduce(((e,t)=>(e[t]=(e,n)=>{oe({...n,type:t,content:e})},e)),{});ie.defaults=re,E.attach(),T.defaults.raxConfig={retryDelay:2e3,backoffType:"static",shouldRetry:e=>{let{config:t,response:n}=e;return!(t.raxConfig?.retryDecider&&!t.raxConfig.retryDecider())&&("GET"===t.method?.toUpperCase()&&449===n?.status)}},T.defaults.maxContentLength=1/0,T.defaults.maxBodyLength=1/0,T.defaults.baseURL="/api",T.defaults.authTokenName="authorization",T.interceptors.request.use((e=>{const t=e.authTokenName;if(t){const n=localStorage.getItem(t);n&&(e.headers={Authorization:`Bearer ${n}`,...e.headers})}return e}),(e=>Promise.reject(e)));const ae=e=>e&&"object"==typeof e;T.interceptors.response.use((e=>(201===e.status&&e.data.location&&(window.location.href=e.data.location,e.data=void 0),e)),(e=>{if(T.isAxiosError(e)&&e.response){const{data:t,status:n}=e.response;401===n?(e.errors="Unauthorized",ae(t)&&t.url&&(e=new te(t.url)),ie.error("Unauthorized")):ae(t)?422===n?e.errors=t:"message"in t&&(e.errors=t.message):e.errors=t}return Promise.reject(e)}));const se=T.isAxiosError,ce=e=>{if(!T.isAxiosError(e))throw e;{let t=e.errors;"string"!=typeof e.errors&&(t=Object.values(e.errors).join("<br />")),ie.error(t)}},le=async function(e){e="string"==typeof e?{url:e}:e;const{data:t}=await T.request({paramsSerializer:function(e){return $.stringify(e,{sort:!1,skipNull:!0,skipEmptyString:!0,arrayFormat:"bracket"})},...e});return t};le.defaults=T.defaults,le.interceptors=T.interceptors;function de(e){const t=(()=>{const e=i(!1);return s((()=>(e.current=!1,()=>{e.current=!0})),[]),e})(),[n,r]=a(e);return[n,u((e=>{t.current||r(e)}),[])]}const ue=function(e){let{state:t,message:r,resolve:o}=e;const a=i(!0),{result:c,checkUrl:l,onComplete:d}=r,[u,f]=de(!1);return s((()=>{le({url:l,method:"post",data:{order_no:c.order_no},raxConfig:{shouldRetry:e=>a.current&&449===e.response?.status}}).then((()=>{d?.(),o()})).catch((()=>null))}),[]),n(ee,{...t,centered:!0,onHide:()=>{a.current=!1,t.onHide()},backdrop:"static",header:"支付结果",okText:"已完成支付",okButtonProps:{loading:u},onOk:async e=>{e.preventDefault();try{f(!0),await le({url:l,method:"post",data:{order_no:c.order_no},raxConfig:{shouldRetry:()=>!1}}),d?.(),o()}catch{}finally{f(!1)}},cancelText:"取消",children:"请在新打开的页面上进行支付,支付完成后再关闭此窗口"})};function fe(e){const{result:t}=e;window.open(t.pay_url),K(ue,e)}const he=H.div`
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`
2
625
  padding: 48px 32px;
3
- `,me=H.div`
626
+ `;
627
+ const Icon = styled.div`
4
628
  margin-bottom: 24px;
5
629
  text-align: center;
6
630
  font-size: 72px;
7
- `,pe=H.div`
631
+ `;
632
+ const Title$1 = styled.div`
8
633
  color: rgba(0, 0, 0, .85);
9
634
  font-size: 24px;
10
635
  line-height: 1.8;
11
636
  text-align: center;
12
- `,ge=H.div`
637
+ `;
638
+ const Extra = styled.div`
13
639
  margin-top: 32px;
14
640
  text-align: center;
15
- `,ye={success:n("i",{className:"bi bi-check-circle-fill text-success"}),error:n("i",{className:"bi bi-exclamation-circle-fill text-danger"}),info:n("i",{className:"bi bi-info-circle-fill text-info"}),warning:n("i",{className:"bi bi-exclamation-triangle-fill text-warning"})};function be(e){let{status:t,title:o,icon:i,extra:a}=e;return!i&&t&&(i=ye[t]),r(he,{children:[i&&n(me,{children:i}),o&&n(pe,{children:o}),a&&n(ge,{children:a})]})}H.div`
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`
16
678
  position: relative;
17
- `;const xe=H.div`
18
- display: ${e=>e.active?"flex":"none"};
679
+ `;
680
+ const Dimmer = styled.div`
681
+ display: ${props => props.active ? 'flex' : 'none'};
19
682
  position: absolute;
20
683
  top: 0 !important;
21
684
  left: 0 !important;
@@ -24,8 +687,8 @@ import e from"sweetalert2/dist/sweetalert2.js";import t from"sweetalert2-react-c
24
687
  text-align: center;
25
688
  vertical-align: middle;
26
689
  padding: 1em;
27
- background-color: ${e=>e.inverted?"rgba(255, 255, 255, .85)":"rgba(0, 0, 0, .85)"};
28
- opacity: ${e=>e.active?1:0};
690
+ background-color: ${props => props.inverted ? 'rgba(255, 255, 255, .85)' : 'rgba(0, 0, 0, .85)'};
691
+ opacity: ${props => props.active ? 1 : 0};
29
692
  line-height: 1;
30
693
  animation-fill-mode: both;
31
694
  animation-duration: .5s;
@@ -36,32 +699,654 @@ import e from"sweetalert2/dist/sweetalert2.js";import t from"sweetalert2-react-c
36
699
  user-select: none;
37
700
  will-change: opacity;
38
701
  z-index: 990;
39
- `;function ve(e){let{loading:t=!0,children:o,variant:i="primary",animation:a="border",wrap:s,...c}=e;return t?(o&&(o=n("p",{className:"mt-3 text-secondary",children:o})),o=r(xe,{inverted:!0,active:!0,children:[n(w,{animation:a,variant:i,...c}),o]}),s?n(we,{$height:"number"==typeof s?s:150,children:o}):o):null}const we=H.div`
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`
40
740
  position: relative;
41
- height: ${e=>`${e.$height}px`};
42
- `;function ke(e){let{children:t,title:i,className:a,...s}=e;return n(z,{className:D("border-0 shadow-sm mb-3",a),...s,children:r("div",{className:"card-body",children:[i&&r(o,{children:[n("h5",{children:i}),n("hr",{})]}),t]})})}function Ce(e){let{errors:t}=e;return t?n(N,{variant:"danger",children:n("ul",{className:"mb-0",children:"string"==typeof t?n("li",{children:t}):Object.entries(t).map((e=>{let[t,r]=e;return n("li",{children:r},t)}))})}):null}function Ne(e){let{children:t,className:r,size:o="small",direction:i="horizontal"}=e;"string"==typeof o&&(o={small:8,middle:16,large:24}[o]);const a=m.map(t,(e=>{if(e)return n(Se,{children:e})}));return n(ze,{className:r,$direction:i,$size:o,children:a})}const ze=H.div`
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`
43
817
  display: inline-flex;
44
818
  align-items: center;
45
- gap: ${e=>e.$size}px;
819
+ gap: ${props => props.$size}px;
46
820
 
47
- ${e=>"vertical"===e.$direction&&A`
821
+ ${props => props.$direction === 'vertical' && css`
48
822
  display: flex;
49
823
  flex-direction: column;
50
824
  align-items: inherit;
51
825
  `}
52
- `,Se=H.div`
826
+ `;
827
+ const Item = styled.div`
828
+
829
+ `;
53
830
 
54
- `,Pe=p((()=>import("./steps-afba29a7.js"))),je=p((()=>import("./steps-afba29a7.js").then((e=>{let{Step:t}=e;return{default:t}}))));function Be(e){return n(g,{fallback:null,children:n(Pe,{...e})})}const Te=function(e){return n(g,{fallback:null,children:n(je,{...e})})};function $e(e){let{title:t,content:o,footer:i}=e;return r(ke,{children:[n(Fe,{children:t}),n(Le,{children:o}),i&&n(Ee,{children:i})]})}Be.Step=Te;const Ee=H.div`
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`
55
875
  margin-top: 9px;
56
876
  padding-top: 10px;
57
877
  border-top: 1px solid #f0f0f0;
58
878
  color: rgba(0, 0, 0, .65);
59
- `,Le=H.div`
879
+ `;
880
+ const Content = styled.div`
60
881
  color: rgba(0, 0, 0, .85);
61
882
  font-size: 24px;
62
- `,Fe=H.div`
883
+ `;
884
+ const Title = styled.div`
63
885
  margin-bottom: 4px;
64
886
  color: rgba(0, 0, 0, .45);
65
887
  font-size: 1.1rem;
66
- `;function He(){}function Ae(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function De(e){let{total:t=0,onChange:r=He,defaultCurrent:o=1,defaultPageSize:i=10,className:c,...l}=e;const[d,h]=a(o),[m,p]=a(i);s((()=>{Ae(l.current)&&h(l.current)}),[l.current]),s((()=>{Ae(l.pageSize)&&p(l.pageSize)}),[l.pageSize]);const g=f((()=>Math.floor((t-1)/m)+1),[t,m]),y=u((e=>()=>{e!==d&&(h(e),r(e,m))}),[r,d,m]),b=d-1>0?d-1:0,x=d+1<g?d+1:g,v=[];let w=null,k=null,C=null,N=null;if(g<=7)for(let e=1;e<=g;e+=1){const t=d===e;v.push(n(S.Item,{active:t,onClick:y(e),children:e},e))}else{N=n(S.Last,{onClick:y(g)},"last"),C=n(S.First,{onClick:y(1)},"first"),w=n(S.Prev,{onClick:y(b)},"prev"),k=n(S.Next,{onClick:y(x)},"next");let e=Math.max(1,d-2),t=Math.min(d+2,g);d-1<=2&&(t=5),g-d<=2&&(e=g-4);for(let r=e;r<=t;r+=1){const e=d===r;v.push(n(S.Item,{active:e,onClick:y(r),children:r},r))}d-1>=4&&3!==d&&v.unshift(w),g-d>=4&&d!==g-2&&v.push(k),1!==e&&v.unshift(C),t!==g&&v.push(N)}return n(S,{className:c,children:v})}function Me(e){let{className:t,value:r,locale:i="zh-CN",currency:a=!0,options:s={}}=e;const c=f((()=>{let e;return e=a?{style:"currency",currency:"CNY"}:{minimumFractionDigits:2},new Intl.NumberFormat(i,{...e,...s})}),[a,i,s]);return t?n("span",{className:t,children:c.format(r)}):n(o,{children:c.format(r)})}function Ue(e){let{loading:t,disabled:r,children:o,...i}=e;return n(k,{...i,disabled:t||r,children:t?"Loading…":o})}const Oe=p((()=>import("./image-zoom-912e2b3b.js")));function Ie(e){return n(g,{fallback:null,children:n(Oe,{...e})})}function Re(e){let{url:t,method:n,confirm:r,onSuccess:o,children:i,disabled:a,as:s=X,...c}=e;const[l,d]=de(!1),f=u((async e=>{e.preventDefault();try{if(d(!0),r&&!await ee.confirm({message:r}))return;const e="string"==typeof t?{url:t,method:n}:{method:n,...t},i=await le(e);o&&o(i)}catch(e){ce(e)}finally{d(!1)}}),[t,n,d]);return y(s,{...c,disabled:a||l,onClick:f},i)}const _e=p((()=>import("./form-9c0e638a.js"))),qe=h(((e,t)=>n(g,{fallback:null,children:n(_e,{...e,ref:t})}))),Ve=p((()=>import("./index-d964165a.js"))),Ge=h(((e,t)=>n(g,{fallback:null,children:n(Ve,{...e,ref:t})})));let Ye=0;function Je(){let{onHide:e,onShow:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const[n,r]=a(!1),[o,i]=a(`visible-${Ye}`),s=u((()=>{r(!1),e&&e()}),[r,e]),c=u((()=>{i("visible-"+ ++Ye)}),[i,Ye]),l=u((()=>{r(!0),t&&t()}),[r,t]),d={show:n,onHide:s,onExited:c,key:o};return{visible:n,show:l,hide:s,state:d}}const Ke=h(((e,t)=>{let{text:i,onOk:a,modalProps:s,children:c,onShow:l,confirmLoading:d,as:u=X,...f}=e;const{state:h,show:m,hide:p}=Je({onShow:l});b(t,(()=>({close:p})));const g=y(u,{...f,onClick:m},i);return r(o,{children:[g,n(ee,{header:i,...s,...h,confirmLoading:d,onOk:async e=>{if(a){!1===await a()&&e.preventDefault()}},children:c})]})}));function Qe(e){let{text:t,onSuccess:o,buttonProps:s,modalProps:c,children:l,...d}=e;const[f,h]=a(!1),m=i(null),p=i(null),g=u((()=>(p.current?.submit(),!1)),[]),y=u((e=>{o&&o(e),m.current?.close()}),[o]);return n(Ke,{ref:m,text:t,...s,modalProps:c,onOk:g,confirmLoading:f,children:r(qe,{...d,onSubmitting:h,ref:p,onSuccess:y,children:[l,n("input",{type:"submit",hidden:!0})]})})}function We(e){let{manual:t,refreshDeps:n,...r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{execute:o,currentParams:i,error:a,...c}=M((async t=>(e="string"==typeof e?{url:e}:e,await le({...e,...t}))),r);s((()=>{if(!t&&!n)try{o()}catch{}}),[]),s((()=>{n&&l()}),n);const l=u((async()=>{try{i?await o(...i):await o()}catch{}}),[o,i]);if(a&&se(a)){const e=a.errors;a=new Error("string"==typeof e?e:j(e).join(""))}return{refresh:l,execute:o,error:a,...c}}function Xe(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const n=i(e);return s((()=>{n.current=e})),u((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.current?.(...t)}),t)}function Ze(e){const{value:t,defaultValue:n,onChange:r,shouldUpdate:o=((e,t)=>e!==t)}=e,i=Xe(r),s=Xe(o),[c,l]=a(n),d=void 0!==t,u=d?t:c,f=Xe((e=>{const t="function"==typeof e?e(u):e;s(u,t)&&(d||l(t),i(t))}),[d,i,u,s]);return[u,f]}function et(e,t,n){const r=i(e),o=i(B(e,t,n));return s((()=>{r.current=e})),s((()=>{o.current=B((function(){r.current(...arguments)}),t,n)}),[t,n]),o.current}export{X as B,ke as C,Ce as E,qe as F,Ie as I,ve as L,I as M,Me as N,De as P,be as R,Ne as S,W as T,te as U,et as a,Ze as b,ie as c,Be as d,Te as e,$e as f,Ue as g,Re as h,Ge as i,Qe as j,Ke as k,ee as l,Q as m,We as n,Je as o,se as p,le as r,ce as s,de as u,fe as w};
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 };
67
1352
  //# sourceMappingURL=index-4f51cece.js.map