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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| import { Avatar, Button, Space, Tag } from 'antd';
| import type { ProColumns } from '@ant-design/pro-components';
| import type { EmployeeStatus, EmployeeVO, SelectOption } from './types';
|
| export const employeeStatusMeta: Record<EmployeeStatus, { text: string; color: string }> = {
| ACTIVE: { text: '启用', color: 'green' },
| DISABLED: { text: '禁用', color: 'default' },
| };
|
| /** 兼容后端返回 null、小写或未知状态:ACTIVE 与空值均为启用,仅 DISABLED 为禁用。 */
| export const getEmployeeStatusMeta = (status?: string | null) => {
| const key = String(status ?? '').toUpperCase();
|
| if (!key || key === 'ACTIVE') return employeeStatusMeta.ACTIVE;
| if (key === 'DISABLED') return employeeStatusMeta.DISABLED;
| return { text: status || '-', color: 'default' };
| };
|
| export const createUserColumns = (options: {
| orgOptions: SelectOption[];
| roleOptions: SelectOption[];
| orgNameMap: Map<number, string>;
| roleNameMap: Map<number, string>;
| onDetail: (record: EmployeeVO) => void;
| onEdit: (record: EmployeeVO) => void;
| onDelete: (record: EmployeeVO) => void;
| }): ProColumns<EmployeeVO>[] => [
| {
| title: '员工',
| dataIndex: 'name',
| width: 220,
| ellipsis: true,
| fieldProps: { placeholder: '姓名 / 手机号' },
| search: {
| transform: (value) => ({ keyword: value }),
| },
| render: (_value, record) => (
| <div className="user-cell">
| <Avatar className="user-cell__avatar" src={record.avatarUrl} size={36}>
| {record.name?.charAt(0)}
| </Avatar>
| <div className="user-cell__meta">
| <span className="user-cell__name">{record.name}</span>
| <span className="user-cell__username">{record.phone}</span>
| </div>
| </div>
| ),
| },
| {
| title: '所属组织',
| dataIndex: 'orgId',
| width: 170,
| valueType: 'select',
| fieldProps: {
| options: options.orgOptions,
| showSearch: true,
| optionFilterProp: 'label',
| allowClear: true,
| placeholder: '请选择组织',
| },
| render: (_value, record) =>
| options.orgNameMap.get(record.orgId) ?? (record.orgId ? `#${record.orgId}` : '-'),
| },
| {
| title: '角色',
| dataIndex: 'roleId',
| width: 150,
| valueType: 'select',
| fieldProps: {
| options: options.roleOptions,
| showSearch: true,
| optionFilterProp: 'label',
| allowClear: true,
| placeholder: '请选择角色',
| },
| render: (_value, record) =>
| options.roleNameMap.get(record.roleId) ?? (record.roleId ? `#${record.roleId}` : '-'),
| },
| {
| title: '职位',
| dataIndex: 'position',
| width: 120,
| search: false,
| render: (_value, record) => record.position || '-',
| },
| {
| title: '负责区域',
| dataIndex: 'region',
| width: 120,
| search: false,
| render: (_value, record) => record.region || '-',
| },
| {
| title: '客户上限',
| dataIndex: 'holdLimit',
| width: 100,
| search: false,
| render: (_value, record) => record.holdLimit ?? '-',
| },
| {
| title: '状态',
| dataIndex: 'status',
| width: 100,
| valueType: 'select',
| valueEnum: {
| ACTIVE: { text: '启用' },
| DISABLED: { text: '禁用' },
| },
| render: (_value, record) => {
| const meta = getEmployeeStatusMeta(record.status);
| return (
| <Tag color={meta.color} bordered={false}>
| {meta.text}
| </Tag>
| );
| },
| },
| {
| title: '入职日期',
| dataIndex: 'hireDate',
| width: 130,
| search: false,
| render: (_value, record) => record.hireDate || '-',
| },
| {
| title: '操作',
| key: 'action',
| valueType: 'option',
| width: 180,
| render: (_value, record) => (
| <Space size={0}>
| <Button type="link" size="small" onClick={() => options.onDetail(record)}>
| 详情
| </Button>
| <Button type="link" size="small" onClick={() => options.onEdit(record)}>
| 编辑
| </Button>
| <Button type="link" size="small" danger onClick={() => options.onDelete(record)}>
| 删除
| </Button>
| </Space>
| ),
| },
| ];
|
|