Commit be4eb0f5 authored by Bill's avatar Bill

fix: 修改详情页列展示组件

parent 3bde83cd
/** /*
* 详情页分裂显示, * @Author: XieZhiXiong
* 这里类似table 组件, 同样有column * @Date: 2021-05-11 10:46:57
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-05-11 15:46:24
* @Description: 申请单基础信息
*/ */
import React from 'react'; import React, { CSSProperties } from 'react';
import { Descriptions } from 'antd';
import MellowCard, { MellowCardProps } from '@/components/MellowCard'; import MellowCard, { MellowCardProps } from '@/components/MellowCard';
import styles from './index.less'; import styles from './index.less';
import cx from 'classnames';
type ColumnType = { export interface ColumnProps {
dataIndex: string, span?: number,
title: string, contentStyle?: CSSProperties,
render?: (value?: any, record?: any, dataIndex?: string) => React.ReactNode labelStyle?: CSSProperties,
} }
interface Iprops extends MellowCardProps { export interface DataItem {
/** /**
* * 标题
*/ */
columns: { [key: string]: ColumnType[] }, title: React.ReactNode,
/** /**
* 数据 * 值
*/
value: React.ReactNode,
/**
* DescriptionItem props
*/ */
dataSource: { columnProps?: ColumnProps,
[key: string]: any
}
} }
const CustomizeColumn: React.FC<Iprops> = (props: Iprops) => { interface IProps extends MellowCardProps {
const { columns, dataSource, ...rest } = props; /**
* 数据
*/
data: DataItem[],
/**
* column
*/
column: number
};
const defaultColumnProps: ColumnProps = {
labelStyle: {
width: 104,
},
};
const CustomizeColumn: React.FC<IProps> = (props: IProps) => {
const { data, column, ...rest } = props;
return ( return (
<MellowCard {...rest}> <MellowCard
<div className={styles.container}> bodyStyle={{
{ paddingBottom: 0,
Object.keys(columns).map((_item) => { }}
return ( // className={styles.basicInfo}
<div className={styles.col} key={_item}> {...rest}
{ >
columns[_item].map((_row, index) => { <Descriptions column={column}>
const length = columns[_item].length; {data.map((item, index) => (
return ( <Descriptions.Item
<div className={cx(styles.row, { [styles.lastRow]: index === length - 1 })} key={_row.dataIndex}> key={index}
<span className={styles.title}>{_row.title}</span> label={item.title}
{ {...({...defaultColumnProps, ...item.columnProps} || defaultColumnProps)}
_row.render && (_row.render(dataSource[_row.dataIndex], dataSource, _row.dataIndex)) >
|| (<span>{dataSource[_row.dataIndex]}</span>) {item.value}
} </Descriptions.Item>
</div> ))}
) </Descriptions>
})
}
</div>
)
})
}
</div>
</MellowCard> </MellowCard>
) );
} };
export default CustomizeColumn export default CustomizeColumn;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment