import React, { useState } from 'react'; import { PlusOutlined } from '@ant-design/icons'; import { Button, Tabs, Tag, Space, message } from 'antd'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions'; import type { ProColumns } from '@ant-design/pro-table'; import ProTable, { TableDropdown } from '@ant-design/pro-table'; import request from 'umi-request'; type GithubIssueItem = { url: string; id: number; number: number; title: string; labels: { name: string; color: string; }[]; state: string; comments: number; created_at: string; updated_at: string; closed_at?: string; }; const columns: ProColumns[] = [ { title: '序号', dataIndex: 'index', width: 64, valueType: 'indexBorder', }, { title: '标题', dataIndex: 'title', copyable: true, ellipsis: true, search: false, }, { title: (_, type) => (type === 'table' ? '状态' : '列表状态'), dataIndex: 'state', initialValue: 'all', filters: true, onFilter: true, valueType: 'select', valueEnum: { all: { text: '全部', status: 'Default' }, open: { text: '未解决', status: 'Error', }, closed: { text: '已解决', status: 'Success', }, }, }, { title: '排序方式', key: 'direction', hideInTable: true, hideInDescriptions: true, dataIndex: 'direction', filters: true, onFilter: true, valueType: 'select', valueEnum: { asc: '正序', desc: '倒序', }, }, { title: '标签', dataIndex: 'labels', width: 120, render: (_, row) => ( {row.labels.map(({ name, color }) => ( {name} ))} ), }, { title: '创建时间', key: 'since', dataIndex: 'created_at', valueType: 'dateTime', }, { title: 'option', valueType: 'option', dataIndex: 'id', render: (text, row) => [ 查看 , message.info(key)} menus={[ { key: 'copy', name: '复制' }, { key: 'delete', name: '删除' }, ]} />, ], }, ]; export default () => { const [type, setType] = useState('table'); return ( <> setType(e)}> {['table', 'form'].includes(type) && ( columns={columns} type={type as 'table'} request={async (params = {}) => request<{ data: GithubIssueItem[]; }>('https://proapi.azurewebsites.net/github/issues', { params, }) } pagination={{ pageSize: 5, }} rowKey="id" dateFormatter="string" headerTitle="查询 Table" toolBarRender={() => [ , ]} /> )} {type === 'descriptions' && ( []} request={async (params) => { const msg = await request<{ data: GithubIssueItem[]; }>('https://proapi.azurewebsites.net/github/issues', { params, }); return { ...msg, data: msg?.data[0], }; }} /> )} ); };