#CRUD
ProTable,ProDescriptions,ProForm 都是基于 ProField 来进行封装。ProTable 和 ProDescriptions 根据 valueType 来渲染不同的 ProField,Form 则是通过不同的 FormField 来实现封装。
使用同样的底层实现为 ProTable,ProDescriptions,ProForm 打通带来了便利。ProForm 可以很方便的实现只读模式,ProTable 可以快速实现查询表单和可编辑表格。ProDescriptions 可以实现节点编辑,以下有个例子可以切换三个组件。
import { PlusOutlined } from '@ant-design/icons';
import type {
ProColumns,
ProDescriptionsItemProps,
} from '@ant-design/pro-components';
import {
ProCard,
ProDescriptions,
ProTable,
TableDropdown,
} from '@ant-design/pro-components';
import { Button, Space, Tabs, Tag, message } from 'antd';
import { useState } from 'react';
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 MOCK_ISSUES: GithubIssueItem[] = [
{
url: 'https://github.com/ant-design/pro-components/issues/1',
id: 1,
number: 1,
title: 'ProTable 查询表单与可编辑表格联动',
labels: [
{ name: 'bug', color: 'error' },
{ name: 'table', color: 'processing' },
],
state: 'open',
comments: 3,
created_at: '2024-01-15T10:00:00Z',
updated_at: '2024-01-16T12:00:00Z',
},
{
url: 'https://github.com/ant-design/pro-components/issues/2',
id: 2,
number: 2,
title: 'ProForm 布局切换与只读模式',
labels: [{ name: 'feature', color: 'success' }],
state: 'closed',
comments: 8,
created_at: '2024-01-14T09:00:00Z',
updated_at: '2024-01-15T18:00:00Z',
closed_at: '2024-01-15T18:00:00Z',
},
{
url: 'https://github.com/ant-design/pro-components/issues/3',
id: 3,
number: 3,
title: 'ProDescriptions 支持节点编辑',
labels: [
{ name: 'docs', color: 'default' },
{ name: 'descriptions', color: 'processing' },
],
state: 'open',
comments: 1,
created_at: '2024-01-13T08:00:00Z',
updated_at: '2024-01-14T11:00:00Z',
},
{
url: 'https://github.com/ant-design/pro-components/issues/4',
id: 4,
number: 4,
title: 'Playground CRUD 三视图切换示例',
labels: [{ name: 'demo', color: 'warning' }],
state: 'closed',
comments: 5,
created_at: '2024-01-12T07:00:00Z',
updated_at: '2024-01-13T16:00:00Z',
closed_at: '2024-01-13T16:00:00Z',
},
{
url: 'https://github.com/ant-design/pro-components/issues/5',
id: 5,
number: 5,
title: 'LightFilter 工具栏扁平布局',
labels: [{ name: 'bug', color: 'error' }],
state: 'open',
comments: 2,
created_at: '2024-01-11T06:00:00Z',
updated_at: '2024-01-12T10:00:00Z',
},
];
async function fetchIssues(params: Record<string, any> = {}) {
const state = params.state;
const keyword = String(params.keyword ?? params.title ?? '')
.trim()
.toLowerCase();
let data = MOCK_ISSUES;
if (state && state !== 'all') {
data = data.filter((item) => item.state === state);
}
if (keyword) {
data = data.filter((item) => item.title.toLowerCase().includes(keyword));
}
return {
data,
success: true,
total: data.length,
};
}
const columns: ProColumns<GithubIssueItem>[] = [
{
title: '序号',
dataIndex: 'index',
width: 64,
valueType: 'indexBorder',
},
{
title: '