Clock.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. export default function Component() {
  10. const [checkData, setCheckData] = useState(null)
  11. useEffect(() => {
  12. if (machine.context.checkData) {
  13. setCheckData(machine.context.checkData as any);
  14. }
  15. }, [machine.context.checkData]);
  16. useEffect(() => {
  17. trackTimeService.onTransition(_ => {
  18. if (machine.context.checkData) {
  19. setCheckData(machine.context.checkData as any);
  20. }
  21. });
  22. }, []);
  23. //外环
  24. function bigRing() {
  25. var common = getCommon(null, true)
  26. common.radius = 126;
  27. common.lineWidth = 28;
  28. var bgRing = getBgRing()
  29. if (!checkData) {
  30. var currentDot1 = getDot(null, true)
  31. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock0' />
  32. }
  33. var current_record = (checkData as any).current_record
  34. var currentDot1 = getDot((checkData as any).current_record, true)
  35. var targetBigRing1 = getTarget((checkData as any).current_record, true)
  36. targetBigRing1.color = ColorType.fast+'33'//'rgba(170,255,0,0.4)'
  37. if (current_record.status == 'ONGOING') {
  38. var realRing1 = getReal((checkData as any).current_record, true, false)
  39. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId='clock1' />
  40. }
  41. if (current_record.status == 'WAIT_FOR_START') {
  42. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId='clock2' />
  43. }
  44. var realRing1 = getReal((checkData as any).current_record, true, false)
  45. return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId='clock3' />
  46. }
  47. //内环
  48. function smallRing() {
  49. var current_record = (checkData as any).current_record
  50. if (current_record.scenario == 'FAST_SLEEP') {
  51. var common = getCommon(null, false)
  52. common.radius = 90;
  53. common.lineWidth = 28;
  54. var bgRing = getBgRing()
  55. var realRing = getReal((checkData as any).current_record, false, false)
  56. var currentDot = getDot((checkData as any).current_record, false)
  57. var targetRing = getTarget((checkData as any).current_record, false)
  58. targetRing.color = ColorType.sleep+'33'//'rgba(0, 255, 255, 0.4)'
  59. if (current_record.status == 'ONGOING2') {
  60. return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId='clock7' />
  61. }
  62. //ongoing3时,睡眠点整理亮度降低
  63. if (current_record.status == 'ONGOING3') {
  64. currentDot.color = ColorType.sleep+'66'
  65. }
  66. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId='clock8' />
  67. }
  68. return null;
  69. }
  70. if (!checkData)
  71. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%', marginTop: 20 }}>
  72. {
  73. bigRing()
  74. }
  75. </View>
  76. return (
  77. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%' }}>
  78. <View style={{ position: 'relative', zIndex: 1 }}>
  79. {
  80. bigRing()
  81. }
  82. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  83. {
  84. smallRing()
  85. }
  86. </View>
  87. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  88. {
  89. (checkData as any).current_record.status == 'WAIT_FOR_START' && <Text className="clock_text" style={{ color: ColorType.fast }}>{TimeFormatter.getCurrentHourAndMinute()}</Text>
  90. }
  91. {
  92. (checkData as any).current_record.status == 'ONGOING' && <Text className="clock_text" style={{ color: (checkData as any).current_record.scenario == 'FAST' ? ColorType.fast : ColorType.sleep }}>
  93. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast ?
  94. (checkData as any).current_record.fast.real_start_time :
  95. (checkData as any).current_record.sleep.real_start_time)}
  96. </Text>
  97. }
  98. {
  99. (checkData as any).current_record.status == 'ONGOING1' && <Text className="clock_text" style={{ color: ColorType.fast }}>
  100. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  101. </Text>
  102. }
  103. {
  104. (checkData as any).current_record.status == 'ONGOING2' && <View style={{ flexDirection: 'column', display: 'flex' }}>
  105. <Text className="clock_text"style={{ color: ColorType.fast }}>
  106. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  107. </Text>
  108. <Text className="clock_text" style={{ color: ColorType.sleep }}>
  109. {TimeFormatter.formateTimeNow((checkData as any).current_record.sleep.real_start_time)}
  110. </Text>
  111. </View>
  112. }
  113. {
  114. (checkData as any).current_record.status == 'ONGOING3' && <Text>
  115. <Text className="clock_text" style={{ color: ColorType.fast }}>
  116. {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)}
  117. </Text>
  118. </Text>
  119. }
  120. </View>
  121. </View>
  122. </View>
  123. )
  124. }