|
|
@@ -12,7 +12,12 @@ import {
|
|
|
useUserProductRoles,
|
|
|
} from '@/pages/Admin/_shared/useUserProductRoles';
|
|
|
import { fetchDeptTree } from '@/services/dept';
|
|
|
-import { fetchUpdateUserStatus, fetchUserList } from '@/services/user';
|
|
|
+import {
|
|
|
+ fetchResetPassword,
|
|
|
+ fetchUpdateUserStatus,
|
|
|
+ fetchUserCredentials,
|
|
|
+ fetchUserList,
|
|
|
+} from '@/services/user';
|
|
|
import { unixTimeFormat } from '@/utils/timeUtils';
|
|
|
import { StopOutlined } from '@ant-design/icons';
|
|
|
import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
|
@@ -20,6 +25,7 @@ import { useIntl } from '@umijs/max';
|
|
|
import { Button, Popconfirm, Tag, message } from 'antd';
|
|
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
import { UserForm } from './components/Form';
|
|
|
+import { UserCredentialModal } from './components/UserCredentialModal';
|
|
|
|
|
|
const flattenDeptTree = (items: API.DeptItem[]): { label: string; value: number }[] =>
|
|
|
items.flatMap((d) => [
|
|
|
@@ -41,6 +47,8 @@ export default function UserPage() {
|
|
|
userId: 0,
|
|
|
});
|
|
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
|
+ const [credData, setCredData] = useState<API.FetchUserCredentialsResp | null>(null);
|
|
|
+ const [credOpen, setCredOpen] = useState(false);
|
|
|
|
|
|
useEffect(() => {
|
|
|
fetchDeptTree().then((res) => {
|
|
|
@@ -62,6 +70,25 @@ export default function UserPage() {
|
|
|
actionRef.current?.reload();
|
|
|
};
|
|
|
|
|
|
+ const showCredentials = async (ticket: string) => {
|
|
|
+ const res = await fetchUserCredentials({ ticket });
|
|
|
+ if (!res.success || !res.data) return;
|
|
|
+ setCredData(res.data);
|
|
|
+ setCredOpen(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleCreateSuccess = async (ticket?: string) => {
|
|
|
+ actionRef.current?.reload();
|
|
|
+ if (ticket) await showCredentials(ticket);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleResetPassword = async (r: API.UserItem) => {
|
|
|
+ const res = await fetchResetPassword({ userId: r.id });
|
|
|
+ if (!res.success || !res.data) return;
|
|
|
+ message.success('密码已重置');
|
|
|
+ await showCredentials(res.data.credentialsTicket);
|
|
|
+ };
|
|
|
+
|
|
|
const columns: ProColumns<API.UserItem>[] = [
|
|
|
{ title: '用户名', dataIndex: 'username', width: 200 },
|
|
|
{ title: '昵称', dataIndex: 'nickname', width: 200 },
|
|
|
@@ -146,7 +173,7 @@ export default function UserPage() {
|
|
|
{
|
|
|
title: '操作',
|
|
|
valueType: 'option',
|
|
|
- width: 260,
|
|
|
+ width: 320,
|
|
|
render: (_, r) => [
|
|
|
<UserForm
|
|
|
key="edit"
|
|
|
@@ -160,7 +187,7 @@ export default function UserPage() {
|
|
|
mode="copy"
|
|
|
initialValues={r}
|
|
|
trigger={<a>复制</a>}
|
|
|
- onSuccess={() => actionRef.current?.reload()}
|
|
|
+ onSuccess={handleCreateSuccess}
|
|
|
/>,
|
|
|
<a key="roles" onClick={() => setRolesDrawer({ open: true, userId: r.id })}>
|
|
|
分配角色
|
|
|
@@ -168,6 +195,13 @@ export default function UserPage() {
|
|
|
<a key="perms" onClick={() => setPermDrawer({ open: true, userId: r.id })}>
|
|
|
设置权限
|
|
|
</a>,
|
|
|
+ <Popconfirm
|
|
|
+ key="reset"
|
|
|
+ title={`确认重置「${r.username}」的密码?`}
|
|
|
+ onConfirm={() => handleResetPassword(r)}
|
|
|
+ >
|
|
|
+ <a>重置密码</a>
|
|
|
+ </Popconfirm>,
|
|
|
<Popconfirm
|
|
|
key="status"
|
|
|
title={
|
|
|
@@ -194,7 +228,7 @@ export default function UserPage() {
|
|
|
search={{ span: { xs: 24, sm: 12, md: 8, lg: 6, xl: 4, xxl: 4 } }}
|
|
|
request={fetchUserList}
|
|
|
onDataSourceChange={setPageUsers}
|
|
|
- scroll={{ x: 1220 }}
|
|
|
+ scroll={{ x: 1280 }}
|
|
|
tableLayout="fixed"
|
|
|
pagination={{
|
|
|
defaultPageSize: 20,
|
|
|
@@ -206,7 +240,7 @@ export default function UserPage() {
|
|
|
key="create"
|
|
|
mode="add"
|
|
|
trigger={<Button type="primary">新建用户</Button>}
|
|
|
- onSuccess={() => actionRef.current?.reload()}
|
|
|
+ onSuccess={handleCreateSuccess}
|
|
|
/>,
|
|
|
]}
|
|
|
/>
|
|
|
@@ -219,6 +253,7 @@ export default function UserPage() {
|
|
|
{...permDrawer}
|
|
|
onClose={() => setPermDrawer((p) => ({ ...p, open: false }))}
|
|
|
/>
|
|
|
+ <UserCredentialModal open={credOpen} data={credData} onClose={() => setCredOpen(false)} />
|
|
|
</PageContainer>
|
|
|
);
|
|
|
}
|