import React, { useMemo, useState } from 'react'; import classNames from 'classnames'; import Skeleton from 'antd/es/skeleton'; import 'antd/es/skeleton/style/index'; import Row from 'antd/es/row'; import Col from 'antd/es/col'; import 'antd/es/grid/style/index'; import Tooltip from 'antd/es/tooltip'; import 'antd/es/tooltip/style/index'; import Collapse from 'antd/es/collapse'; import 'antd/es/collapse/style/index'; import { tableScroll, inspectEllipsisQuick } from '@jy-fe/utils/es/joyowoUmi'; import XuiListPage from '../xui-list-page'; import { XuiDetailInformationProps } from './xui-detail-information.d'; const XuiDetailInformation: React.FC = ({ title, buttonGroup, extra, type = 'info', info, grid = 3, rowKey = 'id', columns = [], dataSource = [], paginationConfig, list, border, footerInfo, loading, listCollapseData, }) => { const className = 'xui-ant__detail-information'; const [visible, setVisible] = useState(false); const [overClassName, setOverClassName] = useState(''); /** info模式下 组装基本信息/图片信息展示 */ const getColItems = () => { if (!info) { return []; } if (type === 'info') { return info.map((data, index) => { if (data.type === 'pictures') { return ( {data.label} {(data.content as string[]).map(item => ( {item} window.open(item)} /> ))} ); } const currentParentClassNameNoEllipsis = `${className}--body--col_no-ellipsis`; const currentClassNameNoEllipsis = `${className}--body--col--content_no-ellipsis`; if (data.noEllipsis) { return ( {data.label} {data.hasLineBreak ? ( {data.content} ) : ( {data.content} )} ); } const currentParentClassName = `${className}--body--col`; const currentClassName = `${className}--body--col--content`; const currentClassNameIndex = `${className}--body--col--content${index}`; return ( {data.label} { if (inspectEllipsisQuick(e.currentTarget)) { setVisible(true); setOverClassName(currentClassNameIndex); } }} onMouseLeave={() => { setVisible(false); }} onFocus={() => {}} onBlur={() => {}} > {data.content} ); }); } if (type === 'picture') { return (info as { label: string; content: string }[]).map(data => { const extraProps = { className: classNames({ [`${className}--body--pic--item--img`]: true, [`${className}--body--pic--item--imgNormal`]: true, }), } as { className: string; href?: string }; if (data.content) { extraProps.className = `${className}--body--pic--item--img`; extraProps.href = data.content as string; } return (
{data.label}
{data.content && }
); }); } return []; }; /** 组装尾部信息展示 */ const FooterItems = useMemo(() => { if (!footerInfo) { return []; } return footerInfo.map((data: { label: string; content: string }) => (
{data.label} {data.content}
)); }, [footerInfo]); /** list模式下 组装多个基本信息展示 */ const ListItems = useMemo(() => { if (!list) { return []; } if (type === 'list') { const Items: JSX.Element[][] = []; list.forEach(data => { Items.push( data.map((child: { label: string; content: string }) => ( {child.label} {child.content} )), ); }); return Items; } return []; }, [list, type, columns]); /** listTable模式下 组装多个表格展示 */ const ListTable = useMemo(() => { if (!list) { return []; } if (type === 'listTable') { const Items: JSX.Element[] = []; list.forEach((data, index: number) => { const { columns: newColumns, scroll } = tableScroll({ oldColumns: columns, dataSource: data.dataSource, }); delete scroll?.y; Items.push(
{data.title && (
{data.title}
)}
, ); }); return Items; } return []; }, [list, type, columns, rowKey]); const ListCollapse = useMemo(() => { return listCollapseData?.map(item => (
{item.title} {item.headerExtra}
} key='1' disabled={!item.canExpand} showArrow={!!item.canExpand} > {item.content} )); }, [listCollapseData]); const { columns: newColumns, scroll } = useMemo( () => tableScroll({ oldColumns: columns, dataSource }), [dataSource, columns], ); delete scroll?.y; return (
{title && (
{title}
{buttonGroup &&
{buttonGroup}
}
)} {extra &&
{extra}
}
{type === 'info' && ( {getColItems()} {FooterItems} )} {type === 'table' && (
)} {type === 'picture' &&
{getColItems()}
} {type === 'picture' &&
{getColItems()}
} {type === 'list' && ListItems.map((data, index) => ( // eslint-disable-next-line react/no-array-index-key
{`${title}${index + 1}`}
{data}
))} {type === 'listTable' && ListTable} {type !== 'info' && FooterItems} {type === 'listCollapse' && ListCollapse}
); }; export default XuiDetailInformation;