Clock.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import trackTimeService, { machine } from "@/store/trackTimeMachine";
  2. import { View, Text } from "@tarojs/components";
  3. import { useEffect, useState } from "react";
  4. import { TimeFormatter } from "@/utils/time_format";
  5. import Rings, { BgRing, CurrentDot, RealRing, RingCommon } from './Rings';
  6. import { getBgRing, getCommon, getDot, getReal, getTarget } from "../hooks/RingData";
  7. import './Clock.scss'
  8. import { ColorType } from "@/context/themes/color";
  9. import { useSelector } from "react-redux";
  10. export default function Component() {
  11. const [checkData, setCheckData] = useState(null)
  12. const time = useSelector((state: any) => state.time);
  13. const user = useSelector((state: any) => state.user);
  14. useEffect(()=>{
  15. if (!user.isLogin){
  16. setCheckData(null)
  17. }
  18. },[user.isLogin])
  19. useEffect(() => {
  20. if (machine.context.checkData) {
  21. setCheckData(machine.context.checkData as any);
  22. }
  23. }, [machine.context.checkData]);
  24. useEffect(() => {
  25. trackTimeService.onTransition(_ => {
  26. if (machine.context.checkData) {
  27. setCheckData(machine.context.checkData as any);
  28. }
  29. });
  30. }, []);
  31. //外环
  32. function bigRing() {
  33. var common = getCommon(null, true)
  34. common.radius = 126;
  35. common.lineWidth = 28;
  36. var bgRing = getBgRing()
  37. if (!checkData) {
  38. var currentDot1 = getDot(null, true)
  39. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock0' />
  40. }
  41. var current_record = (checkData as any).current_record
  42. var currentDot1 = getDot((checkData as any).current_record, true)
  43. var targetBigRing1 = getTarget((checkData as any).current_record, true)
  44. targetBigRing1.color = global.fastColor ? global.fastColor+'66' : ColorType.fast + '66'//'rgba(170,255,0,0.4)'
  45. if ((checkData as any).current_record.scenario == 'SLEEP'){
  46. targetBigRing1.color = global.sleepColor ? global.sleepColor+'66' : ColorType.sleep + '66'//'rgba(170,255,0,0.4)'
  47. }
  48. // console.log(targetBigRing1.color)
  49. if (current_record.status == 'ONGOING') {
  50. var realRing1 = getReal((checkData as any).current_record, true, false)
  51. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId='clock1' />
  52. }
  53. if (current_record.status == 'WAIT_FOR_START') {
  54. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock2' />
  55. }
  56. var realRing1 = getReal((checkData as any).current_record, true, false)
  57. return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId='clock3' />
  58. }
  59. //内环
  60. function smallRing() {
  61. var current_record = (checkData as any).current_record
  62. if (current_record.scenario == 'FAST_SLEEP') {
  63. var common = getCommon(null, false)
  64. common.radius = 90;
  65. common.lineWidth = 28;
  66. var bgRing = getBgRing()
  67. var realRing = getReal((checkData as any).current_record, false, false)
  68. var currentDot = getDot((checkData as any).current_record, false)
  69. var targetRing = getTarget((checkData as any).current_record, false)
  70. targetRing.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'//'rgba(0, 255, 255, 0.4)'
  71. if (current_record.status == 'ONGOING2') {
  72. return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId='clock7' />
  73. }
  74. //ongoing3时,睡眠点整理亮度降低
  75. if (current_record.status == 'ONGOING3') {
  76. currentDot.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'
  77. }
  78. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId='clock8' />
  79. }
  80. return null;
  81. }
  82. if (!checkData)
  83. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%', marginTop: 20,position:'relative' }}>
  84. {
  85. bigRing()
  86. }
  87. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  88. {
  89. <Text className="clock_text fast_sleep_text" style={{ fontSize: 24 }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  90. }
  91. </View>
  92. </View>
  93. return (
  94. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%' }}>
  95. <View style={{ position: 'relative', zIndex: 1 }}>
  96. {
  97. bigRing()
  98. }
  99. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  100. {
  101. smallRing()
  102. }
  103. </View>
  104. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  105. {
  106. (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario == 'FAST_SLEEP' &&
  107. <Text className="clock_text fast_sleep_text" style={{ fontSize: 24 }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  108. }
  109. {
  110. (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario != 'FAST_SLEEP' &&
  111. <Text className="clock_text" style={{ color: time.scenario == 'FAST' ? ColorType.fast : ColorType.sleep, fontSize: 24 }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  112. }
  113. {
  114. (checkData as any).current_record.status == 'ONGOING' && <Text className="clock_text" style={{ color: (checkData as any).current_record.scenario == 'FAST' ? global.fastColor ? global.fastColor : ColorType.fast : global.sleepColor ? global.sleepColor : ColorType.sleep, fontSize: 32 }}>
  115. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast ?
  116. (checkData as any).current_record.fast.real_start_time :
  117. (checkData as any).current_record.sleep.real_start_time)}
  118. </Text>
  119. }
  120. {
  121. (checkData as any).current_record.status == 'ONGOING1' && <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  122. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  123. </Text>
  124. }
  125. {
  126. (checkData as any).current_record.status == 'ONGOING2' && <View style={{ flexDirection: 'column', display: 'flex' }}>
  127. <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  128. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  129. </Text>
  130. <Text className="clock_text" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep, fontSize: 32 }}>
  131. {TimeFormatter.formateTimeNow((checkData as any).current_record.sleep.real_start_time)}
  132. </Text>
  133. </View>
  134. }
  135. {
  136. (checkData as any).current_record.status == 'ONGOING3' && <Text>
  137. <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  138. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  139. </Text>
  140. </Text>
  141. }
  142. </View>
  143. </View>
  144. </View>
  145. )
  146. }