wsj
3 days ago 71719ffa0eeb4a28a1b736f87499bcda2847a848
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Button, Space, Tag } from 'antd';
import type { ProColumns } from '@ant-design/pro-components';
import type { XxxRecord, XxxStatus } from './types';
 
const statusMeta: Record<XxxStatus, { text: string; color: string }> = {
  active: { text: '启用', color: 'success' },
  disabled: { text: '停用', color: 'default' },
};
 
export const createXxxColumns = (options: {
  onEdit?: (record: XxxRecord) => void;
  onDelete: (record: XxxRecord) => void;
}): ProColumns<XxxRecord>[] => [
  {
    title: '名称',
    dataIndex: 'name',
    width: 240,
    fieldProps: { placeholder: '请输入名称' },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 110,
    valueEnum: {
      active: { text: '启用' },
      disabled: { text: '停用' },
    },
    render: (_value, record) => (
      <Tag color={statusMeta[record.status].color} bordered={false}>
        {statusMeta[record.status].text}
      </Tag>
    ),
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    width: 170,
    search: false,
  },
  {
    title: '操作',
    key: 'action',
    valueType: 'option',
    width: 140,
    render: (_value, record) => (
      <Space size={0}>
        {options.onEdit && (
          <Button type="link" size="small" onClick={() => options.onEdit?.(record)}>
            编辑
          </Button>
        )}
        <Button type="link" size="small" danger onClick={() => options.onDelete(record)}>
          删除
        </Button>
      </Space>
    ),
  },
];