提交 4bc92de1 作者: ZhangLingKun

功能:代码优化

上级 cb160300
......@@ -4,14 +4,26 @@ import { DownOutlined, UpOutlined } from '@ant-design/icons';
import { Button, Dropdown, MenuProps, Modal } from 'antd';
import Logo from '../../../assets/icon/logo_big.png';
import './index.scss';
import { REMOVE_MENU, REMOVE_MENU_ID, SET_COLLAPSE } from '~/store/module/menu';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import Cookies from 'js-cookie';
export function TitleView() {
// 弹窗
const { confirm } = Modal;
// redux
const dispatch = useDispatch();
// 路由钩子
const navigate = useNavigate();
// 菜单栏是否收起
const [isActive, setIsActive] = useState(false);
// 用户信息
const { userInfo } = useSelector((state: any) => state.UserInfo);
// 菜单栏收起
const setMenuCollapsed = () => {
setIsActive(!isActive);
dispatch(SET_COLLAPSE(!isActive));
};
// 右上角按钮
const items: MenuProps['items'] = [
......@@ -25,7 +37,10 @@ export function TitleView() {
title: '退出登录',
content: '退出后未保存数据将会丢失,确定登出吗?',
onOk: () => {
console.log('点击');
navigate('/login', { replace: true });
Cookies.remove('SHAREFLY_TOKEN');
dispatch(REMOVE_MENU());
dispatch(REMOVE_MENU_ID());
},
});
}}
......@@ -62,7 +77,7 @@ export function TitleView() {
<div className='title-user'>
<div className='user-content'>
<div className='user-company'>科比特</div>
<div className='user-name'>admin</div>
<div className='user-name'>{userInfo.accountNo}</div>
</div>
<Dropdown
overlayStyle={{ textAlign: 'center' }}
......
......@@ -9,6 +9,7 @@ import { BackEndLoginType } from '~/api/interface/commonType';
import { CommonAPI } from '~/api';
import { useDispatch } from 'react-redux';
import { SET_USERINFO } from '~/store/module/userInfo';
import { authRouterList } from '~/router';
// 请求的类型
type ReqType = InterReqType<BackEndLoginType>;
......@@ -39,28 +40,20 @@ function LoginView() {
// 存用户信息
dispatch(SET_USERINFO(res.result));
// 获取用户的权限
await getUserRole();
await getFirstRoute();
// console.log('SXTB_TOKEN --->', Cookies.get('SXTB-TOKEN'));
} else {
message.error('登录失败,请检查账号信息');
}
};
// 获取用户权限
const getUserRole = async () => {
// TODO: 获取用户权限
// 模拟获取用户权限成功
// 获取用户能使用的全部路由
// 获取用户路由列表
// 获取第一个路由
await getFirstRoute();
};
// 获取第一个路由
const getFirstRoute = () => {
// TODO: 获取第一个路由
// 获取可用的路由表
const routeList = authRouterList();
// 获取第一个路由
// console.log('获取第一个路由--->', route);
// navigate(route[0].path);
navigate('/orderManage/productOrder');
navigate(routeList[0]?.children?.[0]?.path);
// console.log('获取第一个路由--->', routeList[0]?.children?.[0]?.path);
};
// componentDidMount
useEffect(() => {
......
......@@ -3,7 +3,11 @@ import { RouteObjectType, routerList, whiteRouterList } from '~/router/router';
// 获取用户权限路由列表
export const authRouterList = () => {
// TODO: 获取用户权限
// 模拟获取用户权限成功
// 获取用户能使用的全部路由
// TODO: 在此处对用户权限进行判断,返回不同的路由表
// 获取用户可用路由列表
return [...routerList];
};
// 整合路由数据
......
......@@ -15,7 +15,7 @@ export interface menuItem {
pid: number;
}
// 遍历路由树形结构
const getRouteList = (router: routerItem[]) => {
export const getRouteList = (router: routerItem[]) => {
const list = router;
const arr: routerItem[] = [];
const getRoute = (item: routerItem) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论