import React, { useState, useEffect } from 'react';
import { Outlet, history, useLocation, useAppData } from '@umijs/max';
import { NavBar, TabBar, List } from 'antd-mobile';
import {
AppOutline,
MessageOutline,
UnorderedListOutline,
UserOutline,
PayCircleOutline,
SetOutline,
} from 'antd-mobile-icons';
import './index.less';
import { useMemo } from 'react';
import {
MenuOutlined,
ArrowLeftOutlined,
EditOutlined,
UsergroupAddOutlined,
HomeOutlined,
LogoutOutlined,
LockOutlined
} from '@ant-design/icons';
import { Drawer, Avatar, Button, Divider } from 'antd';
import { UserOutlined } from '@ant-design/icons';
/*
menulist 中的表示主路由菜单上左上角是打开 drawer 否则为返回上一页
*/
const menulist = ['/home'];
function BasicLayout() {
const setRouteActive = (value) => {
history.push(value);
};
const tabs = [
{
key: '/home',
title: '首页',
icon: ,
},
{
key: '/todo',
title: '待办',
icon: ,
},
{
key: '/message',
title: '消息',
icon: ,
},
{
key: '/me',
title: '我的',
icon: ,
},
];
const location = useLocation();
const { pathname } = location;
const { routes } = useAppData();
const currouter = useMemo(() => {
let allroutes = Object.values(routes).filter((it, i) => {
return it.path === pathname;
})?.[0];
return allroutes;
}, [pathname]);
const [drawer, setdrawer] = useState({ open: false });
const [startX, setStartX] = useState(null);
const [startY, setStartY] = useState(null);
function handleTouchStart(event) {
setStartX(event.touches[0].clientX);
setStartY(event.touches[0].clientY);
}
function handleTouchMove(event) {
const { clientX, clientY } = event.touches[0];
const distance = clientX - startX;
const distancey = clientY - startY;
if (distancey > 10 || distancey < -10) {
return;
}
if (distance > 20) {
// 执行左滑操作
setdrawer((s) => ({
...s,
open: true,
}));
}
}
return (
{
setdrawer((s) => ({
...s,
open: false,
}));
}}
closable={false}
{...drawer}
width={'80%'}
placement="left"
>
}>
} extra="李翰林">用户名
} extra="维修部">组织
} extra="天华院">公司
} onClick={()=>{}} style={{backgroundColor:"rgba(0,0,0,0.2)",borderRadius:8}}>修改密码
) : (
)
}
onBack={() => {
if (menulist.includes(pathname)) {
setdrawer((s) => ({
...s,
open: true,
}));
} else {
history.go(-1);
}
}}
>
{currouter?.name}
setRouteActive(value)}
>
{tabs.map((item) => (
))}
);
}
export default BasicLayout;