|
@@ -1,7 +1,7 @@
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
import { Button, Input, Table } from 'antd';
|
|
import { Button, Input, Table } from 'antd';
|
|
import { ColumnsType } from 'antd/lib/table';
|
|
import { ColumnsType } from 'antd/lib/table';
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
+import React, { useState } from 'react';
|
|
import DDDateField from '@/components/DDComponents/DDDateField';
|
|
import DDDateField from '@/components/DDComponents/DDDateField';
|
|
import DDSelectField from '@/components/DDComponents/DDSelectField';
|
|
import DDSelectField from '@/components/DDComponents/DDSelectField';
|
|
import NumberField from '@/components/DDComponents/NumberField';
|
|
import NumberField from '@/components/DDComponents/NumberField';
|
|
@@ -30,13 +30,17 @@ function DIYTable(props: IProps) {
|
|
// table数据
|
|
// table数据
|
|
const [tableData, setTableData] = useState<TableDataType[]>([{ index: 1 }]);
|
|
const [tableData, setTableData] = useState<TableDataType[]>([{ index: 1 }]);
|
|
// table 列配置
|
|
// table 列配置
|
|
- const [tableColumnDef, setTableColumnDef] = useState<ColumnsType<any>>([
|
|
|
|
|
|
+ // const [tableColumnDef, setTableColumnDef] = useState<ColumnsType<any>>([
|
|
|
|
+ //
|
|
|
|
+ // ]);
|
|
|
|
+
|
|
|
|
+ const tableColumnDef: ColumnsType<any> = [
|
|
{
|
|
{
|
|
title: '序号',
|
|
title: '序号',
|
|
dataIndex: 'index',
|
|
dataIndex: 'index',
|
|
className: 'hidden',
|
|
className: 'hidden',
|
|
},
|
|
},
|
|
- ]);
|
|
|
|
|
|
+ ];
|
|
|
|
|
|
// 表单填写时的表格生成
|
|
// 表单填写时的表格生成
|
|
const handleGenerateTable = () => {
|
|
const handleGenerateTable = () => {
|
|
@@ -140,7 +144,6 @@ function DIYTable(props: IProps) {
|
|
const handleDisplayOnly = () => {
|
|
const handleDisplayOnly = () => {
|
|
const rows = columns;
|
|
const rows = columns;
|
|
const newTableData = [];
|
|
const newTableData = [];
|
|
- const newColumnDef: ColumnsType<any> = [];
|
|
|
|
if (rows && columns.length) {
|
|
if (rows && columns.length) {
|
|
for (let index = 0; index < rows.length; index++) {
|
|
for (let index = 0; index < rows.length; index++) {
|
|
// 把每一行的数据提出来到一个对象里
|
|
// 把每一行的数据提出来到一个对象里
|
|
@@ -150,7 +153,7 @@ function DIYTable(props: IProps) {
|
|
if (index === 0) {
|
|
if (index === 0) {
|
|
// 列配置
|
|
// 列配置
|
|
row.forEach((col: any) => {
|
|
row.forEach((col: any) => {
|
|
- newColumnDef.push({ title: col.name, dataIndex: col.type });
|
|
|
|
|
|
+ tableColumnDef.push({ title: col.name, dataIndex: col.type });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
const rowData: any = {};
|
|
const rowData: any = {};
|
|
@@ -158,10 +161,9 @@ function DIYTable(props: IProps) {
|
|
rowData[col.type] = col.value[0];
|
|
rowData[col.type] = col.value[0];
|
|
rowData.key = col.id + index;
|
|
rowData.key = col.id + index;
|
|
});
|
|
});
|
|
- newTableData.push(rowData);
|
|
|
|
|
|
+ tableColumnDef.push(rowData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- setTableColumnDef(newColumnDef);
|
|
|
|
setTableData(newTableData);
|
|
setTableData(newTableData);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -170,13 +172,11 @@ function DIYTable(props: IProps) {
|
|
setTableData([...tableData, { index: tableData.length + 1 }]);
|
|
setTableData([...tableData, { index: tableData.length + 1 }]);
|
|
};
|
|
};
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (displayOnly) {
|
|
|
|
- handleDisplayOnly();
|
|
|
|
- } else {
|
|
|
|
- handleGenerateTable();
|
|
|
|
- }
|
|
|
|
- }, []);
|
|
|
|
|
|
+ if (displayOnly) {
|
|
|
|
+ handleDisplayOnly();
|
|
|
|
+ } else {
|
|
|
|
+ handleGenerateTable();
|
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|