增加用户、角色的编辑、删除等操作
This commit is contained in:
@@ -8,32 +8,24 @@
|
||||
*/
|
||||
export default {
|
||||
dev: {
|
||||
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
|
||||
'/api/': {
|
||||
// 要代理的地址
|
||||
target: 'https://preview.pro.ant.design',
|
||||
// 配置了这个可以从 http 代理到 https
|
||||
// 依赖 origin 的功能可能需要这个,比如 cookie
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-uaa/': {
|
||||
target: 'http://gateway.zlt2000.cn',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-user/': {
|
||||
target: 'http://gateway.zlt2000.cn',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-log/': {
|
||||
target: 'http://gateway.zlt2000.cn',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-search/': {
|
||||
target: 'http://gateway.zlt2000.cn',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-generator/': {
|
||||
target: 'http://gateway.zlt2000.cn',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
import { app } from '@/services/system/api';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { app, deleteApp } from '@/services/system/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components';
|
||||
import { Typography, message } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import { Typography, message, Popconfirm } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleDelete = async (data: SYSTEM.App) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
await deleteApp(data.id);
|
||||
hide();
|
||||
message.success('删除应用成功');
|
||||
return true;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('删除应用失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>();
|
||||
|
||||
const actionRef = useRef<ActionType>();
|
||||
const columns: ProColumns<SYSTEM.App>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -73,7 +87,19 @@ const TableList: React.FC = () => {
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
width: 40,
|
||||
render: () => <Link onClick={() => message.info('演示环境不支持该功能')}>删除</Link>,
|
||||
render: (_, entity) => <Popconfirm
|
||||
title={`确认删除用户[${entity.clientName}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>,
|
||||
},
|
||||
];
|
||||
return (
|
||||
@@ -90,7 +116,8 @@ const TableList: React.FC = () => {
|
||||
</QueryFilter>
|
||||
<ProTable<SYSTEM.App>
|
||||
rowKey="id"
|
||||
headerTitle="Token管理"
|
||||
headerTitle="应用管理"
|
||||
actionRef={actionRef}
|
||||
request={app}
|
||||
columns={columns}
|
||||
search={false}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import { menu } from '@/services/system/api';
|
||||
import { treeify } from '@/util/treeify';
|
||||
import { FolderOpenOutlined, MenuOutlined, ProfileOutlined } from '@ant-design/icons';
|
||||
import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined } from '@ant-design/icons';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { ProFormSelect } from '@ant-design/pro-components';
|
||||
import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components';
|
||||
import { Space, Tag, Typography } from 'antd';
|
||||
import { Button, Space, Tag, Typography } from 'antd';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const Generator: React.FC = () => {
|
||||
const [data, setData] = useState<SYSTEM.Menu[]>();
|
||||
|
||||
const [keys, setKeys] = useState<(React.Key)[]>([]);
|
||||
const [expandedRowKeys, setExpandedRowKeys] = useState<(React.Key)[]>([]);
|
||||
const query = async (params: Record<string, string | number>) => {
|
||||
const menus = (await menu(params)) ?? [];
|
||||
const menus = await menu(params);
|
||||
const treeData = treeify(menus, {});
|
||||
menus.forEach((node) => {
|
||||
if (node.children && node.children.length === 0) delete node.children;
|
||||
});
|
||||
// debugger;
|
||||
setKeys(menus.map(m=>m.id));
|
||||
setData(treeData);
|
||||
};
|
||||
|
||||
@@ -30,7 +32,7 @@ const Generator: React.FC = () => {
|
||||
{
|
||||
title: '菜单名称',
|
||||
key: 'name',
|
||||
width: 80,
|
||||
width: 120,
|
||||
render(dom, entity) {
|
||||
if (entity.type === 1) {
|
||||
if (entity.url?.startsWith('javascript')) {
|
||||
@@ -136,6 +138,36 @@ const Generator: React.FC = () => {
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={false}
|
||||
expandable={{
|
||||
expandedRowKeys,
|
||||
onExpandedRowsChange: (expandedRows) => setExpandedRowKeys([...expandedRows]),
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setExpandedRowKeys(keys);
|
||||
}}
|
||||
>
|
||||
全部展开
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setExpandedRowKeys([]);
|
||||
}}
|
||||
>
|
||||
全部折叠
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
//handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
]}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { menuForAuth } from '@/services/system/api';
|
||||
import { assignMenu, menuForAuth } from '@/services/system/api';
|
||||
import { treeify } from '@/util/treeify';
|
||||
import type { TreeDataNode } from 'antd';
|
||||
import { Modal, Tree, message } from 'antd';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
type AssignAuthProps = {
|
||||
roleId?: number;
|
||||
roleId: number;
|
||||
tenantId?: string;
|
||||
onCancel: () => void;
|
||||
assignModalVisible: boolean;
|
||||
@@ -13,6 +13,25 @@ type AssignAuthProps = {
|
||||
|
||||
type Key = string | number;
|
||||
|
||||
const handleAssign = async (roleId: number, menuIds: Key[]) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await assignMenu({ roleId, menuIds });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('权限分配成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('权限分配失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const AssignAuth: React.FC<AssignAuthProps> = (props) => {
|
||||
const [treeData, setTreeData] = useState<TreeDataNode[]>([]);
|
||||
const [checkedKeys, setCheckedKeys] = useState<Key[]>([]);
|
||||
@@ -39,9 +58,14 @@ const AssignAuth: React.FC<AssignAuthProps> = (props) => {
|
||||
// layout="horizontal"
|
||||
open={props.assignModalVisible}
|
||||
// initialValues={formData}
|
||||
onOk={() => {
|
||||
message.info('演示环境不支持该功能');
|
||||
props.onCancel();
|
||||
destroyOnClose
|
||||
onOk={async () => {
|
||||
const success = await handleAssign(roleId, checkedKeys);
|
||||
if (success) {
|
||||
setTreeData([]);
|
||||
setCheckedKeys([]);
|
||||
props.onCancel();;
|
||||
}
|
||||
}}
|
||||
onCancel={() => {
|
||||
setTreeData([]);
|
||||
|
||||
@@ -9,10 +9,10 @@ import React, { useEffect } from 'react';
|
||||
export type FormValueType = Partial<SYSTEM.Role>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onCancel: (flag?: boolean, formVals?: FormValueType) => void;
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
updateModalVisible: boolean;
|
||||
values: Partial<SYSTEM.Role>;
|
||||
values?: SYSTEM.Role;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
@@ -32,7 +32,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
visible={props.updateModalVisible}
|
||||
// initialValues={formData}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onCancel}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { pageRole } from '@/services/system/api';
|
||||
import { deleteRole, pageRole, saveOrUpdateRole } from '@/services/system/api';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ProFormSelect,
|
||||
ModalForm,
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Space, Typography } from 'antd';
|
||||
import { Popconfirm, Space, Typography } from 'antd';
|
||||
import { Button, message } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import AssignAuth from './components/AssignAuth';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
@@ -24,13 +24,70 @@ type AssignAuthProps = {
|
||||
assignModalVisible: boolean;
|
||||
};
|
||||
|
||||
const handleAdd = async (fields: SYSTEM.Role) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await saveOrUpdateRole({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加角色成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('添加角色失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (fields: SYSTEM.Role) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateRole({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改角色成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('修改角色失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (data: SYSTEM.Role) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteRole(data.id);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('删除角色成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('删除角色失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
|
||||
const [currentRow, setCurrentRow] = useState<SYSTEM.User>();
|
||||
const [currentRow, setCurrentRow] = useState<SYSTEM.Role>();
|
||||
|
||||
const [assignAuth, setAssignAuth] = useState<AssignAuthProps>({ assignModalVisible: false });
|
||||
|
||||
@@ -59,20 +116,32 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, entity) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
handleUpdateModalVisible(true);
|
||||
setCurrentRow(record);
|
||||
setCurrentRow(entity);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Link onClick={() => message.info('演示环境不支持该功能')}>删除</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除用户[${entity.name}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setAssignAuth({ roleId: record.id, assignModalVisible: true, tenantId: 'webApp' });
|
||||
setAssignAuth({ roleId: entity.id, assignModalVisible: true, tenantId: 'webApp' });
|
||||
}}
|
||||
>
|
||||
权限分配
|
||||
@@ -112,6 +181,7 @@ const TableList: React.FC = () => {
|
||||
<ProTable<SYSTEM.Role>
|
||||
rowKey="id"
|
||||
headerTitle="角色管理"
|
||||
actionRef={actionRef}
|
||||
request={pageRole}
|
||||
columns={columns}
|
||||
search={false}
|
||||
@@ -139,8 +209,15 @@ const TableList: React.FC = () => {
|
||||
width={500}
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
onFinish={async () => {
|
||||
message.info('演示环境不支持该功能');
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
const success = await handleAdd(values as SYSTEM.Role);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
@@ -171,17 +248,21 @@ const TableList: React.FC = () => {
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async () => {
|
||||
message.info('演示环境不支持该功能');
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}}
|
||||
onCancel={(flag) => {
|
||||
handleUpdateModalVisible(flag ?? true);
|
||||
setCurrentRow(undefined);
|
||||
onSubmit={async (values) => {
|
||||
if (currentRow) {
|
||||
const success = await handleEdit({ ...currentRow, ...values });
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow || {}}
|
||||
values={currentRow}
|
||||
/>
|
||||
<AssignAuth {...assignAuth} onCancel={() => setAssignAuth({ assignModalVisible: false })} />
|
||||
</PageContainer>
|
||||
|
||||
@@ -10,14 +10,14 @@ import { Form } from 'antd';
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
export type FormValueType = {
|
||||
roleCodes?: string[];
|
||||
roleIds?: number[];
|
||||
} & Partial<SYSTEM.User>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onCancel: (flag?: boolean, formVals?: FormValueType) => void;
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
updateModalVisible: boolean;
|
||||
values: Partial<SYSTEM.User>;
|
||||
values?: SYSTEM.User;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
@@ -25,9 +25,9 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { values } = props;
|
||||
|
||||
useEffect(() => {
|
||||
if (values.roles) {
|
||||
const roleCodes = values.roles.map((r) => r.code);
|
||||
const formData: FormValueType = { ...values, roleCodes };
|
||||
if (values?.roles) {
|
||||
const roleIds = values.roles.map((r) => r.id);
|
||||
const formData: FormValueType = { ...values, roleIds };
|
||||
form.setFieldsValue(formData);
|
||||
}
|
||||
}, [form, values]);
|
||||
@@ -39,7 +39,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
visible={props.updateModalVisible}
|
||||
// initialValues={formData}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onCancel}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
@@ -95,14 +95,14 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
/>
|
||||
<ProFormSelect
|
||||
mode="multiple"
|
||||
name="roleCodes"
|
||||
name="roleIds"
|
||||
label="角色"
|
||||
width="md"
|
||||
request={async () => {
|
||||
const roles = await role();
|
||||
if (roles)
|
||||
return roles.map((r) => {
|
||||
return { label: r.name, value: r.code };
|
||||
return { label: r.name, value: r.id };
|
||||
});
|
||||
return [];
|
||||
}}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { user, exportUser, role } from '@/services/system/api';
|
||||
import {
|
||||
user,
|
||||
saveOrUpdateUser,
|
||||
exportUser,
|
||||
role,
|
||||
updateEnabled,
|
||||
resetPassword,
|
||||
deleteUser,
|
||||
importUser,
|
||||
} from '@/services/system/api';
|
||||
import { ExportOutlined, ImportOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ProFormRadio,
|
||||
ProFormSelect,
|
||||
@@ -11,16 +20,131 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Space, Typography } from 'antd';
|
||||
import { Popconfirm, Space, Typography, Upload } from 'antd';
|
||||
import { Button, Switch, message } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: SYSTEM.User) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await saveOrUpdateUser({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加用户成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('添加用户失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (fields: SYSTEM.User) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateUser({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改用户成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('修改用户失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const swichUser = async (sysUser: SYSTEM.User) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await updateEnabled(sysUser.id, !sysUser.enabled);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改用户成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('修改用户失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleResetPassword = async (sysUser: SYSTEM.User) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await resetPassword(sysUser.id);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('重置密码成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('重置密码失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (sysUser: SYSTEM.User) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteUser(sysUser.id);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('删除用户成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('删除用户失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在导入');
|
||||
debugger
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importUser(formData);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('导入用户成功');
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('导入用户失败');
|
||||
}
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
@@ -65,25 +189,44 @@ const TableList: React.FC = () => {
|
||||
checkedChildren="正常"
|
||||
unCheckedChildren="锁定"
|
||||
checked={entity.enabled}
|
||||
onClick={() => message.info('演示环境不支持该功能')}
|
||||
onClick={async () => {
|
||||
const success = await swichUser(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, entity) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
setCurrentRow(record);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Link onClick={() => message.info('演示环境不支持该功能')}>重置密码</Link>
|
||||
<Link onClick={() => message.info('演示环境不支持该功能')}>删除</Link>
|
||||
<Link onClick={async () => await handleResetPassword(entity)}>重置密码</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除用户[${entity.username}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@@ -112,6 +255,7 @@ const TableList: React.FC = () => {
|
||||
<ProTable<SYSTEM.User>
|
||||
rowKey="id"
|
||||
headerTitle="用户管理"
|
||||
actionRef={actionRef}
|
||||
request={user}
|
||||
columns={columns}
|
||||
search={false}
|
||||
@@ -129,13 +273,20 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ExportOutlined /> 导出
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
message.info('演示环境不支持该功能');
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-user/users/import"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
await handleImport(file);
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<ImportOutlined /> 导入
|
||||
</Button>
|
||||
<Button>
|
||||
<ImportOutlined /> 导入
|
||||
</Button>
|
||||
</Upload>
|
||||
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
@@ -153,9 +304,18 @@ const TableList: React.FC = () => {
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
initialValues={{ sex: 0 }}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
console.log(values);
|
||||
message.info('演示环境不支持该功能');
|
||||
const roleIds: string[] = values.roleIds;
|
||||
const roleId = roleIds.join(',');
|
||||
values.roleId = roleId;
|
||||
const success = await handleAdd(values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
@@ -212,14 +372,14 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
<ProFormSelect
|
||||
mode="multiple"
|
||||
name="roleCodes"
|
||||
name="roleIds"
|
||||
label="角色"
|
||||
width="md"
|
||||
request={async () => {
|
||||
const roles = await role();
|
||||
if (roles)
|
||||
return roles.map((r) => {
|
||||
return { label: r.name, value: r.code };
|
||||
return { label: r.name, value: r.id };
|
||||
});
|
||||
return [];
|
||||
}}
|
||||
@@ -228,17 +388,24 @@ const TableList: React.FC = () => {
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async () => {
|
||||
message.info('演示环境不支持该功能');
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}}
|
||||
onCancel={(flag) => {
|
||||
handleUpdateModalVisible(flag ?? true);
|
||||
setCurrentRow(undefined);
|
||||
onSubmit={async (values) => {
|
||||
if (currentRow) {
|
||||
const roleIds: number[] = values.roleIds || [];
|
||||
const roleId = roleIds.join(',');
|
||||
values.roleId = roleId;
|
||||
const success = await handleEdit({ ...currentRow, ...values });
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow || {}}
|
||||
values={currentRow}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -47,4 +47,11 @@ declare namespace SEARCH {
|
||||
userId?: string;
|
||||
userName?: string;
|
||||
};
|
||||
|
||||
type SlowSqlLog = {
|
||||
id?: string;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,27 +12,34 @@ export async function user(params?: { [key: string]: string | number }) {
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function role() {
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
|
||||
method: 'GET',
|
||||
export async function saveOrUpdateUser(data: SYSTEM.User): Promise<API.Result<SYSTEM.User>> {
|
||||
const result = await request<API.Result<SYSTEM.User>>('/api-user/users/saveOrUpdate', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result.data;
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function pageRole(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
|
||||
export async function updateEnabled(id: number, enabled: boolean) {
|
||||
const result = await request<API.Result<SYSTEM.User>>('/api-user/users/updateEnabled', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
params: { id, enabled },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function menuForAuth(roleId: number, tenantId: string) {
|
||||
const url = `/api-user/menus/${roleId}/menus`;
|
||||
const result = await request<SYSTEM.Menu[]>(url, {
|
||||
method: 'GET',
|
||||
params: { tenantId },
|
||||
export async function resetPassword(id: number) {
|
||||
const url = `/api-user/users/${id}/password`;
|
||||
const result = await request<API.Result<SYSTEM.User>>(url, {
|
||||
method: 'PUT',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteUser(id: number) {
|
||||
const url = `/api-user/users/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -53,6 +60,57 @@ export function exportUser(params?: { [key: string]: string | number }) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function importUser(formData: FormData) {
|
||||
const result = await request<API.Result<void>>("/api-user/users/import", {
|
||||
method: 'POST',
|
||||
requestType: 'form',
|
||||
data: formData,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function role() {
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
|
||||
method: 'GET',
|
||||
});
|
||||
return result.data;
|
||||
}
|
||||
|
||||
export async function pageRole(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function saveOrUpdateRole(data: SYSTEM.Role): Promise<API.Result<SYSTEM.Role>> {
|
||||
const result = await request<API.Result<SYSTEM.Role>>('/api-user/roles/saveOrUpdate', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteRole(id: number) {
|
||||
const url = `/api-user/roles/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function menuForAuth(roleId: number, tenantId: string) {
|
||||
const url = `/api-user/menus/${roleId}/menus`;
|
||||
const result = await request<SYSTEM.Menu[]>(url, {
|
||||
method: 'GET',
|
||||
params: { tenantId },
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export async function token(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Token>>('/api-uaa/tokens', {
|
||||
@@ -71,6 +129,13 @@ export async function app(params?: { [key: string]: string | number }) {
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function deleteApp(id: number) {
|
||||
const url = `/api-uaa/clients/${id}`
|
||||
await request<void>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
export async function generator(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Generator>>('/api-generator/generator/list', {
|
||||
@@ -98,3 +163,11 @@ export async function menu(params: { [key: string]: string | number }) {
|
||||
});
|
||||
return result.data;
|
||||
}
|
||||
|
||||
export async function assignMenu(assignMenu: SYSTEM.AssignMenu) {
|
||||
const result = await request<API.Result<void>>("/api-user/menus/granted", {
|
||||
method: 'POST',
|
||||
data: assignMenu,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
+11
-5
@@ -3,9 +3,9 @@
|
||||
|
||||
declare namespace SYSTEM {
|
||||
type Page<T> = {
|
||||
code?: number;
|
||||
count?: number;
|
||||
data?: T[];
|
||||
code: number;
|
||||
count: number;
|
||||
data: T[];
|
||||
};
|
||||
|
||||
type Role = {
|
||||
@@ -18,7 +18,7 @@ declare namespace SYSTEM {
|
||||
};
|
||||
|
||||
type User = {
|
||||
id?: number;
|
||||
id: number;
|
||||
username?: string;
|
||||
nickname?: string;
|
||||
headImgUrl?: string;
|
||||
@@ -26,9 +26,10 @@ declare namespace SYSTEM {
|
||||
type?: string;
|
||||
mobile?: string;
|
||||
createTime?: Date;
|
||||
enabled?: boolean;
|
||||
enabled: boolean;
|
||||
del?: boolean;
|
||||
roles?: Role[];
|
||||
roleId?: string;
|
||||
};
|
||||
|
||||
type Menu = {
|
||||
@@ -45,6 +46,11 @@ declare namespace SYSTEM {
|
||||
children?: Menu[];
|
||||
};
|
||||
|
||||
type AssignMenu = {
|
||||
roleId: number;
|
||||
menuIds: (string|number)[];
|
||||
};
|
||||
|
||||
type Token = {
|
||||
accountType?: string;
|
||||
clientId?: string;
|
||||
|
||||
Reference in New Issue
Block a user