TabBar.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { View, Text } from '@tarojs/components'
  2. import './TabBar.scss'
  3. import Taro from '@tarojs/taro';
  4. import { useState } from 'react';
  5. import { useSelector } from 'react-redux';
  6. import { ColorType } from '@/context/themes/color';
  7. export default function Component(props: { index: number }) {
  8. const common = useSelector((state: any) => state.common);
  9. const [selIndex] = useState(props.index)
  10. function switchTab(index: number) {
  11. switch (index) {
  12. case 0:
  13. Taro.switchTab({
  14. url: '/pages/clock/Clock'
  15. })
  16. break;
  17. case 2:
  18. Taro.switchTab({
  19. url: '/pages/explore/Index'
  20. })
  21. break;
  22. case 1:
  23. Taro.switchTab({
  24. url: '/pages/metric/Metric'
  25. })
  26. break;
  27. // case 2:
  28. // Taro.switchTab({
  29. // // url: '/pages/activity/Activity'
  30. // url:'/pages/workout/Workout'
  31. // })
  32. // break;
  33. case 3:
  34. Taro.switchTab({
  35. url: '/pages/account/Profile'
  36. })
  37. break;
  38. case 4:
  39. Taro.switchTab({
  40. url: '/pages/food/Food'
  41. })
  42. break;
  43. }
  44. }
  45. return <View className='tabbar'>
  46. <View className={selIndex == 0 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(0)}>
  47. <Text>生物钟</Text>
  48. </View>
  49. {/* <View className={selIndex == 4 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(4)}>
  50. <View style={{ position: 'relative' }}>
  51. <Text>饮食</Text>
  52. {
  53. common.showFoodTabBadge && process.env.TARO_ENV == 'weapp' && <View className='food-tab-badge' style={{ backgroundColor: ColorType.food }} />
  54. }
  55. </View>
  56. </View>
  57. <View className={selIndex == 2 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(2)}>
  58. <Text>运动</Text>
  59. </View> */}
  60. <View className={selIndex == 2 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(2)}>
  61. <Text>发现</Text>
  62. </View>
  63. <View className={selIndex == 1 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(1)}>
  64. <Text>指标</Text>
  65. </View>
  66. <View className={selIndex == 3 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(3)}>
  67. <Text>更多</Text>
  68. </View>
  69. </View>
  70. }