import React, { useEffect, useState } from 'react'; import type { BadgeProps } from 'antd'; import { Button, Badge } from 'antd'; import type { ProColumns } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; import ProCard from '@ant-design/pro-card'; // @ts-ignore import styles from './split.less'; type TableListItem = { createdAtRange?: number[]; createdAt: number; code: string; }; type DetailListProps = { ip: string; }; const DetailList: React.FC = (props) => { const { ip } = props; const [tableListDataSource, setTableListDataSource] = useState([]); const columns: ProColumns[] = [ { title: '时间点', key: 'createdAt', dataIndex: 'createdAt', valueType: 'dateTime', }, { title: '代码', key: 'code', width: 80, dataIndex: 'code', valueType: 'code', }, { title: '操作', key: 'option', width: 80, valueType: 'option', render: () => [预警], }, ]; useEffect(() => { const source = []; for (let i = 0; i < 15; i += 1) { source.push({ createdAt: Date.now() - Math.floor(Math.random() * 10000), code: `const getData = async params => { const data = await getData(params); return { list: data.data, ...data }; };`, key: i, }); } setTableListDataSource(source); }, [ip]); return ( columns={columns} dataSource={tableListDataSource} pagination={{ pageSize: 3, showSizeChanger: false, }} rowKey="key" toolBarRender={false} search={false} /> ); }; type statusType = BadgeProps['status']; const valueEnum: statusType[] = ['success', 'error', 'processing', 'default']; export type IpListItem = { ip?: string; cpu?: number | string; mem?: number | string; disk?: number | string; status: statusType; }; const ipListDataSource: IpListItem[] = []; for (let i = 0; i < 10; i += 1) { ipListDataSource.push({ ip: `106.14.98.1${i}4`, cpu: 10, mem: 20, status: valueEnum[Math.floor(Math.random() * 10) % 4], disk: 30, }); } type IPListProps = { ip: string; onChange: (id: string) => void; }; const IPList: React.FC = (props) => { const { onChange, ip } = props; const columns: ProColumns[] = [ { title: 'IP', key: 'ip', dataIndex: 'ip', render: (_, item) => { return ; }, }, { title: 'CPU', key: 'cpu', dataIndex: 'cpu', valueType: { type: 'percent', precision: 0, }, }, { title: 'Mem', key: 'mem', dataIndex: 'mem', valueType: { type: 'percent', precision: 0, }, }, { title: 'Disk', key: 'disk', dataIndex: 'disk', valueType: { type: 'percent', precision: 0, }, }, ]; return ( columns={columns} request={(params, sorter, filter) => { // 表单搜索项会从 params 传入,传递给后端接口。 console.log(params, sorter, filter); return Promise.resolve({ data: ipListDataSource, success: true, }); }} rowKey="ip" rowClassName={(record) => { return record.ip === ip ? styles['split-row-select-active'] : ''; }} toolbar={{ search: { onSearch: (value) => { alert(value); }, }, actions: [ , ], }} options={false} pagination={false} search={false} onRow={(record) => { return { onClick: () => { if (record.ip) { onChange(record.ip); } }, }; }} /> ); }; const Demo: React.FC = () => { const [ip, setIp] = useState('0.0.0.0'); return ( setIp(cIp)} ip={ip} /> ); }; export default Demo;