|
|
@@ -0,0 +1,80 @@
|
|
|
+import { View, Text } from "@tarojs/components";
|
|
|
+import './Stage.scss'
|
|
|
+import { TimeFormatter } from "@/utils/time_format";
|
|
|
+
|
|
|
+export default function Component(props: { data: any }) {
|
|
|
+ function getTime(t1: number, t2: number) {
|
|
|
+ return TimeFormatter.calculateTimeDifference(t1, t2)
|
|
|
+ }
|
|
|
+
|
|
|
+ function getStepATime(obj) {
|
|
|
+ if (obj.status == 'COMPLETED' && obj.sleep.status == 'NOT_STARTED') {
|
|
|
+ return '未知'
|
|
|
+ }
|
|
|
+ return obj.status == 'ONGOING1' ?
|
|
|
+ getTime(obj.fast.real_start_time, (new Date()).getTime()) :
|
|
|
+ obj.sleep.real_start_time ? getTime(obj.sleep.real_start_time, obj.fast.real_start_time ? obj.fast.real_start_time : obj.fast.target_start_time) :
|
|
|
+ getTime(obj.sleep.target_start_time, obj.fast.real_start_time ? obj.fast.real_start_time : obj.fast.target_start_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ function getStepBTime(obj) {
|
|
|
+ if (obj.status == 'ONGOING1') return 'Next up'
|
|
|
+ if (obj.status == 'ONGOING2') return getTime(obj.sleep.real_start_time, (new Date()).getTime())
|
|
|
+ if (obj.status == 'WAIT_FOR_START') return getTime(obj.sleep.target_end_time, obj.sleep.target_start_time)
|
|
|
+ if (obj.sleep.status == 'NOT_COMPLETED' || obj.sleep.status == 'NOT_STARTED') return '未知'
|
|
|
+ return getTime(obj.sleep.real_end_time, obj.sleep.real_start_time)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function getStepCTime(obj) {
|
|
|
+ if (obj.status == 'ONGOING1') return 'Final stage'
|
|
|
+ if (obj.status == 'ONGOING2') return 'Next up'
|
|
|
+ if (obj.status == 'ONGOING3') return getTime(obj.sleep.real_end_time, (new Date()).getTime())
|
|
|
+ if (obj.status == 'WAIT_FOR_START') return getTime(obj.fast.target_end_time, obj.sleep.target_end_time)
|
|
|
+ if (obj.sleep.status == 'NOT_COMPLETED' || obj.sleep.status == 'NOT_STARTED') return '未知'
|
|
|
+ return getTime(obj.fast.real_end_time, obj.sleep.real_end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View className="stage">
|
|
|
+ <View className="stage_item">
|
|
|
+ <Text className={props.data.status == 'ONGOING1' ?
|
|
|
+ 'stage_step stage_step_border_ing' :
|
|
|
+ 'stage_step stage_step_border'}>阶段A</Text>
|
|
|
+ <Text className="stage_title" style={{
|
|
|
+ color: props.data.status == 'ONGOING1' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>睡前断食</Text>
|
|
|
+ <Text className="stage_value" style={{
|
|
|
+ color: props.data.status == 'ONGOING1' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>{getStepATime(props.data)}</Text>
|
|
|
+ </View>
|
|
|
+ <View className="stage_item">
|
|
|
+ <Text className={props.data.status == 'ONGOING2' ?
|
|
|
+ 'stage_step stage_step_border_ing' :
|
|
|
+ 'stage_step stage_step_border'}>阶段B</Text>
|
|
|
+ <Text className="stage_title" style={{
|
|
|
+ color: props.data.status == 'ONGOING2' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>睡眠中断食</Text>
|
|
|
+ <Text className="stage_value" style={{
|
|
|
+ color: props.data.status == 'ONGOING2' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>{getStepBTime(props.data)}</Text>
|
|
|
+ </View>
|
|
|
+ <View className="stage_item">
|
|
|
+ <Text className={props.data.status == 'ONGOING3' ?
|
|
|
+ 'stage_step stage_step_border_ing' :
|
|
|
+ 'stage_step stage_step_border'}>阶段C</Text>
|
|
|
+ <Text className="stage_title" style={{
|
|
|
+ color: props.data.status == 'ONGOING3' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>起床后断食</Text>
|
|
|
+ <Text className="stage_value" style={{
|
|
|
+ color: props.data.status == 'ONGOING3' ?
|
|
|
+ '#AAFF00' : 'rgba(255, 255, 255, 0.8)'
|
|
|
+ }}>{getStepCTime(props.data)}</Text>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ </View>
|
|
|
+}
|