xiugai
This commit is contained in:
123
src/api/mune/index.ts
Normal file
123
src/api/mune/index.ts
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import request from '../request';
|
||||||
|
|
||||||
|
// ==================== 菜单管理接口 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单列表
|
||||||
|
* @param {Object} params - 查询参数
|
||||||
|
* @param {string} [params.menuName] - 菜单名称
|
||||||
|
* @param {string} [params.status] - 菜单状态(0正常 1停用)
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function getMenuList() {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu/list',
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜单ID获取菜单详情
|
||||||
|
* @param {number} menuId - 菜单ID
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function getMenuInfo(menuId) {
|
||||||
|
return request({
|
||||||
|
url: `/system/menu/${menuId}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单下拉树结构(用于新增/编辑选择父菜单)
|
||||||
|
* @param {Object} params - 查询参数
|
||||||
|
* @param {string} [params.menuName] - 菜单名称
|
||||||
|
* @param {string} [params.status] - 状态
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function getMenuTreeSelect(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu/treeselect',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色ID加载对应角色菜单列表树
|
||||||
|
* @param {number} roleId - 角色ID
|
||||||
|
* @param {number} deptId - 部门ID
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function getRoleMenuTreeSelect(roleId, deptId) {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu/roleMenuTreeselect',
|
||||||
|
method: 'get',
|
||||||
|
params: { roleId, deptId }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜单
|
||||||
|
* @param {Object} data - 菜单信息
|
||||||
|
* @param {string} data.menuName - 菜单名称
|
||||||
|
* @param {number} data.parentId - 父菜单ID
|
||||||
|
* @param {string} data.path - 路由地址
|
||||||
|
* @param {string} [data.icon] - 图标
|
||||||
|
* @param {string} [data.status] - 状态(0正常 1停用)
|
||||||
|
* @param {number} data.sort - 排序
|
||||||
|
* @param {string} [data.permission] - 权限标识
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function addMenu(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜单
|
||||||
|
* @param {Object} data - 菜单信息
|
||||||
|
* @param {number} data.menuId - 菜单ID
|
||||||
|
* @param {string} data.menuName - 菜单名称
|
||||||
|
* @param {number} data.parentId - 父菜单ID
|
||||||
|
* @param {string} data.path - 路由地址
|
||||||
|
* @param {string} [data.icon] - 图标
|
||||||
|
* @param {string} [data.status] - 状态
|
||||||
|
* @param {number} data.sort - 排序
|
||||||
|
* @param {string} [data.permission] - 权限标识
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function updateMenu(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜单
|
||||||
|
* @param {number} menuId - 菜单ID
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function deleteMenu(menuId) {
|
||||||
|
return request({
|
||||||
|
url: `/system/menu/${menuId}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门ID加载对应部门菜单树
|
||||||
|
* @param {number} deptId - 部门ID
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
export function getDeptMenuTreeSelect(deptId) {
|
||||||
|
return request({
|
||||||
|
url: `/system/menu/deptMenuTreeselect/${deptId}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -34,16 +34,15 @@ api.interceptors.request.use(
|
|||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
api.interceptors.response.use(
|
api.interceptors.response.use(
|
||||||
(response: AxiosResponse) => {
|
(response) => {
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
async (error: AxiosError) => { // 👈 加 async
|
async (error: AxiosError) => { // 👈 加 async
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
localStorage.removeItem('token');
|
localStorage.clear();
|
||||||
localStorage.removeItem('isAuthenticated');
|
Cookies.remove('userId');
|
||||||
localStorage.removeItem('user');
|
Cookies.remove('Admin-Token');
|
||||||
|
|
||||||
// 🔥 🔥 🔥 在这里动态导入!!!
|
|
||||||
const store = await import('../store');
|
const store = await import('../store');
|
||||||
const { logout } = await import('../store/userSlice');
|
const { logout } = await import('../store/userSlice');
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,14 @@ import {
|
|||||||
MenuUnfoldOutlined,
|
MenuUnfoldOutlined,
|
||||||
MenuFoldOutlined,
|
MenuFoldOutlined,
|
||||||
GlobalOutlined,
|
GlobalOutlined,
|
||||||
TeamOutlined
|
TeamOutlined,
|
||||||
|
MenuOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { MOCK_USER } from '../constants';
|
|
||||||
import logo from '../assets/logo.png';
|
import logo from '../assets/logo.png';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { RootState } from '../store';
|
import { RootState, useAppDispatch } from '../store';
|
||||||
|
import { logout } from '../store/userSlice';
|
||||||
|
import { getMenuList } from '../api/mune';
|
||||||
const { Header, Sider, Content } = Layout;
|
const { Header, Sider, Content } = Layout;
|
||||||
|
|
||||||
export default function AppLayout() {
|
export default function AppLayout() {
|
||||||
@@ -37,17 +39,33 @@ export default function AppLayout() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const getMenu = () => {
|
||||||
|
getMenuList().then(res => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
message.success("获取菜单成功")
|
||||||
|
} else {
|
||||||
|
message.error("获取菜单失败:" + res.msg)
|
||||||
|
}
|
||||||
|
console.log("菜单列表:", res);
|
||||||
|
//if (res.code == 200) {
|
||||||
|
// setMenuList(res.data)
|
||||||
|
//} else {
|
||||||
|
// //message.error("获取菜单失败:"+res.msg)
|
||||||
|
//}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
||||||
|
getMenu();
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = async () => {
|
||||||
localStorage.removeItem('isAuthenticated');
|
await dispatch(logout());
|
||||||
localStorage.removeItem('user');
|
navigate('/login', { replace: true });
|
||||||
localStorage.removeItem('token');
|
|
||||||
navigate('/login');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
@@ -59,9 +77,16 @@ export default function AppLayout() {
|
|||||||
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
|
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
|
||||||
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
|
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
|
||||||
{ key: '/serialNumGenerate', icon: <UserOutlined />, label: '序列号生成', roles: ['admin'] },
|
{ key: '/serialNumGenerate', icon: <UserOutlined />, label: '序列号生成', roles: ['admin'] },
|
||||||
|
{
|
||||||
|
key: '/menuList',
|
||||||
|
icon: <MenuOutlined />,
|
||||||
|
label: '菜单管理',
|
||||||
|
roles: ['admin']
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const filteredMenu = menuItems.filter(item => item.roles.includes(userInfo.role));
|
const filteredMenu = menuItems
|
||||||
|
//.filter(item => item.roles.includes(userInfo?.role));
|
||||||
|
|
||||||
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
||||||
|
|
||||||
@@ -124,7 +149,7 @@ export default function AppLayout() {
|
|||||||
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
|
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
|
||||||
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
|
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
|
||||||
<Badge status="success" />
|
<Badge status="success" />
|
||||||
<span className="text-gray-800 font-medium">{userInfo.username}</span>
|
<span className="text-gray-800 font-medium">{userInfo?.username}</span>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import { Device, Alert, VideoRecord, User } from './types';
|
import { Device, Alert, VideoRecord, User } from './types';
|
||||||
|
|
||||||
export const MOCK_USER: User = {
|
|
||||||
id: 'user-1',
|
|
||||||
name: 'mabaoyu',
|
|
||||||
role: 'admin',
|
|
||||||
avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=Felix',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DEVICES: Device[] = [
|
export const DEVICES: Device[] = [
|
||||||
{ id: 'R001', name: '巡检机器人 A1', type: '巡检型', status: 'online', battery: 85, cpu: 12, temp: 32.08, lastUpdate: '2024-03-20 10:00:00' },
|
{ id: 'R001', name: '巡检机器人 A1', type: '巡检型', status: 'online', battery: 85, cpu: 12, temp: 32.08, lastUpdate: '2024-03-20 10:00:00' },
|
||||||
{ id: 'R002', name: '安防辅助 B2', type: '安防型', status: 'alert', battery: 45, cpu: 45, temp: 42.5, lastUpdate: '2024-03-20 09:55:00' },
|
{ id: 'R002', name: '安防辅助 B2', type: '安防型', status: 'alert', battery: 45, cpu: 45, temp: 42.5, lastUpdate: '2024-03-20 09:55:00' },
|
||||||
|
|||||||
10
src/images.d.ts
vendored
Normal file
10
src/images.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// images.d.ts
|
||||||
|
declare module '*.png' {
|
||||||
|
const src: string;
|
||||||
|
export default src;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '*.jpg'
|
||||||
|
declare module '*.jpeg'
|
||||||
|
declare module '*.svg'
|
||||||
|
declare module '*.gif'
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
@layer base {
|
@layer base {
|
||||||
body {
|
body {
|
||||||
@apply bg-bg text-text-main font-sans;
|
@apply bg-bg text-text-main font-sans;
|
||||||
width:100vm;
|
width:100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
#root{
|
#root{
|
||||||
@@ -30,3 +30,8 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ export default function Home() {
|
|||||||
<Row gutter={[16, 16]} style={{ marginTop: 4 }}>
|
<Row gutter={[16, 16]} style={{ marginTop: 4 }}>
|
||||||
{/* 设备表格 */}
|
{/* 设备表格 */}
|
||||||
<Col xs={24} lg={16}>
|
<Col xs={24} lg={16}>
|
||||||
<Card
|
<AntdCard
|
||||||
title={<span style={{ fontSize: 14, fontWeight: 600 }}>核心节点实时清单</span>}
|
title={<span style={{ fontSize: 14, fontWeight: 600 }}>核心节点实时清单</span>}
|
||||||
bordered={false}
|
bordered={false}
|
||||||
style={{ borderRadius: 10, boxShadow: '0 2px 12px rgba(0,0,0,0.06)' }}
|
style={{ borderRadius: 10, boxShadow: '0 2px 12px rgba(0,0,0,0.06)' }}
|
||||||
@@ -158,7 +158,7 @@ export default function Home() {
|
|||||||
})}
|
})}
|
||||||
rowHoverable
|
rowHoverable
|
||||||
/>
|
/>
|
||||||
</Card>
|
</AntdCard>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* 告警列表 */}
|
{/* 告警列表 */}
|
||||||
|
|||||||
@@ -17,18 +17,16 @@ import {
|
|||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
import bgcImg from '../assets/bgc2.png';
|
import bgcImg from '../assets/bgc2.png';
|
||||||
import logincard from '../assets/logincard.png';
|
import logincard from '../assets/logincard.png';
|
||||||
import { useDispatch } from 'react-redux';
|
import { userLogin } from '../store/userSlice';
|
||||||
import { setUserInfo, userLogin } from '../store/userSlice';
|
|
||||||
import { useAppDispatch } from '../store';
|
import { useAppDispatch } from '../store';
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
|
|
||||||
const { Text, Title } = Typography;
|
const { Text, Title } = Typography;
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { message, modal, notification } = App.useApp();
|
const { message, } = App.useApp();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 账号密码登录
|
// 账号密码登录
|
||||||
const onFinish = async (values: any) => {
|
const onFinish = async (values: any) => {
|
||||||
@@ -41,9 +39,19 @@ export default function Login() {
|
|||||||
|
|
||||||
if (loginResult.code == 200) {
|
if (loginResult.code == 200) {
|
||||||
//dispatch(setUserInfo(loginResult))
|
//dispatch(setUserInfo(loginResult))
|
||||||
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
|
const goRemote = searchParams.get('goRemote');
|
||||||
|
if (Number(goRemote) == 1) {
|
||||||
|
const rawUserId = Cookies.get("userId"); // 比如 "32434"
|
||||||
|
|
||||||
|
const encodedUserId = btoa(unescape(encodeURIComponent(rawUserId)));
|
||||||
|
window.location.href = `https://ai.satabot.com/?userId=${encodedUserId}`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
message.success(`登录成功`);
|
message.success(`登录成功`);
|
||||||
navigate('/');
|
navigate('/', { replace: true });
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
message.error("登录失败:" + loginResult.msg);
|
message.error("登录失败:" + loginResult.msg);
|
||||||
@@ -54,12 +62,10 @@ export default function Login() {
|
|||||||
// 登录成功后跳转
|
// 登录成功后跳转
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// 接口失败、密码错误都会进这里
|
message.error("登录失败:" + err.toString());
|
||||||
//console.error("登录失败:", err);
|
|
||||||
//message.error('登录失败,请检查账号密码');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//navigate('/');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -107,11 +113,11 @@ export default function Login() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
{/* 记住密码 */}
|
{/* 记住密码 */}
|
||||||
<Form.Item name="remember" valuePropName="checked" noStyle>
|
{/*<Form.Item name="remember" valuePropName="checked" noStyle>
|
||||||
<Checkbox>
|
<Checkbox>
|
||||||
<Text style={{ fontSize: 14, color: '#666' }}>记住密码</Text>
|
<Text style={{ fontSize: 14, color: '#666' }}>记住密码</Text>
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Form.Item>
|
</Form.Item>*/}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
242
src/pages/MenuList.tsx
Normal file
242
src/pages/MenuList.tsx
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Select,
|
||||||
|
TreeSelect,
|
||||||
|
Space,
|
||||||
|
Popconfirm,
|
||||||
|
message,
|
||||||
|
Card,
|
||||||
|
Typography
|
||||||
|
} from 'antd';
|
||||||
|
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||||
|
import type { MenuItem, RoleItem } from '@/types/menu';
|
||||||
|
|
||||||
|
const { Title } = Typography;
|
||||||
|
const { Option } = Select;
|
||||||
|
|
||||||
|
// 模拟系统角色
|
||||||
|
const roleOptions: RoleItem[] = [
|
||||||
|
{ label: '系统管理员', value: 'admin' },
|
||||||
|
{ label: '操作员', value: 'operator' },
|
||||||
|
{ label: '观察员', value: 'viewer' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 模拟菜单数据
|
||||||
|
const mockMenuData: MenuItem[] = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: '控制台',
|
||||||
|
path: '/',
|
||||||
|
parentId: null,
|
||||||
|
sort: 1,
|
||||||
|
roles: ['admin', 'operator', 'viewer'],
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: '设备管理',
|
||||||
|
path: '/devices',
|
||||||
|
parentId: null,
|
||||||
|
sort: 2,
|
||||||
|
roles: ['admin', 'operator'],
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
name: '视频监控',
|
||||||
|
path: '/video',
|
||||||
|
parentId: '2',
|
||||||
|
sort: 1,
|
||||||
|
roles: ['admin', 'operator', 'viewer'],
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const MenuList: React.FC = () => {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [menuList, setMenuList] = useState<MenuItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [modalVisible, setModalVisible] = useState(false);
|
||||||
|
const [title, setTitle] = useState('新增菜单');
|
||||||
|
const [currentRecord, setCurrentRecord] = useState<MenuItem | null>(null);
|
||||||
|
|
||||||
|
// 加载菜单
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true);
|
||||||
|
setTimeout(() => {
|
||||||
|
setMenuList(mockMenuData);
|
||||||
|
setLoading(false);
|
||||||
|
}, 300);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 打开新增
|
||||||
|
const handleAdd = () => {
|
||||||
|
form.resetFields();
|
||||||
|
setTitle('新增菜单');
|
||||||
|
setCurrentRecord(null);
|
||||||
|
setModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 打开编辑
|
||||||
|
const handleEdit = (record: MenuItem) => {
|
||||||
|
form.setFieldsValue(record);
|
||||||
|
setTitle('编辑菜单');
|
||||||
|
setCurrentRecord(record);
|
||||||
|
setModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
const handleDelete = (id: string) => {
|
||||||
|
setMenuList(prev => prev.filter(item => item.id !== id));
|
||||||
|
message.success('删除成功');
|
||||||
|
};
|
||||||
|
|
||||||
|
// 提交保存
|
||||||
|
const handleSubmit = () => {
|
||||||
|
form.validateFields().then(values => {
|
||||||
|
const params: MenuItem = {
|
||||||
|
...values,
|
||||||
|
id: currentRecord?.id || Date.now().toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (currentRecord) {
|
||||||
|
// 编辑
|
||||||
|
setMenuList(prev => prev.map(m => m.id === currentRecord.id ? params : m));
|
||||||
|
message.success('编辑成功');
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
setMenuList(prev => [...prev, params]);
|
||||||
|
message.success('新增成功');
|
||||||
|
}
|
||||||
|
setModalVisible(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格列
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: '菜单名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
key: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '路由地址',
|
||||||
|
dataIndex: 'path',
|
||||||
|
key: 'path',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '父级菜单',
|
||||||
|
key: 'parentName',
|
||||||
|
render: (_, record) => {
|
||||||
|
if (!record.parentId) return '一级菜单';
|
||||||
|
const p = menuList.find(m => m.id === record.parentId);
|
||||||
|
return p?.name || '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '关联角色',
|
||||||
|
key: 'roles',
|
||||||
|
render: (_, record) => (
|
||||||
|
<div>
|
||||||
|
{record.roles.map(r => {
|
||||||
|
const ro = roleOptions.find(o => o.value === r);
|
||||||
|
return <span key={r} style={{ marginRight: 8 }}>{ro?.label}</span>;
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
render: (_, record) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>编辑</Button>
|
||||||
|
<Popconfirm
|
||||||
|
title="确定删除?"
|
||||||
|
onConfirm={() => handleDelete(record.id)}
|
||||||
|
>
|
||||||
|
<Button type="link" danger icon={<DeleteOutlined />}>删除</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<div className="flex justify-between mb-4">
|
||||||
|
<Title level={5}>菜单管理</Title>
|
||||||
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增菜单</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={menuList}
|
||||||
|
pagination={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={title}
|
||||||
|
open={modalVisible}
|
||||||
|
onCancel={() => setModalVisible(false)}
|
||||||
|
onOk={handleSubmit}
|
||||||
|
maskClosable={false}
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="name"
|
||||||
|
label="菜单名称"
|
||||||
|
rules={[{ required: true, message: '请输入菜单名称' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="path"
|
||||||
|
label="路由地址"
|
||||||
|
rules={[{ required: true, message: '请输入路由' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="/devices" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item name="parentId" label="上级菜单">
|
||||||
|
<TreeSelect
|
||||||
|
placeholder="请选择"
|
||||||
|
allowClear
|
||||||
|
treeData={menuList.map(m => ({
|
||||||
|
title: m.name,
|
||||||
|
value: m.id,
|
||||||
|
disabled: m.id === currentRecord?.id,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="roles"
|
||||||
|
label="关联角色"
|
||||||
|
rules={[{ required: true, message: '请选择至少一个角色' }]}
|
||||||
|
>
|
||||||
|
<Select mode="multiple" placeholder="请选择">
|
||||||
|
{roleOptions.map(o => (
|
||||||
|
<Option key={o.value} value={o.value}>{o.label}</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item name="sort" label="排序号">
|
||||||
|
<Input type="number" placeholder="数字越小越靠前" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MenuList;
|
||||||
@@ -11,6 +11,7 @@ import Downloads from '../pages/Downloads';
|
|||||||
import Roles from '../pages/Roles';
|
import Roles from '../pages/Roles';
|
||||||
import Users from '../pages/Users';
|
import Users from '../pages/Users';
|
||||||
import SerialNumGenerate from '../pages/SerialNumGenerate';
|
import SerialNumGenerate from '../pages/SerialNumGenerate';
|
||||||
|
import MenuList from '../pages/MenuList';
|
||||||
|
|
||||||
export const router = createBrowserRouter([
|
export const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@@ -56,6 +57,10 @@ export const router = createBrowserRouter([
|
|||||||
path: 'serialNumGenerate',
|
path: 'serialNumGenerate',
|
||||||
element: <SerialNumGenerate />,
|
element: <SerialNumGenerate />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'menuList',
|
||||||
|
element: <MenuList />,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
element: <div className="p-10 text-center font-bold text-gray-400">模块开发中...</div>,
|
element: <div className="p-10 text-center font-bold text-gray-400">模块开发中...</div>,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
|
|||||||
import { login } from '@/api/login';
|
import { login } from '@/api/login';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import { setToken, setTokenAi } from '@/lib/utils';
|
import { setToken, setTokenAi } from '@/lib/utils';
|
||||||
|
import { Cookie } from 'lucide-react';
|
||||||
|
|
||||||
export const userLogin = createAsyncThunk(
|
export const userLogin = createAsyncThunk(
|
||||||
'user/login',
|
'user/login',
|
||||||
@@ -16,19 +17,19 @@ export const userLogin = createAsyncThunk(
|
|||||||
const res = await login(data);
|
const res = await login(data);
|
||||||
|
|
||||||
localStorage.setItem('username', userInfo.username.trim());
|
localStorage.setItem('username', userInfo.username.trim());
|
||||||
localStorage.setItem('password', userInfo.password);
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
const goRemote = searchParams.get('goRemote');
|
const goRemote = searchParams.get('goRemote');
|
||||||
|
|
||||||
|
|
||||||
|
document.cookie = `sharetoken=${res.token}; path=/; domain=.satabot.com; secure`;
|
||||||
|
localStorage.setItem('token', res.token);
|
||||||
if (goRemote) {
|
if (goRemote) {
|
||||||
setTokenAi(res.token);
|
setTokenAi(res.token);
|
||||||
} else {
|
} else {
|
||||||
setToken(res.token);
|
setToken(res.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.cookie = `sharetoken=${res.token}; path=/; domain=.satabot.com; secure`;
|
|
||||||
localStorage.setItem('token', res.token);
|
|
||||||
Cookies.set('userId', res.userId);
|
Cookies.set('userId', res.userId);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -40,7 +41,7 @@ export const userLogin = createAsyncThunk(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
token: localStorage.getItem('token') || null,
|
token: localStorage.getItem('token') || Cookies.get('Admin-Token') || null,
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
isAuthenticated: !!localStorage.getItem('token'),
|
isAuthenticated: !!localStorage.getItem('token'),
|
||||||
};
|
};
|
||||||
@@ -55,6 +56,7 @@ const userSlice = createSlice({
|
|||||||
state.isAuthenticated = false;
|
state.isAuthenticated = false;
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
Cookies.remove('userId');
|
Cookies.remove('userId');
|
||||||
|
Cookies.remove('Admin-Token');
|
||||||
},
|
},
|
||||||
setUserInfo: (state, action) => {
|
setUserInfo: (state, action) => {
|
||||||
state.userInfo = action.payload;
|
state.userInfo = action.payload;
|
||||||
|
|||||||
7
src/vite-env.d.ts
vendored
Normal file
7
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare module '*.png'
|
||||||
|
declare module '*.jpg'
|
||||||
|
declare module '*.jpeg'
|
||||||
|
declare module '*.svg'
|
||||||
|
declare module '*.gif'
|
||||||
Reference in New Issue
Block a user