index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { View, Text } from '@tarojs/components'
  2. import './index.scss'
  3. import { useTranslation } from 'react-i18next'
  4. import Taro from '@tarojs/taro'
  5. import { useEffect, useState } from 'react'
  6. import { useDispatch, useSelector } from 'react-redux'
  7. import { changeTabbar } from '@/store/common'
  8. export default function TabBar() {
  9. const { t } = useTranslation()
  10. const common = useSelector((state: any) => state.common);
  11. const [selIndex, setSelIndex] = useState(common.pageIndex)
  12. const dispatch = useDispatch();
  13. // useEffect(() => {
  14. // console.log('aaa',global.index)
  15. // setSelIndex(global.index?global.index:0)
  16. // }, [global.index])
  17. // useEffect(()=>{
  18. // console.log('page 初始化')
  19. // },[])
  20. useEffect(()=>{
  21. setSelIndex(common.pageIndex)
  22. },[common.pageIndex])
  23. function switchTab(index: number) {
  24. // console.log(index,common.showTabbar)
  25. if (!common.showTabbar){
  26. return
  27. }
  28. // global.index = index;
  29. // console.log(index,'apple')
  30. // console.log(global.index)
  31. dispatch(changeTabbar(index))
  32. switch (index) {
  33. case 0:
  34. Taro.switchTab({
  35. url: '/pages/clock/ClockMain'
  36. })
  37. break;
  38. case 1:
  39. Taro.switchTab({
  40. url: '/pages/metric/Metric'
  41. })
  42. break;
  43. case 2:
  44. Taro.switchTab({
  45. url: '/pages/activity/Activity'
  46. })
  47. break;
  48. case 3:
  49. Taro.switchTab({
  50. url: '/pages/account/Profile'
  51. })
  52. break;
  53. }
  54. }
  55. return (
  56. <View className='tabbar'>
  57. <View className={selIndex == 0 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(0)}>
  58. {/* <Text>{t('tabbar.clock')}</Text> */}
  59. <Text>生物钟</Text>
  60. </View>
  61. <View className={selIndex == 1 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(1)}>
  62. <Text>指标</Text>
  63. {/* <Text>{t('tabbar.metric')}</Text> */}
  64. </View>
  65. <View className={selIndex == 2 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(2)}>
  66. <Text>运动</Text>
  67. {/* <Text>{t('tabbar.activity')}</Text> */}
  68. </View>
  69. <View className={selIndex == 3 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(3)}>
  70. {/* <Text>{t('tabbar.more')}</Text> */}
  71. <Text>更多</Text>
  72. </View>
  73. </View>
  74. )
  75. }