Skip to content

Commit aa749bc

Browse files
authored
💥 feat(department): Add user selection for department leader and upda… (#64)
1 parent 97593a9 commit aa749bc

File tree

6 files changed

+63
-25
lines changed

6 files changed

+63
-25
lines changed

config/routes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,31 @@ export default [
125125
},
126126
{
127127
icon: 'table',
128-
path: '/department',
128+
path: '/departments',
129129
routes: [
130130
{
131-
path: '/department',
131+
path: '/departments',
132132
hideInMenu: true,
133133
component: './Department',
134134
},
135135
{
136-
path: '/department/:id',
136+
path: '/departments/:id',
137137
hideInMenu: true,
138138
component: './Department',
139139
},
140140
],
141141
},
142142
{
143143
icon: 'table',
144-
path: '/post',
144+
path: '/posts',
145145
routes: [
146146
{
147-
path: '/post',
147+
path: '/posts',
148148
hideInMenu: true,
149149
component: './Post',
150150
},
151151
{
152-
path: '/post/:id',
152+
path: '/posts/:id',
153153
hideInMenu: true,
154154
component: './Post',
155155
},

src/locales/en-US/pages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export default {
176176
'pages.accessToken.settings.longTime': 'Long time',
177177
'pages.email.settings.title': 'Email Settings',
178178
'pages.security.settings.changePassword': 'Change Password',
179+
'pages.department.leader.placeholder': 'Please select leader',
179180
/****************** field ******************/
180181
'pages.fields.namespace': 'Namespace',
181182
'pages.fields.cluster': 'Cluster',

src/locales/zh-CN/pages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export default {
160160
'pages.accessToken.settings.longTime': '长期',
161161
'pages.email.settings.title': '邮件设置',
162162
'pages.security.settings.changePassword': '修改密码',
163+
'pages.department.leader.placeholder': '请选择负责人',
163164
/****************** field ******************/
164165
'pages.fields.namespace': '命名空间',
165166
'pages.fields.cluster': '集群',

src/pages/Department/index.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PlusOutlined } from '@ant-design/icons';
55
import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components';
66
import { PageContainer, ProDescriptions, ProTable } from '@ant-design/pro-components';
77
import { FormattedMessage, history, Link, useIntl, useParams } from '@umijs/max';
8-
import { Button, Drawer, message, Popconfirm, TreeSelect } from 'antd';
8+
import { Button, Drawer, message, Popconfirm, TreeSelect, Select } from 'antd';
99
import { DataNode } from 'antd/es/tree';
1010
import React, { useEffect, useRef, useState } from 'react';
1111
import { fieldIntl } from '@/util/fieldIntl';
@@ -17,9 +17,11 @@ import {
1717
putDepartmentsId,
1818
} from '@/services/admin/department';
1919
import { statusOptions } from '@/util/statusOptions';
20+
import { getUsers } from '@/services/admin/user';
2021

2122
const TableList: React.FC = () => {
2223
const [showDetail, setShowDetail] = useState<boolean>(false);
24+
const [userOptions, setUserOptions] = useState<{ label: string; value: string }[]>([]);
2325

2426
const actionRef = useRef<ActionType>();
2527
const [currentRow, setCurrentRow] = useState<API.Role>();
@@ -79,6 +81,23 @@ const TableList: React.FC = () => {
7981
{
8082
title: fieldIntl(intl, 'leaderID'),
8183
dataIndex: 'leaderID',
84+
render: (_, record) => {
85+
const leader = userOptions.find((user) => user.value === record.leaderID);
86+
return leader?.label || '-';
87+
},
88+
renderFormItem: () => (
89+
<Select
90+
showSearch
91+
placeholder={intl.formatMessage({
92+
id: 'pages.department.leader.placeholder',
93+
defaultMessage: '请选择负责人',
94+
})}
95+
options={userOptions}
96+
filterOption={(input, option) =>
97+
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
98+
}
99+
/>
100+
),
82101
},
83102
{
84103
title: fieldIntl(intl, 'phone'),
@@ -136,14 +155,14 @@ const TableList: React.FC = () => {
136155
hideInDescriptions: true,
137156
hideInForm: true,
138157
render: (_, record) => [
139-
<Access key="/department/edit">
140-
<Link to={`/department/${record.id}`} key="edit">
158+
<Access key="/departments/edit">
159+
<Link to={`/departments/${record.id}`} key="edit">
141160
<Button key="edit">
142161
<FormattedMessage id="pages.title.edit" defaultMessage="Edit" />
143162
</Button>
144163
</Link>
145164
</Access>,
146-
<Access key="/department/delete">
165+
<Access key="/departments/delete">
147166
<Popconfirm
148167
key="delete"
149168
title={intl.formatMessage({
@@ -224,6 +243,20 @@ const TableList: React.FC = () => {
224243
}
225244
}, [id]);
226245

246+
useEffect(() => {
247+
// 获取用户列表用于选择负责人
248+
getUsers({ pageSize: 1000 }).then((res) => {
249+
if (res.data) {
250+
setUserOptions(
251+
res.data.map((user) => ({
252+
label: user.name || user.username || '',
253+
value: user.id || '',
254+
})),
255+
);
256+
}
257+
});
258+
}, []);
259+
227260
return (
228261
<PageContainer title={indexTitle(id)}>
229262
<ProTable<API.Department, API.getDepartmentsParams>
@@ -239,8 +272,8 @@ const TableList: React.FC = () => {
239272
type={id ? 'form' : 'table'}
240273
onSubmit={id ? onSubmit : undefined}
241274
toolBarRender={() => [
242-
<Access key="/department/create">
243-
<Link to="/department/create" key="create">
275+
<Access key="/departments/create">
276+
<Link to="/departments/create" key="create">
244277
<Button type="primary" key="create">
245278
<PlusOutlined /> <FormattedMessage id="pages.table.new" defaultMessage="New" />
246279
</Button>

src/pages/Post/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { statusOptions } from '@/util/statusOptions';
1313
import { deletePostsId, getPosts, getPostsId, postPosts, putPostsId } from '@/services/admin/post';
1414
import { dataScopeOptions } from '@/util/dataScopeOptions';
1515

16-
const Index: React.FC = () => {
16+
const TableList: React.FC = () => {
1717
const [showDetail, setShowDetail] = useState<boolean>(false);
1818

1919
const actionRef = useRef<ActionType>();
@@ -103,14 +103,14 @@ const Index: React.FC = () => {
103103
hideInDescriptions: true,
104104
hideInForm: true,
105105
render: (_, record) => [
106-
<Access key="/post/edit">
107-
<Link to={`/post/${record.id}`} key="edit">
106+
<Access key="/posts/edit">
107+
<Link to={`/posts/${record.id}`} key="edit">
108108
<Button key="edit">
109109
<FormattedMessage id="pages.title.edit" defaultMessage="Edit" />
110110
</Button>
111111
</Link>
112112
</Access>,
113-
<Access key="/post/delete">
113+
<Access key="/posts/delete">
114114
<Popconfirm
115115
key="delete"
116116
title={intl.formatMessage({
@@ -206,12 +206,12 @@ const Index: React.FC = () => {
206206
type={id ? 'form' : 'table'}
207207
onSubmit={id ? onSubmit : undefined}
208208
toolBarRender={() => [
209-
<Access key="/post/create">
210-
<Link to="/post/create" key="create">
211-
<Button type="primary" key="create">
209+
<Access key="/posts/create">
210+
<Button type="primary" key="create">
211+
<Link type="primary" to="/posts/create" key="/posts/create">
212212
<PlusOutlined /> <FormattedMessage id="pages.table.new" defaultMessage="New" />
213-
</Button>
214-
</Link>
213+
</Link>
214+
</Button>
215215
</Access>,
216216
]}
217217
form={
@@ -265,4 +265,4 @@ const Index: React.FC = () => {
265265
);
266266
};
267267

268-
export default Index;
268+
export default TableList;

src/pages/Role/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const TableList: React.FC = () => {
209209

210210
return (
211211
<PageContainer title={indexTitle(id)}>
212-
<ProTable<API.Role, API.Page>
212+
<ProTable<API.Role, API.getRolesParams>
213213
headerTitle={intl.formatMessage({
214214
id: 'pages.role.list.title',
215215
defaultMessage: 'Role List',
@@ -238,9 +238,12 @@ const TableList: React.FC = () => {
238238
return res;
239239
},
240240
}
241-
: undefined
241+
: {
242+
initialValues: {
243+
status: 'enabled',
244+
},
245+
}
242246
}
243-
// @ts-ignore
244247
request={getRoles}
245248
columns={columns}
246249
/>

0 commit comments

Comments
 (0)