import { Outlet, Link, useHref, useNavigate, useLocation, NavLink } from "react-router-dom";
import { useEffect, useState } from 'react';
import { observer } from "mobx-react";
import { toJS } from "mobx";
import { Layout, Menu, ConfigProvider, theme, Dropdown, Space, Row, Col, Badge, Typography, Modal, Input, Button, App as AntApp } from "antd";
import { DownOutlined } from "@ant-design/icons";
import "antd/dist/reset.css";
import AppLogo from "@/assets/logo-gh.png";
import { isEmpty } from "@/utils/commons";
import { useStore } from "@/stores/StoreContext.js";
import * as config from "@/config";
const { Header, Content, Footer } = Layout;
const { Title } = Typography;
let items = [];
const items_default = [
{
label: Change password,
key: "0",
},
{
label: Profile,
key: "1",
},
{
type: "divider",
},
{
label: Logout,
key: "3",
},
];
const item_manager =
[
{
label: Change password,
key: "0",
},
{
label: Profile,
key: "1",
},
{
type: "divider",
},
{
label: Logout,
key: "3",
},
{
label:Change Vendor,
key:"4",
},
];
function App() {
const [password, setPassword] = useState('');
const { authStore, noticeStore } = useStore();
const { notification } = AntApp.useApp();
const login = toJS(authStore.login);
const { noticeUnRead } = noticeStore;
const href = useHref();
const loginToken = login.token;
const navigate = useNavigate();
const location = useLocation();
const arrManager = config.arrManager; // ["testzp","testzac","testycc","testlyj","testqqs","testjjh","testhn"];//特定账号加修改所属供应商的菜单 zp
if (arrManager.includes(authStore.login.username)){
items = item_manager;
}else{
items = items_default;
}
useEffect(() => {
if (href !== '/login' && isEmpty(loginToken)) {
navigate('/login');
}
}, [href]);
useEffect(() => {
window.gtag('event', 'page_view', { page_location: window.location.href });
}, [location]);
const onSubmit = () => {
authStore.valdateUserPassword(login.username, password)
.then(() => {
authStore.fetchUserDetail()
.catch(ex => {
notification.error({
message: `Notification`,
description: 'Failed to get user information.',
placement: 'top',
duration: 4,
});
});
})
.catch(ex => {
notification.error({
message: `Notification`,
description: ex.message,
placement: 'top',
duration: 4,
});
});
setPassword('');
};
const splitPath = href.split("/");
let defaultPath = "reservation";
if (splitPath.length > 1) {
defaultPath = splitPath[1];
}
const {
token: { colorBgContainer },
} = theme.useToken();
return (
Login timeout
Please input your password
setPassword(e.target.value)}
onPressEnter={() => onSubmit()}
addonBefore={login.username} />
);
}
export default observer(App);