App.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, {Component} from 'react'
  2. import {Icon} from 'antd'
  3. import {TabBar} from 'antd-mobile'
  4. import Home from './pages/home'
  5. import Cart from './pages/cart'
  6. import My from './pages/my'
  7. class App extends Component {
  8. constructor(props) {
  9. super(props)
  10. this.state = {
  11. selectedTab: 'home',
  12. tabHidden: false
  13. }
  14. }
  15. changeTabBar = (tab, hidden) => {
  16. this.setState({
  17. selectedTab: tab,
  18. tabHidden: hidden !== undefined ? hidden : false
  19. })
  20. }
  21. render() {
  22. let {selectedTab, tabHidden} = this.state
  23. return (
  24. <div style={{
  25. position: 'fixed',
  26. height: '100%',
  27. width: '100%',
  28. top: 0
  29. }}>
  30. <TabBar
  31. unselectedTintColor="#949494"
  32. tintColor="#33A3F4"
  33. barTintColor="white"
  34. hidden={tabHidden}
  35. >
  36. <TabBar.Item
  37. title="首页"
  38. key="home"
  39. icon={<HomeUnselectedIcon/>}
  40. selectedIcon={<HomeSelectedIcon/>}
  41. selected={selectedTab === 'home'}
  42. onPress={() => {
  43. this.changeTabBar('home')
  44. }}
  45. >
  46. <Home changeTabBar={this.changeTabBar}/>
  47. </TabBar.Item>
  48. <TabBar.Item
  49. icon={<CartUnselectedIcon/>}
  50. selectedIcon={<CartSelectedIcon/>}
  51. title="购物袋"
  52. key="cart"
  53. selected={selectedTab === 'cart'}
  54. onPress={() => {
  55. this.changeTabBar('cart')
  56. }}
  57. >
  58. <Cart changeTabBar={this.changeTabBar}/>
  59. </TabBar.Item>
  60. <TabBar.Item
  61. icon={<MyUnselectedIcon/>}
  62. selectedIcon={<MySelectedIcon/>}
  63. title="我的"
  64. key="my"
  65. selected={selectedTab === 'my'}
  66. onPress={() => {
  67. this.changeTabBar('my')
  68. }}
  69. >
  70. <My changeTabBar={this.changeTabBar}/>
  71. </TabBar.Item>
  72. </TabBar>
  73. </div>
  74. )
  75. }
  76. }
  77. export default App
  78. const HomeUnselectedIcon = () => (
  79. <Icon type="home" style={{fontSize: 22}}/>
  80. )
  81. const HomeSelectedIcon = () => (
  82. <Icon type="home" theme="twoTone" style={{fontSize: 22}}/>
  83. )
  84. const CartUnselectedIcon = () => (
  85. <Icon type="shopping" style={{fontSize: 22}}/>
  86. )
  87. const CartSelectedIcon = () => (
  88. <Icon type="shopping" theme="twoTone" style={{fontSize: 22}}/>
  89. )
  90. const MyUnselectedIcon = () => (
  91. <div style={{
  92. width: '22px',
  93. height: '22px',
  94. background: 'url(https://zos.alipayobjects.com/rmsportal/psUFoAMjkCcjqtUCNPxB.svg) center center / 21px 21px no-repeat'
  95. }}/>
  96. )
  97. const MySelectedIcon = () => (
  98. <div style={{
  99. width: '22px',
  100. height: '22px',
  101. background: 'url(https://zos.alipayobjects.com/rmsportal/IIRLrXXrFAhXVdhMWgUI.svg) center center / 21px 21px no-repeat'
  102. }}/>
  103. )