fast_sleep_card.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. import { View, Text } from '@tarojs/components'
  2. import './fast_sleep_card.scss'
  3. import { rpxToPx } from '@/utils/tools'
  4. import { MainColorType } from '@/context/themes/color';
  5. import { TimeFormatter } from '@/utils/time_format';
  6. import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  7. import { getDurationArc, getStartArc, getThemeColor } from '@/features/health/hooks/health_hooks';
  8. import { useSelector } from 'react-redux';
  9. import { useTranslation } from 'react-i18next';
  10. import StatusIndicator, { StatusType } from '../base/status_indicator';
  11. import { IconCheck, IconCircle, IconMiss } from '@/components/basic/Icons';
  12. export default function FastSleepCard(props: { step: number, data: any }) {
  13. const health = useSelector((state: any) => state.health);
  14. const { t } = useTranslation()
  15. const common: RingCommon = {
  16. useCase: 'ChooseScenario',
  17. radius: 50,
  18. lineWidth: 14,
  19. isFast: true,
  20. status: 'WAIT_FOR_START'
  21. }
  22. const common2: RingCommon = {
  23. useCase: 'ChooseScenario',
  24. radius: 31,
  25. lineWidth: 14,
  26. isFast: true,
  27. status: 'WAIT_FOR_START'
  28. }
  29. const common3: RingCommon = {
  30. useCase: 'ChooseScenario',
  31. radius: 40,
  32. lineWidth: 14,
  33. isFast: true,
  34. status: 'WAIT_FOR_START'
  35. }
  36. const bgRing: BgRing = {
  37. color: MainColorType.ringBg
  38. }
  39. function target0BigRing() {
  40. const { fast } = props.data
  41. return {
  42. color: MainColorType.fastLight,
  43. startArc: getStartArc(fast.target.start_timestamp),
  44. durationArc: getDurationArc(fast.target.start_timestamp, fast.target.end_timestamp)
  45. }
  46. }
  47. function target0SmallRing() {
  48. const { sleep } = props.data
  49. if (sleep.real && sleep.real.end_timestamp) {
  50. return {
  51. color: MainColorType.sleepLight,
  52. startArc: getStartArc(sleep.real.start_timestamp),
  53. durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
  54. }
  55. }
  56. return {
  57. color: MainColorType.sleepLight,
  58. startArc: getStartArc(sleep.target.start_timestamp),
  59. durationArc: getDurationArc(sleep.target.start_timestamp, sleep.target.end_timestamp)
  60. }
  61. }
  62. function target1BigRing() {
  63. const { fast, sleep, status } = props.data
  64. if (status == 'OG2_NO1') {
  65. var fastStarttoSleepDuration = 0
  66. var time1 = sleep.period.start_time
  67. var time2 = fast.period.start_time
  68. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  69. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  70. fastStarttoSleepDuration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  71. return {
  72. color: MainColorType.fastLight,
  73. startArc: getStartArc(fast.target.start_timestamp),
  74. durationArc: getDurationArc(fast.target.start_timestamp, fast.target.start_timestamp + fastStarttoSleepDuration)
  75. }
  76. // var now = new Date().getTime()
  77. // return TimeFormatter.calculateTimeDifference(now, now + fastStarttoSleepDuration)
  78. }
  79. return {
  80. color: MainColorType.fastLight,
  81. startArc: getStartArc(fast.target.start_timestamp),
  82. durationArc: getDurationArc(fast.target.start_timestamp, sleep.target.start_timestamp)
  83. }
  84. }
  85. function target2BigRing() {
  86. const { sleep } = props.data
  87. if (sleep.real && sleep.real.end_timestamp) {
  88. return {
  89. color: MainColorType.sleepLight,
  90. startArc: getStartArc(sleep.real.start_timestamp),
  91. durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
  92. }
  93. }
  94. return {
  95. color: MainColorType.sleepLight,
  96. startArc: getStartArc(sleep.target.start_timestamp),
  97. durationArc: getDurationArc(sleep.target.start_timestamp, sleep.target.end_timestamp)
  98. }
  99. }
  100. function target3BigRing() {
  101. const { fast, sleep, status } = props.data
  102. if (status == 'OG2_NO1') {
  103. var time1 = fast.period.end_time
  104. var time2 = sleep.period.end_time
  105. var duration = 0
  106. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  107. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  108. duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  109. return {
  110. color: MainColorType.fastLight,
  111. startArc: getStartArc(fast.target.end_timestamp - duration),
  112. durationArc: getDurationArc(fast.target.end_timestamp - duration, fast.target.end_timestamp)
  113. }
  114. }
  115. return {
  116. color: MainColorType.fastLight,
  117. startArc: getStartArc(status == 'OG3' ? sleep.real.end_timestamp : sleep.target.end_timestamp),
  118. durationArc: getDurationArc(status == 'OG3' ? sleep.real.end_timestamp : sleep.target.end_timestamp, fast.target.end_timestamp)
  119. }
  120. }
  121. function real0BigRing() {
  122. const { fast, sleep, status } = props.data
  123. if (status == 'WFS') {
  124. if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp)
  125. return {
  126. color: MainColorType.fast,
  127. startArc: getStartArc(fast.target.start_timestamp),
  128. durationArc: getDurationArc(fast.target.start_timestamp, new Date().getTime())
  129. }
  130. return null
  131. }
  132. if (status == 'OG2_NO1') {
  133. return null;
  134. }
  135. return {
  136. color: MainColorType.fast,
  137. startArc: getStartArc(fast.real.start_timestamp),
  138. durationArc: getDurationArc(fast.real.start_timestamp, new Date().getTime())
  139. }
  140. }
  141. function real0SmallRing() {
  142. const { sleep } = props.data
  143. if (!sleep.real) {
  144. return null;
  145. }
  146. if (sleep.real.end_timestamp) {
  147. return {
  148. color: MainColorType.sleep,
  149. startArc: getStartArc(sleep.real.start_timestamp),
  150. durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
  151. }
  152. }
  153. return {
  154. color: MainColorType.sleep,
  155. startArc: getStartArc(sleep.real.start_timestamp),
  156. durationArc: getDurationArc(sleep.real.start_timestamp, new Date().getTime())
  157. }
  158. }
  159. function real1BigRing() {
  160. const { fast, sleep, status } = props.data
  161. if (fast.real) {
  162. if (status == 'OG1') {
  163. return {
  164. color: MainColorType.fast,
  165. startArc: getStartArc(fast.real.start_timestamp),
  166. durationArc: getDurationArc(fast.real.start_timestamp, new Date().getTime())
  167. }
  168. }
  169. return {
  170. color: MainColorType.fast,
  171. startArc: getStartArc(fast.real.start_timestamp),
  172. durationArc: getDurationArc(fast.real.start_timestamp, sleep.real.start_timestamp)
  173. }
  174. }
  175. return null;
  176. }
  177. function real2BigRing() {
  178. const { sleep } = props.data
  179. if (!sleep.real) {
  180. return null;
  181. }
  182. return {
  183. color: MainColorType.sleep,
  184. startArc: getStartArc(sleep.real.start_timestamp),
  185. durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp ? sleep.real.end_timestamp : new Date().getTime())
  186. }
  187. }
  188. function real3BigRing() {
  189. const { fast, sleep } = props.data
  190. if (!sleep.real || !sleep.real.end_timestamp) {
  191. return null;
  192. }
  193. return {
  194. color: MainColorType.fast,
  195. startArc: getStartArc(sleep.real.end_timestamp),
  196. durationArc: getDurationArc(sleep.real.end_timestamp, new Date().getTime())
  197. }
  198. }
  199. function currentDot(mode, outRange?: boolean) {
  200. return {
  201. color: outRange ? '#B2B2B2' : getThemeColor(mode),
  202. lineWidth: 4,
  203. borderColor: '#ffffff',
  204. offset: 0
  205. }
  206. }
  207. function circle0() {
  208. const { fast, sleep, status } = props.data
  209. var outRange = true
  210. var outRange2 = true
  211. if (fast.status == 'OG') {
  212. outRange = false
  213. }
  214. else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
  215. outRange = false
  216. }
  217. if (sleep.status == 'OG') {
  218. outRange2 = false
  219. }
  220. else if (sleep.target.start_timestamp <= new Date().getTime() && new Date().getTime() < sleep.target.end_timestamp) {
  221. outRange2 = false
  222. }
  223. return <View style={{
  224. display: 'flex', alignItems: 'center', justifyContent: 'center', width: 114, height: 114,
  225. marginLeft: rpxToPx(50),
  226. marginTop: rpxToPx(86),
  227. position: 'relative',
  228. }}>
  229. <Rings common={common}
  230. bgRing={bgRing}
  231. targetRing={target0BigRing()}
  232. realRing={real0BigRing()}
  233. canvasId={'circle0_big'}
  234. currentDot={currentDot('FAST', outRange)}
  235. />
  236. <View style={{
  237. position: 'absolute',
  238. display: 'flex',
  239. alignItems: 'center',
  240. justifyContent: 'center',
  241. left: 0,
  242. right: 0,
  243. top: 0,
  244. bottom: 0
  245. }}>
  246. <Rings common={common2}
  247. bgRing={bgRing}
  248. targetRing={target0SmallRing()}
  249. realRing={real0SmallRing()}
  250. canvasId={'circle0_small'}
  251. currentDot={currentDot('SLEEP', outRange2)}
  252. />
  253. </View>
  254. </View>
  255. }
  256. function circle1() {
  257. const { fast, sleep, status } = props.data
  258. var outRange = true
  259. if (fast.status == 'OG') {
  260. outRange = false
  261. }
  262. else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
  263. outRange = false
  264. }
  265. return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
  266. bgRing={bgRing}
  267. targetRing={target1BigRing()}
  268. realRing={real1BigRing()}
  269. canvasId={'circle1_big'}
  270. currentDot={currentDot('FAST', outRange)}
  271. /></View>
  272. }
  273. function circle2() {
  274. const { fast, sleep, status } = props.data
  275. var outRange = true
  276. if (sleep.status == 'OG') {
  277. outRange = false
  278. }
  279. else if (sleep.target.start_timestamp <= new Date().getTime() && new Date().getTime() < sleep.target.end_timestamp) {
  280. outRange = false
  281. }
  282. return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
  283. bgRing={bgRing}
  284. targetRing={target2BigRing()}
  285. realRing={real2BigRing()}
  286. canvasId={'circle2_big'}
  287. currentDot={currentDot('SLEEP', outRange)}
  288. /></View>
  289. }
  290. function circle3() {
  291. const { fast, sleep, status } = props.data
  292. var outRange = true
  293. if (fast.status == 'OG') {
  294. outRange = false
  295. }
  296. else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
  297. outRange = false
  298. }
  299. return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
  300. bgRing={bgRing}
  301. targetRing={target3BigRing()}
  302. realRing={real3BigRing()}
  303. canvasId={'circle3_big'}
  304. currentDot={currentDot('FAST',outRange)}
  305. /></View>
  306. }
  307. function circleContent() {
  308. switch (props.step) {
  309. case 0:
  310. return circle0()
  311. case 1:
  312. return circle1()
  313. case 2:
  314. return circle2()
  315. case 3:
  316. return circle3()
  317. }
  318. }
  319. function statusBar() {
  320. var title = ''
  321. var hide = false;
  322. const { status } = props.data
  323. switch (props.step) {
  324. case 0:
  325. {
  326. if (status == 'WFS') {
  327. title = t('health.ready_for_logging')
  328. }
  329. else {
  330. title = t('health.logging_progress')
  331. }
  332. return <View style={{
  333. position: 'absolute',
  334. display: 'flex',
  335. alignItems: 'center',
  336. flexDirection: 'row',
  337. left: rpxToPx(20),
  338. top: rpxToPx(20),
  339. opacity: hide ? 0 : 1
  340. }}>
  341. <StatusIndicator type={status == 'WFS' ? StatusType.normal : StatusType.ing}
  342. color={status == 'OG2_NO1' || status == 'OG2' ? MainColorType.sleep : MainColorType.fast}
  343. text={title}
  344. fontColor={MainColorType.g01}
  345. fontSize={rpxToPx(20)}
  346. >
  347. {/* {status == 'WFS' && <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />} */}
  348. </StatusIndicator>
  349. </View>
  350. // else if (status == 'OG2_NO1') {
  351. // title = ''
  352. // hide = true
  353. // }
  354. // else {
  355. // title = 'In progress'
  356. // }
  357. }
  358. break;
  359. case 1:
  360. {
  361. title = t('health.stage1')
  362. var type = StatusType.normal
  363. var color: any = MainColorType.fast
  364. var img: any = null
  365. if (status == 'WFS') {
  366. type = StatusType.img
  367. color = 'transparent'
  368. img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
  369. }
  370. else if (status == 'OG1') {
  371. type = StatusType.ing
  372. }
  373. else if (status == 'OG2_NO1') {
  374. type = StatusType.img
  375. color = MainColorType.error
  376. img = <IconMiss width={rpxToPx(26)} color='#fff' />
  377. }
  378. else {
  379. type = StatusType.img
  380. img = <IconCheck width={rpxToPx(26)} height={rpxToPx(26)} color='#fff' />
  381. }
  382. return <View style={{
  383. position: 'absolute',
  384. display: 'flex',
  385. alignItems: 'center',
  386. flexDirection: 'row',
  387. left: rpxToPx(20),
  388. top: rpxToPx(20),
  389. opacity: hide ? 0 : 1
  390. }}>
  391. <StatusIndicator type={type}
  392. color={color}
  393. text={title}
  394. fontColor={MainColorType.g01}
  395. fontSize={rpxToPx(20)}
  396. >
  397. {
  398. img
  399. }
  400. </StatusIndicator>
  401. </View>
  402. }
  403. break;
  404. case 2:
  405. {
  406. title = t('health.stage2')
  407. // if (status == 'OG2') {
  408. // title = 'Stage 2 in progress'
  409. // }
  410. // else if (status == 'OG3' || status == 'OG2_NO1') {
  411. // title = 'Stage 2'
  412. // }
  413. // else {
  414. // title = 'Stage 2'
  415. // }
  416. var type = StatusType.normal
  417. var img: any = null
  418. var color: any = MainColorType.sleep
  419. if (status == 'WFS' || status == 'OG1') {
  420. type = StatusType.img
  421. img = <IconCircle width={rpxToPx(26)} color={MainColorType.sleep} />
  422. color = 'transparent'
  423. }
  424. else if (status == 'OG2') {
  425. type = StatusType.ing
  426. }
  427. else if (status == 'OG2_NO1') {
  428. type = StatusType.ing
  429. img = <IconMiss width={rpxToPx(26)} color='#fff' />
  430. }
  431. else {
  432. type = StatusType.img
  433. img = <IconCheck width={rpxToPx(26)} height={rpxToPx(26)} color='#fff' />
  434. }
  435. return <View style={{
  436. position: 'absolute',
  437. display: 'flex',
  438. alignItems: 'center',
  439. flexDirection: 'row',
  440. left: rpxToPx(20),
  441. top: rpxToPx(20),
  442. opacity: hide ? 0 : 1
  443. }}>
  444. <StatusIndicator type={type}
  445. color={color}
  446. text={title}
  447. fontColor={MainColorType.g01}
  448. fontSize={rpxToPx(20)}
  449. >
  450. {
  451. img
  452. }
  453. </StatusIndicator>
  454. </View>
  455. }
  456. case 3:
  457. {
  458. title = t('health.stage3')
  459. var type = StatusType.normal
  460. var img: any = null
  461. if (status == 'OG3') {
  462. type = StatusType.ing
  463. }
  464. else if (status == 'OG2_NO1') {
  465. type = StatusType.img
  466. img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
  467. }
  468. else {
  469. type = StatusType.img
  470. img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
  471. }
  472. return <View style={{
  473. position: 'absolute',
  474. display: 'flex',
  475. alignItems: 'center',
  476. flexDirection: 'row',
  477. left: rpxToPx(20),
  478. top: rpxToPx(20),
  479. opacity: hide ? 0 : 1
  480. }}>
  481. <StatusIndicator type={type}
  482. color={status == 'OG3' ? MainColorType.fast : 'transparent'}
  483. text={title}
  484. fontColor={MainColorType.g01}
  485. fontSize={rpxToPx(20)}
  486. >
  487. {
  488. img
  489. }
  490. </StatusIndicator>
  491. </View>
  492. // if (status == 'OG3') {
  493. // title = 'Stage 3 in progress'
  494. // }
  495. // else if (status == 'OG2_NO1') {
  496. // title = 'Stage 3 pending start'
  497. // }
  498. // else {
  499. // title = 'Stage 3'
  500. // }
  501. }
  502. break;
  503. }
  504. return <View style={{
  505. position: 'absolute',
  506. display: 'flex',
  507. alignItems: 'center',
  508. flexDirection: 'row',
  509. left: rpxToPx(20),
  510. top: rpxToPx(20),
  511. opacity: hide ? 0 : 1
  512. }}>
  513. <View style={{
  514. width: rpxToPx(12),
  515. height: rpxToPx(12),
  516. borderRadius: rpxToPx(6),
  517. marginLeft: rpxToPx(10),
  518. marginRight: rpxToPx(10),
  519. backgroundColor: props.step == 2 ? MainColorType.sleep : MainColorType.fast
  520. }} />
  521. <View className='h20' style={{ color: MainColorType.g01 }}>{title}</View>
  522. </View>
  523. }
  524. function fastTime() {
  525. const { fast, status } = props.data
  526. if (status == 'WFS' || status == 'OG2_NO1') {
  527. var now = new Date().getTime()
  528. return TimeFormatter.calculateTimeDifference(now, now + fast.target.duration)
  529. }
  530. return TimeFormatter.countdown(fast.real.start_timestamp)
  531. }
  532. function sleepTime() {
  533. const { sleep, status } = props.data
  534. if (status == 'WFS' || status == 'OG1') {
  535. var now = new Date().getTime()
  536. return TimeFormatter.calculateTimeDifference(now, now + sleep.target.duration)
  537. }
  538. else if (status == 'OG3') {
  539. return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
  540. }
  541. return TimeFormatter.countdown(sleep.real.start_timestamp)
  542. }
  543. function step1() {
  544. if (health.fast_with_sleep.status == 'OG2_MISALIGNED') {
  545. return 'Not Available'
  546. }
  547. const { fast, sleep, status } = props.data
  548. if (status == 'WFS') {
  549. return TimeFormatter.calculateTimeDifference(fast.target.start_timestamp, sleep.target.start_timestamp)
  550. }
  551. else if (status == 'OG1') {
  552. var now = new Date().getTime()
  553. return TimeFormatter.countdown(fast.real.start_timestamp)
  554. }
  555. else if (status == 'OG2_NO1') {
  556. var fastStarttoSleepDuration = 0
  557. var time1 = sleep.period.start_time
  558. var time2 = fast.period.start_time
  559. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  560. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  561. fastStarttoSleepDuration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  562. var now = new Date().getTime()
  563. return TimeFormatter.calculateTimeDifference(now, now + fastStarttoSleepDuration)
  564. }
  565. return TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp)
  566. }
  567. function step2() {
  568. if (health.fast_with_sleep.status == 'OG2_MISALIGNED') {
  569. return 'Not Meaningful'
  570. }
  571. const { fast, sleep, status } = props.data
  572. if (status == 'OG2_NO1' || status == 'OG2') {
  573. return TimeFormatter.countdown(sleep.real.start_timestamp)
  574. }
  575. else if (status == 'OG3') {
  576. return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
  577. }
  578. return TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp)
  579. }
  580. function step3() {
  581. const { fast, sleep, status } = props.data
  582. if (status == 'OG3') {
  583. return TimeFormatter.countdown(sleep.real.end_timestamp)
  584. }
  585. return diffentTime(sleep.period.end_time, fast.period.end_time)
  586. }
  587. function diffentTime(time2, time1) {
  588. var duration = 0
  589. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  590. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  591. duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  592. var now = new Date().getTime()
  593. return TimeFormatter.calculateTimeDifference(now, now + duration)
  594. }
  595. function statusDetail() {
  596. switch (props.step) {
  597. case 0:
  598. return <View className='right_content'>
  599. <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fasting')}</View>
  600. <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{fastTime()}</View>
  601. <View style={{ height: rpxToPx(24) }} />
  602. <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.sleep')}</View>
  603. <View className='h36 bold' style={{ color: MainColorType.sleep, lineHeight: rpxToPx(52) + 'px' }}>{sleepTime()}</View>
  604. </View>
  605. case 1:
  606. return <View className='right_content'>
  607. <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_before_bed')}</View>
  608. <View style={{ height: rpxToPx(12) }} />
  609. <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{step1()}</View>
  610. </View>
  611. case 2:
  612. return <View className='right_content'>
  613. <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_while_sleep')}</View>
  614. <View style={{ height: rpxToPx(12) }} />
  615. <View className='h36 bold' style={{ color: MainColorType.sleep, lineHeight: rpxToPx(52) + 'px' }}>{step2()}</View>
  616. </View>
  617. case 3:
  618. return <View className='right_content'>
  619. <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_after_sleep')}</View>
  620. <View style={{ height: rpxToPx(12) }} />
  621. <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{step3()}</View>
  622. </View>
  623. }
  624. return <View className='right_content'></View>
  625. }
  626. return <View style={{
  627. position: 'relative', display: 'flex', flexDirection: 'row',
  628. height: rpxToPx(384),
  629. boxSizing: 'border-box'
  630. }}>
  631. {
  632. statusBar()
  633. }
  634. {
  635. circleContent()
  636. }
  637. <View style={{
  638. marginLeft: rpxToPx(36), height: props.step == 0 ? 114 : 96,
  639. marginTop: props.step == 0 ? rpxToPx(86) : rpxToPx(100),
  640. display: 'flex',
  641. flexDirection: 'row',
  642. alignItems: 'center'
  643. }}>
  644. {
  645. statusDetail()
  646. }
  647. </View>
  648. </View>
  649. }