ClockNew.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { View, ScrollView, Swiper, SwiperItem } from "@tarojs/components";
  2. import './Clock.scss'
  3. import { useEffect, useState } from "react";
  4. import MainDayNightCard from "@/features/health/MainDayNightCard";
  5. import MainFastEatCard from "@/features/health/MainFastEatCard";
  6. import MainSleepActiveCard from "@/features/health/MainSleepActiveCard";
  7. import TabBar from "@/components/navigation/TabBar";
  8. import { rpxToPx } from "@/utils/tools";
  9. import MainSwiper from "@/features/health/MainSwiper";
  10. import MainConsole from "@/features/health/MainConsole";
  11. import MainHistory from "@/features/health/MainHistory";
  12. import { WindowType } from "@/utils/types";
  13. export default function ClockNew() {
  14. const [count, setCount] = useState(0)
  15. const [scrollLeft, setScrollLeft] = useState(rpxToPx(750) * 0)
  16. const [type,setType] = useState(WindowType.day)
  17. useEffect(() => {
  18. setInterval(() => {
  19. setCount(index => index + 1)
  20. }, 1000)
  21. }, [])
  22. function tapScroll(index) {
  23. setScrollLeft(rpxToPx(750) * index)
  24. }
  25. function scroll(e) {
  26. console.log(e.detail.scrollLeft)
  27. }
  28. function pageChanged(index){
  29. }
  30. function typeChanged(str){
  31. }
  32. function detail() {
  33. return <View>
  34. <MainSwiper count={count} pageChanged={pageChanged} typeChanged={typeChanged}/>
  35. <MainConsole type={type}/>
  36. <MainHistory type={type}/>
  37. <View style={{height:200}}/>
  38. </View>
  39. }
  40. //https://blog.csdn.net/weixin_43525284/article/details/130182218
  41. return <View style={{flex:1}}>
  42. {
  43. process.env.TARO_ENV == 'weapp' ? detail() : <ScrollView style={{flex:1}}>
  44. {
  45. detail()
  46. }
  47. </ScrollView>
  48. }
  49. {/* <View className="tabs">
  50. <View className="item" onClick={() => tapScroll(0)}> tab 0</View>
  51. <View className="item" onClick={() => tapScroll(1)}>tab 1</View>
  52. <View className="item" onClick={() => tapScroll(2)}>tab 2</View>
  53. </View>
  54. <ScrollView scrollX
  55. scrollLeft={scrollLeft}
  56. scrollWithAnimation={true}
  57. pagingEnabled={true}
  58. enableFlex
  59. onScroll={scroll}
  60. style={{ width: rpxToPx(750), display: 'flex', flexDirection: 'row', overflow: 'hidden' }}
  61. enhanced>
  62. <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
  63. <MainDayNightCard count={count} />
  64. </View>
  65. <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
  66. <MainFastEatCard count={count} />
  67. </View>
  68. <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
  69. <MainSleepActiveCard count={count} />
  70. </View>
  71. </ScrollView> */}
  72. <TabBar index={0} />
  73. </View>
  74. }