完善了路由

main
wuyize 2022-12-29 15:20:09 +08:00
parent e005d48d56
commit 08b5f2b0a2
5 changed files with 44 additions and 17 deletions

View File

@ -3,7 +3,7 @@ import {UploadOutlined, UserOutlined, VideoCameraOutlined} from '@ant-design/ico
import {Layout, Menu, theme, Typography, Button, Dropdown, MenuProps} from 'antd';
import {useAppDispatch, useAppSelector} from "../models/hooks";
import {getToken, setToken, store} from "../models/store";
import {Link, Outlet, useNavigate} from "react-router-dom";
import {Link, Outlet, useLocation, useNavigate} from "react-router-dom";
import Icon from '@ant-design/icons';
import {Logo} from "../assets/icons";
import axiosInstance from "../utils/axiosInstance";
@ -105,11 +105,11 @@ function HeaderBar(props: any) {
}
function MyMenu(props: any) {
console.log(props)
return (
<Menu
mode="inline"
defaultSelectedKeys={['0']}
defaultSelectedKeys={props.defaultSelectedKeys}
items={props.items}
/>
)
@ -118,28 +118,29 @@ function MyMenu(props: any) {
function HomeView() {
const token = useAppSelector(getToken);
const navigate = useNavigate();
const location = useLocation()
console.log(store.getState())
let items = [{
key: "0",
key: "/invoice/mine",
//icon: React.createElement(UserOutlined),
label: <Link to="/invoice/mine"></Link>
}, {
key: "1",
key: "/reimbursement/mine",
//icon: React.createElement(UserOutlined),
label: <Link to="/reimbursement/mine"></Link>,
}, {
key: "2",
key: "/invoice/management",
//icon: React.createElement(UserOutlined),
label: <Link to="/reimbursement/mine"></Link>,
label: <Link to="/invoice/management"></Link>,
}, {
key: "3",
key: "/reimbursement/approval",
//icon: React.createElement(UserOutlined),
label: <Link to="/reimbursement/mine"></Link>,
label: <Link to="/reimbursement/approval"></Link>,
}, {
key: "4",
key: "/stat",
//icon: React.createElement(UserOutlined),
label: <Link to="/reimbursement/mine"></Link>,
label: <Link to="/stat"></Link>,
}]
const {
@ -154,6 +155,7 @@ function HomeView() {
})
const [menuItems, setMenuItems] = useState(items.slice(0,2))
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(['/invoice/mine'])
const getStaffInfo = () => {
axiosInstance({
@ -163,23 +165,24 @@ function HomeView() {
console.log(response.data)
const staff = response.data
setStaff( response.data)
navigate('/invoice/mine')
if(location.pathname==='/')
navigate('/invoice/mine')
setDefaultSelectedKeys([location.pathname])
if(staff.managingDepartment)
{
// @ts-ignore
if(staff.managingDepartment.departmentName==='财务部')
if(staff.managingDepartment.departmentId===1)
{
setMenuItems(items)
}
else{
console.log('aaaaaaaaaaa')
setMenuItems(items.slice(0,3))
setMenuItems(items.slice(0,4))
}
}
else {
setMenuItems(items.slice(0,2))
}
}).catch(function (error) {
console.log(error)
})
@ -221,7 +224,7 @@ function HomeView() {
marginLeft: '4px'
}}></span>
</div>
<MyMenu items={menuItems}/>
<MyMenu items={menuItems} defaultSelectedKeys={defaultSelectedKeys}/>
</Sider>
<Layout>
<HeaderBar staff={staff}/>

View File

@ -0,0 +1,6 @@
function InvoiceManagement() {
return(
<div></div>
)
}
export default InvoiceManagement

View File

@ -0,0 +1,6 @@
function ReimbursementApproval() {
return(
<div></div>
)
}
export default ReimbursementApproval

View File

@ -0,0 +1,6 @@
function StatView() {
return(
<div></div>
)
}
export default StatView

View File

@ -5,6 +5,9 @@ import HomeView from "../pages/HomeView";
import InvoiceListView from "../pages/Invoice/mine/InvoiceListView";
import MyReimbursement from "../pages/reimbursement/mine/MyReimbursement";
import {BrowserRouter} from "./BrowserRouter"
import InvoiceManagement from "../pages/Invoice/management/InvoiceManagement";
import ReimbursementApproval from "../pages/reimbursement/approval/ReimbursementApproval";
import StatView from "../pages/stat/StatView";
export const history = createBrowserHistory()
@ -15,6 +18,9 @@ function CustomRouter() {
<Route path="/" element={<HomeView/>}>
<Route path="invoice/mine" element={<InvoiceListView/>}></Route>
<Route path="reimbursement/mine" element={<MyReimbursement/>}></Route>
<Route path="invoice/management" element={<InvoiceManagement/>}></Route>
<Route path="reimbursement/approval" element={<ReimbursementApproval/>}></Route>
<Route path="stat" element={<StatView/>}></Route>
</Route>
<Route path="/login" element={<LoginView/>}></Route>
</Routes>