权限 继续
This commit is contained in:
@@ -17,7 +17,7 @@ export function editRoleApi(data) {
|
||||
data
|
||||
});
|
||||
}
|
||||
//获取角色列表
|
||||
//获取角色列表 所有角色
|
||||
export function getRoleList(params) {
|
||||
return request({
|
||||
url: '/system/role/selectRoleAll',
|
||||
|
||||
@@ -57,7 +57,7 @@ export default function UserRolePage() {
|
||||
|
||||
// 获取组织列表
|
||||
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 || []);
|
||||
});
|
||||
};
|
||||
@@ -104,7 +104,8 @@ export default function UserRolePage() {
|
||||
const getUserData = () => {
|
||||
const params = {
|
||||
pageNum: userPagination.pageNum,
|
||||
pageSize: userPagination.pageSize
|
||||
pageSize: userPagination.pageSize,
|
||||
userId: userInfo?.userId
|
||||
};
|
||||
getUser(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
@@ -121,7 +122,7 @@ export default function UserRolePage() {
|
||||
const getRoleForSelect = () => {
|
||||
getRoleList({
|
||||
pageNum: 1, pageSize: 1000,
|
||||
...(userInfo?.roleId && { roleId: userInfo.roleId }),
|
||||
//...(userInfo?.roleId && { roleId: userInfo.roleId }),
|
||||
}).then(res => {
|
||||
if (res.code === 200) setRolesOption(res.data || []);
|
||||
});
|
||||
@@ -260,39 +261,50 @@ export default function UserRolePage() {
|
||||
const handleAddUser = () => {
|
||||
setCurrentUser(null);
|
||||
setSiteList([]);
|
||||
setOrgList([]);
|
||||
form.resetFields();
|
||||
|
||||
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleEditUser = (record) => {
|
||||
setCurrentUser(record);
|
||||
console.log(record, "record")
|
||||
|
||||
// 回填表单所有值
|
||||
form.setFieldsValue({
|
||||
...record,
|
||||
roleIds: record.roleId
|
||||
roleIds: record.roleId || (record.roles?.[0]?.roleId),
|
||||
password: undefined, // 编辑不显示密码
|
||||
});
|
||||
|
||||
setSiteList([]);
|
||||
|
||||
// ✅ 关键修复:如果用户有 orgId,自动加载对应场站
|
||||
if (record.orgId) {
|
||||
getSiteByOrg(record.orgId);
|
||||
|
||||
setTimeout(() => {
|
||||
form.setFieldsValue({
|
||||
siteId: record.siteId
|
||||
});
|
||||
}, 800);
|
||||
form.setFieldsValue({ siteId: record.siteId });
|
||||
}, 300);
|
||||
}
|
||||
|
||||
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) => {
|
||||
deleteUser(userId).then(res => {
|
||||
if (res.code === 200) {
|
||||
@@ -322,12 +334,15 @@ export default function UserRolePage() {
|
||||
|
||||
const handleSaveUser = () => {
|
||||
form.validateFields().then(values => {
|
||||
console.log(values, "vsss")
|
||||
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;
|
||||
api(params).then(res => {
|
||||
@@ -335,7 +350,9 @@ export default function UserRolePage() {
|
||||
messageApi.success(currentUser ? '编辑成功' : '新增成功');
|
||||
setModalVisible(false);
|
||||
getUserData();
|
||||
} else messageApi.error(res.msg || '保存失败');
|
||||
} else {
|
||||
messageApi.error(res.msg || '保存失败');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -390,10 +407,40 @@ export default function UserRolePage() {
|
||||
{
|
||||
title: '操作', render: (_, r) => (
|
||||
<Space>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditUser(r)}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => handleDeleteUser(r.userId)} title="确定删除?">
|
||||
<Button type="text" danger>删除</Button>
|
||||
{/* 编辑 - 蓝色主色 */}
|
||||
<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>
|
||||
|
||||
{/* 重置密码 - 橙色醒目色 */}
|
||||
<Button
|
||||
type="text"
|
||||
icon={<UserOutlined style={{ color: '#faad14' }} />}
|
||||
onClick={() => {
|
||||
setCurrentUser(r); // 必须先赋值当前用户
|
||||
handleResetPassword();
|
||||
}}
|
||||
>
|
||||
重置密码
|
||||
</Button>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
@@ -413,67 +460,70 @@ export default function UserRolePage() {
|
||||
</TabPane>
|
||||
|
||||
{/* ========== 角色管理 ========== */}
|
||||
<TabPane tab="角色管理" key="role">
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
{selectedRoleIds.length > 0 && (
|
||||
<Button danger onClick={handleBatchDeleteRoles}>
|
||||
批量删除(已选 {selectedRoleIds.length} 项)
|
||||
</Button>
|
||||
)}
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
||||
</div>
|
||||
{userInfo?.userId == 1 && (
|
||||
<TabPane tab="角色管理" key="role">
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
{selectedRoleIds.length > 0 && (
|
||||
<Button danger onClick={handleBatchDeleteRoles}>
|
||||
批量删除(已选 {selectedRoleIds.length} 项)
|
||||
</Button>
|
||||
)}
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
||||
</div>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles.length > 0 ? roles.map(r => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={r.roleId}>
|
||||
<AntdCard
|
||||
hoverable
|
||||
style={{ borderRadius: 10, position: 'relative' }}
|
||||
actions={[
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(r)}>编辑</Button>,
|
||||
<Popconfirm onConfirm={() => handleDeleteRole(r.roleId)} title="确定删除?">
|
||||
<Button type="text" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<div style={{ position: 'absolute', top: 10, right: 10 }}>
|
||||
<Checkbox
|
||||
checked={selectedRoleIds.includes(r.roleId)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setSelectedRoleIds([...selectedRoleIds, r.roleId]);
|
||||
} else {
|
||||
setSelectedRoleIds(selectedRoleIds.filter(id => id !== r.roleId));
|
||||
}
|
||||
}}
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles.length > 0 ? roles.map(r => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={r.roleId}>
|
||||
<AntdCard
|
||||
hoverable
|
||||
style={{ borderRadius: 10, position: 'relative' }}
|
||||
actions={[
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(r)}>编辑</Button>,
|
||||
<Popconfirm onConfirm={() => handleDeleteRole(r.roleId)} title="确定删除?">
|
||||
<Button type="text" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<div style={{ position: 'absolute', top: 10, right: 10 }}>
|
||||
<Checkbox
|
||||
checked={selectedRoleIds.includes(r.roleId)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setSelectedRoleIds([...selectedRoleIds, r.roleId]);
|
||||
} else {
|
||||
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>
|
||||
<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>
|
||||
}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
)) : <EmptyData height={260} />}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
)) : <EmptyData height={260} />}
|
||||
</Row>
|
||||
|
||||
<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>
|
||||
)}
|
||||
|
||||
<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>
|
||||
</AntdCard>
|
||||
|
||||
@@ -537,7 +587,6 @@ export default function UserRolePage() {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* ========== 用户弹窗 ========== */}
|
||||
<Modal
|
||||
title={currentUser ? '编辑用户' : '新增用户'}
|
||||
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="email" label="邮箱"><Input /></Form.Item></Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}><Form.Item name="password" label="密码"><Input.Password placeholder="不填不修改" /></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>
|
||||
<Col span={12}>
|
||||
<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 gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}>
|
||||
@@ -588,47 +655,36 @@ export default function UserRolePage() {
|
||||
</Form.Item>
|
||||
</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}>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
{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>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user