权限 继续
This commit is contained in:
@@ -17,7 +17,7 @@ export function editRoleApi(data) {
|
|||||||
data
|
data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//获取角色列表
|
//获取角色列表 所有角色
|
||||||
export function getRoleList(params) {
|
export function getRoleList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/role/selectRoleAll',
|
url: '/system/role/selectRoleAll',
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default function UserRolePage() {
|
|||||||
|
|
||||||
// 获取组织列表
|
// 获取组织列表
|
||||||
const getOrgData = () => {
|
const getOrgData = () => {
|
||||||
getOrgList({ pageNum: 1, pageSize: 9999 }).then(res => {
|
getOrgList({ pageNum: 1, pageSize: 9999, userId: userInfo?.userId }).then(res => {
|
||||||
if (res.code === 200) setOrgList(res.rows || []);
|
if (res.code === 200) setOrgList(res.rows || []);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -104,7 +104,8 @@ export default function UserRolePage() {
|
|||||||
const getUserData = () => {
|
const getUserData = () => {
|
||||||
const params = {
|
const params = {
|
||||||
pageNum: userPagination.pageNum,
|
pageNum: userPagination.pageNum,
|
||||||
pageSize: userPagination.pageSize
|
pageSize: userPagination.pageSize,
|
||||||
|
userId: userInfo?.userId
|
||||||
};
|
};
|
||||||
getUser(params).then(res => {
|
getUser(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -121,7 +122,7 @@ export default function UserRolePage() {
|
|||||||
const getRoleForSelect = () => {
|
const getRoleForSelect = () => {
|
||||||
getRoleList({
|
getRoleList({
|
||||||
pageNum: 1, pageSize: 1000,
|
pageNum: 1, pageSize: 1000,
|
||||||
...(userInfo?.roleId && { roleId: userInfo.roleId }),
|
//...(userInfo?.roleId && { roleId: userInfo.roleId }),
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.code === 200) setRolesOption(res.data || []);
|
if (res.code === 200) setRolesOption(res.data || []);
|
||||||
});
|
});
|
||||||
@@ -260,39 +261,50 @@ export default function UserRolePage() {
|
|||||||
const handleAddUser = () => {
|
const handleAddUser = () => {
|
||||||
setCurrentUser(null);
|
setCurrentUser(null);
|
||||||
setSiteList([]);
|
setSiteList([]);
|
||||||
setOrgList([]);
|
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
|
|
||||||
|
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditUser = (record) => {
|
const handleEditUser = (record) => {
|
||||||
setCurrentUser(record);
|
setCurrentUser(record);
|
||||||
console.log(record, "record")
|
|
||||||
|
|
||||||
// 回填表单所有值
|
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
...record,
|
...record,
|
||||||
roleIds: record.roleId
|
roleIds: record.roleId || (record.roles?.[0]?.roleId),
|
||||||
|
password: undefined, // 编辑不显示密码
|
||||||
});
|
});
|
||||||
|
|
||||||
setSiteList([]);
|
setSiteList([]);
|
||||||
|
|
||||||
// ✅ 关键修复:如果用户有 orgId,自动加载对应场站
|
|
||||||
if (record.orgId) {
|
if (record.orgId) {
|
||||||
getSiteByOrg(record.orgId);
|
getSiteByOrg(record.orgId);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({ siteId: record.siteId });
|
||||||
siteId: record.siteId
|
}, 300);
|
||||||
});
|
|
||||||
}, 800);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleResetPassword = () => {
|
||||||
|
modal.confirm({
|
||||||
|
title: '重置密码',
|
||||||
|
content: '确定将密码重置为 123456 吗?',
|
||||||
|
okText: '确认',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
editUser({
|
||||||
|
userId: currentUser.userId,
|
||||||
|
password: '123456'
|
||||||
|
}).then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
messageApi.success('密码已重置为:123456');
|
||||||
|
} else {
|
||||||
|
messageApi.error('重置失败');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleDeleteUser = (userId) => {
|
const handleDeleteUser = (userId) => {
|
||||||
deleteUser(userId).then(res => {
|
deleteUser(userId).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -322,12 +334,15 @@ export default function UserRolePage() {
|
|||||||
|
|
||||||
const handleSaveUser = () => {
|
const handleSaveUser = () => {
|
||||||
form.validateFields().then(values => {
|
form.validateFields().then(values => {
|
||||||
console.log(values, "vsss")
|
|
||||||
const params = {
|
const params = {
|
||||||
...values, roleIds: [values.roleIds].flat()
|
...values,
|
||||||
|
roleIds: [values.roleIds].flat()
|
||||||
};
|
};
|
||||||
if (currentUser) params.userId = currentUser.userId;
|
|
||||||
|
if (currentUser) {
|
||||||
|
params.userId = currentUser.userId;
|
||||||
|
delete params.password; // 编辑不提交密码
|
||||||
|
}
|
||||||
|
|
||||||
const api = currentUser ? editUser : addUser;
|
const api = currentUser ? editUser : addUser;
|
||||||
api(params).then(res => {
|
api(params).then(res => {
|
||||||
@@ -335,7 +350,9 @@ export default function UserRolePage() {
|
|||||||
messageApi.success(currentUser ? '编辑成功' : '新增成功');
|
messageApi.success(currentUser ? '编辑成功' : '新增成功');
|
||||||
setModalVisible(false);
|
setModalVisible(false);
|
||||||
getUserData();
|
getUserData();
|
||||||
} else messageApi.error(res.msg || '保存失败');
|
} else {
|
||||||
|
messageApi.error(res.msg || '保存失败');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -390,10 +407,40 @@ export default function UserRolePage() {
|
|||||||
{
|
{
|
||||||
title: '操作', render: (_, r) => (
|
title: '操作', render: (_, r) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditUser(r)}>编辑</Button>
|
{/* 编辑 - 蓝色主色 */}
|
||||||
<Popconfirm onConfirm={() => handleDeleteUser(r.userId)} title="确定删除?">
|
<Button
|
||||||
<Button type="text" danger>删除</Button>
|
type="text"
|
||||||
|
icon={<EditOutlined style={{ color: '#1890ff' }} />}
|
||||||
|
onClick={() => handleEditUser(r)}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* 删除 - 红色危险色 */}
|
||||||
|
<Popconfirm
|
||||||
|
onConfirm={() => handleDeleteUser(r.userId)}
|
||||||
|
title="确定删除该用户吗?"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
danger
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|
||||||
|
{/* 重置密码 - 橙色醒目色 */}
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<UserOutlined style={{ color: '#faad14' }} />}
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentUser(r); // 必须先赋值当前用户
|
||||||
|
handleResetPassword();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置密码
|
||||||
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -413,67 +460,70 @@ export default function UserRolePage() {
|
|||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
{/* ========== 角色管理 ========== */}
|
{/* ========== 角色管理 ========== */}
|
||||||
<TabPane tab="角色管理" key="role">
|
{userInfo?.userId == 1 && (
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<TabPane tab="角色管理" key="role">
|
||||||
{selectedRoleIds.length > 0 && (
|
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<Button danger onClick={handleBatchDeleteRoles}>
|
{selectedRoleIds.length > 0 && (
|
||||||
批量删除(已选 {selectedRoleIds.length} 项)
|
<Button danger onClick={handleBatchDeleteRoles}>
|
||||||
</Button>
|
批量删除(已选 {selectedRoleIds.length} 项)
|
||||||
)}
|
</Button>
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
)}
|
||||||
</div>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
{roles.length > 0 ? roles.map(r => (
|
{roles.length > 0 ? roles.map(r => (
|
||||||
<Col xs={24} sm={12} md={8} lg={6} key={r.roleId}>
|
<Col xs={24} sm={12} md={8} lg={6} key={r.roleId}>
|
||||||
<AntdCard
|
<AntdCard
|
||||||
hoverable
|
hoverable
|
||||||
style={{ borderRadius: 10, position: 'relative' }}
|
style={{ borderRadius: 10, position: 'relative' }}
|
||||||
actions={[
|
actions={[
|
||||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(r)}>编辑</Button>,
|
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(r)}>编辑</Button>,
|
||||||
<Popconfirm onConfirm={() => handleDeleteRole(r.roleId)} title="确定删除?">
|
<Popconfirm onConfirm={() => handleDeleteRole(r.roleId)} title="确定删除?">
|
||||||
<Button type="text" danger>删除</Button>
|
<Button type="text" danger>删除</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<div style={{ position: 'absolute', top: 10, right: 10 }}>
|
<div style={{ position: 'absolute', top: 10, right: 10 }}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={selectedRoleIds.includes(r.roleId)}
|
checked={selectedRoleIds.includes(r.roleId)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
setSelectedRoleIds([...selectedRoleIds, r.roleId]);
|
setSelectedRoleIds([...selectedRoleIds, r.roleId]);
|
||||||
} else {
|
} else {
|
||||||
setSelectedRoleIds(selectedRoleIds.filter(id => id !== r.roleId));
|
setSelectedRoleIds(selectedRoleIds.filter(id => id !== r.roleId));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Card.Meta
|
||||||
|
title={<strong>{r.roleName}</strong>}
|
||||||
|
description={
|
||||||
|
<Space direction="vertical" size={2}>
|
||||||
|
<Text type="secondary">权限:{r.roleKey}</Text>
|
||||||
|
<Text type="secondary">状态:{r.status == 1 ? '正常' : '停用'}</Text>
|
||||||
|
{r.admin && <Tag color="red">超级管理员</Tag>}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</AntdCard>
|
||||||
<Card.Meta
|
</Col>
|
||||||
title={<strong>{r.roleName}</strong>}
|
)) : <EmptyData height={260} />}
|
||||||
description={
|
</Row>
|
||||||
<Space direction="vertical" size={2}>
|
|
||||||
<Text type="secondary">权限:{r.roleKey}</Text>
|
<div style={{ textAlign: 'right', marginTop: 20 }}>
|
||||||
<Text type="secondary">状态:{r.status == 1 ? '正常' : '停用'}</Text>
|
<Pagination
|
||||||
{r.admin && <Tag color="red">超级管理员</Tag>}
|
current={rolePagination.pageNum}
|
||||||
</Space>
|
pageSize={rolePagination.pageSize}
|
||||||
}
|
total={rolePagination.total}
|
||||||
/>
|
showSizeChanger
|
||||||
</AntdCard>
|
showTotal={(t) => `共 ${t} 条`}
|
||||||
</Col>
|
onChange={(p, s) => setRolePagination({ pageNum: p, pageSize: s, total: rolePagination.total })}
|
||||||
)) : <EmptyData height={260} />}
|
/>
|
||||||
</Row>
|
</div>
|
||||||
|
</TabPane>
|
||||||
|
)}
|
||||||
|
|
||||||
<div style={{ textAlign: 'right', marginTop: 20 }}>
|
|
||||||
<Pagination
|
|
||||||
current={rolePagination.pageNum}
|
|
||||||
pageSize={rolePagination.pageSize}
|
|
||||||
total={rolePagination.total}
|
|
||||||
showSizeChanger
|
|
||||||
showTotal={(t) => `共 ${t} 条`}
|
|
||||||
onChange={(p, s) => setRolePagination({ pageNum: p, pageSize: s, total: rolePagination.total })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</TabPane>
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</AntdCard>
|
</AntdCard>
|
||||||
|
|
||||||
@@ -537,7 +587,6 @@ export default function UserRolePage() {
|
|||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
{/* ========== 用户弹窗 ========== */}
|
|
||||||
<Modal
|
<Modal
|
||||||
title={currentUser ? '编辑用户' : '新增用户'}
|
title={currentUser ? '编辑用户' : '新增用户'}
|
||||||
open={modalVisible}
|
open={modalVisible}
|
||||||
@@ -555,10 +604,28 @@ export default function UserRolePage() {
|
|||||||
<Col span={12}><Form.Item name="phonenumber" label="手机"><Input /></Form.Item></Col>
|
<Col span={12}><Form.Item name="phonenumber" label="手机"><Input /></Form.Item></Col>
|
||||||
<Col span={12}><Form.Item name="email" label="邮箱"><Input /></Form.Item></Col>
|
<Col span={12}><Form.Item name="email" label="邮箱"><Input /></Form.Item></Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={12}><Form.Item name="password" label="密码"><Input.Password placeholder="不填不修改" /></Form.Item></Col>
|
<Col span={12}>
|
||||||
<Col span={12}><Form.Item name="language" label="语言"><Select><Select.Option value="zh-CN">中文</Select.Option><Select.Option value="en">英语</Select.Option></Select></Form.Item></Col>
|
<Form.Item name="password" label="密码">
|
||||||
|
<Input.Password
|
||||||
|
placeholder={currentUser ? "编辑不显示,重置为123456" : "请输入密码"}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Col span={12}>
|
||||||
|
<Form.Item name="language" label="语言">
|
||||||
|
<Select>
|
||||||
|
<Select.Option value="zh-CN">中文</Select.Option>
|
||||||
|
<Select.Option value="en">英语</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}>
|
<Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}>
|
||||||
@@ -588,47 +655,36 @@ export default function UserRolePage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* 管理员:组织 + 场站 */}
|
<>
|
||||||
{userInfo?.userId == 1 ? (
|
<Col span={12}>
|
||||||
<>
|
<Form.Item name="orgId" label="所属组织">
|
||||||
|
<Select
|
||||||
|
placeholder="请选择组织"
|
||||||
|
allowClear
|
||||||
|
onChange={(val) => {
|
||||||
|
getSiteByOrg(val);
|
||||||
|
form.setFieldsValue({ siteId: null });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{orgList.map(item => (
|
||||||
|
<Select.Option key={item.id} value={item.id}>{item.orgName}</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
{siteList.length > 0 && (
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="orgId" label="所属组织">
|
<Form.Item name="siteId" label="所属场站">
|
||||||
<Select
|
<Select placeholder="请选择场站" allowClear>
|
||||||
placeholder="请选择组织"
|
{siteList.map(item => (
|
||||||
allowClear
|
<Select.Option key={item.id} value={item.id}>{item.siteName}</Select.Option>
|
||||||
onChange={(val) => {
|
|
||||||
getSiteByOrg(val);
|
|
||||||
form.setFieldsValue({ siteId: null });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{orgList.map(item => (
|
|
||||||
<Select.Option key={item.id} value={item.id}>{item.orgName}</Select.Option>
|
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
)}
|
||||||
{siteList.length > 0 && (
|
</>
|
||||||
<Col span={12}>
|
|
||||||
<Form.Item name="siteId" label="所属场站">
|
|
||||||
<Select placeholder="请选择场站" allowClear>
|
|
||||||
{siteList.map(item => (
|
|
||||||
<Select.Option key={item.id} value={item.id}>{item.siteName}</Select.Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
</Col>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
roleDetail?.siteAccess && (
|
|
||||||
<Col span={12}>
|
|
||||||
<Form.Item name="siteId" label="场站ID">
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
</Col>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</Row>
|
</Row>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user