Clock.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import trackTimeService, { machine } from "@/store/trackTimeMachine";
  2. import { View, Text, CoverView } 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. import { jumpPage } from "../hooks/Common";
  11. export default function Component(props: { showCoverView: boolean }) {
  12. const [checkData, setCheckData] = useState(null)
  13. const time = useSelector((state: any) => state.time);
  14. const user = useSelector((state: any) => state.user);
  15. const [showCover, setShowCover] = useState(props.showCoverView)
  16. useEffect(() => {
  17. if (!user.isLogin) {
  18. setCheckData(null)
  19. }
  20. }, [user.isLogin])
  21. useEffect(() => {
  22. if (machine.context.checkData) {
  23. setCheckData(machine.context.checkData as any);
  24. }
  25. }, [machine.context.checkData]);
  26. useEffect(() => {
  27. trackTimeService.onTransition(_ => {
  28. if (machine.context.checkData) {
  29. setCheckData(machine.context.checkData as any);
  30. }
  31. });
  32. }, []);
  33. useEffect(() => {
  34. setShowCover(props.showCoverView)
  35. }, [props.showCoverView])
  36. //外环
  37. function bigRing() {
  38. var common = getCommon(null, true)
  39. common.radius = 126;
  40. common.lineWidth = 28;
  41. var bgRing = getBgRing()
  42. if (!checkData) {
  43. var currentDot1 = getDot(null, true)
  44. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock0' />
  45. }
  46. var current_record = (checkData as any).current_record
  47. var currentDot1 = getDot((checkData as any).current_record, true)
  48. var targetBigRing1 = getTarget((checkData as any).current_record, true)
  49. targetBigRing1.color = global.fastColor ? global.fastColor + '66' : ColorType.fast + '66'//'rgba(170,255,0,0.4)'
  50. if ((checkData as any).current_record.scenario == 'SLEEP') {
  51. targetBigRing1.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'//'rgba(170,255,0,0.4)'
  52. }
  53. // console.log(targetBigRing1.color)
  54. if (current_record.status == 'ONGOING') {
  55. var realRing1 = getReal((checkData as any).current_record, true, false)
  56. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId='clock1' />
  57. }
  58. if (current_record.status == 'WAIT_FOR_START') {
  59. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock2' />
  60. }
  61. var realRing1 = getReal((checkData as any).current_record, true, false)
  62. return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId='clock3' />
  63. }
  64. //内环
  65. function smallRing() {
  66. var current_record = (checkData as any).current_record
  67. if (current_record.scenario == 'FAST_SLEEP') {
  68. var common = getCommon(null, false)
  69. common.radius = 90;
  70. common.lineWidth = 28;
  71. var bgRing = getBgRing()
  72. var realRing = getReal((checkData as any).current_record, false, false)
  73. var currentDot = getDot((checkData as any).current_record, false)
  74. var targetRing = getTarget((checkData as any).current_record, false)
  75. targetRing.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'//'rgba(0, 255, 255, 0.4)'
  76. if (current_record.status == 'ONGOING2') {
  77. return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId='clock7' />
  78. }
  79. //ongoing3时,睡眠点整理亮度降低
  80. if (current_record.status == 'ONGOING3') {
  81. currentDot.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'
  82. }
  83. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId='clock8' />
  84. }
  85. return null;
  86. }
  87. function tapCover(){
  88. if (user.isLogin){
  89. }
  90. else {
  91. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', null)
  92. }
  93. }
  94. if (!checkData)
  95. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%', position: 'relative', pointerEvents: 'none' }}>
  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. <Text className="clock_text" style={{ fontSize: 24, color: ColorType.fast }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  102. }
  103. </View>
  104. {
  105. showCover && <CoverView onClick={tapCover} style={{
  106. display: 'flex', position: 'absolute',
  107. left: 0, right: 0, top: 0, bottom: 0, backgroundColor: 'transparent'
  108. }} />
  109. }
  110. </View>
  111. return (
  112. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%', pointerEvents: 'none' }}>
  113. <View style={{ position: 'relative', zIndex: 1 }}>
  114. {
  115. bigRing()
  116. }
  117. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  118. {
  119. smallRing()
  120. }
  121. </View>
  122. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  123. {
  124. (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario == 'FAST_SLEEP' &&
  125. <Text className="clock_text fast_sleep_text" style={{ fontSize: 24 }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  126. }
  127. {
  128. (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario != 'FAST_SLEEP' &&
  129. <Text className="clock_text" style={{ color: time.scenario == 'FAST' ? ColorType.fast : ColorType.sleep, fontSize: 24 }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  130. }
  131. {
  132. (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 }}>
  133. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast ?
  134. (checkData as any).current_record.fast.real_start_time :
  135. (checkData as any).current_record.sleep.real_start_time)}
  136. </Text>
  137. }
  138. {
  139. (checkData as any).current_record.status == 'ONGOING1' && <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  140. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  141. </Text>
  142. }
  143. {
  144. (checkData as any).current_record.status == 'ONGOING2' && <View style={{ flexDirection: 'column', display: 'flex' }}>
  145. <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  146. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  147. </Text>
  148. <Text className="clock_text" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep, fontSize: 32 }}>
  149. {TimeFormatter.formateTimeNow((checkData as any).current_record.sleep.real_start_time)}
  150. </Text>
  151. </View>
  152. }
  153. {
  154. (checkData as any).current_record.status == 'ONGOING3' && <Text>
  155. <Text className="clock_text" style={{ color: global.fastColor ? global.fastColor : ColorType.fast, fontSize: 32 }}>
  156. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  157. </Text>
  158. </Text>
  159. }
  160. </View>
  161. {
  162. showCover && <CoverView style={{
  163. display: 'flex', position: 'absolute',
  164. left: 0, right: 0, top: 0, bottom: 0, backgroundColor: 'transparent'
  165. }} />
  166. }
  167. </View>
  168. </View>
  169. )
  170. }