index.tsx
1.56 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
import React from 'react';
import { Table } from 'antd';
import type { TableProps } from 'antd';
import * as commonUtils from '@/utils/utils';
import style from './index.less';
interface PropsType {
data: TableProps['dataSource'];
headerColumn: TableProps['columns'];
}
const TableNew: React.FC<PropsType> = (props) => {
const tableProps = {
columns: TableHeader(props),
dataSource: TableData(props),
scroll: {
// x: 'max-content',
y: '100%',
}
};
return (
<div className={style.tableNew}>
<Table<TableProps> {...tableProps} />
</div>
);
};
// 处理数据
const TableData = (props: PropsType): PropsType['data'] => {
const { data = [] } = props;
return data;
}
// 处理表头
const TableHeader = (props: PropsType): PropsType['headerColumn'] => {
const { headerColumn = [], data = [] } = props;
return headerColumn.map((colunm) => {
colunm.ellipsis = true;
// colunm.textWrap = 'word-break',
if (!('dataIndex' in colunm)) return colunm;
const { dataIndex } = colunm;
if (dataIndex === 'sPartNameStatus') {
interface TextJsonItem {
sProcessName: string;
sState: number;
}
return {
...colunm,
render: (text: string, record: object) => {
const textJson: TextJsonItem[] = commonUtils.convertStrToObj(text.replace(",]", ']'), []) as TextJsonItem[];
console.log('=====xxx', text, textJson);
return textJson.map(item => item.sProcessName).join('->');
},
};
}
return colunm;
});
}
export default TableNew;