场站和组织增删改查
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
Input, Popconfirm, Divider, InputNumber, Switch
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, SettingOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { getMenuList } from '../api/mune';
|
||||
import { buildPermTree, buildTreeFromFlat } from '../lib/utils';
|
||||
@@ -18,9 +18,6 @@ export default function Roles() {
|
||||
const [roles, setRoles] = useState([]);
|
||||
const [menuTree, setMenuTree] = useState([]);
|
||||
const [checkedKeys, setCheckedKeys] = useState<number[]>([]);
|
||||
const [permVisible, setPermVisible] = useState(false);
|
||||
const [currentRole, setCurrentRole] = useState(null);
|
||||
|
||||
const [roleModalVisible, setRoleModalVisible] = useState(false);
|
||||
const [roleForm] = Form.useForm();
|
||||
const [editRole, setEditRole] = useState(null);
|
||||
@@ -52,8 +49,6 @@ export default function Roles() {
|
||||
getRole();
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
// 新增角色
|
||||
const handleAddRole = () => {
|
||||
roleForm.resetFields();
|
||||
@@ -62,7 +57,6 @@ export default function Roles() {
|
||||
roleForm.setFieldsValue({
|
||||
status: true,
|
||||
roleSort: 1,
|
||||
|
||||
});
|
||||
setRoleModalVisible(true);
|
||||
};
|
||||
@@ -74,7 +68,6 @@ export default function Roles() {
|
||||
...record,
|
||||
status: record.status == 1,
|
||||
});
|
||||
// 🔥 编辑时自动勾选菜单
|
||||
setCheckedKeys((record.menuIds || []).map(Number));
|
||||
setRoleModalVisible(true);
|
||||
};
|
||||
@@ -96,17 +89,13 @@ export default function Roles() {
|
||||
// 提交保存角色
|
||||
const handleSaveRole = () => {
|
||||
roleForm.validateFields().then(values => {
|
||||
|
||||
|
||||
if (editRole) {
|
||||
|
||||
const params = {
|
||||
...values,
|
||||
menuIds: checkedKeys,
|
||||
status: values.status ? 1 : 0,
|
||||
roleSort: values.roleSort || 1,
|
||||
roleId: editRole.roleId
|
||||
|
||||
};
|
||||
editRoleApi(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
@@ -119,16 +108,13 @@ export default function Roles() {
|
||||
}).catch(() => {
|
||||
messageApi.error("编辑失败");
|
||||
});
|
||||
|
||||
} else {
|
||||
const params = {
|
||||
...values,
|
||||
menuIds: checkedKeys,
|
||||
status: values.status ? 1 : 0,
|
||||
roleSort: values.roleSort || 1,
|
||||
|
||||
};
|
||||
// 新增
|
||||
addRole(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
messageApi.success('新增角色成功');
|
||||
@@ -145,59 +131,76 @@ export default function Roles() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: '16px', background: '#f4f7f9', minHeight: '100%' }}>
|
||||
<div style={{ padding: '20px' }}>
|
||||
{contextHolder}
|
||||
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>角色管理</div>
|
||||
{/* 统一卡片容器(和菜单管理一致) */}
|
||||
<AntdCard title="角色管理" style={{ borderRadius: 8 }}>
|
||||
{/* 顶部操作栏(和菜单管理统一) */}
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={handleAddRole}
|
||||
>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 16 }}>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles && roles.length > 0 ? (
|
||||
roles.map(role => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
hoverable
|
||||
style={{ borderRadius: 8 }}
|
||||
actions={[
|
||||
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(role)}>
|
||||
编辑
|
||||
</Button>,
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDeleteRole(role.roleId)}>
|
||||
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={<span style={{ fontWeight: 600 }}>{role.roleName}</span>}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text type="secondary">权限标识:{role.roleKey}</Text>
|
||||
<Text type="secondary">状态:{role.status == 1 ? '正常' : '停用'}</Text>
|
||||
<Text type="secondary">
|
||||
{role.admin && '【超级管理员】'}
|
||||
{role.manager && '【机构管理员】'}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</AntdCard>
|
||||
{/* 角色卡片列表 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles && roles.length > 0 ? (
|
||||
roles.map(role => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
hoverable
|
||||
style={{ borderRadius: 8 }}
|
||||
actions={[
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleEditRole(role)}
|
||||
>
|
||||
编辑
|
||||
</Button>,
|
||||
<Popconfirm
|
||||
title="确定删除该角色?"
|
||||
onConfirm={() => handleDeleteRole(role.roleId)}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={<span style={{ fontWeight: 600 }}>{role.roleName}</span>}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text type="secondary">权限标识:{role.roleKey}</Text>
|
||||
<Text type="secondary">状态:{role.status == 1 ? '正常' : '停用'}</Text>
|
||||
<Text type="secondary">
|
||||
{role.admin && '【超级管理员】'}
|
||||
{role.manager && '【机构管理员】'}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))
|
||||
) : (
|
||||
<Col span={24}>
|
||||
<EmptyData height={260} description="暂无角色数据" />
|
||||
</Col>
|
||||
))
|
||||
) : (
|
||||
<Col span={24}>
|
||||
<EmptyData height={260} description="暂无角色数据" />
|
||||
</Col>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
|
||||
)}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑弹窗 */}
|
||||
<Modal
|
||||
@@ -221,14 +224,13 @@ export default function Roles() {
|
||||
<InputNumber style={{ width: '100%' }} min={1} />
|
||||
</Form.Item>
|
||||
|
||||
{/* 三个 Switch 一行 */}
|
||||
{/* 状态 Switch */}
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Form.Item name="status" label="状态" valuePropName="checked">
|
||||
<Switch checkedChildren="正常" unCheckedChildren="停用" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
</Row>
|
||||
|
||||
<Divider>菜单权限配置</Divider>
|
||||
|
||||
Reference in New Issue
Block a user