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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
| // 表格组件
class TableComponent implements LowCodeComponent {
meta: ComponentMeta = {
type: 'table',
displayName: '数据表格',
category: 'data',
icon: 'table',
props: [
{
name: 'dataSource',
type: 'array',
required: true,
description: '表格数据源',
},
{
name: 'columns',
type: 'array',
required: true,
description: '列配置',
},
{
name: 'pagination',
type: 'boolean',
required: false,
defaultValue: true,
description: '是否分页',
},
{
name: 'rowSelection',
type: 'boolean',
required: false,
defaultValue: false,
description: '是否支持行选择',
},
],
events: [
{ name: 'onRowClick', description: '行点击事件' },
{ name: 'onSelectionChange', description: '选择变化事件' },
],
styles: [
{ name: 'border', type: 'boolean' },
{ name: 'size', type: 'enum', options: ['small', 'middle', 'large'] },
],
container: false,
defaultProps: {
pagination: true,
rowSelection: false,
},
};
render(props: ComponentProps): JSX.Element {
return (
<div className={`lowcode-table ${props.className || ''}`}>
<Table
dataSource={props.dataSource}
columns={props.columns}
pagination={props.pagination}
rowSelection={props.rowSelection}
onRow={(record) => ({
onClick: () => {
this.handleEvent({
type: 'onRowClick',
payload: { record },
});
},
})}
onChange={(selection) => {
this.handleEvent({
type: 'onSelectionChange',
payload: { selection },
});
}}
/>
</div>
);
}
validateProps(props: unknown): ValidationResult {
const schema = {
type: 'object',
required: ['dataSource', 'columns'],
properties: {
dataSource: { type: 'array' },
columns: { type: 'array' },
pagination: { type: 'boolean' },
rowSelection: { type: 'boolean' },
},
};
return validate(schema, props);
}
handleEvent(event: ComponentEvent): void {
// 事件处理逻辑
console.log('Table event:', event);
}
}
// 表单组件
class FormComponent implements LowCodeComponent {
meta: ComponentMeta = {
type: 'form',
displayName: '表单容器',
category: 'form',
icon: 'form',
container: true,
props: [
{
name: 'fields',
type: 'array',
required: true,
description: '表单字段配置',
},
{
name: 'layout',
type: 'enum',
options: ['horizontal', 'vertical', 'inline'],
defaultValue: 'horizontal',
},
{
name: 'labelWidth',
type: 'number',
description: '标签宽度',
},
],
events: [
{ name: 'onSubmit', description: '表单提交事件' },
{ name: 'onValuesChange', description: '值变化事件' },
],
defaultProps: {
layout: 'horizontal',
labelWidth: 120,
},
};
render(props: ComponentProps): JSX.Element {
const [form] = Form.useForm();
return (
<Form
form={form}
layout={props.layout}
labelCol={{ style: { width: props.labelWidth } }}
onFinish={(values) => {
this.handleEvent({
type: 'onSubmit',
payload: { values },
});
}}
onValuesChange={(changedValues, allValues) => {
this.handleEvent({
type: 'onValuesChange',
payload: { changedValues, allValues },
});
}}
>
{props.fields.map((field: FieldConfig) => (
<Form.Item
key={field.name}
name={field.name}
label={field.label}
rules={field.rules}
>
{this.renderFieldInput(field)}
</Form.Item>
))}
</Form>
);
}
private renderFieldInput(field: FieldConfig): JSX.Element {
switch (field.type) {
case 'input':
return <Input placeholder={field.placeholder} />;
case 'textarea':
return <Input.TextArea rows={field.rows} />;
case 'select':
return (
<Select options={field.options} placeholder={field.placeholder} />
);
case 'date':
return <DatePicker />;
case 'number':
return <InputNumber />;
default:
return <Input />;
}
}
validateProps(props: unknown): ValidationResult {
return validate(
{
type: 'object',
required: ['fields'],
properties: {
fields: { type: 'array' },
layout: { type: 'string' },
labelWidth: { type: 'number' },
},
},
props
);
}
handleEvent(event: ComponentEvent): void {
console.log('Form event:', event);
}
}
|