xx
This commit is contained in:
@@ -7,7 +7,7 @@ const API_BASE_URL = envConfig.baseURL;
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 20000,
|
||||
timeout: 50000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
|
||||
@@ -59,6 +59,16 @@ export function deleteRegion(data) {
|
||||
});
|
||||
}
|
||||
|
||||
//根据组织id查询场站 /system/site/selectByOrgId
|
||||
|
||||
export function getSiteByOrgId(params) {
|
||||
return request({
|
||||
url: '/system/site/selectByOrgId',
|
||||
method: 'get',
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import {
|
||||
getStationList, saveSite, deleteSite,
|
||||
getStationRegions, saveRegion, deleteRegion
|
||||
} from '../api/stationManage';
|
||||
import { getOrgList } from '../api/organization';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '../store';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
@@ -18,6 +21,12 @@ export default function StationManage() {
|
||||
const [currentStation, setCurrentStation] = useState(null);
|
||||
const [regionList, setRegionList] = useState([]);
|
||||
|
||||
// 组织列表
|
||||
const [orgList, setOrgList] = useState([]);
|
||||
|
||||
// 获取当前登录用户信息
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
|
||||
// 场站弹窗
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
@@ -39,6 +48,21 @@ export default function StationManage() {
|
||||
total: 0
|
||||
});
|
||||
|
||||
// ====================== 获取组织列表(根据 userId 过滤) ======================
|
||||
const getOrgData = () => {
|
||||
console.log(userInfo, "userInfo")
|
||||
const params = {
|
||||
pageNum: 1,
|
||||
pageSize: 9999,
|
||||
userId: userInfo?.userId
|
||||
};
|
||||
getOrgList(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
setOrgList(res.rows || []);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// ====================== 获取场站列表(分页) ======================
|
||||
const getStationData = () => {
|
||||
const params = {
|
||||
@@ -66,8 +90,10 @@ export default function StationManage() {
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化加载
|
||||
useEffect(() => {
|
||||
getStationData();
|
||||
getOrgData(); // 进入页面就加载组织
|
||||
}, [pagination.pageNum, pagination.pageSize]);
|
||||
|
||||
// ====================== 新增 / 编辑 场站 ======================
|
||||
@@ -80,7 +106,10 @@ export default function StationManage() {
|
||||
|
||||
const handleEdit = (record) => {
|
||||
setEditRecord(record);
|
||||
form.setFieldsValue({ ...record, status: record.status === 1 });
|
||||
form.setFieldsValue({
|
||||
...record,
|
||||
status: record.status === 1
|
||||
});
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
@@ -244,8 +273,14 @@ export default function StationManage() {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item name="orgId" label="所属组织ID">
|
||||
<Input placeholder="选填" />
|
||||
<Form.Item name="orgId" label="所属组织">
|
||||
<Select placeholder="请选择所属组织" allowClear>
|
||||
{orgList.map(item => (
|
||||
<Select.Option key={item.id} value={item.orgId}>
|
||||
{item.orgName}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Row gutter={16}>
|
||||
|
||||
@@ -14,6 +14,9 @@ import { addUser, deleteUser, editUser, getUser } from '../api/user';
|
||||
import EmptyData from '../components/Empty';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '../store';
|
||||
import { getOrgList } from '../api/organization';
|
||||
import { getSiteByOrgId } from '../api/stationManage';
|
||||
|
||||
|
||||
const { Text } = Typography;
|
||||
const { TabPane } = Tabs;
|
||||
@@ -41,6 +44,8 @@ export default function UserRolePage() {
|
||||
const [selectedUserIds, setSelectedUserIds] = useState<number[]>([]);
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const [roleDetail, setRoleDetail] = useState(null);
|
||||
const [orgList, setOrgList] = useState([]);
|
||||
const [siteList, setSiteList] = useState([]);
|
||||
|
||||
// ====================== 统一分页 ======================
|
||||
const [rolePagination, setRolePagination] = useState({
|
||||
@@ -50,6 +55,24 @@ export default function UserRolePage() {
|
||||
pageNum: 1, pageSize: 10, total: 0
|
||||
});
|
||||
|
||||
// 获取组织列表
|
||||
const getOrgData = () => {
|
||||
getOrgList({ pageNum: 1, pageSize: 9999 }).then(res => {
|
||||
if (res.code === 200) setOrgList(res.rows || []);
|
||||
});
|
||||
};
|
||||
|
||||
// 根据组织ID获取场站
|
||||
const getSiteByOrg = (orgId) => {
|
||||
if (!orgId) {
|
||||
setSiteList([]);
|
||||
return;
|
||||
}
|
||||
getSiteByOrgId({ id: orgId }).then(res => {
|
||||
if (res.code === 200) setSiteList(res.data || res.rows || []);
|
||||
}).catch(() => setSiteList([]));
|
||||
};
|
||||
|
||||
// ====================== 获取角色列表 ======================
|
||||
const getRoleData = () => {
|
||||
const params = {
|
||||
@@ -106,24 +129,22 @@ export default function UserRolePage() {
|
||||
|
||||
// ====================== 获取当前角色详情 ======================
|
||||
const getRoleById = () => {
|
||||
if (!userInfo?.roleId) return; // 无 roleId 不请求
|
||||
if (!userInfo?.roleId) return;
|
||||
getRoleDetailById(userInfo.roleId).then(res => {
|
||||
if (res.code == 200) setRoleDetail(res.data);
|
||||
});
|
||||
};
|
||||
|
||||
// ====================== 【核心优化】只在首次加载请求 ======================
|
||||
// ====================== 初始化加载 ======================
|
||||
useEffect(() => {
|
||||
getMenuData(); // 菜单树只请求一次
|
||||
getRoleById(); // 角色详情只请求一次
|
||||
}, []); // 空依赖 → 只执行一次
|
||||
getMenuData();
|
||||
getRoleById();
|
||||
}, []);
|
||||
|
||||
// ====================== 角色分页变化 ======================
|
||||
useEffect(() => {
|
||||
getRoleData();
|
||||
}, [rolePagination.pageNum, rolePagination.pageSize]);
|
||||
|
||||
// ====================== 用户分页变化 ======================
|
||||
useEffect(() => {
|
||||
getUserData();
|
||||
getRoleForSelect();
|
||||
@@ -226,7 +247,6 @@ export default function UserRolePage() {
|
||||
messageApi.success(editRole ? '编辑成功' : '新增成功');
|
||||
setRoleModalVisible(false);
|
||||
getRoleById();
|
||||
|
||||
getRoleData();
|
||||
getRoleForSelect();
|
||||
} else messageApi.error(res.msg || '保存失败');
|
||||
@@ -236,14 +256,30 @@ export default function UserRolePage() {
|
||||
|
||||
// ====================== 用户操作 ======================
|
||||
const handleAddUser = () => {
|
||||
form.resetFields();
|
||||
setCurrentUser(null);
|
||||
setSiteList([]);
|
||||
setOrgList([]);
|
||||
form.resetFields();
|
||||
if (userInfo?.userId == 1) {
|
||||
getOrgData();
|
||||
}
|
||||
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleEditUser = (record) => {
|
||||
setCurrentUser(record);
|
||||
form.setFieldsValue({ ...record, roleIds: record.roles?.map(i => i.roleId) || [] });
|
||||
form.setFieldsValue({
|
||||
...record,
|
||||
roleIds: record.roles?.map(i => i.roleId) || []
|
||||
});
|
||||
|
||||
setSiteList([]);
|
||||
if (userInfo?.userId === 1) {
|
||||
getOrgData();
|
||||
|
||||
}
|
||||
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
@@ -276,7 +312,9 @@ export default function UserRolePage() {
|
||||
|
||||
const handleSaveUser = () => {
|
||||
form.validateFields().then(values => {
|
||||
const params = { ...values, roleIds: values.roleIds || [] };
|
||||
const params = {
|
||||
...values, roleIds: values.roleIds ? [values.roleIds] : []
|
||||
};
|
||||
if (currentUser) params.userId = currentUser.userId;
|
||||
|
||||
const api = currentUser ? editUser : addUser;
|
||||
@@ -436,7 +474,6 @@ export default function UserRolePage() {
|
||||
width={560}
|
||||
>
|
||||
<Form form={roleForm} layout="vertical">
|
||||
{/* 一行两个:角色名称 + 权限标识 */}
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="roleName" label="角色名称" rules={[{ required: true }]}>
|
||||
@@ -450,7 +487,6 @@ export default function UserRolePage() {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 一行两个:排序 + 状态 */}
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="roleSort" label="排序">
|
||||
@@ -464,7 +500,6 @@ export default function UserRolePage() {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 场站权限 */}
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="siteAccess" label="是否有场站权限" valuePropName="checked">
|
||||
@@ -474,7 +509,6 @@ export default function UserRolePage() {
|
||||
<Col span={12}></Col>
|
||||
</Row>
|
||||
|
||||
{/* 菜单权限 */}
|
||||
{userInfo?.roleId == 23 && (
|
||||
<>
|
||||
<Divider>菜单权限</Divider>
|
||||
@@ -530,6 +564,7 @@ export default function UserRolePage() {
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="sex" label="性别" initialValue="2">
|
||||
@@ -540,12 +575,47 @@ export default function UserRolePage() {
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
{roleDetail?.siteAccess && (
|
||||
<Col span={12}>
|
||||
<Form.Item name="siteId" label="场站ID">
|
||||
<Input />
|
||||
</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="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>
|
||||
|
||||
Reference in New Issue
Block a user