index.tsx
2.98 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 数据流名称编辑通用组件
import React, { useImperativeHandle, useState } from 'react';
import { Button, Modal, Space } from 'antd';
// import { useForm } from '@qx/form-render';
import { QxIcon } from '@/components';
import _ from 'lodash-es';
import '@/styles/modal-reset.less';
import './index.less';
import { Form } from 'antd';
// import QxFormRender from '@/packages/qx-form-generator/src/form-render';
const FORM_SCHEMA: object = {
type: 'object',
properties: {
id: {
type: 'string',
hidden: true,
},
name: {
title: '名称',
type: 'string',
max: 20,
placeholder: '请输入名称',
required: true,
props: {
allowClear: true,
},
className: 'qx-data-flow-input--clear',
},
remark: {
type: 'string',
widget: 'textarea',
title: '说明',
placeholder: '请输入说明',
max: 200,
props: {
allowClear: true,
// showCount: true, // 显示字数提示
},
className: 'qx-data-flow-input--clear',
},
},
};
interface NameDescriptionSettingProps {
cRef: any;
handleClick: (type: string, data?: any) => void; // 名称变化调用方法
}
const NameDescriptionSetting: React.FC<NameDescriptionSettingProps> = (
props,
) => {
const { cRef, handleClick } = props;
const [form] = Form.useForm();
const [visible, setVisible] = useState(false);
useImperativeHandle(cRef, () => ({
// 暴露给父组件
open: (values: any) => {
setTimeout(() => {
if (_.isEmpty(values)) {
form.resetFields();
} else {
// @ts-ignore
form.setValues(values);
}
}, 100);
setVisible(true);
},
}));
const onFinish = async (data: any, error: any) => {
// console.log('表单数据:',data);
if (error.length > 0) {
return;
}
// 校验成功 保存名称、说明
handleClick('SAVE_NAME', data);
setVisible(false);
};
return (
<div>
<Modal
width={480}
title="编辑名称与说明"
onCancel={() => setVisible(false)}
keyboard={false}
maskClosable={false}
visible={visible}
footer={
<Space size={8}>
<Button onClick={() => setVisible(false)}>取消</Button>
<Button
type={'primary'}
onClick={() => {
form.submit();
}}
>
保存
</Button>
</Space>
}
wrapClassName={'qx-data-flow__modal qx-name-description-modal'}
closeIcon={
<QxIcon
className={'qx-data-flow__modal__close'}
type={'icon-close'}
/>
}
destroyOnClose
>
<Form
form={form}
schema={FORM_SCHEMA}
onMount={() => {}}
// @ts-ignore
onFinish={onFinish}
watch={{}}
/>
</Modal>
</div>
);
};
export default NameDescriptionSetting;