StatusIndicator.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { View, Text } from "@tarojs/components";
  2. import './StatusIndicator.scss'
  3. import { useSelector } from "react-redux";
  4. import { ColorType } from "@/context/themes/color";
  5. import { useEffect } from "react";
  6. import { useTranslation } from "react-i18next";
  7. export default function Component() {
  8. const time = useSelector((state: any) => state.time);
  9. const user = useSelector((state: any) => state.user);
  10. const {t} = useTranslation()
  11. function getFastName() {
  12. var strName = t('feature.track_time_duration.status_indicator.fast_wait_for_start')//'断食'
  13. switch (time.scenario) {
  14. case 'FAST':
  15. {
  16. if (time.status == 'ONGOING') {
  17. strName = t('feature.track_time_duration.status_indicator.fast_ongoing')//'断食进行中'
  18. }
  19. }
  20. break;
  21. case 'SLEEP':
  22. break;
  23. case 'FAST_SLEEP':
  24. {
  25. switch (time.status) {
  26. case 'ONGOING1':
  27. case 'ONGOING2':
  28. case 'ONGOING3':
  29. strName = t('feature.track_time_duration.status_indicator.fast_ongoing')//'断食进行中'
  30. break;
  31. }
  32. }
  33. break;
  34. }
  35. return strName
  36. }
  37. function sleepAlpha() {
  38. return time.status == 'ONGOING3' ? 0.4 : 1
  39. }
  40. function getSleepName() {
  41. var strName = t('feature.track_time_duration.status_indicator.sleep_wait_for_start')//'睡眠'
  42. switch (time.scenario) {
  43. case 'FAST':
  44. break;
  45. case 'SLEEP':
  46. {
  47. if (time.status == 'ONGOING') {
  48. strName = t('feature.track_time_duration.status_indicator.sleep_ongoing')//'睡眠进行中'
  49. }
  50. }
  51. break;
  52. case 'FAST_SLEEP':
  53. {
  54. switch (time.status) {
  55. case 'ONGOING1':
  56. strName = t('feature.track_time_duration.status_indicator.sleep_ongoing1')//'睡眠待开始'
  57. break;
  58. case 'ONGOING2':
  59. strName = t('feature.track_time_duration.status_indicator.sleep_ongoing')//'睡眠进行中'
  60. break;
  61. case 'ONGOING3':
  62. strName = t('feature.track_time_duration.status_indicator.sleep_ongoing3')//'睡眠已结束'
  63. break;
  64. }
  65. }
  66. break;
  67. }
  68. return strName
  69. }
  70. if (!time.scenario) {
  71. return <View className='subcontent'>
  72. <View className='scenario' style={{backgroundColor:global.isDebug?'red':'transparent'}}>
  73. <View className='point' style={{ backgroundColor: global.fastColor ? global.fastColor : ColorType.fast }} />
  74. <Text className='name'>{getFastName()}</Text>
  75. </View>
  76. </View>
  77. }
  78. if (!user.isLogin) {
  79. return <View className='subcontent' >
  80. <View className='scenario' style={{backgroundColor:global.isDebug?'red':'transparent'}}>
  81. <View className='point' style={{ backgroundColor: global.fastColor ? global.fastColor : ColorType.fast }} />
  82. <Text className='name'>{getFastName()}</Text>
  83. </View>
  84. </View>
  85. }
  86. return <View className='subcontent'>
  87. {
  88. time.scenario != 'SLEEP' && <View className='scenario' style={{backgroundColor:global.isDebug?'red':'transparent'}}>
  89. <View className='point' style={{ backgroundColor: global.fastColor ? global.fastColor : ColorType.fast }} />
  90. <Text className='name'>{getFastName()}</Text>
  91. </View>
  92. }
  93. {
  94. time.scenario != 'FAST' && <View className='scenario' style={{ opacity: sleepAlpha() }}>
  95. <View className='point' style={{ backgroundColor: global.sleepColor ? global.sleepColor : ColorType.sleep }} />
  96. <Text className='name'>{getSleepName()}</Text>
  97. </View>
  98. }
  99. </View>
  100. }