import React from 'react'; import { Button, Tooltip, Tag } from 'antd'; import { DownOutlined, QuestionCircleOutlined, EllipsisOutlined } from '@ant-design/icons'; import type { ProColumns } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; export type Status = { color: string; text: string; }; const statusMap = { 0: { color: 'blue', text: '进行中', }, 1: { color: 'green', text: '已完成', }, 2: { color: 'volcano', text: '警告', }, 3: { color: 'red', text: '失败', }, 4: { color: '', text: '未完成', }, }; export type TableListItem = { key: number; name: string; containers: number; creator: string; status: Status; createdAt: number; }; const tableListDataSource: TableListItem[] = []; const creators = ['付小小', '曲丽丽', '林东东', '陈帅帅', '兼某某']; for (let i = 0; i < 5; i += 1) { tableListDataSource.push({ key: i, name: 'AppName', containers: Math.floor(Math.random() * 20), creator: creators[Math.floor(Math.random() * creators.length)], status: statusMap[Math.floor(Math.random() * 10) % 5], createdAt: Date.now() - Math.floor(Math.random() * 100000), }); } const columns: ProColumns[] = [ { title: '应用名称', width: 120, dataIndex: 'name', render: (_) => {_}, }, { title: '状态', width: 120, dataIndex: 'status', render: (_, record) => {record.status.text}, }, { title: '容器数量', width: 120, dataIndex: 'containers', align: 'right', sorter: (a, b) => a.containers - b.containers, }, { title: '创建者', width: 120, dataIndex: 'creator', valueEnum: { all: { text: '全部' }, 付小小: { text: '付小小' }, 曲丽丽: { text: '曲丽丽' }, 林东东: { text: '林东东' }, 陈帅帅: { text: '陈帅帅' }, 兼某某: { text: '兼某某' }, }, }, { title: ( <> 创建时间 ), width: 140, key: 'since', dataIndex: 'createdAt', valueType: 'date', sorter: (a, b) => a.createdAt - b.createdAt, }, { title: '操作', width: 164, key: 'option', valueType: 'option', render: () => [ 链路, 报警, 监控, , ], }, ]; const expandedRowRender = () => { const data = []; for (let i = 0; i < 3; i += 1) { data.push({ key: i, date: '2014-12-24 23:12:00', name: 'This is production name', upgradeNum: 'Upgraded: 56', }); } return ( [Pause, Stop], }, ]} headerTitle={false} search={false} options={false} dataSource={data} pagination={false} /> ); }; export default () => { return ( columns={columns} request={(params, sorter, filter) => { // 表单搜索项会从 params 传入,传递给后端接口。 console.log(params, sorter, filter); return Promise.resolve({ data: tableListDataSource, success: true, }); }} rowKey="key" pagination={{ showQuickJumper: true, }} expandable={{ expandedRowRender }} search={false} dateFormatter="string" headerTitle="嵌套表格" options={false} toolBarRender={() => [ , , , ]} /> ); };