Demos#
#Code Demo
#Basic Usage
Issue 管理
标题 | 状态 | 标签 | 创建时间 | 操作 | |
|---|---|---|---|---|---|
暂无数据 | |||||
Query Table
import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button, Dropdown, message, Space, Tag } from 'antd';
import { useRef } from 'react';
import request from 'umi-request';
export const waitTimePromise = async (time: number = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
export const waitTime = async (time: number = 100) => {
await waitTimePromise(time);
};
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<GithubIssueItem>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
width: 48,
},
{
title: '标题',
dataIndex: 'title',
copyable: true,
ellipsis: true,
tooltip: '标题过长会自动收缩',
formItemProps: {
rules: [
{
required: true,
message: '此项为必填项',
},
],
},
},
{
disable: true,
title: '状态',
dataIndex: 'state',
filters: true,
onFilter: true,
ellipsis: true,
valueType: 'select',
valueEnum: {
all: { text: '超长'.repeat(50) },
open: {
text: '未解决',
status: 'Error',
},
closed: {
text: '已解决',
status: 'Success',
disabled: true,
},
processing: {
text: '处理中',
status: 'Processing',
},
},
},
{
disable: true,
title: '标签',
dataIndex: 'labels',
search: false,
formItemRender: (_, { defaultRender }) => {
return defaultRender(_);
},
render: (_, record) => (
<Space>
{record.labels.map(({ name, color }) => (
<Tag color={color} key={name}>
{name}
</Tag>
))}
</Space>
),
},
{
title: '创建时间',
key: 'showTime',
dataIndex: 'created_at',
valueType: 'date',
sorter: true,
search: false,
},
{
title: '创建时间',
dataIndex: 'created_at',
valueType: 'dateRange',
hideInTable: true,
search: {
transform: (value) => {
return {
startTime: value[0],
endTime: value[1],
};
},
},
},
{
title: '操作',
valueType: 'option',
key: 'option',
render: (text, record, _, action) => [
<a
key="editable"
onClick={() => {
action?.startEditable?.(record.id);
}}
>
编辑
</a>,
<a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
查看
</a>,
<TableDropdown
key="actionGroup"
onSelect={() => action?.reload()}
menus={[
{ key: 'copy', name: '复制' },
{ key: 'delete', name: '删除' },
]}
/>,
],
},
];
const Demo = () => {
const actionRef = useRef<ActionType>();
return (
<ProTable<GithubIssueItem>
columns={columns}
actionRef={actionRef}
cardBordered
request={async (params) => {
await waitTime(2000);
return request<{
data: GithubIssueItem[];
}>('https://proapi.azurewebsites.net/github/issues', {
params,
});
}}
editable={{
type: 'multiple',
}}
columnsState={{
persistenceKey: 'pro-table-singe-demos',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
onChange: () => {
message.info('列设置已更新');
},
}}
rowKey="id"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 400,
},
}}
form={{
syncToUrl: (values, type) => {
if (type === 'get') {
return {
...values,
created_at: [values.startTime, values.endTime],
};
}
return values;
},
}}
pagination={{
pageSize: 5,
onChange: (page, pageSize) => {
message.info(`第 ${page} 页${pageSize ? `,每页 ${pageSize} 条` : ''}`);
},
}}
dateFormatter="string"
headerTitle="Issue 管理"
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
actionRef.current?.reload();
}}
type="primary"
>
新建
</Button>,
<Dropdown
key="menu"
menu={{
items: [
{ label: '导入数据', key: 'import' },
{ label: '导出数据', key: 'export' },
{ label: '批量分配', key: 'assign' },
],
}}
>
<Button>
<EllipsisOutlined />
</Button>
</Dropdown>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
Table without Search Form
import { DownOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button } from 'antd';
import {
createTableDataSource,
DEMO_CREATOR_VALUE_ENUM,
DEMO_STATUS_VALUE_ENUM,
} from '../mockData';
export type TableListItem = {
key: number;
name: string;
containers: number;
creator: string;
status: string;
createdAt: number;
memo: string;
};
const tableListDataSource = createTableDataSource({
count: 5,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '应用名称',
width: 120,
dataIndex: 'name',
render: (_) => <a>{_}</a>,
},
{
title: '容器数量',
dataIndex: 'containers',
align: 'right',
sorter: (a, b) => a.containers - b.containers,
},
{
title: '状态',
width: 80,
dataIndex: 'status',
initialValue: 'all',
valueEnum: DEMO_STATUS_VALUE_ENUM,
},
{
title: '负责人',
width: 80,
dataIndex: 'creator',
valueEnum: DEMO_CREATOR_VALUE_ENUM,
},
{
title: '操作',
width: 180,
key: 'option',
valueType: 'option',
render: () => [
<a key="detail">详情</a>,
<a key="log">日志</a>,
<a key="monitor">监控</a>,
<TableDropdown
key="actionGroup"
menus={[
{ key: 'restart', name: '重启' },
{ key: 'delete', name: '下线' },
]}
/>,
],
},
];
const Demo = () => {
return (
<ProTable<TableListItem>
dataSource={tableListDataSource}
rowKey="key"
pagination={{
showQuickJumper: true,
}}
columns={columns}
search={false}
dateFormatter="string"
headerTitle="微服务应用列表"
toolBarRender={() => [
<Button key="log">查看日志</Button>,
<Button key="export">
导出数据
<DownOutlined />
</Button>,
<Button type="primary" key="primary">
部署应用
</Button>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);