|
|
@@ -1,3 +1,134 @@
|
|
|
+import { fetchProductList } from '@/services/product';
|
|
|
+import { fetchUpdateUserStatus, fetchUserList } from '@/services/user';
|
|
|
+import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
|
+import { useIntl } from '@umijs/max';
|
|
|
+import { Button, Popconfirm, Select, Tag, message } from 'antd';
|
|
|
+import { useEffect, useRef, useState } from 'react';
|
|
|
+import { BindRolesDrawer } from './components/BindRolesDrawer';
|
|
|
+import { UserForm } from './components/Form';
|
|
|
+import { UserPermDrawer } from './components/UserPermDrawer';
|
|
|
+
|
|
|
export default function UserPage() {
|
|
|
- return null;
|
|
|
+ const intl = useIntl();
|
|
|
+ const actionRef = useRef<ActionType>();
|
|
|
+ const [products, setProducts] = useState<API.ProductItem[]>([]);
|
|
|
+ const [productCode, setProductCode] = useState<string | undefined>();
|
|
|
+ const [rolesDrawer, setRolesDrawer] = useState<{ open: boolean; userId: number }>({
|
|
|
+ open: false,
|
|
|
+ userId: 0,
|
|
|
+ });
|
|
|
+ const [permDrawer, setPermDrawer] = useState<{ open: boolean; userId: number }>({
|
|
|
+ open: false,
|
|
|
+ userId: 0,
|
|
|
+ });
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ fetchProductList({ pageSize: 999 }).then((res) => setProducts(res.data?.list ?? []));
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const handleToggleStatus = async (r: API.UserItem) => {
|
|
|
+ await fetchUpdateUserStatus({ id: r.id, status: r.status === 1 ? 0 : 1 });
|
|
|
+ message.success('操作成功');
|
|
|
+ actionRef.current?.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ const columns: ProColumns<API.UserItem>[] = [
|
|
|
+ { title: '用户名', dataIndex: 'username' },
|
|
|
+ { title: '昵称', dataIndex: 'nickname' },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ render: (_, r) => (
|
|
|
+ <Tag color={r.status === 1 ? 'success' : 'default'}>{r.status === 1 ? '启用' : '禁用'}</Tag>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ valueType: 'option',
|
|
|
+ render: (_, r) =>
|
|
|
+ [
|
|
|
+ <UserForm
|
|
|
+ key="edit"
|
|
|
+ mode="edit"
|
|
|
+ initialValues={r}
|
|
|
+ trigger={<a>编辑</a>}
|
|
|
+ onSuccess={() => actionRef.current?.reload()}
|
|
|
+ />,
|
|
|
+ <UserForm
|
|
|
+ key="copy"
|
|
|
+ mode="copy"
|
|
|
+ initialValues={r}
|
|
|
+ trigger={<a>复制</a>}
|
|
|
+ onSuccess={() => actionRef.current?.reload()}
|
|
|
+ />,
|
|
|
+ productCode ? (
|
|
|
+ <a key="roles" onClick={() => setRolesDrawer({ open: true, userId: r.id })}>
|
|
|
+ 分配角色
|
|
|
+ </a>
|
|
|
+ ) : null,
|
|
|
+ productCode ? (
|
|
|
+ <a key="perms" onClick={() => setPermDrawer({ open: true, userId: r.id })}>
|
|
|
+ 设置权限
|
|
|
+ </a>
|
|
|
+ ) : null,
|
|
|
+ <Popconfirm
|
|
|
+ key="status"
|
|
|
+ title={r.status === 1 ? '确认冻结?' : '确认解冻?'}
|
|
|
+ onConfirm={() => handleToggleStatus(r)}
|
|
|
+ >
|
|
|
+ <a className={r.status === 1 ? 'text-red-500' : ''}>
|
|
|
+ {r.status === 1 ? '冻结' : '解冻'}
|
|
|
+ </a>
|
|
|
+ </Popconfirm>,
|
|
|
+ ].filter(Boolean),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageContainer title={intl.formatMessage({ id: 'admin.user.title' })}>
|
|
|
+ <div className="mb-3 flex items-center gap-2">
|
|
|
+ <span className="text-sm text-gray-500">当前产品:</span>
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ placeholder="选择产品(用于角色/权限操作)"
|
|
|
+ options={products.map((p) => ({ label: p.name, value: p.code }))}
|
|
|
+ value={productCode}
|
|
|
+ onChange={setProductCode}
|
|
|
+ className="w-64"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <ProTable<API.UserItem>
|
|
|
+ actionRef={actionRef}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ request={async ({ current, pageSize }) => {
|
|
|
+ const res = await fetchUserList({ page: current, pageSize });
|
|
|
+ return { data: res.data?.list ?? [], total: res.data?.total ?? 0, success: true };
|
|
|
+ }}
|
|
|
+ toolBarRender={() => [
|
|
|
+ <UserForm
|
|
|
+ key="create"
|
|
|
+ mode="add"
|
|
|
+ trigger={<Button type="primary">新建用户</Button>}
|
|
|
+ onSuccess={() => actionRef.current?.reload()}
|
|
|
+ />,
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ {productCode && (
|
|
|
+ <>
|
|
|
+ <BindRolesDrawer
|
|
|
+ {...rolesDrawer}
|
|
|
+ productCode={productCode}
|
|
|
+ onClose={() => setRolesDrawer((p) => ({ ...p, open: false }))}
|
|
|
+ />
|
|
|
+ <UserPermDrawer
|
|
|
+ {...permDrawer}
|
|
|
+ productCode={productCode}
|
|
|
+ onClose={() => setPermDrawer((p) => ({ ...p, open: false }))}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </PageContainer>
|
|
|
+ );
|
|
|
}
|