From 006ce5cf707fe47ae8a945e6b8967355a19d7fe5 Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 30 Dec 2022 16:59:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86staff=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/HomeView.tsx | 56 ++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/pages/HomeView.tsx b/src/pages/HomeView.tsx index 03193f8..1fcc10e 100644 --- a/src/pages/HomeView.tsx +++ b/src/pages/HomeView.tsx @@ -13,7 +13,6 @@ const {Title} = Typography; const {Header, Content, Footer, Sider} = Layout; - function HeaderBar(props: any) { const { token: {colorBgContainer, colorPrimary}, @@ -67,11 +66,10 @@ function HeaderBar(props: any) { } ]; - const departmentToString = (staff:Staff) => { - let result = staff.managingDepartment===null?'':staff.managingDepartment.departmentName+'主管' - for(const department of staff.staffDepartments) - { - result+=' '+department.departmentName + const departmentToString = (staff: Staff) => { + let result = staff.managingDepartment === null ? '' : staff.managingDepartment.departmentName + '主管' + for (const department of staff.staffDepartments) { + result += ' ' + department.departmentName } return result } @@ -106,13 +104,16 @@ function HeaderBar(props: any) { function MyMenu(props: any) { console.log(props) - return ( - - ) + if (props.defaultSelectedKeys[0] === '') + return null + else + return ( + + ) } function HomeView() { @@ -154,34 +155,31 @@ function HomeView() { staffDepartments: [] }) - const [menuItems, setMenuItems] = useState(items.slice(0,2)) - const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(['/invoice/mine']) + const [menuItems, setMenuItems] = useState(items.slice(0, 2)) + const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(['']) const getStaffInfo = () => { axiosInstance({ - url: 'staff', + url: 'common/staff', method: 'get' }).then(response => { console.log(response.data) const staff = response.data - setStaff( response.data) - if(location.pathname==='/') + setStaff(response.data) + if (location.pathname === '/') navigate('/invoice/mine') - setDefaultSelectedKeys([location.pathname]) - if(staff.managingDepartment) - { + + if (staff.managingDepartment) { // @ts-ignore - if(staff.managingDepartment.departmentId===1) - { + if (staff.managingDepartment.departmentId === 1) { setMenuItems(items) + } else { + setMenuItems(items.slice(0, 4)) } - else{ - setMenuItems(items.slice(0,4)) - } - } - else { - setMenuItems(items.slice(0,2)) + } else { + setMenuItems(items.slice(0, 2)) } + setDefaultSelectedKeys([location.pathname]) }).catch(function (error) { console.log(error)