Index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { View, Text, Image } from "@tarojs/components";
  2. import Tabbar from "@/components/navigation/TabBar";
  3. import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
  4. import './Index.scss'
  5. import { useDispatch, useSelector } from "react-redux";
  6. import { useReady } from "@tarojs/taro";
  7. import Taro from "@tarojs/taro";
  8. import { getInfoSuccess } from "@/store/user";
  9. import { clockHome, getClocks } from "@/services/trackTimeDuration";
  10. import { updateScenario } from "@/store/time";
  11. import { setConfigs } from "@/store/common";
  12. import { setScenario } from "@/store/scenario";
  13. import { useEffect, useState } from "react";
  14. import { IconPlus, IconRadioCheck, IconRadioCross } from "@/components/basic/Icons";
  15. import { ColorType } from "@/context/themes/color";
  16. export default function Page() {
  17. const dispatch = useDispatch();
  18. global.dispatch = dispatch;
  19. const user = useSelector((state: any) => state.user);
  20. const time = useSelector((state: any) => state.time);
  21. const [showErrorPage, setErrorPage] = useState(false)
  22. const [data, setData] = useState(null)
  23. const [count, setCount] = useState(0)
  24. const [homeData, setHomeData] = useState(null)
  25. const [selIndex, setSelIndex] = useState(0)
  26. const [multiData, setMultiData] = useState([
  27. {
  28. title: '睡前断食',
  29. checked: false
  30. },
  31. {
  32. title: '睡眠中断食',
  33. checked: false
  34. },
  35. {
  36. title: '起床后断食',
  37. checked: false
  38. },
  39. ])
  40. useEffect(() => {
  41. setInterval(() => {
  42. setCount((prevCounter) => prevCounter + 1)
  43. }, 1000)
  44. }, [])
  45. useEffect(() => {
  46. // if (user.isLogin) {
  47. getCheckData()
  48. // }
  49. }, [user.isLogin, time.status])
  50. useReady(async () => {
  51. const userData = await getStorage('userData');
  52. if (userData) {
  53. dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
  54. // setTimeout(() => {
  55. // // checkWXPubFollow()
  56. // getCheckData()
  57. // }, 200)
  58. }
  59. })
  60. function getCheckData() {
  61. getClocks().then(res => {
  62. // setErrorPage(false)
  63. // setData(res as any)
  64. // dispatch(updateScenario((res as any).current_record))
  65. // dispatch(setConfigs((res as any).time_input_schema));
  66. // dispatch(setScenario((res as any).scenario));
  67. if ((res as any).theme_color) {
  68. global.fastColor = (res as any).theme_color.fast
  69. global.sleepColor = (res as any).theme_color.sleep
  70. }
  71. })
  72. clockHome().then(res => {
  73. setHomeData(res as any)
  74. })
  75. }
  76. async function getStorage(key: string) {
  77. try {
  78. const res = await Taro.getStorage({ key });
  79. return res.data;
  80. } catch {
  81. return '';
  82. }
  83. }
  84. if (!homeData) {
  85. return <View>
  86. <Tabbar index={0} />
  87. </View>
  88. }
  89. var timestamp = new Date().getTime()
  90. return <View className="index_container">
  91. <Text className="count">{count}</Text>
  92. <IndexItem type="FAST" data={(homeData as any).fast} time={timestamp} />
  93. <IndexItem type='SLEEP' data={(homeData as any).sleep} time={timestamp} />
  94. <Text className="discovery">探索</Text>
  95. <IndexItem type="FAST_SLEEP" data={(homeData as any).fast_sleep} time={timestamp} />
  96. <Tabbar index={0} />
  97. <View>
  98. <Text>Single Sel</Text>
  99. <View className={selIndex == 0 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(0)}>
  100. <Text className={selIndex == 0 ? "single_check_text_sel" : "single_check_text_nor"}>睡前断食</Text>
  101. {
  102. selIndex == 0 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
  103. <IconPlus color={ColorType.fast} />
  104. }
  105. </View>
  106. <View className={selIndex == 1 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(1)}>
  107. <Text className={selIndex == 1 ? "single_check_text_sel" : "single_check_text_nor"}>睡眠中断食</Text>
  108. {
  109. selIndex == 1 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
  110. <IconPlus color={ColorType.fast} />
  111. }
  112. </View>
  113. <View className={selIndex == 2 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(2)}>
  114. <Text className={selIndex == 2 ? "single_check_text_sel" : "single_check_text_nor"}>起床后断食</Text>
  115. {
  116. selIndex == 2 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
  117. <IconPlus color={ColorType.fast} />
  118. }
  119. </View>
  120. </View>
  121. <View style={{ marginTop: 50 }}>
  122. <Text>Multi Sel</Text>
  123. {
  124. multiData.map((item) => {
  125. return <View className={item.checked ? "single_check_sel" : "single_check_nor"} onClick={() => {
  126. item.checked = !item.checked
  127. setMultiData(JSON.parse(JSON.stringify(multiData)))
  128. }}>
  129. <Text className={item.checked ? "single_check_text_sel" : "single_check_text_nor"}>{item.title}</Text>
  130. {
  131. item.checked ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
  132. <IconPlus color={ColorType.fast} />
  133. }
  134. </View>
  135. })
  136. }
  137. </View>
  138. <View style={{ height: 100 }} />
  139. </View>
  140. }