fast_sleep.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { View, Text, Image, Swiper, SwiperItem } from "@tarojs/components";
  2. import './fast_sleep.scss'
  3. import { useSelector } from "react-redux";
  4. import { useEffect, useState } from "react";
  5. import NewButton, { NewButtonType } from "../base/new_button";
  6. import { rpxToPx } from "@/utils/tools";
  7. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  8. import NewTimePicker from "../base/new_timepicker";
  9. import { IconCalendar } from "@/components/basic/Icons";
  10. import dayjs from "dayjs";
  11. import { MainColorType } from "@/context/themes/color";
  12. import NewHeader, { NewHeaderType } from "../components/new_header";
  13. import Card from "../components/card";
  14. import FastSleepConsole from "../components/fast_sleep_console";
  15. import { fastWithSleep } from "@/services/health";
  16. import FastSleepCard from "../components/fast_sleep_card";
  17. import FastSleepDetailCard from "../components/fast_sleep_detail_card";
  18. import MainHistory from "@/features/health/MainHistory";
  19. export default function FastSleep() {
  20. const health = useSelector((state: any) => state.health);
  21. const [time, setTime] = useState(dayjs().format('HH:mm'))
  22. const [count, setCount] = useState(0)
  23. const [loaded, setLoaded] = useState(false)
  24. const [data, setData] = useState<any>(null)
  25. const [current, setCurrent] = useState(0)
  26. useEffect(() => {
  27. let timer = setInterval(() => {
  28. setCount(count => count + 1)
  29. }, 1000)
  30. switch (health.fast_with_sleep.status) {
  31. case 'WFS':
  32. case 'OG2_NO1':
  33. setCurrent(0)
  34. break;
  35. case 'OG1':
  36. setCurrent(1)
  37. break;
  38. case 'OG2':
  39. setCurrent(2)
  40. break;
  41. case 'OG3':
  42. setCurrent(3)
  43. break;
  44. }
  45. getDatas()
  46. return () => {
  47. clearInterval(timer)
  48. }
  49. }, [])
  50. global.refreshFastSleep = () => {
  51. getDatas()
  52. }
  53. function getDatas() {
  54. fastWithSleep().then(res => {
  55. setLoaded(true)
  56. setData(res)
  57. })
  58. }
  59. if (!loaded) return <View />
  60. return <View className="page_container">
  61. <NewHeader type={NewHeaderType.left_subtitle}
  62. title="Fast with Sleep"
  63. subtitle="Tune Into Your Circadian Rhythm "
  64. />
  65. <Swiper indicatorColor='#999'
  66. indicatorActiveColor='#333'
  67. style={{ height: rpxToPx(344), marginBottom: 20, flexShrink: 0 }}
  68. onChange={e => setCurrent(e.detail.current)}
  69. current={current}
  70. indicatorDots>
  71. <SwiperItem>
  72. <Card>
  73. <FastSleepCard step={0} data={data} />
  74. </Card>
  75. </SwiperItem>
  76. <SwiperItem>
  77. <Card>
  78. <FastSleepCard step={1} data={data} />
  79. </Card>
  80. </SwiperItem>
  81. <SwiperItem>
  82. <Card>
  83. <FastSleepCard step={2} data={data} />
  84. </Card>
  85. </SwiperItem>
  86. <SwiperItem>
  87. <Card>
  88. <FastSleepCard step={3} data={data} />
  89. </Card>
  90. </SwiperItem>
  91. </Swiper>
  92. <FastSleepDetailCard data={data} />
  93. <FastSleepConsole step={current} data={data} />
  94. <MainHistory type='FAST,SLEEP' />
  95. {/* <NewButton type={NewButtonType.link} title="hello world" onClick={() => {
  96. }} />
  97. <NewButton type={NewButtonType.label} title="hello world" onClick={() => {
  98. }} />
  99. <NewButton type={NewButtonType.label} title="hello world" labelBorder onClick={() => {
  100. }} /> */}
  101. </View>
  102. }