权限基本完善
This commit is contained in:
7
env.js
7
env.js
@@ -9,13 +9,14 @@ const currentEnv = import.meta.env?.MODE || process.env.NODE_ENV;
|
|||||||
// 环境配置映射
|
// 环境配置映射
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
[ENV.DEV]: {
|
[ENV.DEV]: {
|
||||||
baseURL: 'http://192.168.2.59:8081',//http://192.168.2.56:8081
|
//baseURL: 'http://192.168.2.59:8081',//http://192.168.2.56:8081
|
||||||
//baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081
|
baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081
|
||||||
WS_URL: 'ws://192.168.2.56:9002/ws/',
|
WS_URL: 'ws://192.168.2.56:9002/ws/',
|
||||||
},
|
},
|
||||||
[ENV.PROD]: {
|
[ENV.PROD]: {
|
||||||
// baseURL: 'http://192.168.2.56:8081',
|
// baseURL: 'http://192.168.2.56:8081',
|
||||||
baseURL: 'https://serviceri.satabot.com',
|
baseURL: 'http://1.95.137.212:59015',//http://192.168.2.56:8081
|
||||||
|
//baseURL: 'https://serviceri.satabot.com',
|
||||||
WS_URL: 'wss://ri.satabot.com/ws/'
|
WS_URL: 'wss://ri.satabot.com/ws/'
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ export default function StationManage() {
|
|||||||
|
|
||||||
// ====================== 获取组织列表(根据 userId 过滤) ======================
|
// ====================== 获取组织列表(根据 userId 过滤) ======================
|
||||||
const getOrgData = () => {
|
const getOrgData = () => {
|
||||||
console.log(userInfo, "userInfo")
|
|
||||||
const params = {
|
const params = {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 9999,
|
pageSize: 9999,
|
||||||
@@ -65,13 +64,11 @@ export default function StationManage() {
|
|||||||
|
|
||||||
// ====================== 获取场站列表(分页) ======================
|
// ====================== 获取场站列表(分页) ======================
|
||||||
const getStationData = () => {
|
const getStationData = () => {
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
pageNum: pagination.pageNum,
|
pageNum: pagination.pageNum,
|
||||||
pageSize: pagination.pageSize,
|
pageSize: pagination.pageSize,
|
||||||
orgId: userInfo?.orgId, // 根据用户所属组织过滤场站
|
orgId: userInfo?.orgId,
|
||||||
};
|
};
|
||||||
|
|
||||||
getStationList(params).then(res => {
|
getStationList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
setStationList(res.rows || []);
|
setStationList(res.rows || []);
|
||||||
@@ -95,7 +92,7 @@ export default function StationManage() {
|
|||||||
// 初始化加载
|
// 初始化加载
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getStationData();
|
getStationData();
|
||||||
getOrgData(); // 进入页面就加载组织
|
getOrgData();
|
||||||
}, [pagination.pageNum, pagination.pageSize]);
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
// ====================== 新增 / 编辑 场站 ======================
|
// ====================== 新增 / 编辑 场站 ======================
|
||||||
@@ -234,10 +231,8 @@ export default function StationManage() {
|
|||||||
<div style={{ padding: '20px' }}>
|
<div style={{ padding: '20px' }}>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
|
||||||
{/* 统一卡片样式 */}
|
|
||||||
<Card title="场站管理" style={{ borderRadius: 8 }}>
|
<Card title="场站管理" style={{ borderRadius: 8 }}>
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<div></div>
|
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
||||||
新增场站
|
新增场站
|
||||||
</Button>
|
</Button>
|
||||||
@@ -286,9 +281,10 @@ export default function StationManage() {
|
|||||||
<Form.Item name="orgId" label="所属组织" rules={[{ required: true }]}>
|
<Form.Item name="orgId" label="所属组织" rules={[{ required: true }]}>
|
||||||
<Select placeholder="请选择所属组织" allowClear>
|
<Select placeholder="请选择所属组织" allowClear>
|
||||||
{orgList.map(item => (
|
{orgList.map(item => (
|
||||||
<Select.Option key={item.id} value={item.orgId}>
|
// ✅ 这里修复了!原来是 item.orgId,现在是 item.id
|
||||||
|
<Option key={item.id} value={item.id}>
|
||||||
{item.orgName}
|
{item.orgName}
|
||||||
</Select.Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Layout, Tabs, Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
Layout, Tabs, Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
||||||
Input, Popconfirm, Divider, InputNumber, Switch, Pagination, Table, Select,
|
Input, Popconfirm, Divider, InputNumber, Pagination, Table, Select,
|
||||||
Tag, Checkbox, App
|
Tag, Checkbox, App
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
@@ -17,16 +17,16 @@ import { RootState } from '../store';
|
|||||||
import { getOrgList } from '../api/organization';
|
import { getOrgList } from '../api/organization';
|
||||||
import { getSiteByOrgId } from '../api/stationManage';
|
import { getSiteByOrgId } from '../api/stationManage';
|
||||||
|
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
const AntdCard = Card as any;
|
const AntdCard = Card as any;
|
||||||
|
|
||||||
export default function UserRolePage() {
|
export default function UserRolePage() {
|
||||||
// ====================== 角色管理状态 ======================
|
// ====================== 全局提示 ======================
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
const { modal } = App.useApp();
|
const { modal } = App.useApp();
|
||||||
|
|
||||||
|
// ====================== 角色管理状态 ======================
|
||||||
const [roles, setRoles] = useState([]);
|
const [roles, setRoles] = useState([]);
|
||||||
const [menuTree, setMenuTree] = useState([]);
|
const [menuTree, setMenuTree] = useState([]);
|
||||||
const [checkedKeys, setCheckedKeys] = useState<number[]>([]);
|
const [checkedKeys, setCheckedKeys] = useState<number[]>([]);
|
||||||
@@ -43,13 +43,18 @@ export default function UserRolePage() {
|
|||||||
const [rolesOption, setRolesOption] = useState([]);
|
const [rolesOption, setRolesOption] = useState([]);
|
||||||
const [selectedUserIds, setSelectedUserIds] = useState<number[]>([]);
|
const [selectedUserIds, setSelectedUserIds] = useState<number[]>([]);
|
||||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||||
const [roleDetail, setRoleDetail] = useState(null);
|
|
||||||
const [orgList, setOrgList] = useState([]);
|
const [orgList, setOrgList] = useState([]);
|
||||||
const [siteList, setSiteList] = useState([]);
|
const [siteList, setSiteList] = useState([]);
|
||||||
// ✅ 控制是否显示所属场站
|
// 全局缓存:所有场站(用于表格展示)
|
||||||
const [showSite, setShowSite] = useState(true);
|
const [allSiteList, setAllSiteList] = useState([]);
|
||||||
|
|
||||||
// ====================== 统一分页 ======================
|
const [showSite, setShowSite] = useState(true);
|
||||||
|
const [siteDisabled, setSiteDisabled] = useState(false);
|
||||||
|
const isEditSelf = currentUser?.userId == userInfo?.userId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ====================== 分页 ======================
|
||||||
const [rolePagination, setRolePagination] = useState({
|
const [rolePagination, setRolePagination] = useState({
|
||||||
pageNum: 1, pageSize: 12, total: 0
|
pageNum: 1, pageSize: 12, total: 0
|
||||||
});
|
});
|
||||||
@@ -58,32 +63,44 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 获取组织列表
|
// 获取组织列表
|
||||||
const getOrgData = () => {
|
const getOrgData = async () => {
|
||||||
getOrgList({ pageNum: 1, pageSize: 9999, userId: userInfo?.userId }).then(res => {
|
const res = await getOrgList({ pageNum: 1, pageSize: 9999, userId: userInfo?.userId });
|
||||||
if (res.code === 200) setOrgList(res.rows || []);
|
if (res.code === 200) {
|
||||||
});
|
const orgs = res.rows || [];
|
||||||
|
setOrgList(orgs);
|
||||||
|
// 预加载所有组织下的场站,缓存
|
||||||
|
await loadAllSite(orgs);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 根据组织ID获取场站
|
// 预加载全部场站
|
||||||
|
const loadAllSite = async (orgs) => {
|
||||||
|
let totalSite = [];
|
||||||
|
for (const org of orgs) {
|
||||||
|
const res = await getSiteByOrgId({ id: org.id }).catch(() => ({ code: 200, data: [] }));
|
||||||
|
if (res.code === 200) {
|
||||||
|
const list = res.data || res.rows || [];
|
||||||
|
totalSite = [...totalSite, ...list];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setAllSiteList(totalSite);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据组织ID获取场站(弹窗下拉用)
|
||||||
const getSiteByOrg = (orgId) => {
|
const getSiteByOrg = (orgId) => {
|
||||||
if (!orgId) {
|
if (!orgId) {
|
||||||
setSiteList([]);
|
setSiteList([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getSiteByOrgId({ id: orgId }).then(res => {
|
const list = allSiteList.filter(item => item.orgId == orgId);
|
||||||
if (res.code === 200) setSiteList(res.data || res.rows || []);
|
setSiteList(list);
|
||||||
}).catch(() => setSiteList([]));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 获取角色列表 ======================
|
// 获取角色列表
|
||||||
const getRoleData = () => {
|
const getRoleData = () => {
|
||||||
const params = {
|
const params = { pageNum: rolePagination.pageNum, pageSize: rolePagination.pageSize };
|
||||||
pageNum: rolePagination.pageNum,
|
|
||||||
pageSize: rolePagination.pageSize,
|
|
||||||
};
|
|
||||||
getRoleList(params).then(res => {
|
getRoleList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
// 根据 roleSort 升序排序(越小越靠前)
|
|
||||||
let sortedRoles = (res.data || []).sort((a, b) => (a.roleSort || 999) - (b.roleSort || 999));
|
let sortedRoles = (res.data || []).sort((a, b) => (a.roleSort || 999) - (b.roleSort || 999));
|
||||||
setRoles(sortedRoles);
|
setRoles(sortedRoles);
|
||||||
setRolePagination({
|
setRolePagination({
|
||||||
@@ -94,7 +111,7 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 获取菜单树(只加载一次) ======================
|
// 获取菜单树
|
||||||
const getMenuData = () => {
|
const getMenuData = () => {
|
||||||
getMenuList({ pageNum: 1, pageSize: 1000 }).then(res => {
|
getMenuList({ pageNum: 1, pageSize: 1000 }).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
@@ -104,14 +121,13 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 获取用户列表 ======================
|
// 获取用户列表
|
||||||
const getUserData = () => {
|
const getUserData = () => {
|
||||||
const params = {
|
const params = {
|
||||||
pageNum: userPagination.pageNum,
|
pageNum: userPagination.pageNum,
|
||||||
pageSize: userPagination.pageSize,
|
pageSize: userPagination.pageSize,
|
||||||
orgId: userInfo?.orgId,
|
orgId: userInfo?.orgId,
|
||||||
siteId: userInfo?.siteId,
|
siteId: userInfo?.siteId,
|
||||||
//userId: userInfo?.userId
|
|
||||||
};
|
};
|
||||||
getUser(params).then(res => {
|
getUser(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -124,11 +140,9 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 获取角色下拉框 ======================
|
// 角色下拉选项
|
||||||
const getRoleForSelect = () => {
|
const getRoleForSelect = () => {
|
||||||
getRoleAllocate({
|
getRoleAllocate({ pageNum: 1, pageSize: 1000 }).then(res => {
|
||||||
pageNum: 1, pageSize: 1000,
|
|
||||||
}).then(res => {
|
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
let sortedRoles = (res.data || []).sort((a, b) => (a.roleSort || 999) - (b.roleSort || 999));
|
let sortedRoles = (res.data || []).sort((a, b) => (a.roleSort || 999) - (b.roleSort || 999));
|
||||||
setRolesOption(sortedRoles);
|
setRolesOption(sortedRoles);
|
||||||
@@ -136,15 +150,7 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 获取当前角色详情 ======================
|
// 初始化
|
||||||
const getRoleById = () => {
|
|
||||||
if (!userInfo?.roleId) return;
|
|
||||||
getRoleDetailById(userInfo.roleId).then(res => {
|
|
||||||
if (res.code == 200) setRoleDetail(res.data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// ====================== 初始化加载 ======================
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getMenuData();
|
getMenuData();
|
||||||
getOrgData();
|
getOrgData();
|
||||||
@@ -164,21 +170,17 @@ export default function UserRolePage() {
|
|||||||
roleForm.resetFields();
|
roleForm.resetFields();
|
||||||
setCheckedKeys([]);
|
setCheckedKeys([]);
|
||||||
setEditRole(null);
|
setEditRole(null);
|
||||||
// 默认值
|
|
||||||
roleForm.setFieldsValue({ status: true, roleSort: 1, roleLevel: 1 });
|
roleForm.setFieldsValue({ status: true, roleSort: 1, roleLevel: 1 });
|
||||||
setRoleModalVisible(true);
|
setRoleModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditRole = (record) => {
|
const handleEditRole = (record) => {
|
||||||
setEditRole(record);
|
setEditRole(record);
|
||||||
roleForm.setFieldsValue({
|
roleForm.setFieldsValue({ ...record, roleLevel: record.roleLevel });
|
||||||
...record,
|
|
||||||
roleLevel: record.roleLevel
|
|
||||||
});
|
|
||||||
|
|
||||||
const getAllLeafKeys = (tree) => {
|
const getAllLeafKeys = (tree) => {
|
||||||
let leaves = [];
|
let leaves: number[] = [];
|
||||||
function traverse(nodes) {
|
function traverse(nodes: any[]) {
|
||||||
nodes.forEach(node => {
|
nodes.forEach(node => {
|
||||||
if (!node.children || node.children.length === 0) {
|
if (!node.children || node.children.length === 0) {
|
||||||
leaves.push(node.key);
|
leaves.push(node.key);
|
||||||
@@ -190,15 +192,12 @@ export default function UserRolePage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const leafKeys = getAllLeafKeys(menuTree);
|
const leafKeys = getAllLeafKeys(menuTree);
|
||||||
const leafChecked = (record.menuIds || [])
|
const leafChecked = (record.menuIds || []).map(Number).filter(id => leafKeys.includes(id));
|
||||||
.map(Number)
|
|
||||||
.filter(id => leafKeys.includes(id));
|
|
||||||
|
|
||||||
setCheckedKeys(leafChecked);
|
setCheckedKeys(leafChecked);
|
||||||
setRoleModalVisible(true);
|
setRoleModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteRole = (roleId) => {
|
const handleDeleteRole = (roleId: number) => {
|
||||||
deleteRole([roleId]).then(res => {
|
deleteRole([roleId]).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
messageApi.success('删除成功');
|
messageApi.success('删除成功');
|
||||||
@@ -229,7 +228,7 @@ export default function UserRolePage() {
|
|||||||
|
|
||||||
const handleSaveRole = () => {
|
const handleSaveRole = () => {
|
||||||
roleForm.validateFields().then(values => {
|
roleForm.validateFields().then(values => {
|
||||||
const getParentKeys = (key, tree) => {
|
const getParentKeys = (key: number, tree: any[]) => {
|
||||||
for (let node of tree) {
|
for (let node of tree) {
|
||||||
if (node.key === key) return [node.key];
|
if (node.key === key) return [node.key];
|
||||||
if (node.children) {
|
if (node.children) {
|
||||||
@@ -240,7 +239,7 @@ export default function UserRolePage() {
|
|||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
let allMenuIds = [];
|
let allMenuIds: number[] = [];
|
||||||
checkedKeys.forEach(key => {
|
checkedKeys.forEach(key => {
|
||||||
allMenuIds.push(...getParentKeys(key, menuTree));
|
allMenuIds.push(...getParentKeys(key, menuTree));
|
||||||
});
|
});
|
||||||
@@ -254,7 +253,6 @@ export default function UserRolePage() {
|
|||||||
roleLevel: values.roleLevel
|
roleLevel: values.roleLevel
|
||||||
};
|
};
|
||||||
if (editRole) params.roleId = editRole.roleId;
|
if (editRole) params.roleId = editRole.roleId;
|
||||||
|
|
||||||
const api = editRole ? editRoleApi : addRole;
|
const api = editRole ? editRoleApi : addRole;
|
||||||
api(params).then(res => {
|
api(params).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
@@ -268,63 +266,71 @@ export default function UserRolePage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 用户操作 ======================
|
// ====================== 用户操作 ======================
|
||||||
|
// 新增用户
|
||||||
const handleAddUser = () => {
|
const handleAddUser = () => {
|
||||||
setCurrentUser(null);
|
setCurrentUser(null);
|
||||||
|
setShowSite(true);
|
||||||
setSiteList([]);
|
setSiteList([]);
|
||||||
setShowSite(true); // ✅ 默认显示
|
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
|
|
||||||
|
const defaultOrgId = userInfo?.orgId ?? '';
|
||||||
|
const defaultSiteId = userInfo?.siteId ?? '';
|
||||||
|
|
||||||
|
form.setFieldsValue({
|
||||||
|
orgId: defaultOrgId,
|
||||||
|
siteId: defaultSiteId
|
||||||
|
});
|
||||||
|
|
||||||
|
setSiteDisabled(!!defaultSiteId);
|
||||||
|
|
||||||
|
if (defaultOrgId) {
|
||||||
|
getSiteByOrg(defaultOrgId);
|
||||||
|
}
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditUser = (record) => {
|
// 编辑用户
|
||||||
|
const handleEditUser = (record: any) => {
|
||||||
setCurrentUser(record);
|
setCurrentUser(record);
|
||||||
// ✅ 1. 先拿到当前用户的角色ID(优先取roles里的,兼容roleId字段)
|
|
||||||
const userRoleId = record.roles?.[0]?.roleId ?? record.roleId;
|
const userRoleId = record.roles?.[0]?.roleId ?? record.roleId;
|
||||||
// ✅ 2. 从角色下拉选项里,找到匹配ID的「中文名称」
|
const targetRole = rolesOption.find(item => String(item.roleId) === String(userRoleId));
|
||||||
const targetRole = rolesOption.find(item => item.roleId == userRoleId);
|
|
||||||
|
|
||||||
// ✅ 3. 回填表单:roleIds 赋值「角色ID」,确保下拉框显示中文
|
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
...record,
|
...record,
|
||||||
roleIds: targetRole?.roleId ?? userRoleId, // 用找到的角色ID(确保匹配)
|
roleIds: targetRole?.roleId ?? userRoleId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isOrgAdmin = targetRole?.roleKey == 'manager';
|
const isOrgAdmin = targetRole?.roleKey === 'manager';
|
||||||
setShowSite(!isOrgAdmin);
|
setShowSite(!isOrgAdmin);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setSiteList([]);
|
setSiteList([]);
|
||||||
if (record.orgId) {
|
if (record.orgId) {
|
||||||
getSiteByOrg(record.orgId);
|
getSiteByOrg(record.orgId);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
form.setFieldsValue({ siteId: record.siteId });
|
form.setFieldsValue({ siteId: record.siteId });
|
||||||
}, 300);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResetPassword = () => {
|
// 重置密码
|
||||||
|
const handleResetPassword = (user: any) => {
|
||||||
modal.confirm({
|
modal.confirm({
|
||||||
title: '重置密码',
|
title: '重置密码',
|
||||||
content: '确定将密码重置为 123456 吗?',
|
content: '确定将密码重置为 123456 吗?',
|
||||||
okText: '确认',
|
okText: '确认',
|
||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
editUser({
|
editUser({ userId: user.userId, password: '123456' }).then(res => {
|
||||||
userId: currentUser.userId,
|
res.code === 200 ? messageApi.success('密码已重置为:123456') : messageApi.error('重置失败');
|
||||||
password: '123456'
|
|
||||||
}).then(res => {
|
|
||||||
if (res.code === 200) {
|
|
||||||
messageApi.success('密码已重置为:123456');
|
|
||||||
} else {
|
|
||||||
messageApi.error('重置失败');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteUser = (userId) => {
|
const handleDeleteUser = (userId: number) => {
|
||||||
deleteUser(userId).then(res => {
|
deleteUser(userId).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
messageApi.success('删除成功');
|
messageApi.success('删除成功');
|
||||||
@@ -357,12 +363,10 @@ export default function UserRolePage() {
|
|||||||
...values,
|
...values,
|
||||||
roleIds: [values.roleIds].flat()
|
roleIds: [values.roleIds].flat()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
params.userId = currentUser.userId;
|
params.userId = currentUser.userId;
|
||||||
delete params.password;
|
delete params.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = currentUser ? editUser : addUser;
|
const api = currentUser ? editUser : addUser;
|
||||||
api(params).then(res => {
|
api(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -376,7 +380,7 @@ export default function UserRolePage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ====================== 页面主体 ======================
|
// ====================== 页面渲染 ======================
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
height: '100%',
|
height: '100%',
|
||||||
@@ -388,11 +392,9 @@ export default function UserRolePage() {
|
|||||||
background: '#f5f7fa'
|
background: '#f5f7fa'
|
||||||
}}>
|
}}>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
|
||||||
<AntdCard style={{ borderRadius: 12, boxShadow: '0 2px 10px rgba(0,0,0,0.06)' }}>
|
<AntdCard style={{ borderRadius: 12, boxShadow: '0 2px 10px rgba(0,0,0,0.06)' }}>
|
||||||
<Tabs defaultActiveKey="user" type="card" size="large" style={{ marginBottom: 20 }}>
|
<Tabs defaultActiveKey="user" type="card" size="large" style={{ marginBottom: 20 }}>
|
||||||
|
{/* 用户管理 */}
|
||||||
{/* ========== 用户管理 ========== */}
|
|
||||||
<TabPane tab="用户管理" key="user">
|
<TabPane tab="用户管理" key="user">
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||||
{selectedUserIds.length > 0 && (
|
{selectedUserIds.length > 0 && (
|
||||||
@@ -402,7 +404,6 @@ export default function UserRolePage() {
|
|||||||
)}
|
)}
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddUser}>新增用户</Button>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddUser}>新增用户</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
rowKey="userId"
|
rowKey="userId"
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
@@ -414,47 +415,44 @@ export default function UserRolePage() {
|
|||||||
{ title: '用户昵称', dataIndex: 'nickName' },
|
{ title: '用户昵称', dataIndex: 'nickName' },
|
||||||
{ title: '手机号', dataIndex: 'phonenumber' },
|
{ title: '手机号', dataIndex: 'phonenumber' },
|
||||||
{ title: '邮箱', dataIndex: 'email' },
|
{ title: '邮箱', dataIndex: 'email' },
|
||||||
|
// 所属机构
|
||||||
{
|
{
|
||||||
title: '角色', render: (_, r) => (r.roles || []).map(i => (
|
title: '所属机构',
|
||||||
<Tag color="blue" key={i.roleId}>{i.roleName || i.roleKey}</Tag>
|
render: (_, r) => {
|
||||||
|
const org = orgList.find(o => o.id == r.orgId);
|
||||||
|
return org ? org.orgName : '—';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 所属场站(纯缓存匹配,无接口)
|
||||||
|
{
|
||||||
|
title: '所属场站',
|
||||||
|
render: (_, r) => {
|
||||||
|
if (!r.siteId) return '—';
|
||||||
|
const site = allSiteList.find(s => s.id == r.siteId);
|
||||||
|
return site ? site.siteName : '—';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
render: (_, r) => (r.roles || []).map(i => (
|
||||||
|
<Tag color="blue" key={i.roleId}>{i?.roleKey}</Tag>
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '状态', render: (_, s) => s.status == '0' ?
|
title: '状态',
|
||||||
<Tag color="green">正常</Tag> : <Tag color="red">停用</Tag>
|
render: (_, s) => s.status === '0'
|
||||||
|
? <Tag color="green">正常</Tag>
|
||||||
|
: <Tag color="red">停用</Tag>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作', render: (_, r) => (
|
title: '操作',
|
||||||
|
render: (_, r) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button
|
<Button type="text" icon={<EditOutlined style={{ color: '#1890ff' }} />} onClick={() => handleEditUser(r)}>编辑</Button>
|
||||||
type="text"
|
<Popconfirm onConfirm={() => handleDeleteUser(r.userId)} title="确定删除该用户吗?">
|
||||||
icon={<EditOutlined style={{ color: '#1890ff' }} />}
|
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||||
onClick={() => handleEditUser(r)}
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</Button>
|
|
||||||
<Popconfirm
|
|
||||||
onConfirm={() => handleDeleteUser(r.userId)}
|
|
||||||
title="确定删除该用户吗?"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
type="text"
|
|
||||||
danger
|
|
||||||
icon={<DeleteOutlined />}
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</Button>
|
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
<Button
|
<Button type="text" icon={<UserOutlined style={{ color: '#faad14' }} />} onClick={() => { setCurrentUser(r); handleResetPassword(r); }}>重置密码</Button>
|
||||||
type="text"
|
|
||||||
icon={<UserOutlined style={{ color: '#faad14' }} />}
|
|
||||||
onClick={() => {
|
|
||||||
setCurrentUser(r);
|
|
||||||
handleResetPassword();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
重置密码
|
|
||||||
</Button>
|
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -467,13 +465,13 @@ export default function UserRolePage() {
|
|||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
showTotal: t => `共 ${t} 条`
|
showTotal: t => `共 ${t} 条`
|
||||||
}}
|
}}
|
||||||
onChange={(p) => setUserPagination({ ...userPagination, pageNum: p.current, pageSize: p.pageSize })}
|
onChange={(p) => setUserPagination({ ...userPagination, pageNum: p.current!, pageSize: p.pageSize! })}
|
||||||
bordered
|
bordered
|
||||||
size="middle"
|
size="middle"
|
||||||
/>
|
/>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
{/* ========== 角色管理 ========== */}
|
{/* 角色管理 */}
|
||||||
{userInfo?.userId == 1 && (
|
{userInfo?.userId == 1 && (
|
||||||
<TabPane tab="角色管理" key="role">
|
<TabPane tab="角色管理" key="role">
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||||
@@ -484,7 +482,6 @@ export default function UserRolePage() {
|
|||||||
)}
|
)}
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>新增角色</Button>
|
||||||
</div>
|
</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}>
|
||||||
@@ -524,7 +521,6 @@ export default function UserRolePage() {
|
|||||||
</Col>
|
</Col>
|
||||||
)) : <EmptyData height={260} />}
|
)) : <EmptyData height={260} />}
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<div style={{ textAlign: 'right', marginTop: 20 }}>
|
<div style={{ textAlign: 'right', marginTop: 20 }}>
|
||||||
<Pagination
|
<Pagination
|
||||||
current={rolePagination.pageNum}
|
current={rolePagination.pageNum}
|
||||||
@@ -537,11 +533,10 @@ export default function UserRolePage() {
|
|||||||
</div>
|
</div>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</AntdCard>
|
</AntdCard>
|
||||||
|
|
||||||
{/* ========== 角色弹窗 ========== */}
|
{/* 角色弹窗 */}
|
||||||
<Modal
|
<Modal
|
||||||
title={editRole ? '编辑角色' : '新增角色'}
|
title={editRole ? '编辑角色' : '新增角色'}
|
||||||
open={roleModalVisible}
|
open={roleModalVisible}
|
||||||
@@ -562,7 +557,6 @@ export default function UserRolePage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="roleSort" label="排序">
|
<Form.Item name="roleSort" label="排序">
|
||||||
@@ -570,11 +564,7 @@ export default function UserRolePage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item
|
<Form.Item name="roleLevel" label="角色等级" rules={[{ required: true, message: '请输入角色等级' }]}>
|
||||||
name="roleLevel"
|
|
||||||
label="角色等级"
|
|
||||||
rules={[{ required: true, message: '请输入角色等级' }]}
|
|
||||||
>
|
|
||||||
<InputNumber style={{ width: '100%' }} placeholder="1~100" min={1} max={100} />
|
<InputNumber style={{ width: '100%' }} placeholder="1~100" min={1} max={100} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -596,6 +586,7 @@ export default function UserRolePage() {
|
|||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/* 用户弹窗 */}
|
||||||
<Modal
|
<Modal
|
||||||
title={currentUser ? '编辑用户' : '新增用户'}
|
title={currentUser ? '编辑用户' : '新增用户'}
|
||||||
open={modalVisible}
|
open={modalVisible}
|
||||||
@@ -613,13 +604,10 @@ 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}>
|
<Col span={12}>
|
||||||
<Form.Item name="password" label="密码">
|
<Form.Item name="password" label="密码">
|
||||||
<Input.Password
|
<Input.Password placeholder={currentUser ? "编辑不显示,重置为123456" : "请输入密码"} />
|
||||||
placeholder={currentUser ? "编辑不显示,重置为123456" : "请输入密码"}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
@@ -632,34 +620,51 @@ export default function UserRolePage() {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
{/* ====== 自动适应布局:隐藏角色时,状态自动占满一行 ====== */}
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={12}>
|
{!isEditSelf ? (
|
||||||
<Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}>
|
<>
|
||||||
<Select
|
<Col span={12}>
|
||||||
placeholder="选择角色"
|
<Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}>
|
||||||
onChange={(val) => {
|
<Select
|
||||||
// ✅ 选择角色时判断是否为机构管理员
|
placeholder="选择角色"
|
||||||
const role = rolesOption.find(item => item.roleId == val);
|
key={rolesOption.length}
|
||||||
if (role?.roleKey == 'manager') {
|
onChange={(val) => {
|
||||||
setShowSite(false);
|
const role = rolesOption.find(item => String(item.roleId) === String(val));
|
||||||
form.setFieldsValue({ siteId: null });
|
if (role?.roleKey === 'manager') {
|
||||||
} else {
|
setShowSite(false);
|
||||||
setShowSite(true);
|
form.setFieldsValue({ siteId: null });
|
||||||
}
|
} else {
|
||||||
}}
|
setShowSite(true);
|
||||||
>
|
}
|
||||||
{rolesOption.map(i => <Select.Option key={i.roleId} value={i.roleId}>{i.roleName}</Select.Option>)}
|
}}
|
||||||
</Select>
|
>
|
||||||
</Form.Item>
|
{rolesOption.map(i => (
|
||||||
</Col>
|
<Select.Option key={i.roleId} value={i.roleId}>{i.roleName}</Select.Option>
|
||||||
<Col span={12}>
|
))}
|
||||||
<Form.Item name="status" label="状态" initialValue="0">
|
</Select>
|
||||||
<Select>
|
</Form.Item>
|
||||||
<Select.Option value="0">正常</Select.Option>
|
</Col>
|
||||||
<Select.Option value="1">停用</Select.Option>
|
<Col span={12}>
|
||||||
</Select>
|
<Form.Item name="status" label="状态" initialValue="0">
|
||||||
</Form.Item>
|
<Select>
|
||||||
</Col>
|
<Select.Option value="0">正常</Select.Option>
|
||||||
|
<Select.Option value="1">停用</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
// 编辑自己 → 状态占满一行 span=24
|
||||||
|
<Col span={24}>
|
||||||
|
<Form.Item name="status" label="状态" initialValue="0">
|
||||||
|
<Select>
|
||||||
|
<Select.Option value="0">正常</Select.Option>
|
||||||
|
<Select.Option value="1">停用</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
@@ -672,7 +677,6 @@ export default function UserRolePage() {
|
|||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="orgId" label="所属组织">
|
<Form.Item name="orgId" label="所属组织">
|
||||||
<Select
|
<Select
|
||||||
@@ -689,12 +693,14 @@ export default function UserRolePage() {
|
|||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* ✅ 机构管理员不显示所属场站 */}
|
|
||||||
{showSite && siteList.length > 0 && (
|
{showSite && siteList.length > 0 && (
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="siteId" label="所属场站">
|
<Form.Item name="siteId" label="所属场站">
|
||||||
<Select placeholder="请选择场站" allowClear>
|
<Select
|
||||||
|
placeholder="请选择场站"
|
||||||
|
allowClear
|
||||||
|
disabled={siteDisabled}
|
||||||
|
>
|
||||||
{siteList.map(item => (
|
{siteList.map(item => (
|
||||||
<Select.Option key={item.id} value={item.id}>{item.siteName}</Select.Option>
|
<Select.Option key={item.id} value={item.id}>{item.siteName}</Select.Option>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ export default defineConfig(({ mode }) => {
|
|||||||
react(),
|
react(),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
// 复制 Cesium 静态资源
|
// 复制 Cesium 静态资源
|
||||||
viteStaticCopy({
|
//viteStaticCopy({
|
||||||
targets: [
|
// targets: [
|
||||||
{
|
// {
|
||||||
src: 'node_modules/cesium/Build/Cesium',
|
// src: 'node_modules/cesium/Build/Cesium',
|
||||||
dest: '',
|
// dest: '',
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
}),
|
//}),
|
||||||
],
|
],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
@@ -49,33 +49,33 @@ export default defineConfig(({ mode }) => {
|
|||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
// ---- 手动分包策略 ----
|
// ---- 手动分包策略 ----
|
||||||
manualChunks(id) {
|
//manualChunks(id) {
|
||||||
// 1. 将 React 生态单独打包(利用浏览器缓存)
|
// // 1. 将 React 生态单独打包(利用浏览器缓存)
|
||||||
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) {
|
// if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) {
|
||||||
return 'react-vendor';
|
// return 'react-vendor';
|
||||||
}
|
// }
|
||||||
// 2. Ant Design 单独打包
|
// // 2. Ant Design 单独打包
|
||||||
if (id.includes('node_modules/antd') || id.includes('node_modules/@ant-design')) {
|
// if (id.includes('node_modules/antd') || id.includes('node_modules/@ant-design')) {
|
||||||
return 'antd-vendor';
|
// return 'antd-vendor';
|
||||||
}
|
// }
|
||||||
// 3. Cesium 单独打包(体积巨大)
|
// // 3. Cesium 单独打包(体积巨大)
|
||||||
if (id.includes('node_modules/cesium') || id.includes('cesium')) {
|
// if (id.includes('node_modules/cesium') || id.includes('cesium')) {
|
||||||
return 'cesium-vendor';
|
// return 'cesium-vendor';
|
||||||
}
|
// }
|
||||||
// 4. 其他 node_modules 合并
|
// // 4. 其他 node_modules 合并
|
||||||
if (id.includes('node_modules')) {
|
// if (id.includes('node_modules')) {
|
||||||
return 'vendor';
|
// return 'vendor';
|
||||||
}
|
// }
|
||||||
},
|
//},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
define: {
|
define: {
|
||||||
// Cesium 路径注入
|
// Cesium 路径注入
|
||||||
CESIUM_BASE_URL: JSON.stringify(
|
//CESIUM_BASE_URL: JSON.stringify(
|
||||||
'/Cesium'
|
// '/Cesium'
|
||||||
),
|
//),
|
||||||
// 环境变量注入
|
// 环境变量注入
|
||||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL ?? env.baseURL ?? ''),
|
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL ?? env.baseURL ?? ''),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user