neo-cmp-cli 1.2.25 → 1.3.1
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.
- package/README.md +90 -18
- package/package.json +1 -1
- package/src/template/antd-custom-cmp-template/package.json +1 -1
- package/src/template/echarts-custom-cmp-template/package.json +1 -1
- package/src/template/neo-custom-cmp-template/package.json +1 -1
- package/src/template/neo-custom-cmp-template/src/components/contact-form/index.tsx +20 -17
- package/src/template/neo-custom-cmp-template/src/components/contact-form/model.ts +7 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/README.md +176 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/index.tsx +612 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/model.ts +106 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/style.scss +370 -0
- package/src/template/neo-custom-cmp-template/src/components/xobject-table/index.tsx +2 -1
- package/src/template/react-custom-cmp-template/package.json +1 -1
- package/src/template/react-ts-custom-cmp-template/package.json +1 -1
- package/src/template/vue2-custom-cmp-template/package.json +1 -1
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Object Form 对象表单组件
|
|
3
|
+
* @description 基于 Neo 平台的 XObject 实体对象数据表单组件,用于新增数据
|
|
4
|
+
*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import {
|
|
7
|
+
Form,
|
|
8
|
+
Input,
|
|
9
|
+
Select,
|
|
10
|
+
Button,
|
|
11
|
+
message,
|
|
12
|
+
Card,
|
|
13
|
+
DatePicker,
|
|
14
|
+
InputNumber,
|
|
15
|
+
Space,
|
|
16
|
+
Spin,
|
|
17
|
+
Empty,
|
|
18
|
+
Row,
|
|
19
|
+
Col,
|
|
20
|
+
} from 'antd';
|
|
21
|
+
import {
|
|
22
|
+
SaveOutlined,
|
|
23
|
+
ReloadOutlined,
|
|
24
|
+
CheckCircleOutlined,
|
|
25
|
+
} from '@ant-design/icons';
|
|
26
|
+
import moment from 'moment';
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
import { xObject } from 'neo-open-api'; // Neo Open API
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
import isEqual from 'lodash/isEqual';
|
|
31
|
+
import './style.scss';
|
|
32
|
+
|
|
33
|
+
const { Option } = Select;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 组件属性接口
|
|
37
|
+
*/
|
|
38
|
+
interface ObjectFormProps {
|
|
39
|
+
/** XObject 实体对象的 API Key,用于标识要操作的数据对象 */
|
|
40
|
+
xObjectDataApi: {
|
|
41
|
+
xObjectApiKey: string;
|
|
42
|
+
fields?: string[];
|
|
43
|
+
fieldDescList?: any[];
|
|
44
|
+
};
|
|
45
|
+
/** Neo 平台传递的数据,包含系统信息等 */
|
|
46
|
+
data?: any;
|
|
47
|
+
/** 表单标题 */
|
|
48
|
+
formTitle?: string;
|
|
49
|
+
/** 是否显示重置按钮 */
|
|
50
|
+
showResetButton?: boolean;
|
|
51
|
+
/** 表单列数(1列或2列) */
|
|
52
|
+
columnCount?: 1 | 2;
|
|
53
|
+
/** 提交成功后的回调 */
|
|
54
|
+
onSuccess?: (data: any) => void;
|
|
55
|
+
/** 是否为自定义实体对象 */
|
|
56
|
+
custom?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 字段信息接口
|
|
61
|
+
*/
|
|
62
|
+
interface FieldInfo {
|
|
63
|
+
/** 字段名称 */
|
|
64
|
+
name: string;
|
|
65
|
+
/** 字段显示标签 */
|
|
66
|
+
label: string;
|
|
67
|
+
/** 字段 API Key */
|
|
68
|
+
apiKey: string;
|
|
69
|
+
/** 字段类型 */
|
|
70
|
+
type: string;
|
|
71
|
+
/** 字段项类型 */
|
|
72
|
+
itemType: string;
|
|
73
|
+
/** 复选框选项列表 */
|
|
74
|
+
checkitem: any[];
|
|
75
|
+
/** 下拉选择选项列表 */
|
|
76
|
+
selectitem?: any[];
|
|
77
|
+
/** 是否必填 */
|
|
78
|
+
required: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 组件状态接口
|
|
83
|
+
*/
|
|
84
|
+
interface ObjectFormState {
|
|
85
|
+
/** 表单标题 */
|
|
86
|
+
title?: string;
|
|
87
|
+
/** 字段列表 */
|
|
88
|
+
fieldList: FieldInfo[];
|
|
89
|
+
/** 加载状态 */
|
|
90
|
+
loading: boolean;
|
|
91
|
+
/** 提交中状态 */
|
|
92
|
+
submitting: boolean;
|
|
93
|
+
/** 错误信息 */
|
|
94
|
+
error: string | null;
|
|
95
|
+
/** 表单实例 */
|
|
96
|
+
form: any;
|
|
97
|
+
/** 业务类型列表 */
|
|
98
|
+
entityTypeList: any[];
|
|
99
|
+
/** 提交成功状态 */
|
|
100
|
+
submitSuccess: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Object Form 对象表单组件
|
|
105
|
+
* 支持对 Neo 平台的 XObject 实体对象进行新增操作
|
|
106
|
+
*/
|
|
107
|
+
export default class ObjectForm extends React.PureComponent<
|
|
108
|
+
ObjectFormProps,
|
|
109
|
+
ObjectFormState
|
|
110
|
+
> {
|
|
111
|
+
constructor(props: ObjectFormProps) {
|
|
112
|
+
super(props);
|
|
113
|
+
const { xObjectDataApi } = props;
|
|
114
|
+
const { xObjectApiKey } = xObjectDataApi || {};
|
|
115
|
+
|
|
116
|
+
// 初始化组件状态
|
|
117
|
+
this.state = {
|
|
118
|
+
fieldList: [],
|
|
119
|
+
loading: false,
|
|
120
|
+
submitting: false,
|
|
121
|
+
error: null,
|
|
122
|
+
form: null,
|
|
123
|
+
entityTypeList: [],
|
|
124
|
+
submitSuccess: false,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (xObjectApiKey) {
|
|
128
|
+
// 初始化字段列表和业务类型列表
|
|
129
|
+
this.getEntityTypeList(xObjectApiKey);
|
|
130
|
+
this.loadFieldList();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 绑定方法上下文
|
|
134
|
+
this.loadFieldList = this.loadFieldList.bind(this);
|
|
135
|
+
this.handleSubmit = this.handleSubmit.bind(this);
|
|
136
|
+
this.handleReset = this.handleReset.bind(this);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 组件更新后执行
|
|
141
|
+
* 当 xObjectApiKey 发生变化时重新加载字段列表
|
|
142
|
+
*/
|
|
143
|
+
async componentDidUpdate(prevProps: ObjectFormProps) {
|
|
144
|
+
const { xObjectApiKey, fields } = this.props.xObjectDataApi || {};
|
|
145
|
+
const { xObjectApiKey: prevXObjectApiKey, fields: prevFields } =
|
|
146
|
+
prevProps.xObjectDataApi || {};
|
|
147
|
+
|
|
148
|
+
if (xObjectApiKey !== prevXObjectApiKey || !isEqual(fields, prevFields)) {
|
|
149
|
+
if (xObjectApiKey) {
|
|
150
|
+
await this.loadFieldList();
|
|
151
|
+
await this.getEntityTypeList(xObjectApiKey);
|
|
152
|
+
} else {
|
|
153
|
+
this.setState({
|
|
154
|
+
fieldList: [],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 获取业务类型列表
|
|
162
|
+
* 用于下拉选择框的选项数据
|
|
163
|
+
*/
|
|
164
|
+
async getEntityTypeList(xObjectApiKey?: string) {
|
|
165
|
+
const { xObjectDataApi } = this.props;
|
|
166
|
+
const curXObjectApiKey = xObjectApiKey || xObjectDataApi?.xObjectApiKey;
|
|
167
|
+
try {
|
|
168
|
+
const result = await xObject.getEntityTypeList(curXObjectApiKey);
|
|
169
|
+
if (result && result.status) {
|
|
170
|
+
const records = result.data || [];
|
|
171
|
+
this.setState({
|
|
172
|
+
entityTypeList: records,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('获取业务类型列表失败:', error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 加载字段列表
|
|
182
|
+
* 从 Neo 平台获取 XObject 的字段描述信息
|
|
183
|
+
*/
|
|
184
|
+
async loadFieldList() {
|
|
185
|
+
const { xObjectDataApi } = this.props || {};
|
|
186
|
+
|
|
187
|
+
this.setState({ loading: true });
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
// 方式一:直接从 props.xObjectDataApi 中获取字段描述
|
|
191
|
+
if (xObjectDataApi && xObjectDataApi.fieldDescList) {
|
|
192
|
+
this.setState({
|
|
193
|
+
fieldList: xObjectDataApi.fieldDescList,
|
|
194
|
+
loading: false,
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
// 方式二:自行通过 OpenAPI SDK 获取字段描述
|
|
198
|
+
if (!xObjectDataApi.xObjectApiKey) {
|
|
199
|
+
this.setState({ loading: false });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const resultData = await xObject.getDesc(xObjectDataApi.xObjectApiKey);
|
|
203
|
+
if (resultData && resultData.status) {
|
|
204
|
+
const result = resultData.data || {};
|
|
205
|
+
const fieldList = result.fields || [];
|
|
206
|
+
this.setState({
|
|
207
|
+
fieldList,
|
|
208
|
+
title: result.label,
|
|
209
|
+
loading: false,
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
this.setState({
|
|
213
|
+
error: '获取字段列表失败',
|
|
214
|
+
loading: false,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('获取字段列表失败:', error);
|
|
220
|
+
message.error('获取字段列表失败');
|
|
221
|
+
this.setState({
|
|
222
|
+
error: '获取字段列表失败',
|
|
223
|
+
loading: false,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 处理表单提交
|
|
230
|
+
* 执行新增操作
|
|
231
|
+
*/
|
|
232
|
+
handleSubmit() {
|
|
233
|
+
this.state.form?.validateFields().then(async (values: any) => {
|
|
234
|
+
const { xObjectApiKey } = this.props.xObjectDataApi || {};
|
|
235
|
+
const { fieldList } = this.state;
|
|
236
|
+
|
|
237
|
+
if (!xObjectApiKey) {
|
|
238
|
+
message.error('请先选择要操作的对象');
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
this.setState({ submitting: true });
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
// 处理日期格式的字段,转换为时间戳
|
|
246
|
+
Object.keys(values).forEach((fieldKey: any) => {
|
|
247
|
+
const field = fieldList.find(
|
|
248
|
+
(field: any) => field.apiKey === fieldKey,
|
|
249
|
+
);
|
|
250
|
+
if (
|
|
251
|
+
field &&
|
|
252
|
+
values[fieldKey] &&
|
|
253
|
+
(field.type === 'date' ||
|
|
254
|
+
field.type === 'datetime' ||
|
|
255
|
+
field.type === 'time')
|
|
256
|
+
) {
|
|
257
|
+
values[fieldKey] = new Date(values[fieldKey]).getTime();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// 调用新增接口
|
|
262
|
+
const response = await xObject.create(xObjectApiKey, {
|
|
263
|
+
data: values,
|
|
264
|
+
method: 'POST',
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
if (response && (response.code === 200 || response.code === '200')) {
|
|
268
|
+
message.success('创建成功');
|
|
269
|
+
this.setState({
|
|
270
|
+
submitting: false,
|
|
271
|
+
submitSuccess: true,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// 重置表单
|
|
275
|
+
this.state.form?.resetFields();
|
|
276
|
+
|
|
277
|
+
// 1秒后隐藏成功提示
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
this.setState({ submitSuccess: false });
|
|
280
|
+
}, 2000);
|
|
281
|
+
|
|
282
|
+
// 调用成功回调
|
|
283
|
+
if (this.props.onSuccess) {
|
|
284
|
+
this.props.onSuccess(response.data);
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
message.error(response?.message || '创建失败');
|
|
288
|
+
this.setState({ submitting: false });
|
|
289
|
+
}
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.error('创建失败:', error);
|
|
292
|
+
message.error('创建失败');
|
|
293
|
+
this.setState({ submitting: false });
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 处理表单重置
|
|
300
|
+
*/
|
|
301
|
+
handleReset() {
|
|
302
|
+
this.state.form?.resetFields();
|
|
303
|
+
this.setState({ submitSuccess: false });
|
|
304
|
+
message.info('表单已重置');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 渲染表单内容
|
|
309
|
+
* 根据字段类型动态生成对应的输入组件
|
|
310
|
+
* @returns 表单 JSX 元素
|
|
311
|
+
*/
|
|
312
|
+
renderForm() {
|
|
313
|
+
const { fieldList, entityTypeList, submitSuccess } = this.state;
|
|
314
|
+
const { xObjectApiKey, fields } = this.props.xObjectDataApi || {};
|
|
315
|
+
const { columnCount = 1 } = this.props;
|
|
316
|
+
|
|
317
|
+
let curFieldList = fieldList;
|
|
318
|
+
|
|
319
|
+
// 如果指定了 fields,则只显示指定的字段
|
|
320
|
+
if (fields && fields.length > 0) {
|
|
321
|
+
curFieldList = fieldList.filter((field) => fields.includes(field.apiKey));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 如果没有选择对象,显示提示信息
|
|
325
|
+
if (!xObjectApiKey) {
|
|
326
|
+
return (
|
|
327
|
+
<Empty
|
|
328
|
+
description="请先选择要操作的对象"
|
|
329
|
+
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
330
|
+
/>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// 如果字段列表为空,显示提示信息
|
|
335
|
+
if (curFieldList.length === 0) {
|
|
336
|
+
return (
|
|
337
|
+
<Empty
|
|
338
|
+
description="暂无可用字段"
|
|
339
|
+
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
340
|
+
/>
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const formItemLayout =
|
|
345
|
+
columnCount === 2
|
|
346
|
+
? {
|
|
347
|
+
labelCol: { span: 8 },
|
|
348
|
+
wrapperCol: { span: 16 },
|
|
349
|
+
}
|
|
350
|
+
: {
|
|
351
|
+
labelCol: { span: 4 },
|
|
352
|
+
wrapperCol: { span: 20 },
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<Form
|
|
357
|
+
ref={(form) => this.setState({ form })}
|
|
358
|
+
layout="horizontal"
|
|
359
|
+
{...formItemLayout}
|
|
360
|
+
>
|
|
361
|
+
<Row gutter={16}>
|
|
362
|
+
{curFieldList.map((field) => {
|
|
363
|
+
// 跳过 ID 字段,不需要在表单中显示
|
|
364
|
+
if (field.apiKey === 'id') return null;
|
|
365
|
+
|
|
366
|
+
let inputComponent;
|
|
367
|
+
const selectitem = field.selectitem || [];
|
|
368
|
+
const checkitem = field.checkitem || [];
|
|
369
|
+
|
|
370
|
+
// 根据字段类型生成对应的输入组件
|
|
371
|
+
switch (field.type) {
|
|
372
|
+
case 'entityType':
|
|
373
|
+
case 'entitytype':
|
|
374
|
+
// 业务类型选择器
|
|
375
|
+
inputComponent = (
|
|
376
|
+
<Select placeholder="请选择业务类型" allowClear>
|
|
377
|
+
{entityTypeList.map((item) => (
|
|
378
|
+
<Option
|
|
379
|
+
key={item.apiKey}
|
|
380
|
+
value={item.id}
|
|
381
|
+
disabled={!item.active}
|
|
382
|
+
>
|
|
383
|
+
{item.label}
|
|
384
|
+
</Option>
|
|
385
|
+
))}
|
|
386
|
+
</Select>
|
|
387
|
+
);
|
|
388
|
+
break;
|
|
389
|
+
case 'picklist':
|
|
390
|
+
// 单选下拉框
|
|
391
|
+
inputComponent = (
|
|
392
|
+
<Select placeholder={`请选择${field.label}`} allowClear>
|
|
393
|
+
{selectitem.map((item) => (
|
|
394
|
+
<Option key={item.apiKey} value={item.id}>
|
|
395
|
+
{item.label}
|
|
396
|
+
</Option>
|
|
397
|
+
))}
|
|
398
|
+
</Select>
|
|
399
|
+
);
|
|
400
|
+
break;
|
|
401
|
+
case 'textarea':
|
|
402
|
+
// 多行文本输入框
|
|
403
|
+
inputComponent = (
|
|
404
|
+
<Input.TextArea
|
|
405
|
+
placeholder={`请输入${field.label}`}
|
|
406
|
+
rows={3}
|
|
407
|
+
showCount
|
|
408
|
+
maxLength={500}
|
|
409
|
+
/>
|
|
410
|
+
);
|
|
411
|
+
break;
|
|
412
|
+
case 'multipicklist':
|
|
413
|
+
// 多选下拉框
|
|
414
|
+
inputComponent = (
|
|
415
|
+
<Select
|
|
416
|
+
placeholder={`请选择${field.label}`}
|
|
417
|
+
mode="multiple"
|
|
418
|
+
allowClear
|
|
419
|
+
>
|
|
420
|
+
{checkitem.map((item) => (
|
|
421
|
+
<Option key={item.apiKey} value={item.id}>
|
|
422
|
+
{item.label}
|
|
423
|
+
</Option>
|
|
424
|
+
))}
|
|
425
|
+
</Select>
|
|
426
|
+
);
|
|
427
|
+
break;
|
|
428
|
+
case 'datetime':
|
|
429
|
+
// 日期时间选择器
|
|
430
|
+
inputComponent = (
|
|
431
|
+
<DatePicker
|
|
432
|
+
placeholder={`请选择${field.label}`}
|
|
433
|
+
format={'YYYY/MM/DD HH:mm:ss'}
|
|
434
|
+
showTime={true}
|
|
435
|
+
style={{ width: '100%' }}
|
|
436
|
+
/>
|
|
437
|
+
);
|
|
438
|
+
break;
|
|
439
|
+
case 'date':
|
|
440
|
+
// 日期选择器
|
|
441
|
+
inputComponent = (
|
|
442
|
+
<DatePicker
|
|
443
|
+
placeholder={`请选择${field.label}`}
|
|
444
|
+
format={'YYYY/MM/DD'}
|
|
445
|
+
style={{ width: '100%' }}
|
|
446
|
+
/>
|
|
447
|
+
);
|
|
448
|
+
break;
|
|
449
|
+
case 'time':
|
|
450
|
+
// 时间选择器
|
|
451
|
+
inputComponent = (
|
|
452
|
+
<DatePicker
|
|
453
|
+
placeholder={`请选择${field.label}`}
|
|
454
|
+
format={'HH:mm:ss'}
|
|
455
|
+
showTime={true}
|
|
456
|
+
style={{ width: '100%' }}
|
|
457
|
+
/>
|
|
458
|
+
);
|
|
459
|
+
break;
|
|
460
|
+
case 'int':
|
|
461
|
+
case 'float':
|
|
462
|
+
// 数字输入框
|
|
463
|
+
inputComponent = (
|
|
464
|
+
<InputNumber
|
|
465
|
+
placeholder={`请输入${field.label}`}
|
|
466
|
+
style={{ width: '100%' }}
|
|
467
|
+
/>
|
|
468
|
+
);
|
|
469
|
+
break;
|
|
470
|
+
case 'email':
|
|
471
|
+
// 邮箱输入框
|
|
472
|
+
inputComponent = (
|
|
473
|
+
<Input placeholder={`请输入${field.label}`} type="email" />
|
|
474
|
+
);
|
|
475
|
+
break;
|
|
476
|
+
case 'url':
|
|
477
|
+
// URL 输入框
|
|
478
|
+
inputComponent = (
|
|
479
|
+
<Input placeholder={`请输入${field.label}`} type="url" />
|
|
480
|
+
);
|
|
481
|
+
break;
|
|
482
|
+
case 'phone':
|
|
483
|
+
// 电话号码输入框
|
|
484
|
+
inputComponent = (
|
|
485
|
+
<Input placeholder={`请输入${field.label}`} type="tel" />
|
|
486
|
+
);
|
|
487
|
+
break;
|
|
488
|
+
default:
|
|
489
|
+
// 默认文本输入框
|
|
490
|
+
inputComponent = (
|
|
491
|
+
<Input placeholder={`请输入${field.label}`} maxLength={200} />
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const colSpan = columnCount === 2 ? 12 : 24;
|
|
496
|
+
|
|
497
|
+
return (
|
|
498
|
+
<Col span={colSpan} key={field.apiKey}>
|
|
499
|
+
<Form.Item
|
|
500
|
+
name={field.apiKey}
|
|
501
|
+
label={field.label}
|
|
502
|
+
required={field.required ?? false}
|
|
503
|
+
rules={[
|
|
504
|
+
{
|
|
505
|
+
required: field.required,
|
|
506
|
+
message: `请${
|
|
507
|
+
field.type === 'picklist' ||
|
|
508
|
+
field.type === 'multipicklist' ||
|
|
509
|
+
field.type === 'entityType' ||
|
|
510
|
+
field.type === 'entitytype' ||
|
|
511
|
+
field.type === 'date' ||
|
|
512
|
+
field.type === 'datetime' ||
|
|
513
|
+
field.type === 'time'
|
|
514
|
+
? '选择'
|
|
515
|
+
: '输入'
|
|
516
|
+
}${field.label}`,
|
|
517
|
+
},
|
|
518
|
+
]}
|
|
519
|
+
>
|
|
520
|
+
{inputComponent}
|
|
521
|
+
</Form.Item>
|
|
522
|
+
</Col>
|
|
523
|
+
);
|
|
524
|
+
})}
|
|
525
|
+
</Row>
|
|
526
|
+
|
|
527
|
+
{submitSuccess && (
|
|
528
|
+
<div className="submit-success-message">
|
|
529
|
+
<CheckCircleOutlined /> 数据已成功提交
|
|
530
|
+
</div>
|
|
531
|
+
)}
|
|
532
|
+
</Form>
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* 渲染组件
|
|
538
|
+
* @returns 组件 JSX 元素
|
|
539
|
+
*/
|
|
540
|
+
render() {
|
|
541
|
+
const { title, loading, submitting, error } = this.state;
|
|
542
|
+
const { formTitle, showResetButton = true, data } = this.props;
|
|
543
|
+
|
|
544
|
+
// 测试输出
|
|
545
|
+
console.log('this.props:', this.props);
|
|
546
|
+
|
|
547
|
+
const curAmisData = data || {};
|
|
548
|
+
const systemInfo = curAmisData.__NeoSystemInfo || {};
|
|
549
|
+
const { xObjectApiKey } = this.props.xObjectDataApi || {};
|
|
550
|
+
|
|
551
|
+
const displayTitle = formTitle || title || '新增数据';
|
|
552
|
+
|
|
553
|
+
return (
|
|
554
|
+
<div className="object-form-container">
|
|
555
|
+
<Card>
|
|
556
|
+
<div className="form-header">
|
|
557
|
+
<h3 className="form-title">
|
|
558
|
+
{displayTitle}
|
|
559
|
+
{systemInfo.tenantName ? `【${systemInfo.tenantName}】` : ''}
|
|
560
|
+
</h3>
|
|
561
|
+
</div>
|
|
562
|
+
|
|
563
|
+
<div className="form-content">
|
|
564
|
+
<Spin spinning={loading} tip="加载字段信息...">
|
|
565
|
+
{error ? (
|
|
566
|
+
<Empty
|
|
567
|
+
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
568
|
+
description={
|
|
569
|
+
<div>
|
|
570
|
+
<div style={{ color: '#ff4d4f', marginBottom: 8 }}>
|
|
571
|
+
{error}
|
|
572
|
+
</div>
|
|
573
|
+
<Button type="primary" onClick={this.loadFieldList}>
|
|
574
|
+
重新加载
|
|
575
|
+
</Button>
|
|
576
|
+
</div>
|
|
577
|
+
}
|
|
578
|
+
/>
|
|
579
|
+
) : (
|
|
580
|
+
<>
|
|
581
|
+
{this.renderForm()}
|
|
582
|
+
<div className="form-actions">
|
|
583
|
+
<Space size="middle">
|
|
584
|
+
<Button
|
|
585
|
+
type="primary"
|
|
586
|
+
icon={<SaveOutlined />}
|
|
587
|
+
onClick={this.handleSubmit}
|
|
588
|
+
loading={submitting}
|
|
589
|
+
disabled={!xObjectApiKey}
|
|
590
|
+
>
|
|
591
|
+
{submitting ? '提交中...' : '提交'}
|
|
592
|
+
</Button>
|
|
593
|
+
{showResetButton && (
|
|
594
|
+
<Button
|
|
595
|
+
icon={<ReloadOutlined />}
|
|
596
|
+
onClick={this.handleReset}
|
|
597
|
+
disabled={submitting}
|
|
598
|
+
>
|
|
599
|
+
重置
|
|
600
|
+
</Button>
|
|
601
|
+
)}
|
|
602
|
+
</Space>
|
|
603
|
+
</div>
|
|
604
|
+
</>
|
|
605
|
+
)}
|
|
606
|
+
</Spin>
|
|
607
|
+
</div>
|
|
608
|
+
</Card>
|
|
609
|
+
</div>
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Object Form 表单组件对接编辑器的描述文件
|
|
3
|
+
* @description 定义组件在 Neo 平台编辑器中的配置信息
|
|
4
|
+
* @author Neo Custom Widget CLI
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export class ObjectFormModel {
|
|
8
|
+
/**
|
|
9
|
+
* 组件类型标识
|
|
10
|
+
* 用于标识组件的唯一性,在构建时根据当前组件目录名称自动生成
|
|
11
|
+
* 注意:此字段在构建时会被自动替换,不需要手动设置
|
|
12
|
+
*/
|
|
13
|
+
// cmpType: string = 'object-form';
|
|
14
|
+
|
|
15
|
+
/** 组件名称,用于设置在编辑器左侧组件面板中展示的名称 */
|
|
16
|
+
label: string = '实体对象表单';
|
|
17
|
+
|
|
18
|
+
/** 组件描述,用于设置在编辑器左侧组件面板中展示的描述 */
|
|
19
|
+
description: string = '基于 XObject 的对象表单组件,用于新增数据';
|
|
20
|
+
|
|
21
|
+
/** 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签) */
|
|
22
|
+
tags: string[] = ['自定义组件'];
|
|
23
|
+
|
|
24
|
+
/** 组件图标,用于设置在编辑器左侧组件面板中展示的图标 */
|
|
25
|
+
iconSrc: string = 'https://custom-widgets.bj.bcebos.com/custom-form.svg';
|
|
26
|
+
|
|
27
|
+
/** 初次插入页面的默认属性数据 */
|
|
28
|
+
defaultComProps = {
|
|
29
|
+
formTitle: '新增数据表单',
|
|
30
|
+
showResetButton: true,
|
|
31
|
+
columnCount: 1,
|
|
32
|
+
xObjectDataApi: {
|
|
33
|
+
xObjectApiKey: 'customContact__c',
|
|
34
|
+
fields: ['name', 'entityType', 'phone__c'],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** 设计器端预览时展示的默认数据 */
|
|
39
|
+
previewComProps = {
|
|
40
|
+
formTitle: '新增数据表单',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 组件属性配置模式
|
|
45
|
+
* 支持静态配置:propsSchema,优先级比 propsSchemaCreator 低
|
|
46
|
+
* 定义组件在编辑器中可配置的属性
|
|
47
|
+
*/
|
|
48
|
+
propsSchema = [
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
name: 'formTitle',
|
|
52
|
+
label: '表单标题',
|
|
53
|
+
value: '新增数据表单',
|
|
54
|
+
placeholder: '请输入表单标题',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'xObjectDataApi', // 用于获取实体业务数据列表的配置项
|
|
58
|
+
name: 'xObjectDataApi',
|
|
59
|
+
label: '实体数据源',
|
|
60
|
+
/*
|
|
61
|
+
value: {
|
|
62
|
+
xObjectApiKey: 'customContact__c',
|
|
63
|
+
fields: ['name', 'entityType', 'phone__c'],
|
|
64
|
+
},
|
|
65
|
+
*/
|
|
66
|
+
placeholder: '请选择实体数据源',
|
|
67
|
+
custom: true,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'select',
|
|
71
|
+
name: 'columnCount',
|
|
72
|
+
label: '表单列数',
|
|
73
|
+
value: 1,
|
|
74
|
+
placeholder: '请选择表单列数',
|
|
75
|
+
options: [
|
|
76
|
+
{
|
|
77
|
+
label: '单列',
|
|
78
|
+
value: 1,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: '双列',
|
|
82
|
+
value: 2,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: 'switch',
|
|
88
|
+
name: 'showResetButton',
|
|
89
|
+
label: '显示重置按钮',
|
|
90
|
+
value: true,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 支持函数式写法:propsSchemaCreator
|
|
96
|
+
* com 为组件实例,优先级比 propsSchema 高
|
|
97
|
+
* 可以根据组件实例动态生成属性配置
|
|
98
|
+
*/
|
|
99
|
+
/*
|
|
100
|
+
propsSchemaCreator = (com: any) => {
|
|
101
|
+
return [];
|
|
102
|
+
};
|
|
103
|
+
*/
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default ObjectFormModel;
|