assistant-todo-mobile/src/pages/Bottom/index.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-01-12 08:47:39 -05:00
import React ,{FC} from "react";
2023-01-18 07:57:54 -05:00
import { TabBar } from 'antd-mobile'
import WidthUseNavigate from './../WidthUseNavigate/index'
2023-01-12 08:47:39 -05:00
import {
AppOutline,
MessageOutline,
UnorderedListOutline,
UserOutline,
} from 'antd-mobile-icons'
2023-01-18 07:57:54 -05:00
const tabs = [
{
key: '/home',
title: '首页',
icon: <AppOutline />,
badge: '1',
},
{
key: '/home/todo',
title: '待办',
icon: <UnorderedListOutline />,
badge: '2',
},
{
key: '/home/message',
title: '消息',
icon: <MessageOutline />,
badge: '3',
},
{
key: '/home/me',
title: '我的',
icon: <UserOutline />,
badge: '4',
},
]
class BottomInner extends React.Component{
state = {
// 默认选中的TabBar菜单项
selectedTab: this.props.useLocation
2023-01-12 08:47:39 -05:00
}
2023-01-18 07:57:54 -05:00
// 组件接收到新的props此处实际上是路由信息就会触发该钩子函数
componentDidUpdate(prevProps) {
// prevProps 上一次的props此处也就是上一次的路由信息
// this.props 当前最新的props此处也就是最新的路由信息
// 注意:在该钩子函数中更新状态时,一定要在 条件判断 中进行,否则会造成递归更新的问题
if (prevProps.useLocation !== this.props.useLocation) {
// 此时,就说明路由发生切换了
this.setState({
selectedTab: this.props.useLocation
})
}
}
setRouteActive = (value) => {
this.props.to(value)
this.setState({
selectedTab: value
})
}
render() {
return <TabBar activeKey={this.state.selectedTab} onChange={value => this.setRouteActive(value)}>
2023-01-12 08:47:39 -05:00
{tabs.map(item => (
2023-01-14 02:09:13 -05:00
<TabBar.Item key={item.key} icon={item.icon} title={item.title} badge= {item.badge}/>
2023-01-12 08:47:39 -05:00
))}
</TabBar>
2023-01-18 07:57:54 -05:00
}
2023-01-12 08:47:39 -05:00
}
2023-01-14 02:09:13 -05:00
2023-01-12 08:47:39 -05:00
export function Todo() {
return <div>待办</div>
}
export function Message() {
return <div>消息</div>
}
export function PersonalCenter() {
return <div>我的</div>
2023-01-18 07:57:54 -05:00
}
// 使用高阶组件包裹当前类组件
const Bottom = WidthUseNavigate(BottomInner);
export default Bottom