neo-cmp-cli 1.2.12 → 1.2.15
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/package.json +1 -1
- package/src/module/main.js +4 -4
- package/src/plugins/AddNeoRequirePlugin.js +3 -12
- package/src/template/antd-custom-cmp-template/package.json +1 -1
- package/src/template/develop/neo-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/README.md +1 -1
- package/src/template/neo-custom-cmp-template/package.json +2 -2
- package/src/template/neo-custom-cmp-template/src/assets/img/detail.svg +1 -0
- package/src/template/neo-custom-cmp-template/src/components/contact-card-list/README.md +2 -7
- package/src/template/neo-custom-cmp-template/src/components/contact-card-list/index.tsx +13 -1
- package/src/template/neo-custom-cmp-template/src/components/contact-form/index.tsx +2 -3
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/README.md +193 -0
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +325 -0
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/model.ts +125 -0
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/style.scss +292 -0
- package/src/template/neo-custom-cmp-template/src/components/object-card-list/README.md +61 -0
- package/src/template/neo-custom-cmp-template/src/components/object-card-list/index.tsx +201 -0
- package/src/template/neo-custom-cmp-template/src/components/object-card-list/model.ts +66 -0
- package/src/template/neo-custom-cmp-template/src/components/object-card-list/style.scss +260 -0
- package/src/template/neo-custom-cmp-template/src/components/xobject-table/README.md +3 -11
- package/src/template/neo-custom-cmp-template/src/components/xobject-table/index.tsx +76 -58
- package/src/template/neo-custom-cmp-template/src/components/xobject-table/model.ts +21 -3
- 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
- package/src/template/neo-custom-cmp-template/src/components/xobject-table-v2/README.md +0 -108
- package/src/template/neo-custom-cmp-template/src/components/xobject-table-v2/index.tsx +0 -729
- package/src/template/neo-custom-cmp-template/src/components/xobject-table-v2/model.ts +0 -122
- package/src/template/neo-custom-cmp-template/src/components/xobject-table-v2/style.scss +0 -304
|
@@ -1,729 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file XObject 数据表格组件
|
|
3
|
-
* @description 基于 Neo 平台的 XObject 实体对象数据表格组件,支持增删改查操作
|
|
4
|
-
*/
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
import {
|
|
7
|
-
Table,
|
|
8
|
-
Button,
|
|
9
|
-
Space,
|
|
10
|
-
Modal,
|
|
11
|
-
Form,
|
|
12
|
-
Input,
|
|
13
|
-
Select,
|
|
14
|
-
message,
|
|
15
|
-
Popconfirm,
|
|
16
|
-
Spin,
|
|
17
|
-
Empty,
|
|
18
|
-
Card,
|
|
19
|
-
DatePicker,
|
|
20
|
-
InputNumber,
|
|
21
|
-
Checkbox,
|
|
22
|
-
Row,
|
|
23
|
-
Col,
|
|
24
|
-
} from 'antd';
|
|
25
|
-
import {
|
|
26
|
-
PlusOutlined,
|
|
27
|
-
EditOutlined,
|
|
28
|
-
DeleteOutlined,
|
|
29
|
-
ReloadOutlined,
|
|
30
|
-
} from '@ant-design/icons';
|
|
31
|
-
import moment from 'moment';
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
import { xObject } from 'neo-open-api'; // Neo Open API
|
|
34
|
-
import './style.scss';
|
|
35
|
-
|
|
36
|
-
const { Option } = Select;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 组件属性接口
|
|
40
|
-
*/
|
|
41
|
-
interface XObjectTableProps {
|
|
42
|
-
/** XObject 实体对象的 API Key,用于标识要操作的数据对象 */
|
|
43
|
-
xObjectApiKey: string;
|
|
44
|
-
/** Neo 平台传递的数据,包含系统信息等 */
|
|
45
|
-
data?: any;
|
|
46
|
-
/** 是否显示新增按钮 */
|
|
47
|
-
showAddButton?: boolean;
|
|
48
|
-
/** 是否显示编辑按钮 */
|
|
49
|
-
showEditButton?: boolean;
|
|
50
|
-
/** 是否显示删除按钮 */
|
|
51
|
-
showDeleteButton?: boolean;
|
|
52
|
-
/** 是否为自定义实体对象 */
|
|
53
|
-
custom?: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 字段信息接口
|
|
58
|
-
*/
|
|
59
|
-
interface FieldInfo {
|
|
60
|
-
/** 字段名称 */
|
|
61
|
-
name: string;
|
|
62
|
-
/** 字段显示标签 */
|
|
63
|
-
label: string;
|
|
64
|
-
/** 字段 API Key */
|
|
65
|
-
apiKey: string;
|
|
66
|
-
/** 字段类型 */
|
|
67
|
-
type: string;
|
|
68
|
-
/** 字段项类型 */
|
|
69
|
-
itemType: string;
|
|
70
|
-
/** 复选框选项列表 */
|
|
71
|
-
checkitem: any[];
|
|
72
|
-
/** 下拉选择选项列表 */
|
|
73
|
-
selectitem?: any[];
|
|
74
|
-
/** 是否必填 */
|
|
75
|
-
required: boolean;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 组件状态接口
|
|
80
|
-
*/
|
|
81
|
-
interface XObjectTableState {
|
|
82
|
-
/** 表格标题 */
|
|
83
|
-
title?: string;
|
|
84
|
-
/** 表格数据源 */
|
|
85
|
-
dataSource: any[];
|
|
86
|
-
/** 加载状态 */
|
|
87
|
-
loading: boolean;
|
|
88
|
-
/** 错误信息 */
|
|
89
|
-
error: string | null;
|
|
90
|
-
/** 分页信息 */
|
|
91
|
-
pagination: {
|
|
92
|
-
current: number;
|
|
93
|
-
pageSize: number;
|
|
94
|
-
total: number;
|
|
95
|
-
};
|
|
96
|
-
/** 模态框是否可见 */
|
|
97
|
-
isModalVisible: boolean;
|
|
98
|
-
/** 是否为编辑模式 */
|
|
99
|
-
isEditMode: boolean;
|
|
100
|
-
/** 正在编辑的记录 */
|
|
101
|
-
editingRecord: any;
|
|
102
|
-
/** 表单实例 */
|
|
103
|
-
form: any;
|
|
104
|
-
/** 业务类型列表 */
|
|
105
|
-
entityTypeList: any[];
|
|
106
|
-
/** 字段列表 */
|
|
107
|
-
fieldList: FieldInfo[];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* XObject 数据表格组件
|
|
112
|
-
* 支持对 Neo 平台的 XObject 实体对象进行增删改查操作
|
|
113
|
-
*/
|
|
114
|
-
export default class XObjectTable extends React.PureComponent<
|
|
115
|
-
XObjectTableProps,
|
|
116
|
-
XObjectTableState
|
|
117
|
-
> {
|
|
118
|
-
constructor(props: XObjectTableProps) {
|
|
119
|
-
super(props);
|
|
120
|
-
|
|
121
|
-
// 初始化组件状态
|
|
122
|
-
this.state = {
|
|
123
|
-
dataSource: [],
|
|
124
|
-
loading: false,
|
|
125
|
-
error: null,
|
|
126
|
-
pagination: {
|
|
127
|
-
current: 1,
|
|
128
|
-
pageSize: 10,
|
|
129
|
-
total: 0,
|
|
130
|
-
},
|
|
131
|
-
isModalVisible: false,
|
|
132
|
-
isEditMode: false,
|
|
133
|
-
editingRecord: null,
|
|
134
|
-
form: null,
|
|
135
|
-
fieldList: [],
|
|
136
|
-
entityTypeList: [],
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
if (this.props.xObjectApiKey) {
|
|
140
|
-
// 初始化字段列表、加载数据和业务类型列表
|
|
141
|
-
this.loadFieldList().then(() => {
|
|
142
|
-
this.loadData();
|
|
143
|
-
});
|
|
144
|
-
this.getEntityTypeList();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// 绑定方法上下文
|
|
148
|
-
this.loadData = this.loadData.bind(this);
|
|
149
|
-
this.loadFieldList = this.loadFieldList.bind(this);
|
|
150
|
-
this.handleAdd = this.handleAdd.bind(this);
|
|
151
|
-
this.handleEdit = this.handleEdit.bind(this);
|
|
152
|
-
this.handleDelete = this.handleDelete.bind(this);
|
|
153
|
-
this.handleModalOk = this.handleModalOk.bind(this);
|
|
154
|
-
this.handleModalCancel = this.handleModalCancel.bind(this);
|
|
155
|
-
this.handleTableChange = this.handleTableChange.bind(this);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* 获取业务类型列表
|
|
160
|
-
* 用于下拉选择框的选项数据
|
|
161
|
-
*/
|
|
162
|
-
async getEntityTypeList() {
|
|
163
|
-
const result = await xObject.getEntityTypeList(this.props.xObjectApiKey);
|
|
164
|
-
if (result && result.status) {
|
|
165
|
-
const records = result.data || [];
|
|
166
|
-
this.setState({
|
|
167
|
-
entityTypeList: records,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 组件更新后执行
|
|
174
|
-
* 当 xObjectApiKey 发生变化时重新加载数据
|
|
175
|
-
*/
|
|
176
|
-
async componentDidUpdate(prevProps: XObjectTableProps) {
|
|
177
|
-
if (prevProps.xObjectApiKey !== this.props.xObjectApiKey) {
|
|
178
|
-
if (this.props.xObjectApiKey) {
|
|
179
|
-
await this.loadFieldList();
|
|
180
|
-
this.loadData();
|
|
181
|
-
this.getEntityTypeList();
|
|
182
|
-
} else {
|
|
183
|
-
this.setState({
|
|
184
|
-
dataSource: [],
|
|
185
|
-
fieldList: [],
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 加载字段列表
|
|
193
|
-
* 从 Neo 平台获取 XObject 的字段描述信息
|
|
194
|
-
*/
|
|
195
|
-
async loadFieldList() {
|
|
196
|
-
const { xObjectApiKey } = this.props;
|
|
197
|
-
if (!xObjectApiKey) return;
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
const resultData = await xObject.getDesc(xObjectApiKey);
|
|
201
|
-
if (resultData && resultData.status) {
|
|
202
|
-
const result = resultData.data || {};
|
|
203
|
-
const fieldList = result.fields || [];
|
|
204
|
-
this.setState({ fieldList, title: result.label });
|
|
205
|
-
}
|
|
206
|
-
} catch (error) {
|
|
207
|
-
console.error('获取字段列表失败:', error);
|
|
208
|
-
message.error('获取字段列表失败');
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 生成表格列配置
|
|
214
|
-
* @param _fieldList 字段列表,可选参数
|
|
215
|
-
* @returns 表格列配置数组
|
|
216
|
-
*/
|
|
217
|
-
generateColumns(_fieldList?: FieldInfo[]) {
|
|
218
|
-
const { showEditButton, showDeleteButton } = this.props;
|
|
219
|
-
const { fieldList } = this.state;
|
|
220
|
-
const curFieldList = _fieldList || fieldList;
|
|
221
|
-
|
|
222
|
-
// 根据字段列表生成基础列配置
|
|
223
|
-
const columns: any[] = curFieldList.map((field) => ({
|
|
224
|
-
title: field.label,
|
|
225
|
-
dataIndex: field.apiKey,
|
|
226
|
-
key: field.apiKey,
|
|
227
|
-
ellipsis: true,
|
|
228
|
-
}));
|
|
229
|
-
|
|
230
|
-
// 添加操作列(编辑和删除按钮)
|
|
231
|
-
if (showEditButton || showDeleteButton) {
|
|
232
|
-
columns.push({
|
|
233
|
-
title: '操作',
|
|
234
|
-
key: 'action',
|
|
235
|
-
dataIndex: 'action',
|
|
236
|
-
ellipsis: false,
|
|
237
|
-
width: 150,
|
|
238
|
-
render: (text: any, record: any) => (
|
|
239
|
-
<Space size="middle">
|
|
240
|
-
{showEditButton && (
|
|
241
|
-
<Button
|
|
242
|
-
type="link"
|
|
243
|
-
icon={<EditOutlined />}
|
|
244
|
-
onClick={() => this.handleEdit(record)}
|
|
245
|
-
size="small"
|
|
246
|
-
>
|
|
247
|
-
编辑
|
|
248
|
-
</Button>
|
|
249
|
-
)}
|
|
250
|
-
{showDeleteButton && (
|
|
251
|
-
<Popconfirm
|
|
252
|
-
title="确定要删除这条记录吗?"
|
|
253
|
-
onConfirm={() => this.handleDelete(record.id)}
|
|
254
|
-
okText="确定"
|
|
255
|
-
cancelText="取消"
|
|
256
|
-
>
|
|
257
|
-
<Button
|
|
258
|
-
type="link"
|
|
259
|
-
danger
|
|
260
|
-
icon={<DeleteOutlined />}
|
|
261
|
-
size="small"
|
|
262
|
-
>
|
|
263
|
-
删除
|
|
264
|
-
</Button>
|
|
265
|
-
</Popconfirm>
|
|
266
|
-
)}
|
|
267
|
-
</Space>
|
|
268
|
-
),
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return columns;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* 加载表格数据
|
|
277
|
-
* @param page 页码,默认为 1
|
|
278
|
-
* @param pageSize 每页条数,默认为 10
|
|
279
|
-
*/
|
|
280
|
-
async loadData(page = 1, pageSize = 10) {
|
|
281
|
-
const { xObjectApiKey } = this.props;
|
|
282
|
-
if (!xObjectApiKey) return;
|
|
283
|
-
|
|
284
|
-
this.setState({ loading: true, error: null });
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
// 获取所有字段的 API Key
|
|
288
|
-
const fields = this.state.fieldList.map((field) => field.apiKey);
|
|
289
|
-
const result = await xObject.query({
|
|
290
|
-
xObjectApiKey,
|
|
291
|
-
fields,
|
|
292
|
-
page,
|
|
293
|
-
pageSize,
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
if (result && result.status) {
|
|
297
|
-
const records = result.data || [];
|
|
298
|
-
const totalSize = result.totalSize || 0;
|
|
299
|
-
|
|
300
|
-
this.setState({
|
|
301
|
-
dataSource: records,
|
|
302
|
-
pagination: {
|
|
303
|
-
current: page,
|
|
304
|
-
pageSize,
|
|
305
|
-
total: totalSize,
|
|
306
|
-
},
|
|
307
|
-
loading: false,
|
|
308
|
-
});
|
|
309
|
-
} else {
|
|
310
|
-
this.setState({
|
|
311
|
-
error: result?.msg || '获取数据失败',
|
|
312
|
-
loading: false,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
} catch (error: any) {
|
|
316
|
-
this.setState({
|
|
317
|
-
error: error.message || '获取数据失败',
|
|
318
|
-
loading: false,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* 处理新增按钮点击
|
|
325
|
-
* 打开新增模态框
|
|
326
|
-
*/
|
|
327
|
-
handleAdd() {
|
|
328
|
-
this.setState({
|
|
329
|
-
isModalVisible: true,
|
|
330
|
-
isEditMode: false,
|
|
331
|
-
editingRecord: null,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* 处理编辑按钮点击
|
|
337
|
-
* @param record 要编辑的记录
|
|
338
|
-
*/
|
|
339
|
-
handleEdit(record: any) {
|
|
340
|
-
this.setState({
|
|
341
|
-
isModalVisible: true,
|
|
342
|
-
isEditMode: true,
|
|
343
|
-
editingRecord: record,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* 处理删除操作
|
|
349
|
-
* @param id 要删除的记录 ID
|
|
350
|
-
*/
|
|
351
|
-
async handleDelete(id: string) {
|
|
352
|
-
const { xObjectApiKey } = this.props;
|
|
353
|
-
if (!xObjectApiKey) return;
|
|
354
|
-
|
|
355
|
-
try {
|
|
356
|
-
const response = await xObject.delete(xObjectApiKey, id);
|
|
357
|
-
if (response && (response.code === 200 || response.code === '200')) {
|
|
358
|
-
message.success('删除成功');
|
|
359
|
-
// 删除成功后重新加载当前页数据
|
|
360
|
-
this.loadData(
|
|
361
|
-
this.state.pagination.current,
|
|
362
|
-
this.state.pagination.pageSize,
|
|
363
|
-
);
|
|
364
|
-
} else {
|
|
365
|
-
message.error(response?.message || '删除失败');
|
|
366
|
-
}
|
|
367
|
-
} catch (error) {
|
|
368
|
-
console.error('删除失败:', error);
|
|
369
|
-
message.error('删除失败');
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* 处理模态框确定按钮点击
|
|
375
|
-
* 执行新增或编辑操作
|
|
376
|
-
*/
|
|
377
|
-
handleModalOk() {
|
|
378
|
-
this.state.form?.validateFields().then(async (values: any) => {
|
|
379
|
-
const { xObjectApiKey } = this.props;
|
|
380
|
-
const { isEditMode, editingRecord } = this.state;
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
let response;
|
|
384
|
-
if (isEditMode) {
|
|
385
|
-
// 编辑模式:更新现有记录
|
|
386
|
-
const { fieldList } = this.state;
|
|
387
|
-
// 处理日期格式的字段,转换为时间戳
|
|
388
|
-
Object.keys(values).forEach((fieldKey: any) => {
|
|
389
|
-
const field = fieldList.find(
|
|
390
|
-
(field: any) => field.apiKey === fieldKey,
|
|
391
|
-
);
|
|
392
|
-
if (
|
|
393
|
-
field &&
|
|
394
|
-
(field.type === 'date' ||
|
|
395
|
-
field.type === 'datetime' ||
|
|
396
|
-
field.type === 'time')
|
|
397
|
-
) {
|
|
398
|
-
values[fieldKey] = new Date(values[fieldKey]).getTime();
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
response = await xObject.update(xObjectApiKey, editingRecord.id, {
|
|
402
|
-
data: values,
|
|
403
|
-
method: 'PATCH',
|
|
404
|
-
});
|
|
405
|
-
} else {
|
|
406
|
-
// 新增模式:创建新记录
|
|
407
|
-
response = await xObject.create(xObjectApiKey, {
|
|
408
|
-
data: values,
|
|
409
|
-
method: 'POST',
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (response && (response.code === 200 || response.code === '200')) {
|
|
414
|
-
message.success(isEditMode ? '更新成功' : '创建成功');
|
|
415
|
-
this.setState({ isModalVisible: false });
|
|
416
|
-
// 操作成功后重新加载当前页数据
|
|
417
|
-
this.loadData(
|
|
418
|
-
this.state.pagination.current,
|
|
419
|
-
this.state.pagination.pageSize,
|
|
420
|
-
);
|
|
421
|
-
} else {
|
|
422
|
-
message.error(
|
|
423
|
-
response?.message || (isEditMode ? '更新失败' : '创建失败'),
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
} catch (error) {
|
|
427
|
-
console.error(isEditMode ? '更新失败:' : '创建失败:', error);
|
|
428
|
-
message.error(isEditMode ? '更新失败' : '创建失败');
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* 处理模态框取消按钮点击
|
|
435
|
-
* 关闭模态框并重置状态
|
|
436
|
-
*/
|
|
437
|
-
handleModalCancel() {
|
|
438
|
-
this.setState({
|
|
439
|
-
isModalVisible: false,
|
|
440
|
-
isEditMode: false,
|
|
441
|
-
editingRecord: null,
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* 处理表格分页变化
|
|
447
|
-
* @param pagination 分页信息
|
|
448
|
-
*/
|
|
449
|
-
handleTableChange(pagination: any) {
|
|
450
|
-
this.loadData(pagination.current, pagination.pageSize);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* 渲染表单内容
|
|
455
|
-
* 根据字段类型动态生成对应的输入组件
|
|
456
|
-
* @returns 表单 JSX 元素
|
|
457
|
-
*/
|
|
458
|
-
renderForm() {
|
|
459
|
-
const { fieldList, isEditMode, editingRecord, entityTypeList } = this.state;
|
|
460
|
-
const { xObjectApiKey } = this.props;
|
|
461
|
-
|
|
462
|
-
// 如果没有选择对象,显示提示信息
|
|
463
|
-
if (!xObjectApiKey) {
|
|
464
|
-
return (
|
|
465
|
-
<Empty
|
|
466
|
-
description="请先选择要操作的对象"
|
|
467
|
-
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
468
|
-
/>
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// 处理编辑模式下的日期格式字段
|
|
473
|
-
const curEditingRecord = editingRecord || {};
|
|
474
|
-
if (editingRecord) {
|
|
475
|
-
Object.keys(editingRecord).forEach((fieldKey: any) => {
|
|
476
|
-
const field = fieldList.find((field: any) => field.apiKey === fieldKey);
|
|
477
|
-
if (
|
|
478
|
-
field &&
|
|
479
|
-
editingRecord[fieldKey] &&
|
|
480
|
-
(field.type === 'date' ||
|
|
481
|
-
field.type === 'datetime' ||
|
|
482
|
-
field.type === 'time')
|
|
483
|
-
) {
|
|
484
|
-
// 将时间戳转换为 moment 对象,用于日期选择器
|
|
485
|
-
curEditingRecord[fieldKey] = moment(
|
|
486
|
-
new Date(editingRecord[fieldKey]),
|
|
487
|
-
field.type === 'date'
|
|
488
|
-
? 'YYYY/MM/DD'
|
|
489
|
-
: field.type === 'datetime'
|
|
490
|
-
? 'YYYY/MM/DD HH:mm:ss'
|
|
491
|
-
: 'HH:mm:ss',
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return (
|
|
498
|
-
<Form
|
|
499
|
-
ref={(form) => this.setState({ form })}
|
|
500
|
-
layout="vertical"
|
|
501
|
-
initialValues={isEditMode ? curEditingRecord : {}}
|
|
502
|
-
>
|
|
503
|
-
{fieldList.map((field) => {
|
|
504
|
-
// 跳过 ID 字段,不需要在表单中显示
|
|
505
|
-
if (field.apiKey === 'id') return null;
|
|
506
|
-
|
|
507
|
-
let inputComponent;
|
|
508
|
-
const selectitem = field.selectitem || [];
|
|
509
|
-
const checkitem = field.checkitem || [];
|
|
510
|
-
|
|
511
|
-
// 根据字段类型生成对应的输入组件
|
|
512
|
-
switch (field.type) {
|
|
513
|
-
case 'entityType':
|
|
514
|
-
case 'entitytype':
|
|
515
|
-
// 业务类型选择器
|
|
516
|
-
inputComponent = (
|
|
517
|
-
<Select placeholder="请选择业务类型">
|
|
518
|
-
{entityTypeList.map((item) => (
|
|
519
|
-
<Option
|
|
520
|
-
key={item.apiKey}
|
|
521
|
-
value={item.id}
|
|
522
|
-
disabled={!item.active}
|
|
523
|
-
>
|
|
524
|
-
{item.label}
|
|
525
|
-
</Option>
|
|
526
|
-
))}
|
|
527
|
-
</Select>
|
|
528
|
-
);
|
|
529
|
-
break;
|
|
530
|
-
case 'picklist':
|
|
531
|
-
// 单选下拉框
|
|
532
|
-
inputComponent = (
|
|
533
|
-
<Select placeholder={`请选择${field.label}`}>
|
|
534
|
-
{selectitem.map((item) => (
|
|
535
|
-
<Option key={item.apiKey} value={item.id}>
|
|
536
|
-
{item.label}
|
|
537
|
-
</Option>
|
|
538
|
-
))}
|
|
539
|
-
</Select>
|
|
540
|
-
);
|
|
541
|
-
break;
|
|
542
|
-
case 'textarea':
|
|
543
|
-
// 多行文本输入框
|
|
544
|
-
inputComponent = (
|
|
545
|
-
<Input.TextArea placeholder={`请输入${field.label}`} rows={3} />
|
|
546
|
-
);
|
|
547
|
-
break;
|
|
548
|
-
case 'multipicklist':
|
|
549
|
-
// 多选下拉框
|
|
550
|
-
inputComponent = (
|
|
551
|
-
<Select placeholder={`请选择${field.label}`} mode="multiple">
|
|
552
|
-
{checkitem.map((item) => (
|
|
553
|
-
<Option key={item.apiKey} value={item.id}>
|
|
554
|
-
{item.label}
|
|
555
|
-
</Option>
|
|
556
|
-
))}
|
|
557
|
-
</Select>
|
|
558
|
-
);
|
|
559
|
-
break;
|
|
560
|
-
case 'datetime':
|
|
561
|
-
// 日期时间选择器
|
|
562
|
-
inputComponent = (
|
|
563
|
-
<DatePicker
|
|
564
|
-
placeholder={`请输入${field.label}`}
|
|
565
|
-
format={'YYYY/MM/DD HH:mm:ss'}
|
|
566
|
-
showTime={true}
|
|
567
|
-
/>
|
|
568
|
-
);
|
|
569
|
-
break;
|
|
570
|
-
case 'date':
|
|
571
|
-
// 日期选择器
|
|
572
|
-
inputComponent = (
|
|
573
|
-
<DatePicker
|
|
574
|
-
placeholder={`请输入${field.label}`}
|
|
575
|
-
format={'YYYY/MM/DD'}
|
|
576
|
-
/>
|
|
577
|
-
);
|
|
578
|
-
break;
|
|
579
|
-
case 'time':
|
|
580
|
-
// 时间选择器
|
|
581
|
-
inputComponent = (
|
|
582
|
-
<DatePicker
|
|
583
|
-
placeholder={`请输入${field.label}`}
|
|
584
|
-
format={'HH:mm:ss'}
|
|
585
|
-
showTime={true}
|
|
586
|
-
/>
|
|
587
|
-
);
|
|
588
|
-
break;
|
|
589
|
-
case 'int':
|
|
590
|
-
case 'float':
|
|
591
|
-
// 数字输入框
|
|
592
|
-
inputComponent = (
|
|
593
|
-
<InputNumber placeholder={`请输入${field.label}`} />
|
|
594
|
-
);
|
|
595
|
-
break;
|
|
596
|
-
default:
|
|
597
|
-
// 默认文本输入框
|
|
598
|
-
inputComponent = <Input placeholder={`请输入${field.label}`} />;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return (
|
|
602
|
-
<Form.Item
|
|
603
|
-
key={field.apiKey}
|
|
604
|
-
name={field.apiKey}
|
|
605
|
-
label={field.label}
|
|
606
|
-
required={field.required ?? false}
|
|
607
|
-
rules={[
|
|
608
|
-
{
|
|
609
|
-
required: field.required,
|
|
610
|
-
message: `请输入${field.label}`,
|
|
611
|
-
},
|
|
612
|
-
]}
|
|
613
|
-
>
|
|
614
|
-
{inputComponent}
|
|
615
|
-
</Form.Item>
|
|
616
|
-
);
|
|
617
|
-
})}
|
|
618
|
-
</Form>
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* 渲染组件
|
|
624
|
-
* @returns 组件 JSX 元素
|
|
625
|
-
*/
|
|
626
|
-
render() {
|
|
627
|
-
const {
|
|
628
|
-
title,
|
|
629
|
-
dataSource,
|
|
630
|
-
loading,
|
|
631
|
-
error,
|
|
632
|
-
pagination,
|
|
633
|
-
isModalVisible,
|
|
634
|
-
isEditMode,
|
|
635
|
-
} = this.state;
|
|
636
|
-
const curAmisData = this.props.data || {};
|
|
637
|
-
const systemInfo = curAmisData.__NeoSystemInfo || {};
|
|
638
|
-
const columns = this.generateColumns();
|
|
639
|
-
|
|
640
|
-
return (
|
|
641
|
-
<div className="xobject-table-container">
|
|
642
|
-
<Card>
|
|
643
|
-
<div className="table-header">
|
|
644
|
-
<div className="header-content">
|
|
645
|
-
<h3 className="header-title">
|
|
646
|
-
{title || '数据表格'}
|
|
647
|
-
{systemInfo.tenantName ? `【${systemInfo.tenantName}】` : ''}
|
|
648
|
-
</h3>
|
|
649
|
-
<Space>
|
|
650
|
-
{this.props.showAddButton && (
|
|
651
|
-
<Button
|
|
652
|
-
type="primary"
|
|
653
|
-
icon={<PlusOutlined />}
|
|
654
|
-
onClick={this.handleAdd}
|
|
655
|
-
disabled={!this.props.xObjectApiKey}
|
|
656
|
-
>
|
|
657
|
-
新增
|
|
658
|
-
</Button>
|
|
659
|
-
)}
|
|
660
|
-
<Button
|
|
661
|
-
icon={<ReloadOutlined />}
|
|
662
|
-
onClick={() =>
|
|
663
|
-
this.loadData(pagination.current, pagination.pageSize)
|
|
664
|
-
}
|
|
665
|
-
loading={loading}
|
|
666
|
-
>
|
|
667
|
-
刷新
|
|
668
|
-
</Button>
|
|
669
|
-
</Space>
|
|
670
|
-
</div>
|
|
671
|
-
</div>
|
|
672
|
-
|
|
673
|
-
<div className="table-content">
|
|
674
|
-
<Spin spinning={loading} tip="加载数据中...">
|
|
675
|
-
{error ? (
|
|
676
|
-
<Empty
|
|
677
|
-
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
678
|
-
description={
|
|
679
|
-
<div>
|
|
680
|
-
<div style={{ color: '#ff4d4f', marginBottom: 8 }}>
|
|
681
|
-
{error}
|
|
682
|
-
</div>
|
|
683
|
-
<Button
|
|
684
|
-
type="primary"
|
|
685
|
-
onClick={() =>
|
|
686
|
-
this.loadData(pagination.current, pagination.pageSize)
|
|
687
|
-
}
|
|
688
|
-
>
|
|
689
|
-
重新加载
|
|
690
|
-
</Button>
|
|
691
|
-
</div>
|
|
692
|
-
}
|
|
693
|
-
/>
|
|
694
|
-
) : (
|
|
695
|
-
<Table
|
|
696
|
-
columns={columns}
|
|
697
|
-
dataSource={dataSource}
|
|
698
|
-
rowKey="id"
|
|
699
|
-
pagination={{
|
|
700
|
-
...pagination,
|
|
701
|
-
showSizeChanger: true,
|
|
702
|
-
showQuickJumper: true,
|
|
703
|
-
showTotal: (total, range) =>
|
|
704
|
-
`第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
|
705
|
-
}}
|
|
706
|
-
onChange={this.handleTableChange}
|
|
707
|
-
scroll={{ x: 'max-content' }}
|
|
708
|
-
/>
|
|
709
|
-
)}
|
|
710
|
-
</Spin>
|
|
711
|
-
</div>
|
|
712
|
-
</Card>
|
|
713
|
-
|
|
714
|
-
<Modal
|
|
715
|
-
title={isEditMode ? `编辑${title}` : `新增${title}`}
|
|
716
|
-
visible={isModalVisible}
|
|
717
|
-
onOk={this.handleModalOk}
|
|
718
|
-
onCancel={this.handleModalCancel}
|
|
719
|
-
cancelText="取消"
|
|
720
|
-
okText="确定"
|
|
721
|
-
width={600}
|
|
722
|
-
destroyOnClose
|
|
723
|
-
>
|
|
724
|
-
{this.renderForm()}
|
|
725
|
-
</Modal>
|
|
726
|
-
</div>
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
}
|