AllRings.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import Box from '@/components/layout/Box'
  2. import './AllRings.scss'
  3. import { PageContainer, View, Text } from '@tarojs/components'
  4. import { useEffect, useState } from 'react'
  5. import Modal from '@/components/layout/Modal.weapp'
  6. import { bigRingRadius, getBgRing, getCommon, getDot, getReal, getSchedule, getTarget, ringWidth, smallRingRadius, thirdRingRadius, timeTotimestamp } from '../hooks/RingData'
  7. import { rpxToPx } from '@/utils/tools'
  8. import { ColorType } from '@/context/themes/color'
  9. import { useTranslation } from 'react-i18next'
  10. import Rings from "./Rings";
  11. import { TimeFormatter } from '@/utils/time_format'
  12. import { useSelector } from 'react-redux'
  13. import { RealRing } from '@/features/trackTimeDuration/components/Rings'
  14. import DayNightRing from './DayNightRing'
  15. export default function AllRings(props: { data?: any, time?: any }) {
  16. const [showRing, setShowRing] = useState(false)
  17. const [record, setRecord] = useState(props.data.current_record);
  18. const user = useSelector((state: any) => state.user);
  19. const nightStore = useSelector((state: any) => state.night);
  20. const [authInfo, setAuthInfo] = useState(global.locationDetail ? global.locationDetail : null)
  21. const { t } = useTranslation()
  22. useEffect(() => {
  23. setAuthInfo(global.locationDetail)
  24. }, [global.locationDetail])
  25. useEffect(()=>{
  26. setRecord(props.data.current_record);
  27. },[props.data])
  28. function tapShow() {
  29. setShowRing(true)
  30. }
  31. function durationArc(start_time: number, end_time: number) {
  32. var duration = (end_time - start_time) / 1000;
  33. return duration / (24 * 3600) * 2 * Math.PI;
  34. }
  35. const startArc = (time: number) => {
  36. var date = new Date(time);
  37. var hour = date.getHours();
  38. var minute = date.getMinutes();
  39. var second = date.getSeconds();
  40. return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
  41. }
  42. function bigRing() {
  43. var common = getCommon(null, true)
  44. common.radius = bigRingRadius;
  45. common.lineWidth = ringWidth;
  46. var bgRing = getBgRing()
  47. var currentDot1 = getDot(record, true)
  48. var targetBigRing1 = getTarget(record, true)
  49. targetBigRing1.color = record.scenario == 'SLEEP' ? ColorType.sleep + '66' : ColorType.fast + '66'
  50. debugger
  51. if (record.status == 'ONGOING') {
  52. var realRing1 = getReal(record, true, false)
  53. // debugger
  54. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId={props.type + 'index_big'} />
  55. }
  56. if (record.status == 'WAIT_FOR_START') {
  57. var scenario = JSON.parse(JSON.stringify(props.data.scenario))
  58. if (scenario.name == 'SLEEP') {
  59. var countduration = (props.data.current_record.sleep.target_end_time - props.data.current_record.sleep.target_start_time) / 60000
  60. var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.start_time) / 60
  61. var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.end_time) / 60
  62. var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
  63. if (leftMinutes != countduration) {
  64. min2 = min1 + countduration
  65. if (min2 > 1440) {
  66. min2 -= 1440
  67. }
  68. var hour = Math.floor(min2 / 60)
  69. var minute = min2 % 60
  70. scenario.schedule.sleep.end_time = `${hour}:${minute}`
  71. }
  72. }
  73. else {
  74. var countduration = (props.data.current_record.fast.target_end_time - props.data.current_record.fast.target_start_time) / 60000
  75. var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.start_time) / 60
  76. var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.end_time) / 60
  77. var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
  78. if (leftMinutes != countduration) {
  79. min2 = min1 + countduration
  80. if (min2 > 1440) {
  81. min2 -= 1440
  82. }
  83. var hour = Math.floor(min2 / 60)
  84. var minute = min2 % 60
  85. scenario.schedule.fast.end_time = `${hour}:${minute}`
  86. }
  87. }
  88. var realRing1 = getSchedule(scenario, scenario.name != 'SLEEP', true, true)//getSchedule(record, props.type != 'SLEEP', true)
  89. var list: any = []
  90. if (scenario.name == 'FAST_SLEEP') {
  91. realRing1.color = ColorType.fast + '66'
  92. }
  93. else if (scenario.name == 'SLEEP') {
  94. realRing1.color = ColorType.sleep + '66'
  95. }
  96. else {
  97. realRing1.color = ColorType.fast + '66'
  98. }
  99. if (user.isLogin) {
  100. list = []
  101. }
  102. if (!user.isLogin) {
  103. currentDot1 = null
  104. // realRing1 = null
  105. }
  106. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} stageList={list} realRing={realRing1} canvasId={'full_index_big'} />
  107. }
  108. var realRing1 = getReal(record, true, false)
  109. return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId={'full_index_big'} />
  110. }
  111. function smallRing() {
  112. var common = getCommon(null, false)
  113. common.radius = smallRingRadius;
  114. common.lineWidth = ringWidth;
  115. var bgRing = getBgRing()
  116. var realRing = getReal(record, false, false)
  117. if (props.data.scenario.name == 'FAST_SLEEP') {
  118. if (!record.sleep) {
  119. return null
  120. }
  121. if (record.sleep.status == 'WAIT_FOR_END') {
  122. var targetBigRing1 = getTarget(record, false)
  123. targetBigRing1.color = ColorType.sleep + '66'
  124. var currentDot = getDot(record, false)
  125. realRing.durationArc = durationArc(record.sleep.target_start_time, (new Date()).getTime())
  126. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={'full_index_small'} targetRing={targetBigRing1} realRing={realRing} />
  127. }
  128. else if (record.status == 'WAIT_FOR_START' || record.status == 'ONGOING1') {
  129. var scenario = JSON.parse(JSON.stringify(props.data.scenario))
  130. if (record.status == 'WAIT_FOR_START') {
  131. realRing = getSchedule(scenario, false, true, record.status == 'WAIT_FOR_START')//getSchedule(record, false, true)
  132. }
  133. else {
  134. realRing.startArc = startArc(record.sleep.target_start_time)
  135. realRing.durationArc = durationArc(record.sleep.target_start_time, record.sleep.target_end_time)
  136. }
  137. realRing.color = ColorType.sleep + '66'
  138. var currentDot = getDot(record, false)
  139. if (!user.isLogin) {
  140. currentDot = null
  141. }
  142. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} realRing={realRing} canvasId={'full_index_small'} />
  143. }
  144. else if (record.sleep.status == 'NOT_COMPLETED') {
  145. realRing.durationArc = 0.01
  146. var currentDot = getDot(record, false)
  147. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={'full_index_small'} realRing={realRing} />
  148. }
  149. else if (record.sleep.status == 'COMPLETED') {
  150. realRing = getReal(record, false, true)
  151. var currentDot = getDot(record, false)
  152. if (record.status == 'ONGOING3') {
  153. currentDot = null
  154. // currentDot.color = '#ffffffff'
  155. }
  156. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={'full_index_small'} realRing={realRing} />
  157. }
  158. else if (record.sleep.status == 'ONGOING2') {
  159. var currentDot = getDot(record, false)
  160. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={'full_index_small'} />
  161. }
  162. return <Rings common={common} bgRing={bgRing} canvasId={'full_index_small'} />
  163. }
  164. else {
  165. var currentDot = getDot(record, false)
  166. var targetRing = getTarget(record, false)
  167. if (record.status == 'ONGOING2') {
  168. var realRing = getReal(record, false, false)
  169. return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId={'full_index_small'} />
  170. }
  171. if (record.status == 'ONGOING3') {
  172. currentDot.color = 'rgba(0, 255, 255, 0.5)'
  173. }
  174. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={'full_index_small'} />
  175. }
  176. }
  177. function dayRing() {
  178. return <DayNightRing
  179. isNight={true}
  180. isThirdRing={true}
  181. canvasId={'day_night_card_big_night_ring111'}
  182. authInfo={authInfo}
  183. />
  184. }
  185. function rings() {
  186. return <View style={{
  187. position: 'relative', zIndex: 1,
  188. marginLeft: -6,
  189. }}>
  190. {
  191. bigRing()
  192. }
  193. {
  194. props.data.scenario.name == 'FAST_SLEEP' && <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  195. {
  196. smallRing()
  197. }
  198. </View>
  199. }
  200. {
  201. <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
  202. {
  203. dayRing()
  204. }
  205. </View>
  206. }
  207. </View>
  208. }
  209. function fastDuration() {
  210. return global.fastDuration
  211. }
  212. function sleepDuration() {
  213. return global.sleepDuration
  214. }
  215. function nightDuration() {
  216. return global.sunsetDuration
  217. }
  218. function popDetail() {
  219. return <Box>
  220. <View className="ring_full_container">
  221. <View className="time_operate_item1">
  222. <View className='fast_sleep_item three_ring_card_detail'>
  223. {
  224. rings()
  225. }
  226. <View className="duration_bg2" style={{ marginLeft: rpxToPx(68), height: bigRingRadius * 2, overflow: 'visible' }}>
  227. <Text className="duration_title2">{t('feature.common.overnight')}</Text>
  228. <Text className="duration_value2" style={{ color: ColorType.night }}>{nightDuration()}</Text>
  229. {
  230. (props.data.scenario.name == 'FAST' || props.data.scenario.name == 'FAST_SLEEP') && <Text className="duration_title2">{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
  231. }
  232. {
  233. (props.data.scenario.name == 'FAST' || props.data.scenario.name == 'FAST_SLEEP') && <Text className="duration_value2" style={{ color: global.fastColor ? global.fastColor : ColorType.fast }}>{fastDuration()}</Text>
  234. }
  235. {
  236. (props.data.scenario.name == 'SLEEP' || props.data.scenario.name == 'FAST_SLEEP') && <Text className="duration_title2" >{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
  237. }
  238. {
  239. (props.data.scenario.name == 'SLEEP' || props.data.scenario.name == 'FAST_SLEEP') && <Text className="duration_value2" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep, marginBottom: 0 }}>{sleepDuration()}</Text>
  240. }
  241. </View>
  242. </View>
  243. </View>
  244. </View>
  245. </Box>
  246. }
  247. function modalContent() {
  248. if (process.env.TARO_ENV == 'weapp') {
  249. return <Modal
  250. testInfo={null}
  251. dismiss={() => {
  252. setShowRing(false)
  253. }}
  254. confirm={() => { }}>
  255. {popDetail()}
  256. </Modal>
  257. }
  258. else if (process.env.TARO_ENV == 'rn') {
  259. return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
  260. // overlayStyle='background-color:rgba(0,0,0,0.9)'
  261. // custom-style='background-color:#1c1c1c'
  262. overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
  263. customStyle={{ backgroundColor: '#1c1c1c' }}
  264. closeOnSlideDown={false}
  265. onBeforeEnter={() => {
  266. }}
  267. onBeforeLeave={() => {
  268. }}
  269. onClick={() => { alert('b') }}
  270. onClickOverlay={() => { alert('a') }}
  271. onAfterLeave={() => { setShowRing(false) }}
  272. show={showRing} round={true} overlay={true} position='bottom'
  273. >
  274. {popDetail()}
  275. </PageContainer>
  276. }
  277. }
  278. return <Box onClick={tapShow}>
  279. <View style={{ color: '#fff' }}>同步显示生物钟</View>
  280. {
  281. showRing && modalContent()
  282. }
  283. </Box>
  284. }