react-toolkits 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +8 -3
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -4
- package/.turbo/turbo-build.log +0 -20
- package/postcss.config.js +0 -9
- package/src/assets/512_orange_nobackground.png +0 -0
- package/src/components/DynamicTags/index.tsx +0 -160
- package/src/components/FilterForm/index.tsx +0 -63
- package/src/components/FormModal/hooks.tsx +0 -47
- package/src/components/FormModal/index.tsx +0 -137
- package/src/components/GameSelect/index.tsx +0 -83
- package/src/components/Highlight/index.tsx +0 -51
- package/src/components/Layout/index.tsx +0 -99
- package/src/components/NavMenu/index.tsx +0 -142
- package/src/components/PermissionButton/index.tsx +0 -36
- package/src/components/QueryList/index.tsx +0 -152
- package/src/components/ReactToolkitsProvider/context.ts +0 -76
- package/src/components/ReactToolkitsProvider/index.tsx +0 -23
- package/src/components/UserWidget/index.tsx +0 -46
- package/src/components/index.ts +0 -51
- package/src/constants/index.ts +0 -1
- package/src/features/permission/components/PermissionCollapse/index.tsx +0 -121
- package/src/features/permission/components/PermissionList/index.tsx +0 -28
- package/src/features/permission/components/PermissionListV1/index.tsx +0 -42
- package/src/features/permission/components/PermissionListV2/index.tsx +0 -146
- package/src/features/permission/hooks/index.ts +0 -140
- package/src/features/permission/index.ts +0 -5
- package/src/features/permission/types/index.ts +0 -40
- package/src/hooks/index.ts +0 -2
- package/src/hooks/use-http-client.ts +0 -85
- package/src/hooks/use-permission.ts +0 -75
- package/src/index.ts +0 -7
- package/src/pages/base/Login/default.tsx +0 -864
- package/src/pages/base/Login/index.tsx +0 -101
- package/src/pages/base/NotFound/index.tsx +0 -27
- package/src/pages/base/index.tsx +0 -20
- package/src/pages/index.ts +0 -4
- package/src/pages/permission/RoleDetail/index.tsx +0 -40
- package/src/pages/permission/RoleList/index.tsx +0 -251
- package/src/pages/permission/UserList/index.tsx +0 -236
- package/src/pages/permission/index.tsx +0 -56
- package/src/shims.d.ts +0 -20
- package/src/stores/index.ts +0 -2
- package/src/stores/query-list.ts +0 -61
- package/src/stores/token.ts +0 -39
- package/src/styles/index.css +0 -5
- package/src/types/index.ts +0 -10
- package/tailwind.config.js +0 -5
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -28
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { SSO_URL } from '@/constants'
|
|
2
|
-
import { useTokenStore } from '@/stores'
|
|
3
|
-
import { AliyunOutlined } from '@ant-design/icons'
|
|
4
|
-
import { Alert, Button, Card, Col, Divider, Row, Space, Typography } from 'antd'
|
|
5
|
-
import type { FC, PropsWithChildren } from 'react'
|
|
6
|
-
import { useEffect, useState } from 'react'
|
|
7
|
-
import { Navigate, useSearchParams } from 'react-router-dom'
|
|
8
|
-
import useSWRImmutable from 'swr/immutable'
|
|
9
|
-
import Default from './default'
|
|
10
|
-
import { useHttpClient } from '@/hooks'
|
|
11
|
-
|
|
12
|
-
const { Title } = Typography
|
|
13
|
-
|
|
14
|
-
const Login: FC<PropsWithChildren> = props => {
|
|
15
|
-
const { children } = props
|
|
16
|
-
const [searchParams, setSearchParams] = useSearchParams()
|
|
17
|
-
const token = useTokenStore(state => state.token)
|
|
18
|
-
const setToken = useTokenStore(state => state.setToken)
|
|
19
|
-
const [showAlert, setShowAlert] = useState(false)
|
|
20
|
-
const httpClient = useHttpClient()
|
|
21
|
-
|
|
22
|
-
useSWRImmutable<{ token: string }>(
|
|
23
|
-
searchParams.has('ticket')
|
|
24
|
-
? {
|
|
25
|
-
url: '/api/usystem/user/login',
|
|
26
|
-
params: {
|
|
27
|
-
ticket: searchParams.get('ticket'),
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
: null,
|
|
31
|
-
config => httpClient.request(config),
|
|
32
|
-
{
|
|
33
|
-
suspense: true,
|
|
34
|
-
onSuccess: data => {
|
|
35
|
-
setToken(data.token)
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (searchParams.has('not_registered')) {
|
|
42
|
-
setShowAlert(true)
|
|
43
|
-
searchParams.delete('not_registered')
|
|
44
|
-
setSearchParams(searchParams)
|
|
45
|
-
}
|
|
46
|
-
}, [searchParams, setSearchParams])
|
|
47
|
-
|
|
48
|
-
if (token) {
|
|
49
|
-
return <Navigate replace to="/" />
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Row>
|
|
54
|
-
<Col span={10} offset={3}>
|
|
55
|
-
<div className="h-screen flex justify-end items-center">
|
|
56
|
-
<Default />
|
|
57
|
-
</div>
|
|
58
|
-
</Col>
|
|
59
|
-
<Col span={5} offset={3}>
|
|
60
|
-
<div className="h-screen relative">
|
|
61
|
-
<Card hoverable className="absolute left-0 right-0 top-1/2 -translate-y-1/2">
|
|
62
|
-
{showAlert && (
|
|
63
|
-
<div className="absolute -top-12 left-0 right-0">
|
|
64
|
-
<Alert
|
|
65
|
-
banner
|
|
66
|
-
closable
|
|
67
|
-
message="您还未在平台注册,请联系管理员"
|
|
68
|
-
type="error"
|
|
69
|
-
onClose={() => {
|
|
70
|
-
setShowAlert(false)
|
|
71
|
-
}}
|
|
72
|
-
/>
|
|
73
|
-
</div>
|
|
74
|
-
)}
|
|
75
|
-
<div className="text-center mb-6">
|
|
76
|
-
<Title level={5}>登录方式</Title>
|
|
77
|
-
<div className="min-h-10">{children}</div>
|
|
78
|
-
</div>
|
|
79
|
-
<Divider plain>第三方登录方式</Divider>
|
|
80
|
-
<div className="w-full flex justify-center">
|
|
81
|
-
<Space size="small">
|
|
82
|
-
<Button
|
|
83
|
-
type="link"
|
|
84
|
-
size="small"
|
|
85
|
-
shape="round"
|
|
86
|
-
icon={<AliyunOutlined />}
|
|
87
|
-
href={`${SSO_URL}/login?service=${encodeURIComponent(window.location.origin)}/login`}
|
|
88
|
-
target="_self"
|
|
89
|
-
>
|
|
90
|
-
IDass 登录
|
|
91
|
-
</Button>
|
|
92
|
-
</Space>
|
|
93
|
-
</div>
|
|
94
|
-
</Card>
|
|
95
|
-
</div>
|
|
96
|
-
</Col>
|
|
97
|
-
</Row>
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default Login
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Button, Result } from 'antd'
|
|
2
|
-
import { useNavigate } from 'react-router-dom'
|
|
3
|
-
|
|
4
|
-
const NotFound = () => {
|
|
5
|
-
const navigate = useNavigate()
|
|
6
|
-
return (
|
|
7
|
-
<div className="h-screen flex justify-center items-center">
|
|
8
|
-
<Result
|
|
9
|
-
status="404"
|
|
10
|
-
title="404"
|
|
11
|
-
subTitle="访问的页面不存在"
|
|
12
|
-
extra={
|
|
13
|
-
<Button
|
|
14
|
-
type="primary"
|
|
15
|
-
onClick={() => {
|
|
16
|
-
navigate('/')
|
|
17
|
-
}}
|
|
18
|
-
>
|
|
19
|
-
返回页面
|
|
20
|
-
</Button>
|
|
21
|
-
}
|
|
22
|
-
/>
|
|
23
|
-
</div>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default NotFound
|
package/src/pages/base/index.tsx
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { lazy } from 'react'
|
|
2
|
-
import type { RouteObject } from 'react-router-dom'
|
|
3
|
-
|
|
4
|
-
const Login = lazy(() => import('./Login'))
|
|
5
|
-
const NotFound = lazy(() => import('./NotFound'))
|
|
6
|
-
|
|
7
|
-
const routes: RouteObject = {
|
|
8
|
-
children: [
|
|
9
|
-
{
|
|
10
|
-
path: 'login',
|
|
11
|
-
element: <Login />,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
path: '*',
|
|
15
|
-
element: <NotFound />,
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default routes
|
package/src/pages/index.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { PermissionList, useRole } from '@/features/permission'
|
|
2
|
-
import { Breadcrumb, Card, Descriptions, Skeleton } from 'antd'
|
|
3
|
-
import { Link, useParams } from 'react-router-dom'
|
|
4
|
-
|
|
5
|
-
const RoleDetail = () => {
|
|
6
|
-
const params = useParams()
|
|
7
|
-
const { data, isLoading } = useRole(params.name as string)
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<>
|
|
11
|
-
<Breadcrumb
|
|
12
|
-
style={{ marginBottom: 24 }}
|
|
13
|
-
items={[
|
|
14
|
-
{
|
|
15
|
-
key: '1',
|
|
16
|
-
title: <Link to="/permission/role">角色</Link>,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
key: '2',
|
|
20
|
-
title: params.name,
|
|
21
|
-
},
|
|
22
|
-
]}
|
|
23
|
-
/>
|
|
24
|
-
<Card title="权限详情">
|
|
25
|
-
<Skeleton loading={isLoading}>
|
|
26
|
-
<Descriptions column={3} layout="vertical">
|
|
27
|
-
<Descriptions.Item label="名称">{data?.name}</Descriptions.Item>
|
|
28
|
-
<Descriptions.Item label="ID">{data?.id}</Descriptions.Item>
|
|
29
|
-
<Descriptions.Item label="创建时间">{data?.ctime}</Descriptions.Item>
|
|
30
|
-
<Descriptions.Item label="权限" span={3}>
|
|
31
|
-
<PermissionList readonly value={data?.permissions} />
|
|
32
|
-
</Descriptions.Item>
|
|
33
|
-
</Descriptions>
|
|
34
|
-
</Skeleton>
|
|
35
|
-
</Card>
|
|
36
|
-
</>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default RoleDetail
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { Highlight, PermissionButton, QueryList, useReactToolkitsContext } from '@/components'
|
|
2
|
-
import { useFormModal } from '@/components/FormModal/hooks'
|
|
3
|
-
import type { RoleListItem, RoleV1, RoleV2 } from '@/features/permission'
|
|
4
|
-
import { PermissionList, useCreateRole, useRemoveRole, useUpdateRole } from '@/features/permission'
|
|
5
|
-
import { useHttpClient, usePermission } from '@/hooks'
|
|
6
|
-
import { useQueryListStore } from '@/stores'
|
|
7
|
-
import { UsergroupAddOutlined } from '@ant-design/icons'
|
|
8
|
-
import type { TableColumnsType } from 'antd'
|
|
9
|
-
import { App, Card, Form, Input, Space } from 'antd'
|
|
10
|
-
import { useCallback, useMemo } from 'react'
|
|
11
|
-
import { Link } from 'react-router-dom'
|
|
12
|
-
import type { ListResponse } from '@/types'
|
|
13
|
-
|
|
14
|
-
export const swrKey = {
|
|
15
|
-
url: '/api/usystem/role/list',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const useCreateModal = () => {
|
|
19
|
-
const { message } = App.useApp()
|
|
20
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
21
|
-
const create = useCreateRole()
|
|
22
|
-
|
|
23
|
-
const onConfirm = useCallback(
|
|
24
|
-
async (values: { name: string; permissions: RoleV1['permissions'] | RoleV2['permissions'] }) => {
|
|
25
|
-
await create.trigger(
|
|
26
|
-
{
|
|
27
|
-
name: `role_${values.name}`,
|
|
28
|
-
permissions: values.permissions,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
async onSuccess() {
|
|
32
|
-
await message.success('角色创建成功')
|
|
33
|
-
refresh(swrKey, { page: 1 })
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
},
|
|
38
|
-
[create, refresh, message],
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
return useFormModal<{
|
|
42
|
-
name: string
|
|
43
|
-
permissions: RoleV1['permissions'] | RoleV2['permissions']
|
|
44
|
-
}>({
|
|
45
|
-
title: '创建角色',
|
|
46
|
-
width: '50vw',
|
|
47
|
-
layout: 'vertical',
|
|
48
|
-
content: (
|
|
49
|
-
<>
|
|
50
|
-
<Form.Item label="名称" name="name" rules={[{ required: true }]}>
|
|
51
|
-
<Input addonBefore="role_" />
|
|
52
|
-
</Form.Item>
|
|
53
|
-
<Form.Item label="权限" name="permissions">
|
|
54
|
-
<PermissionList />
|
|
55
|
-
</Form.Item>
|
|
56
|
-
</>
|
|
57
|
-
),
|
|
58
|
-
onConfirm,
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const useUpdateModal = () => {
|
|
63
|
-
const { message } = App.useApp()
|
|
64
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
65
|
-
const update = useUpdateRole()
|
|
66
|
-
|
|
67
|
-
const onConfirm = useCallback(
|
|
68
|
-
async (values: { id: number; name: string; permissions: RoleV1['permissions'] | RoleV2['permissions'] }) => {
|
|
69
|
-
await update.trigger(
|
|
70
|
-
{
|
|
71
|
-
id: values.id,
|
|
72
|
-
name: `role_${values.name}`,
|
|
73
|
-
permissions: values.permissions,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
async onSuccess() {
|
|
77
|
-
await message.success('角色更新成功')
|
|
78
|
-
refresh(swrKey, { page: 1 })
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
)
|
|
82
|
-
},
|
|
83
|
-
[update, refresh, message],
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
return useFormModal<{
|
|
87
|
-
id: number
|
|
88
|
-
name: string
|
|
89
|
-
permissions: RoleV1['permissions'] | RoleV2['permissions']
|
|
90
|
-
}>({
|
|
91
|
-
title: '更新角色',
|
|
92
|
-
width: '50vw',
|
|
93
|
-
layout: 'vertical',
|
|
94
|
-
content: (
|
|
95
|
-
<>
|
|
96
|
-
<Form.Item hidden label="ID" name="id">
|
|
97
|
-
<Input />
|
|
98
|
-
</Form.Item>
|
|
99
|
-
<Form.Item label="名称" name="name" rules={[{ required: true }]}>
|
|
100
|
-
<Input disabled addonBefore="role_" />
|
|
101
|
-
</Form.Item>
|
|
102
|
-
<Form.Item label="权限" name="permissions">
|
|
103
|
-
<PermissionList />
|
|
104
|
-
</Form.Item>
|
|
105
|
-
</>
|
|
106
|
-
),
|
|
107
|
-
onConfirm,
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const RoleList = () => {
|
|
112
|
-
const { accessible: viewable } = usePermission('200005')
|
|
113
|
-
const { modal, message } = App.useApp()
|
|
114
|
-
const httpClient = useHttpClient()
|
|
115
|
-
const isPermissionV2 = useReactToolkitsContext(state => state.isPermissionV2)
|
|
116
|
-
const remove = useRemoveRole()
|
|
117
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
118
|
-
const { showModal: showCreateModal, Modal: CreateModal } = useCreateModal()
|
|
119
|
-
const { showModal: showUpdateModal, Modal: UpdateModal } = useUpdateModal()
|
|
120
|
-
|
|
121
|
-
const columns = useMemo<TableColumnsType<RoleListItem>>(
|
|
122
|
-
() => [
|
|
123
|
-
{
|
|
124
|
-
title: '名称',
|
|
125
|
-
key: 'name',
|
|
126
|
-
render(value: RoleListItem) {
|
|
127
|
-
if (viewable) {
|
|
128
|
-
return <Link to={`${value.name}`}>{value.name}</Link>
|
|
129
|
-
} else {
|
|
130
|
-
return <>{value.name}</>
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
title: 'ID',
|
|
136
|
-
dataIndex: 'id',
|
|
137
|
-
key: 'id',
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
title: '创建时间',
|
|
141
|
-
dataIndex: 'ctime',
|
|
142
|
-
key: 'ctime',
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
title: '操作',
|
|
146
|
-
width: 150,
|
|
147
|
-
align: 'center',
|
|
148
|
-
render: (value: RoleListItem) => {
|
|
149
|
-
return (
|
|
150
|
-
<Space size="small">
|
|
151
|
-
<PermissionButton
|
|
152
|
-
code="200003"
|
|
153
|
-
size="small"
|
|
154
|
-
type="link"
|
|
155
|
-
onClick={async () => {
|
|
156
|
-
const role = await httpClient.get<RoleV1 | RoleV2>(
|
|
157
|
-
isPermissionV2 ? '/api/usystem/role/infoV2' : '/api/usystem/role/info',
|
|
158
|
-
{
|
|
159
|
-
params: { name: value.name },
|
|
160
|
-
},
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
showUpdateModal({
|
|
164
|
-
initialValues: {
|
|
165
|
-
id: role?.id,
|
|
166
|
-
permissions: role?.permissions,
|
|
167
|
-
name: role?.name.replace(/^role_/, ''),
|
|
168
|
-
},
|
|
169
|
-
})
|
|
170
|
-
}}
|
|
171
|
-
>
|
|
172
|
-
更新
|
|
173
|
-
</PermissionButton>
|
|
174
|
-
<PermissionButton
|
|
175
|
-
danger
|
|
176
|
-
code="200004"
|
|
177
|
-
size="small"
|
|
178
|
-
type="link"
|
|
179
|
-
onClick={() => {
|
|
180
|
-
modal.confirm({
|
|
181
|
-
title: '删除角色',
|
|
182
|
-
content: (
|
|
183
|
-
<Highlight texts={[value.name]}>
|
|
184
|
-
确定要删除角色
|
|
185
|
-
{value.name}
|
|
186
|
-
吗?
|
|
187
|
-
</Highlight>
|
|
188
|
-
),
|
|
189
|
-
async onOk() {
|
|
190
|
-
await remove.trigger(
|
|
191
|
-
{
|
|
192
|
-
id: value.id,
|
|
193
|
-
name: value.name,
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
async onSuccess() {
|
|
197
|
-
await message.success('角色删除成功')
|
|
198
|
-
refresh(swrKey, { page: 1 })
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
)
|
|
202
|
-
},
|
|
203
|
-
})
|
|
204
|
-
}}
|
|
205
|
-
>
|
|
206
|
-
删除
|
|
207
|
-
</PermissionButton>
|
|
208
|
-
</Space>
|
|
209
|
-
)
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
[refresh, viewable, httpClient, modal, message, remove, showUpdateModal],
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
return (
|
|
217
|
-
<>
|
|
218
|
-
<Card
|
|
219
|
-
title="角色"
|
|
220
|
-
extra={
|
|
221
|
-
<PermissionButton
|
|
222
|
-
type="primary"
|
|
223
|
-
code="200002"
|
|
224
|
-
icon={<UsergroupAddOutlined />}
|
|
225
|
-
onClick={() => {
|
|
226
|
-
showCreateModal()
|
|
227
|
-
}}
|
|
228
|
-
>
|
|
229
|
-
创建角色
|
|
230
|
-
</PermissionButton>
|
|
231
|
-
}
|
|
232
|
-
>
|
|
233
|
-
<QueryList<RoleListItem, NonNullable<unknown>, ListResponse<RoleListItem>>
|
|
234
|
-
rowKey="name"
|
|
235
|
-
columns={columns}
|
|
236
|
-
code="200001"
|
|
237
|
-
swrKey={swrKey}
|
|
238
|
-
// NOTE: 后端接口返回的数据不满足时转换一下
|
|
239
|
-
transformResponse={response => {
|
|
240
|
-
const { List, Total } = response
|
|
241
|
-
return { List, Total }
|
|
242
|
-
}}
|
|
243
|
-
/>
|
|
244
|
-
</Card>
|
|
245
|
-
{CreateModal}
|
|
246
|
-
{UpdateModal}
|
|
247
|
-
</>
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export default RoleList
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { Highlight, PermissionButton, QueryList } from '@/components'
|
|
2
|
-
import { useFormModal } from '@/components/FormModal/hooks'
|
|
3
|
-
import type { UserListItem } from '@/features/permission'
|
|
4
|
-
import { useAllRoles, useCreateUser, useRemoveUser, useUpdateUser } from '@/features/permission'
|
|
5
|
-
import { useQueryListStore } from '@/stores'
|
|
6
|
-
import { UserAddOutlined } from '@ant-design/icons'
|
|
7
|
-
import type { TableColumnsType } from 'antd'
|
|
8
|
-
import { App, Card, Col, Form, Input, Row, Select, Space, Tag } from 'antd'
|
|
9
|
-
import type { FC } from 'react'
|
|
10
|
-
import { useMemo } from 'react'
|
|
11
|
-
import { Link } from 'react-router-dom'
|
|
12
|
-
|
|
13
|
-
const { Option } = Select
|
|
14
|
-
|
|
15
|
-
export const swrKey = {
|
|
16
|
-
url: '/api/usystem/user/list',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function useCreatingUserModal() {
|
|
20
|
-
const { message } = App.useApp()
|
|
21
|
-
const create = useCreateUser()
|
|
22
|
-
const { data: roles, isLoading } = useAllRoles()
|
|
23
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
24
|
-
|
|
25
|
-
return useFormModal<{ id: string; name: string; roles: string[] }>({
|
|
26
|
-
title: '创建用户',
|
|
27
|
-
labelCol: { flex: '80px' },
|
|
28
|
-
content: (
|
|
29
|
-
<>
|
|
30
|
-
<Form.Item noStyle shouldUpdate={(prevValues, currentValue) => prevValues.type !== currentValue.type}>
|
|
31
|
-
{({ getFieldValue }) => (
|
|
32
|
-
<Form.Item label="名称" name="name" rules={[{ required: true }]}>
|
|
33
|
-
<Input disabled={getFieldValue('id')} />
|
|
34
|
-
</Form.Item>
|
|
35
|
-
)}
|
|
36
|
-
</Form.Item>
|
|
37
|
-
<Form.Item label="角色" name="roles">
|
|
38
|
-
<Select allowClear mode="multiple" loading={isLoading}>
|
|
39
|
-
{(roles ?? []).map(role => (
|
|
40
|
-
<Option value={role.name} key={role.id}>
|
|
41
|
-
{role.name}
|
|
42
|
-
</Option>
|
|
43
|
-
))}
|
|
44
|
-
</Select>
|
|
45
|
-
</Form.Item>
|
|
46
|
-
</>
|
|
47
|
-
),
|
|
48
|
-
async onConfirm(values) {
|
|
49
|
-
await create.trigger(values, {
|
|
50
|
-
onSuccess() {
|
|
51
|
-
message.success('用户创建成功')
|
|
52
|
-
refresh(swrKey, { page: 1 })
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function useUpdatingUserModal() {
|
|
60
|
-
const { message } = App.useApp()
|
|
61
|
-
const update = useUpdateUser()
|
|
62
|
-
const { data: roles, isLoading } = useAllRoles()
|
|
63
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
64
|
-
|
|
65
|
-
return useFormModal<{ id: string; name: string; roles: string[] }>({
|
|
66
|
-
title: '更新用户',
|
|
67
|
-
labelCol: { flex: '80px' },
|
|
68
|
-
content: (
|
|
69
|
-
<>
|
|
70
|
-
<Form.Item hidden name="id">
|
|
71
|
-
<Input />
|
|
72
|
-
</Form.Item>
|
|
73
|
-
<Form.Item noStyle shouldUpdate={(prevValues, currentValue) => prevValues.type !== currentValue.type}>
|
|
74
|
-
{({ getFieldValue }) => (
|
|
75
|
-
<Form.Item label="名称" name="name" rules={[{ required: true }]}>
|
|
76
|
-
<Input disabled={getFieldValue('id')} />
|
|
77
|
-
</Form.Item>
|
|
78
|
-
)}
|
|
79
|
-
</Form.Item>
|
|
80
|
-
<Form.Item label="角色" name="roles">
|
|
81
|
-
<Select allowClear mode="multiple" loading={isLoading}>
|
|
82
|
-
{(roles ?? []).map(role => (
|
|
83
|
-
<Option value={role.name} key={role.id}>
|
|
84
|
-
{role.name}
|
|
85
|
-
</Option>
|
|
86
|
-
))}
|
|
87
|
-
</Select>
|
|
88
|
-
</Form.Item>
|
|
89
|
-
</>
|
|
90
|
-
),
|
|
91
|
-
async onConfirm(values) {
|
|
92
|
-
await update.trigger(values, {
|
|
93
|
-
onSuccess() {
|
|
94
|
-
message.success('用户更新成功')
|
|
95
|
-
refresh(swrKey, { page: 1 })
|
|
96
|
-
},
|
|
97
|
-
})
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const UserList: FC = () => {
|
|
103
|
-
const { modal, message } = App.useApp()
|
|
104
|
-
const remove = useRemoveUser()
|
|
105
|
-
const refresh = useQueryListStore(state => state.refresh)
|
|
106
|
-
const { showModal: showCreatingModal, Modal: CreatingModal } = useCreatingUserModal()
|
|
107
|
-
const { showModal: showUpdatingModal, Modal: UpdatingModal } = useUpdatingUserModal()
|
|
108
|
-
|
|
109
|
-
const columns = useMemo<TableColumnsType<UserListItem>>(() => {
|
|
110
|
-
return [
|
|
111
|
-
{
|
|
112
|
-
title: '名称',
|
|
113
|
-
dataIndex: 'name',
|
|
114
|
-
key: 'name',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
title: 'ID',
|
|
118
|
-
dataIndex: 'id',
|
|
119
|
-
key: 'id',
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
title: '角色',
|
|
123
|
-
dataIndex: 'roles',
|
|
124
|
-
key: 'roles',
|
|
125
|
-
width: '40%',
|
|
126
|
-
render(value: string[]) {
|
|
127
|
-
return (
|
|
128
|
-
<Row gutter={[4, 4]}>
|
|
129
|
-
{(value || []).map((item: string) => (
|
|
130
|
-
<Col key={item}>
|
|
131
|
-
{item === 'root' ? (
|
|
132
|
-
<Tag color="#f50">{item}</Tag>
|
|
133
|
-
) : (
|
|
134
|
-
<Tag color="#ff5a00">
|
|
135
|
-
<Link to={`/permission/role/${item}`}>{item}</Link>
|
|
136
|
-
</Tag>
|
|
137
|
-
)}
|
|
138
|
-
</Col>
|
|
139
|
-
))}
|
|
140
|
-
</Row>
|
|
141
|
-
)
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
title: '创建时间',
|
|
146
|
-
dataIndex: 'Ctime',
|
|
147
|
-
key: 'ctime',
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
title: '操作',
|
|
151
|
-
width: 150,
|
|
152
|
-
align: 'center',
|
|
153
|
-
render: (value: UserListItem) => (
|
|
154
|
-
<Space>
|
|
155
|
-
<PermissionButton
|
|
156
|
-
size="small"
|
|
157
|
-
type="link"
|
|
158
|
-
code="100003"
|
|
159
|
-
onClick={() => {
|
|
160
|
-
showUpdatingModal({
|
|
161
|
-
initialValues: {
|
|
162
|
-
id: value.id,
|
|
163
|
-
name: value.name,
|
|
164
|
-
roles: value.roles,
|
|
165
|
-
},
|
|
166
|
-
})
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
169
|
-
更新
|
|
170
|
-
</PermissionButton>
|
|
171
|
-
<PermissionButton
|
|
172
|
-
danger
|
|
173
|
-
size="small"
|
|
174
|
-
code="100004"
|
|
175
|
-
type="link"
|
|
176
|
-
onClick={() => {
|
|
177
|
-
modal.confirm({
|
|
178
|
-
title: '删除用户',
|
|
179
|
-
content: (
|
|
180
|
-
<Highlight texts={[value.name]}>
|
|
181
|
-
确定要删除用户
|
|
182
|
-
{value.name}
|
|
183
|
-
吗?
|
|
184
|
-
</Highlight>
|
|
185
|
-
),
|
|
186
|
-
async onOk() {
|
|
187
|
-
await remove.trigger(
|
|
188
|
-
{
|
|
189
|
-
id: value.id,
|
|
190
|
-
name: value.name,
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
async onSuccess() {
|
|
194
|
-
await message.success('用户删除成功')
|
|
195
|
-
refresh(swrKey, { page: 1 })
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
)
|
|
199
|
-
},
|
|
200
|
-
})
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
203
|
-
删除
|
|
204
|
-
</PermissionButton>
|
|
205
|
-
</Space>
|
|
206
|
-
),
|
|
207
|
-
},
|
|
208
|
-
]
|
|
209
|
-
}, [refresh, remove, message, modal, showUpdatingModal])
|
|
210
|
-
|
|
211
|
-
return (
|
|
212
|
-
<>
|
|
213
|
-
<Card
|
|
214
|
-
title="用户"
|
|
215
|
-
extra={
|
|
216
|
-
<PermissionButton
|
|
217
|
-
type="primary"
|
|
218
|
-
icon={<UserAddOutlined />}
|
|
219
|
-
code="100002"
|
|
220
|
-
onClick={() => {
|
|
221
|
-
showCreatingModal()
|
|
222
|
-
}}
|
|
223
|
-
>
|
|
224
|
-
创建用户
|
|
225
|
-
</PermissionButton>
|
|
226
|
-
}
|
|
227
|
-
>
|
|
228
|
-
<QueryList code="100001" swrKey={swrKey} rowKey="id" columns={columns} />
|
|
229
|
-
</Card>
|
|
230
|
-
{CreatingModal}
|
|
231
|
-
{UpdatingModal}
|
|
232
|
-
</>
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export default UserList
|