-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
90 lines (82 loc) · 2.27 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { useContext } from 'react';
import { Spin, Button, Drawer, Form } from 'antd';
import _debounce from 'lodash/debounce';
import _get from 'lodash/get';
import { DrawerProps } from 'antd/lib/drawer';
import { WrappedFormUtils } from 'antd/lib/form/Form';
import { PopupProps } from '../DetailModal/index';
import ConfigContext from '../../config-provider/context';
export type CustomModalProps = Omit<DrawerProps,
| 'title'
| 'visible'
| 'onOk'
| 'onClose'
| 'afterClose'
>
export interface DetailDrawerProps extends PopupProps {
drawerProps?: CustomModalProps;
}
function DetailDrawer(props: DetailDrawerProps) {
const { acLocale, debounceWait, createFormItemsFn } = useContext(ConfigContext);
const {
loading = false,
setItemsConfig,
itemsLayout,
getFormInstance = () => { },
onOk: handleOk = () => { },
onClose,
visible,
afterClose = () => { },
title,
drawerProps = {},
form = {} as WrappedFormUtils,
} = props;
getFormInstance(form);
const itemsConfig = setItemsConfig(form);
const okHandle = _debounce(() => {
console.log('DetailFormDrawer _debounce onOk');
form.validateFieldsAndScroll((err?: any, fieldsValue?: any) => {
if (err) return;
handleOk(fieldsValue);
});
}, debounceWait);
return (
<Drawer
destroyOnClose
width={560}
{...drawerProps}
visible={visible}
afterVisibleChange={(isVisible) => {
if (!isVisible) {
afterClose();
}
}}
title={title}
onClose={onClose}
>
<Spin spinning={loading}>
{createFormItemsFn(form)(itemsConfig, itemsLayout)}
<div
style={{
// position: 'absolute',
// left: 0,
// bottom: -10,
width: '100%',
borderTop: '1px solid #e9e9e9',
padding: '10px 16px',
background: '#fff',
textAlign: 'right',
}}
>
<Button onClick={onClose} style={{ marginRight: 8 }}>
{acLocale.drawer.cancel}
</Button>
<Button onClick={okHandle} type="primary">
{acLocale.drawer.ok}
</Button>
</div>
</Spin>
</Drawer>
);
};
export default Form.create<DetailDrawerProps>()(DetailDrawer);