This commit is contained in:
mmc
2026-04-30 10:49:44 +08:00
parent 941ad9c4f1
commit 00def159bf
9 changed files with 388 additions and 665 deletions

View File

@@ -3,10 +3,6 @@ import envConfig from '../../env';
import Cookies from 'js-cookie';
import { message } from 'antd';
// 🔥 删掉这两行!!!
// import store from '../store';
// import { logout } from '../store/userSlice';
const API_BASE_URL = envConfig.baseURL;
const api = axios.create({
@@ -18,7 +14,7 @@ const api = axios.create({
withCredentials: true,
});
// 请求拦截器:自动添加token
// 请求拦截器
api.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
const token = localStorage.getItem('token');
@@ -32,25 +28,51 @@ api.interceptors.request.use(
}
);
// 响应拦截器
// 响应拦截器(处理 401 + 网络错误 + 服务挂了)
api.interceptors.response.use(
(response) => {
return response.data;
},
async (error: AxiosError) => { // 👈 加 async
if (error.response?.status === 401) {
async (error: AxiosError) => {
// ==============================================
// 👇 这里处理:服务挂了 / 断网 / 请求失败 / 500
// ==============================================
if (!error.response) {
message.error('服务异常或网络断开,即将重新登录');
localStorage.clear();
Cookies.remove('userId');
Cookies.remove('Admin-Token');
// 动态加载 store 避免循环引用
const store = await import('../store');
const { logout } = await import('../store/userSlice');
store.default.dispatch(logout());
setTimeout(() => {
window.location.href = '/login';
}, 800);
return Promise.reject(error);
}
// ==============================================
// 👇 这里处理:401 未授权 / token 过期
// ==============================================
if (error.response.status === 401) {
localStorage.clear();
Cookies.remove('userId');
Cookies.remove('Admin-Token');
const store = await import('../store');
const { logout } = await import('../store/userSlice');
store.default.dispatch(logout());
window.location.href = '/login';
message.error('会话已过期,请重新登录');
message.error('登录已过期,请重新登录');
setTimeout(() => {
window.location.href = '/login';
}, 800);
}
// 其他错误(500等)不跳转,只返回错误
return Promise.reject(error);
}
);

View File

@@ -34,5 +34,14 @@ export function deleteRole(data) {
});
}
//通过角色id查看详情/system/role/{roleId}
export function getRoleDetailById(roleId) {
return request({
url: `/system/role/${roleId}`,
method: 'get',
});
}

View File

@@ -1,14 +1,13 @@
import React, { useState, useEffect } from 'react';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import {
Layout, Menu, Button, Space, ConfigProvider, theme,
Breadcrumb, message
Layout, Menu, Button, Space, ConfigProvider, theme
} from 'antd';
import zhCN from 'antd/locale/zh_CN';
import {
DashboardOutlined, ExperimentOutlined, VideoCameraOutlined,
BellOutlined, DownloadOutlined, UserOutlined, LogoutOutlined,
TeamOutlined, MenuOutlined, AppstoreOutlined, SettingOutlined
BellOutlined, UserOutlined, LogoutOutlined,
AppstoreOutlined, SettingOutlined
} from '@ant-design/icons';
import logo from '../assets/logo.png';
import { useSelector } from 'react-redux';
@@ -21,91 +20,53 @@ const { Header, Sider, Content } = Layout;
export default function AppLayout() {
const [collapsed, setCollapsed] = useState(false);
const [time, setTime] = useState(new Date().toLocaleString());
const [menuTree, setMenuTree] = useState([]); // 动态菜单树
const [menuList, setMenuList] = useState([]); // 一级菜单列表
const navigate = useNavigate();
const location = useLocation();
const { userInfo } = useSelector((state: RootState) => state.user);
const dispatch = useAppDispatch();
// ======================
// 工具函数:构建树形菜单
// ======================
const buildMenuTree = (data) => {
const map = {};
const roots = [];
// 先把所有菜单放进map
data.forEach(item => {
map[item.menuId] = { ...item, children: [] };
});
// 构建父子关系
data.forEach(item => {
if (item.parentId !== 0) {
if (map[item.parentId]) {
map[item.parentId].children.push(map[item.menuId]);
}
} else {
roots.push(map[item.menuId]);
}
});
return roots;
};
// ======================
// 把后端菜单转成 antd menu 格式
// ======================
const convertToAntdMenu = (tree) => {
return tree.map(node => {
// 自动匹配图标
let IconComponent = MenuOutlined;
if (node.path.includes('overview')) IconComponent = DashboardOutlined;
if (node.path.includes('device')) IconComponent = ExperimentOutlined;
if (node.path.includes('video')) IconComponent = VideoCameraOutlined;
if (node.path.includes('alert')) IconComponent = BellOutlined;
if (node.path.includes('user')) IconComponent = UserOutlined;
if (node.path.includes('role')) IconComponent = TeamOutlined;
if (node.path.includes('menu')) IconComponent = AppstoreOutlined;
if (node.path.includes('system')) IconComponent = SettingOutlined;
const item = {
key: node.path || `/menu/${node.menuId}`,
icon: <IconComponent />,
label: node.menuName,
};
// 有子菜单递归渲染
if (node.children && node.children.length > 0) {
item.children = convertToAntdMenu(node.children);
}
return item;
});
};
// ======================
// 获取动态菜单
// 只取一级菜单(parentId=0)
// ======================
const getMenu = () => {
const data = {
pageNum: 1,
pageSize: 10000
}
const data = { pageNum: 1, pageSize: 10000 };
getMenuList(data).then(res => {
if (res.code === 200) {
const treeData = buildMenuTree(res.data || []);
const antdMenu = convertToAntdMenu(treeData);
setMenuTree(antdMenu);
if (res.code == 200) {
const rawList = res.rows || [];
// 只保留 parentId=0 的一级菜单
const topMenus = rawList.filter(item => item.parentId === 0);
setMenuList(topMenus);
}
}).catch(() => {
});
};
// ======================
// 菜单图标映射
// ======================
const getIcon = (path) => {
if (path.includes('overview')) return <DashboardOutlined />;
if (path.includes('device')) return <ExperimentOutlined />;
if (path.includes('monitor')) return <VideoCameraOutlined />;
if (path.includes('alert')) return <BellOutlined />;
if (path.includes('user')) return <UserOutlined />;
if (path.includes('system')) return <SettingOutlined />;
if (path.includes('menu')) return <AppstoreOutlined />;
return <AppstoreOutlined />;
};
// ======================
// 构造 antd menu items(纯平铺,无children)
// ======================
const menuItems = menuList.map(item => ({
key: item.path || `/menu/${item.menuId}`,
icon: getIcon(item.path),
label: item.menuName,
}));
useEffect(() => {
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
getMenu(); // 加载动态菜单
getMenu();
return () => clearInterval(timer);
}, []);
@@ -167,11 +128,12 @@ export default function AppLayout() {
theme="light"
style={{ borderRight: '1px solid #e5e7eb' }}
>
{/* 纯平铺一级菜单 */}
<Menu
mode="inline"
theme="light"
selectedKeys={[location.pathname]}
items={menuTree}
items={menuItems}
onClick={({ key }) => navigate(key)}
/>
</Sider>

View File

@@ -13,13 +13,6 @@ import { buildPermTree, buildTreeFromFlat } from '../lib/utils';
const { Option } = Select;
// 角色列表
const roleList = [
{ name: '平台admin', key: 'admin' },
{ name: '区域机构管理员', key: 'region_admin' },
{ name: '单个场站管理员', key: 'site_admin' },
{ name: '场站员工', key: 'site_staff' },
];
// 筛选常用图标(够用、不乱)
const iconList = Object.keys(AllIcons).filter(item => {
@@ -46,7 +39,7 @@ export default function MenuList() {
// 分页状态
const [pagination, setPagination] = useState({
pageNum: 1,
pageSize: 10,
pageSize: 9999,
total: 0
});
@@ -58,8 +51,9 @@ export default function MenuList() {
};
getMenuList(params).then(res => {
console.log(res, "res")
if (res.code === 200) {
const data = res.data || [];
const data = res.rows || [];
setRawMenuList(data);
const tree = buildTreeFromFlat(data);
setMenuTreeData(tree);
@@ -75,14 +69,6 @@ export default function MenuList() {
});
};
// 分页变化
const handleTableChange = (newPagination) => {
setPagination({
...pagination,
pageNum: newPagination.current,
pageSize: newPagination.pageSize
});
};
useEffect(() => {
getMenuListApi();
@@ -160,18 +146,7 @@ export default function MenuList() {
});
};
// 权限弹窗
const handlePermOpen = () => {
if (!selectedRole) return messageApi.warning('请选择角色');
setCheckedKeys(rolePermissionMap[selectedRole] || []);
setPermModal(true);
};
const handlePermSave = () => {
rolePermissionMap[selectedRole] = checkedKeys;
messageApi.success(`【${selectedRole}】权限保存成功`);
setPermModal(false);
};
const topMenus = rawMenuList.filter(m => m.parentId === 0 || !m.parentId);
@@ -225,14 +200,8 @@ export default function MenuList() {
columns={columns}
dataSource={menuTreeData}
rowKey="menuId"
pagination={{
current: pagination.pageNum,
pageSize: pagination.pageSize,
total: pagination.total,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`
}}
onChange={handleTableChange}
pagination={false} // 关闭分页
bordered
size="middle"
indentSize={24}
@@ -302,22 +271,7 @@ export default function MenuList() {
</Row>
</Modal>
{/* 权限树弹窗 */}
<Modal
title={`【${selectedRole}】权限配置`}
open={permModal}
width={520}
onCancel={() => setPermModal(false)}
onOk={handlePermSave}
>
<Tree
checkable
treeData={menuTree}
checkedKeys={checkedKeys}
onCheck={setCheckedKeys}
defaultExpandAll
/>
</Modal>
</Card>
</div>
);

View File

@@ -58,7 +58,7 @@ export default function Roles() {
getMenuList(params).then(res => {
if (res.code === 200) {
const data = res.data || [];
const data = res.rows || [];
const treeData = buildTreeFromFlat(data);
const permTree = buildPermTree(treeData);
setMenuTree(permTree);
@@ -76,7 +76,7 @@ export default function Roles() {
};
useEffect(() => {
getRole();
//getRole();
getMenu();
}, [pagination.pageNum, pagination.pageSize]);

View File

@@ -1,572 +1,207 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
Layout, Menu, Card, Row, Col, Button, Form, Input, Select, Switch, Tag, Space, Typography, Statistic, message, Table, Divider
Layout, Menu, Card, Row, Col, Button, Form, Input, Select, Switch, Tag, Space, Typography, message, Table
} from 'antd';
import {
SettingOutlined, UserOutlined, BellOutlined, LinkOutlined, SafetyOutlined, SyncOutlined,
CloudOutlined, TeamOutlined, FileTextOutlined, DatabaseOutlined, CalendarOutlined,
CheckCircleOutlined, CloseCircleOutlined, ReloadOutlined, DownloadOutlined, DeleteOutlined,
KeyOutlined,
AppstoreOutlined,
BankOutlined
CheckCircleOutlined, ReloadOutlined, DownloadOutlined, DeleteOutlined,
KeyOutlined, AppstoreOutlined, BankOutlined,
NotificationOutlined,
ExperimentOutlined
} from '@ant-design/icons';
import UserRolePage from './UserPage';
import MenuList from './MenuList';
import Organization from './Organization';
import StationManage from './StationManage';
import { getMenuList } from '../api/mune';
const { Header, Content } = Layout;
const { Title, Text } = Typography;
const { Text } = Typography;
const { Option } = Select;
const AntdCard = Card as any;
// 子页面组件,你可以替换成自己的
// 基础设置
const BasicSettings = () => {
const [form] = Form.useForm();
const handleSave = () => {
message.success('设置已保存');
};
const handleSave = () => { message.success('设置已保存'); };
return (
<div style={{ padding: 24 }}>
{/* 顶部概览卡片 */}
<Row gutter={16} style={{ marginBottom: 24 }}>
<Col span={5}>
<AntdCard size="small">
<Space>
<div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}>
<CloudOutlined style={{ color: '#1677ff', fontSize: 20 }} />
</div>
<div>
<div style={{ fontSize: 13, color: '#666' }}>当前版本</div>
<div style={{ fontWeight: 600 }}>v2.8.1 <Tag color="blue">最新版</Tag></div>
</div>
</Space>
</AntdCard>
</Col>
<Col span={5}>
<AntdCard size="small">
<Space>
<div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}>
<TeamOutlined style={{ color: '#52c41a', fontSize: 20 }} />
</div>
<div>
<div style={{ fontSize: 13, color: '#666' }}>在线用户</div>
<div style={{ fontWeight: 600 }}>12 <span style={{ color: '#52c41a', fontSize: 12 }}>↑ 2</span></div>
</div>
</Space>
</AntdCard>
</Col>
<Col span={5}>
<AntdCard size="small">
<Space>
<div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}>
<BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} />
</div>
<div>
<div style={{ fontSize: 13, color: '#666' }}>告警通道</div>
<div style={{ fontWeight: 600 }}>3 / 4 <span style={{ color: '#52c41a', fontSize: 12 }}>正常</span></div>
</div>
</Space>
</AntdCard>
</Col>
<Col span={5}>
<AntdCard size="small">
<Space>
<div style={{ background: '#e6fffb', borderRadius: 8, padding: 8 }}>
<DatabaseOutlined style={{ color: '#13c2c2', fontSize: 20 }} />
</div>
<div>
<div style={{ fontSize: 13, color: '#666' }}>数据备份状态</div>
<div style={{ fontWeight: 600 }}>正常 <span style={{ color: '#52c41a', fontSize: 12 }}>●</span></div>
</div>
</Space>
</AntdCard>
</Col>
<Col span={4}>
<AntdCard size="small">
<Space>
<div style={{ background: '#f9f0ff', borderRadius: 8, padding: 8 }}>
<CalendarOutlined style={{ color: '#722ed1', fontSize: 20 }} />
</div>
<div>
<div style={{ fontSize: 13, color: '#666' }}>最近更新</div>
<div style={{ fontWeight: 600 }}>2025-05-20</div>
</div>
</Space>
</AntdCard>
</Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><CloudOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>当前版本</div><div style={{ fontWeight: 600 }}>v2.8.1 <Tag color="blue">最新版</Tag></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><TeamOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>在线用户</div><div style={{ fontWeight: 600 }}>12 <span style={{ color: '#52c41a', fontSize: 12 }}>↑ 2</span></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>告警通道</div><div style={{ fontWeight: 600 }}>3 / 4 <span style={{ color: '#52c41a', fontSize: 12 }}>正常</span></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#e6fffb', borderRadius: 8, padding: 8 }}><DatabaseOutlined style={{ color: '#13c2c2', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>数据备份状态</div><div style={{ fontWeight: 600 }}>正常 <span style={{ color: '#52c41a', fontSize: 12 }}>●</span></div></div></Space></AntdCard></Col>
<Col span={4}><AntdCard size="small"><Space><div style={{ background: '#f9f0ff', borderRadius: 8, padding: 8 }}><CalendarOutlined style={{ color: '#722ed1', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>最近更新</div><div style={{ fontWeight: 600 }}>2025-05-20</div></div></Space></AntdCard></Col>
</Row>
{/* 基础配置 */}
<AntdCard title="基础配置" style={{ marginBottom: 24 }}>
<Form form={form} layout="vertical">
<Row gutter={16}>
<Col span={8}>
<Form.Item label="系统名称" name="systemName">
<Input defaultValue="光伏电站智能监控与运维系统" />
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="默认电站" name="defaultSite">
<Select defaultValue="1MW 光伏电站">
<Option value="1MW">1MW 光伏电站</Option>
</Select>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="默认语言" name="defaultLang">
<Select defaultValue="中文">
<Option value="zh">中文</Option>
<Option value="en">English</Option>
</Select>
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={8}>
<Form.Item label="时区" name="timezone">
<Select defaultValue="UTC+08:00">
<Option value="UTC+08:00">UTC+08:00</Option>
</Select>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="首页默认页面" name="homePage">
<Select defaultValue="总览首页">
<Option value="overview">总览首页</Option>
</Select>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="数据刷新频率" name="refreshRate">
<Select defaultValue="5分钟">
<Option value="5">5分钟</Option>
</Select>
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={8}>
<Form.Item label="地图服务" name="mapService">
<Select defaultValue="高德地图">
<Option value="amap">高德地图</Option>
</Select>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="工单自动编号" name="autoWorkOrder" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="AI建议自动生成" name="autoAiSuggest" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={8}>
<Form.Item label="移动端同步" name="mobileSync" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
</Row>
<Space>
<Button type="primary" onClick={handleSave}>保存设置</Button>
<Button>恢复默认</Button>
</Space>
<Row gutter={16}><Col span={8}><Form.Item label="系统名称" name="systemName"><Input defaultValue="光伏电站智能监控与运维系统" /></Form.Item></Col><Col span={8}><Form.Item label="默认电站" name="defaultSite"><Select defaultValue="1MW 光伏电站"><Option value="1MW">1MW 光伏电站</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="默认语言" name="defaultLang"><Select defaultValue="中文"><Option value="zh">中文</Option><Option value="en">English</Option></Select></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="时区" name="timezone"><Select defaultValue="UTC+08:00"><Option value="UTC+08:00">UTC+08:00</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="首页默认页面" name="homePage"><Select defaultValue="总览首页"><Option value="overview">总览首页</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="数据刷新频率" name="refreshRate"><Select defaultValue="5分钟"><Option value="5">5分钟</Option></Select></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="地图服务" name="mapService"><Select defaultValue="高德地图"><Option value="amap">高德地图</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="工单自动编号" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="AI建议自动生成" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="移动端同步" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Space><Button type="primary" onClick={handleSave}>保存设置</Button><Button>恢复默认</Button></Space>
</Form>
</AntdCard>
{/* 通知与告警策略 */}
<AntdCard title="通知与告警策略" style={{ marginBottom: 24 }}>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={6}>
<Space>
<div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}>
<BellOutlined style={{ color: '#52c41a', fontSize: 20 }} />
</div>
<div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Text strong>短信</Text>
<Switch defaultChecked />
</div>
<Text type="secondary">已启用</Text>
</div>
</Space>
</Col>
<Col span={6}>
<Space>
<div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}>
<BellOutlined style={{ color: '#1677ff', fontSize: 20 }} />
</div>
<div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Text strong>邮件</Text>
<Switch defaultChecked />
</div>
<Text type="secondary">已启用</Text>
</div>
</Space>
</Col>
<Col span={6}>
<Space>
<div style={{ background: '#fff7e6', borderRadius: 8, padding: 8 }}>
<BellOutlined style={{ color: '#fa8c16', fontSize: 20 }} />
</div>
<div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Text strong>Telegram</Text>
<Switch defaultChecked />
</div>
<Text type="secondary">已启用</Text>
</div>
</Space>
</Col>
<Col span={6}>
<Space>
<div style={{ background: '#fff0f6', borderRadius: 8, padding: 8 }}>
<BellOutlined style={{ color: '#eb2f96', fontSize: 20 }} />
</div>
<div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Text strong>系统通知</Text>
<Switch defaultChecked />
</div>
<Text type="secondary">已启用</Text>
</div>
</Space>
</Col>
</Row>
<Row gutter={16}>
<Col span={8}>
<Form.Item label="严重告警立即通知" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="发电下降超过15%" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="通信中断通知" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={8}>
<Form.Item label="每日汇总推送" valuePropName="checked">
<Switch defaultChecked />
</Form.Item>
</Col>
<Col span={8}>
<Form.Item label="夜间免打扰">
<Select defaultValue="23:00-07:00">
<Option value="23:00-07:00">23:00-07:00</Option>
</Select>
</Form.Item>
</Col>
<Col span={6}><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>短信</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>邮件</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#fff7e6', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#fa8c16', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>Telegram</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#fff0f6', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#eb2f96', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>系统通知</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
</Row>
<Row gutter={16}><Col span={8}><Form.Item label="严重告警立即通知" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="发电下降超过15%" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="通信中断通知" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="每日汇总推送" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="夜间免打扰"><Select defaultValue="23:00-07:00"><Option value="23:00-07:00">23:00-07:00</Option></Select></Form.Item></Col></Row>
</AntdCard>
{/* 用户与权限预览 */}
<AntdCard title="用户与权限预览">
<Table
size="small"
pagination={{ pageSize: 4 }}
columns={[
{ title: '用户名', dataIndex: 'name' },
{ title: '角色', dataIndex: 'role', render: t => <Tag color="blue">{t}</Tag> },
{ title: '手机号', dataIndex: 'phone' },
{ title: '邮箱', dataIndex: 'email' },
{ title: '状态', dataIndex: 'status', render: () => <span style={{ color: '#52c41a' }}>● 在线</span> },
{ title: '操作', render: () => <Button type="link">查看</Button> }
]}
dataSource={[
{ name: '张运维', role: '超级管理员', phone: '138****0001', email: 'zhangyw@pvsrmart.com' },
{ name: '李工程师', role: '运维工程师', phone: '139****0002', email: 'li.gongcheng@pvsrmart.com' },
{ name: '王班长', role: '巡检主管', phone: '137****0003', email: 'wang.banzhang@pvsrmart.com' },
{ name: '赵分析师', role: '数据分析师', phone: '136****0004', email: 'zhao.fx@pvsrmart.com' },
]}
/>
<Table size="small" pagination={{ pageSize: 4 }} columns={[
{ title: '用户名', dataIndex: 'name' },
{ title: '角色', render: () => <Tag color="blue">管理员</Tag> },
{ title: '手机号', dataIndex: 'phone' },
{ title: '邮箱', dataIndex: 'email' },
{ title: '状态', render: () => <span style={{ color: '#52c41a' }}>● 在线</span> },
]} dataSource={[
{ name: '张运维', phone: '138****0001', email: 'zhangyw@pvsrmart.com' },
{ name: '李工程师', phone: '139****0002', email: 'li.gongcheng@pvsrmart.com' },
]} />
</AntdCard>
</div>
);
};
// 右侧面板组件
const RightPanel = () => {
return (
<div style={{ padding: 24 }}>
{/* 角色权限概览 */}
<AntdCard title="角色权限概览" style={{ marginBottom: 24 }}>
<Row gutter={16}>
<Col span={12}>
<AntdCard size="small" hoverable style={{ background: '#f0f5ff' }}>
<Space direction="vertical">
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ background: '#1677ff', borderRadius: '50%', padding: 4 }}>
<SafetyOutlined style={{ color: '#fff', fontSize: 16 }} />
</div>
<Text strong>超级管理员</Text>
</div>
<Text type="secondary">用户2人 | 权限28项</Text>
<Space>
<Tag color="blue">全部权限</Tag>
<Tag color="blue">系统管理</Tag>
</Space>
</Space>
</AntdCard>
</Col>
<Col span={12}>
<AntdCard size="small" hoverable style={{ background: '#f6ffed' }}>
<Space direction="vertical">
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ background: '#52c41a', borderRadius: '50%', padding: 4 }}>
<UserOutlined style={{ color: '#fff', fontSize: 16 }} />
</div>
<Text strong>运维工程师</Text>
</div>
<Text type="secondary">用户5人 | 权限18项</Text>
<Space>
<Tag color="green">设备管理</Tag>
<Tag color="green">工单管理</Tag>
</Space>
</Space>
</AntdCard>
</Col>
<Col span={12} style={{ marginTop: 16 }}>
<AntdCard size="small" hoverable style={{ background: '#fff7e6' }}>
<Space direction="vertical">
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ background: '#fa8c16', borderRadius: '50%', padding: 4 }}>
<BellOutlined style={{ color: '#fff', fontSize: 16 }} />
</div>
<Text strong>巡检主管</Text>
</div>
<Text type="secondary">用户8人 | 权限12项</Text>
<Space>
<Tag color="orange">巡检管理</Tag>
<Tag color="orange">告警处理</Tag>
</Space>
</Space>
</AntdCard>
</Col>
<Col span={12} style={{ marginTop: 16 }}>
<AntdCard size="small" hoverable style={{ background: '#f9f0ff' }}>
<Space direction="vertical">
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ background: '#722ed1', borderRadius: '50%', padding: 4 }}>
<DatabaseOutlined style={{ color: '#fff', fontSize: 16 }} />
</div>
<Text strong>数据分析师</Text>
</div>
<Text type="secondary">用户3人 | 权限15项</Text>
<Space>
<Tag color="purple">数据分析</Tag>
<Tag color="purple">报表查看</Tag>
</Space>
</Space>
</AntdCard>
</Col>
</Row>
</AntdCard>
// 右侧面板
const RightPanel = () => (
<div style={{ padding: 24 }}>
<AntdCard title="角色权限概览" style={{ marginBottom: 24 }}>
<Row gutter={16}>
<Col span={12}><AntdCard size="small" hoverable style={{ background: '#f0f5ff' }}><Space direction="vertical"><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ background: '#1677ff', borderRadius: '50%', padding: 4 }}><SafetyOutlined style={{ color: '#fff', fontSize: 16 }} /></div><Text strong>超级管理员</Text></div><Text type="secondary">全部权限</Text></Space></AntdCard></Col>
<Col span={12}><AntdCard size="small" hoverable style={{ background: '#f6ffed' }}><Space direction="vertical"><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ background: '#52c41a', borderRadius: '50%', padding: 4 }}><UserOutlined style={{ color: '#fff', fontSize: 16 }} /></div><Text strong>运维工程师</Text></div><Text type="secondary">设备管理</Text></Space></AntdCard></Col>
</Row>
</AntdCard>
{/* 设备接入状态 */}
<AntdCard title="设备接入状态" style={{ marginBottom: 24 }} extra={<Button type="link">查看详情 </Button>}>
<Row gutter={16}>
<Col span={12}>
<Space direction="vertical">
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 逆变器</Space>
<Text>5 / 5 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 汇流箱</Space>
<Text>20 / 20 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 气象站</Space>
<Text>1 / 1 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 摄像头</Space>
<Text>12 / 12 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 无人机</Space>
<Text>2 / 2 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> 机器人</Space>
<Text>5 / 5 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> API接口</Space>
<Text>正常 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CheckCircleOutlined style={{ color: '#52c41a' }} /> Modbus</Space>
<Text>正常 <span style={{ color: '#52c41a' }}>● 正常</span></Text>
</div>
</Space>
</Col>
<Col span={12}>
{/* 这里可以放拓扑图,先用占位 */}
<div style={{ height: 240, display: 'flex', alignItems: 'center', justifyContent: 'center', border: '1px dashed #ddd', borderRadius: 8 }}>
<div style={{ textAlign: 'center' }}>
<DatabaseOutlined style={{ fontSize: 48, color: '#1677ff' }} />
<div style={{ marginTop: 8 }}>设备拓扑图</div>
</div>
</div>
</Col>
</Row>
</AntdCard>
<AntdCard title="设备接入状态" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>逆变器</span><span>正常</span></div></Space>
</AntdCard>
{/* 数据与安全 */}
<AntdCard title="数据与安全" style={{ marginBottom: 24 }}>
<Row gutter={16}>
<Col span={12}>
<Space direction="vertical" style={{ width: '100%' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><DatabaseOutlined /> 数据保留</Space>
<Text>3年</Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><ReloadOutlined /> 每日自动备份</Space>
<Text>02:00</Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><CalendarOutlined /> 最近备份时间</Space>
<Text>2025-05-24 02:00</Text>
</div>
</Space>
</Col>
<Col span={12}>
<Space direction="vertical" style={{ width: '100%' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><SafetyOutlined /> 登录审计</Space>
<Tag color="green">已开启</Tag>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><KeyOutlined /> API密钥管理</Space>
<Tag color="green">正常</Tag>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><FileTextOutlined /> SSL证书</Space>
<Text>有效期至 2026-12-31</Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<Space><SafetyOutlined /> 双因素认证</Space>
<Tag color="green">已开启</Tag>
</div>
</Space>
</Col>
</Row>
</AntdCard>
<AntdCard title="数据与安全" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>数据保留</span><span>3年</span></div></Space>
</AntdCard>
{/* 系统维护 */}
<AntdCard title="系统维护" extra={<Text type="danger">操作需管理员权限</Text>}>
<Row gutter={16}>
<Col span={6}>
<Button block size="large" icon={<DeleteOutlined />}>清理缓存</Button>
</Col>
<Col span={6}>
<Button block size="large" icon={<SyncOutlined />}>重启服务</Button>
</Col>
<Col span={6}>
<Button block size="large" icon={<DownloadOutlined />}>备份下载</Button>
</Col>
<Col span={6}>
<Button block size="large" icon={<FileTextOutlined />}>日志导出</Button>
</Col>
</Row>
</AntdCard>
</div>
);
};
<AntdCard title="系统维护">
<Row gutter={16}><Col span={6}><Button block icon={<DeleteOutlined />}>清理缓存</Button></Col><Col span={6}><Button block icon={<SyncOutlined />}>重启服务</Button></Col></Row>
</AntdCard>
</div>
);
// 主页面组件
// ======================
// 主页面
// ======================
export default function SystemSettings() {
const [activeTab, setActiveTab] = useState('basic');
const [rawMenuList, setRawMenuList] = useState([]);
const [showTabs, setShowTabs] = useState([]);
const tabItems = [
{ key: 'basic', label: '基础设置', icon: <SettingOutlined /> },
{ key: 'user-role', label: '用户与角色', icon: <UserOutlined /> },
{ key: 'menu', label: '菜单管理', icon: <AppstoreOutlined /> },
{ key: 'org', label: '组织管理', icon: <TeamOutlined /> }, //
{ key: 'station', label: '场站管理', icon: <BankOutlined /> },
{ key: 'notification', label: '通知策略', icon: <BellOutlined /> },
{ key: 'device', label: '设备接入', icon: <LinkOutlined /> },
{ key: 'security', label: '数据与安全', icon: <SafetyOutlined /> },
{ key: 'maintenance', label: '系统维护', icon: <SyncOutlined /> },
];
// 获取菜单
const getMenuListApi = () => {
const params = { pageNum: 1, pageSize: 99999 };
return getMenuList(params);
};
// 动态生成 tab
useEffect(() => {
getMenuListApi().then(res => {
if (res.code === 200) {
const data = res.rows || [];
// 系统设置 parentId = 3394
const systemChild = data.filter(m => m.parentId == 3394);
// ======================
// 👇 按 orderNum 正序排序(数字越小越靠前)
// ======================
systemChild.sort((a, b) => {
return (a.orderNum || 0) - (b.orderNum || 0);
});
const tabs = systemChild.map(item => {
if (item.path == '/systemSetting/basic') {
return { key: 'basic', label: '基础设置', icon: <SettingOutlined /> };
}
if (item.path === '/systemSetting/User') {
return { key: 'user-role', label: '用户与角色', icon: <UserOutlined /> };
}
if (item.path === '/systemSetting/menu') {
return { key: 'menu', label: '菜单管理', icon: <AppstoreOutlined /> };
}
if (item.path === '/systemSetting/notice') {
return { key: 'notice', label: '通知策略', icon: <NotificationOutlined /> };
}
if (item.path === '/systemSetting/deviceAccess') {
return { key: 'deviceAccess', label: '设备接入', icon: <ExperimentOutlined /> };
}
if (item.path === '/systemSetting/dataSafety') {
return { key: 'dataSafety', label: '数据与安全', icon: <SafetyOutlined /> };
}
if (item.path === '/systemSetting/systemMaintenance') {
return { key: 'systemMaintenance', label: '系统维护', icon: <SyncOutlined /> };
}
return null;
}).filter(Boolean);
setShowTabs(tabs);
// 默认选中第一个
if (tabs.length > 0) {
setActiveTab(tabs[0].key);
}
}
});
}, []);
const BasicSettingsPage = () => <div style={{ padding: 20 }}><h2>基础设置页面</h2></div>;
const NoticePage = () => <div style={{ padding: 20 }}><h2>通知策略页面</h2></div>;
const DeviceAccessPage = () => <div style={{ padding: 20 }}><h2>设备接入页面</h2></div>;
const DataSafetyPage = () => <div style={{ padding: 20 }}><h2>数据与安全页面</h2></div>;
const SystemMaintenancePage = () => <div style={{ padding: 20 }}><h2>系统维护页面</h2></div>;
const DefaultPage = () => <div style={{ padding: 20 }}><h2>请选择菜单</h2></div>;
const renderTabContent = () => {
switch (activeTab) {
case 'basic':
return (
<Row gutter={24}>
<Col span={16}><BasicSettings /></Col>
<Col span={8}><RightPanel /></Col>
</Row>
);
return <BasicSettingsPage />;
case 'user-role':
return <UserRolePage />;
case 'menu':
return <MenuList />; // 菜单管理
case 'org':
return <Organization />; // 组织管理
case 'station':
return <StationManage />; // 场站管理
case 'notification':
return <div style={{ padding: 24 }}>通知策略页面</div>;
case 'device':
return <div style={{ padding: 24 }}>设备接入页面</div>;
case 'security':
return <div style={{ padding: 24 }}>数据与安全页面</div>;
case 'maintenance':
return <div style={{ padding: 24 }}>系统维护页面</div>;
return <MenuList />;
case 'notice':
return <NoticePage />;
case 'deviceAccess':
return <DeviceAccessPage />;
case 'dataSafety':
return <DataSafetyPage />;
case 'systemMaintenance':
return <SystemMaintenancePage />;
default:
return null;
return <DefaultPage />;
}
};
return (
<Layout style={{ minHeight: '100vh', background: '#fff', overflow: 'hidden' }}>
{/* 固定在当前组件内部顶部,不随滚动 */}
<Header style={{
background: '#fff',
padding: 0,
borderBottom: '1px solid #f0f0f0',
position: 'sticky',
top: 0,
left: 0,
zIndex: 10,
width: '100%'
}}>
<Header style={{ background: '#fff', padding: 0, borderBottom: '1px solid #f0f0f0', position: 'sticky', top: 0, zIndex: 10 }}>
<Menu
mode="horizontal"
selectedKeys={[activeTab]}
onClick={({ key }) => setActiveTab(key)}
items={tabItems}
style={{ border: 'none', height: 64, lineHeight: '64px', fontSize: 14 }}
items={showTabs}
style={{ border: 0, height: 64, lineHeight: '64px' }}
/>
</Header>
{/* 内容区域可滚动 */}
<Content style={{
background: '#f5f7fa',
maxHeight: 'calc(100vh - 64px)',
overflowY: 'auto',
paddingBottom: 20,
maxHeight: 'calc(100vh - 64px)', overflowY: 'auto', background: '#f5f7fa',
scrollbarWidth: 'none',
msOverflowStyle: 'none',
}}>
{renderTabContent()}
</Content>

View File

@@ -9,9 +9,11 @@ import {
} from '@ant-design/icons';
import { getMenuList } from '../api/mune';
import { buildPermTree, buildTreeFromFlat } from '../lib/utils';
import { addRole, deleteRole, editRoleApi, getRoleList } from '../api/role';
import { addRole, deleteRole, editRoleApi, getRoleDetailById, getRoleList } from '../api/role';
import { addUser, deleteUser, editUser, getUser } from '../api/user';
import EmptyData from '../components/Empty';
import { useSelector } from 'react-redux';
import { RootState } from '../store';
const { Text } = Typography;
const { TabPane } = Tabs;
@@ -38,6 +40,9 @@ export default function UserRolePage() {
const [currentUser, setCurrentUser] = useState(null);
const [rolesOption, setRolesOption] = useState([]);
const [selectedUserIds, setSelectedUserIds] = useState<number[]>([]);
const { userInfo } = useSelector((state: RootState) => state.user);
const [roleDetail, setRoleDetail] = useState(null);
// ====================== 统一分页 ======================
const [rolePagination, setRolePagination] = useState({
@@ -51,7 +56,7 @@ export default function UserRolePage() {
const getRoleData = () => {
const params = {
pageNum: rolePagination.pageNum,
pageSize: rolePagination.pageSize
pageSize: rolePagination.pageSize,
};
getRoleList(params).then(res => {
if (res.code === 200) {
@@ -67,8 +72,8 @@ export default function UserRolePage() {
// ====================== 获取菜单树 ======================
const getMenuData = () => {
getMenuList({ pageNum: 1, pageSize: 1000 }).then(res => {
if (res.code === 200) {
const treeData = buildTreeFromFlat(res.data || []);
if (res.code == 200) {
const treeData = buildTreeFromFlat(res.rows || []);
setMenuTree(buildPermTree(treeData));
}
});
@@ -93,15 +98,31 @@ export default function UserRolePage() {
// ====================== 获取角色下拉框 ======================
const getRoleForSelect = () => {
getRoleList({ pageNum: 1, pageSize: 1000 }).then(res => {
getRoleList({
pageNum: 1, pageSize: 1000, ...(userInfo?.roleId && { roleId: userInfo.roleId }),
}).then(res => {
if (res.code === 200) setRolesOption(res.data || []);
});
};
const getRoleById = () => {
const roleId = userInfo?.roleId;
getRoleDetailById(roleId).then(res => {
if (res.code === 200) {
setRoleDetail(res.data);
} else {
messageApi.error(res.msg || '获取角色详情失败');
}
}).catch(() => {
});
}
// ====================== 加载数据 ======================
useEffect(() => {
getRoleData();
getMenuData();
getRoleById();
}, [rolePagination.pageNum, rolePagination.pageSize]);
useEffect(() => {
@@ -121,7 +142,32 @@ export default function UserRolePage() {
const handleEditRole = (record) => {
setEditRole(record);
roleForm.setFieldsValue({ ...record, status: record.status == 1 });
setCheckedKeys((record.menuIds || []).map(Number));
// ==============================
// 工具:获取所有叶子节点(最底层菜单)
// ==============================
const getAllLeafKeys = (tree) => {
let leaves = [];
function traverse(nodes) {
nodes.forEach(node => {
if (!node.children || node.children.length === 0) {
leaves.push(node.key);
} else {
traverse(node.children);
}
});
}
traverse(tree);
return leaves;
};
const leafKeys = getAllLeafKeys(menuTree);
const leafChecked = (record.menuIds || [])
.map(Number)
.filter(id => leafKeys.includes(id));
setCheckedKeys(leafChecked);
setRoleModalVisible(true);
};
@@ -157,9 +203,35 @@ export default function UserRolePage() {
const handleSaveRole = () => {
roleForm.validateFields().then(values => {
const getParentKeys = (key, tree) => {
for (let node of tree) {
if (node.key === key) {
return [node.key];
}
if (node.children) {
const res = getParentKeys(key, node.children);
if (res.length > 0) {
return [...res, node.key];
}
}
}
return [];
};
// 所有需要提交的菜单 ID(包含父级)
let allMenuIds = [];
checkedKeys.forEach(key => {
const keys = getParentKeys(key, menuTree);
allMenuIds.push(...keys);
});
// 去重
allMenuIds = [...new Set(allMenuIds)];
const params = {
...values,
menuIds: checkedKeys,
menuIds: allMenuIds, // 👈 这里用自动包含父级的数组
status: values.status ? 1 : 0,
roleSort: values.roleSort || 1,
};
@@ -167,9 +239,10 @@ export default function UserRolePage() {
const api = editRole ? editRoleApi : addRole;
api(params).then(res => {
if (res.code === 200) {
if (res.code == 200) {
messageApi.success(editRole ? '编辑成功' : '新增成功');
setRoleModalVisible(false);
getRoleById();
getRoleData();
getRoleForSelect();
} else messageApi.error(res.msg || '保存失败');
@@ -376,12 +449,63 @@ export default function UserRolePage() {
<Modal title={editRole ? '编辑角色' : '新增角色'} open={roleModalVisible}
onCancel={() => setRoleModalVisible(false)} onOk={handleSaveRole} width={560}>
<Form form={roleForm} layout="vertical">
<Form.Item name="roleName" label="角色名称" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item name="roleKey" label="权限标识" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item name="roleSort" label="排序"><InputNumber style={{ width: '100%' }} /></Form.Item>
<Form.Item name="status" label="状态" valuePropName="checked"><Switch checkedChildren="正常" unCheckedChildren="停用" /></Form.Item>
<Divider>菜单权限</Divider>
<Tree checkable treeData={menuTree} checkedKeys={checkedKeys} onCheck={setCheckedKeys} defaultExpandAll />
<Form form={roleForm} layout="vertical">
{/* 一行两个:角色名称 + 权限标识 */}
<Row gutter={16}>
<Col span={12}>
<Form.Item name="roleName" label="角色名称" rules={[{ required: true }]}>
<Input />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="roleKey" label="权限标识" rules={[{ required: true }]}>
<Input />
</Form.Item>
</Col>
</Row>
{/* 一行两个:排序 + 状态 */}
<Row gutter={16}>
<Col span={12}>
<Form.Item name="roleSort" label="排序">
<InputNumber style={{ width: '100%' }} />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="status" label="状态" valuePropName="checked">
<Switch checkedChildren="正常" unCheckedChildren="停用" />
</Form.Item>
</Col>
</Row>
{/* 一行两个:是否有场站权限(占一半)+ 空着占位 */}
<Row gutter={16}>
<Col span={12}>
<Form.Item name="siteAccess" label="是否有场站权限" valuePropName="checked">
<Switch checkedChildren="是" unCheckedChildren="否" />
</Form.Item>
</Col>
<Col span={12}></Col>
</Row>
</Form>
{!userInfo.roleId && (
<>
<Divider>菜单权限</Divider>
<Tree
checkable
treeData={menuTree}
checkedKeys={checkedKeys}
onCheck={setCheckedKeys}
defaultExpandAll
// 👇 开启:父级自动半选/全选(核心!)
checkStrictly={false}
/>
</>
)}
</Form>
</Modal>
@@ -402,11 +526,18 @@ export default function UserRolePage() {
<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 }]}><Select mode="multiple" placeholder="选择角色">{rolesOption.map(i => <Select.Option key={i.roleId} value={i.roleId}>{i.roleName}</Select.Option>)}</Select></Form.Item></Col>
<Col span={12}><Form.Item name="roleIds" label="分配角色" rules={[{ required: true }]}><Select placeholder="选择角色">{rolesOption.map(i => <Select.Option key={i.roleId} value={i.roleId}>{i.roleName}</Select.Option>)}</Select></Form.Item></Col>
<Col span={12}><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>
<Form.Item name="siteId" label="场站ID"><Input /></Form.Item>
<Form.Item name="sex" label="性别" initialValue="2"><Select><Select.Option value="0">男</Select.Option><Select.Option value="1">女</Select.Option><Select.Option value="2">未知</Select.Option></Select></Form.Item>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="sex" label="性别" initialValue="2"><Select><Select.Option value="0">男</Select.Option><Select.Option value="1">女</Select.Option><Select.Option value="2">未知</Select.Option></Select></Form.Item>
</Col>
{roleDetail?.siteAccess && (<Col span={12}><Form.Item name="siteId" label="场站ID"><Input /></Form.Item></Col>
)}
</Row>
</Form>
</Modal>
</div>

View File

@@ -65,7 +65,7 @@ export default function UserList() {
useEffect(() => {
getUserList();
getRole();
//getRole();
}, [pagination.pageNum, pagination.pageSize]);
// 新增

View File

@@ -2,7 +2,6 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import { login } from '@/api/login';
import Cookies from 'js-cookie';
import { setToken, setTokenAi } from '@/lib/utils';
import { Cookie } from 'lucide-react';
export const userLogin = createAsyncThunk(
'user/login',
@@ -15,15 +14,15 @@ export const userLogin = createAsyncThunk(
}
const res = await login(data);
localStorage.setItem('username', userInfo.username.trim());
localStorage.setItem('userInfo', JSON.stringify(res)); // 👈 保存用户信息
const searchParams = new URLSearchParams(window.location.search);
const goRemote = searchParams.get('goRemote');
document.cookie = `sharetoken=${res.token}; path=/; domain=.satabot.com; secure`;
localStorage.setItem('token', res.token);
if (goRemote) {
setTokenAi(res.token);
} else {
@@ -31,7 +30,6 @@ export const userLogin = createAsyncThunk(
}
Cookies.set('userId', res.userId);
return res;
} catch (err) {
@@ -40,9 +38,19 @@ export const userLogin = createAsyncThunk(
}
);
// 👇 刷新页面时,自动从本地存储恢复用户信息
const loadUserFromStorage = () => {
try {
const user = localStorage.getItem('userInfo');
return user ? JSON.parse(user) : null;
} catch {
return null;
}
};
const initialState = {
token: localStorage.getItem('token') || Cookies.get('Admin-Token') || null,
userInfo: null,
userInfo: loadUserFromStorage(), // 👈 刷新自动恢复
isAuthenticated: !!localStorage.getItem('token'),
};
@@ -54,19 +62,21 @@ const userSlice = createSlice({
state.token = null;
state.userInfo = null;
state.isAuthenticated = false;
// 清空本地
localStorage.clear();
Cookies.remove('userId');
Cookies.remove('Admin-Token');
},
setUserInfo: (state, action) => {
state.userInfo = action.payload;
localStorage.setItem('userInfo', JSON.stringify(action.payload));
},
},
extraReducers: (builder) => {
builder
.addCase(userLogin.fulfilled, (state, action) => {
state.userInfo = action.payload;
//state.token = action.payload.token;
state.isAuthenticated = true;
})
.addCase(userLogin.rejected, (state, action) => {