|
|
@@ -0,0 +1,199 @@
|
|
|
+import { View, Text, Image } from "@tarojs/components";
|
|
|
+import { getBgRing, getCommon, getDot, getReal, getSchedule, getTarget } from "../hooks/RingData";
|
|
|
+import Rings from "./Rings";
|
|
|
+import './IndexItem.scss'
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { ColorType } from "@/context/themes/color";
|
|
|
+import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
+import { TimeFormatter } from "@/utils/time_format";
|
|
|
+
|
|
|
+let useNavigation;
|
|
|
+if (process.env.TARO_ENV == 'rn') {
|
|
|
+ useNavigation = require("@react-navigation/native").useNavigation
|
|
|
+}
|
|
|
+export default function Component(props: { type: string, data: any, time: any }) {
|
|
|
+ const { t } = useTranslation()
|
|
|
+ const record = props.data.current_record;
|
|
|
+ let navigation;
|
|
|
+ if (useNavigation) {
|
|
|
+ navigation = useNavigation()
|
|
|
+ }
|
|
|
+
|
|
|
+ function durationArc(start_time: number, end_time: number) {
|
|
|
+ var duration = (end_time - start_time) / 1000;
|
|
|
+ return duration / (24 * 3600) * 2 * Math.PI;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function bigRing() {
|
|
|
+ debugger
|
|
|
+ var common = getCommon(null, true)
|
|
|
+ common.radius = 42;
|
|
|
+ common.lineWidth = 9;
|
|
|
+ var bgRing = getBgRing()
|
|
|
+
|
|
|
+ if (props.type == 'SLEEP') {
|
|
|
+ var realRing = getReal(record, false, true)
|
|
|
+ if (record.status == 'WAIT_FOR_START' || record.status == 'ONGOING1') {
|
|
|
+ var realRing1 = getSchedule(record, props.type != 'SLEEP', true)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing1} canvasId={props.type + props.time + 'big'} />
|
|
|
+ }
|
|
|
+ if (props.data.status == 'ONGOING3') {
|
|
|
+ realRing.color = 'rgba(0,0,0,0)'
|
|
|
+ // bgRing.color = 'rgba(0,0,0,0)'
|
|
|
+ }
|
|
|
+ return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'big'} realRing={realRing} />
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var currentDot1 = getDot(record, true)
|
|
|
+ var targetBigRing1 = getTarget(record, true)
|
|
|
+ if (record.status == 'ONGOING') {
|
|
|
+ var realRing1 = getReal(record, true, false)
|
|
|
+
|
|
|
+ return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId={props.type + props.time + 'big'} />
|
|
|
+ }
|
|
|
+ if (record.status == 'WAIT_FOR_START') {
|
|
|
+ var realRing1 = getSchedule(record, props.type != 'SLEEP', true)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing1} canvasId={props.type + props.time + 'big'} />
|
|
|
+ }
|
|
|
+ var realRing1 = getReal(record, true, false)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId={props.type + props.time + 'big'} />
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function smallRing() {
|
|
|
+ if (record.scenario == 'FAST_SLEEP') {
|
|
|
+ var common = getCommon(null, false)
|
|
|
+ common.radius = 28;
|
|
|
+ common.lineWidth = 9;
|
|
|
+ var bgRing = getBgRing()
|
|
|
+ var realRing = getReal(record, false, false)
|
|
|
+ if (props.type == 'SLEEP' || props.type == 'FAST_SLEEP') {
|
|
|
+ if (record.sleep.status == 'WAIT_FOR_END') {
|
|
|
+ realRing.durationArc = durationArc(record.sleep.target_start_time, (new Date()).getTime())
|
|
|
+ return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} realRing={realRing} />
|
|
|
+ }
|
|
|
+ else if (record.status == 'WAIT_FOR_START' || record.status == 'ONGOING1') {
|
|
|
+ realRing = getSchedule(record, false, true)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={props.type + props.time + 'small'} />
|
|
|
+ }
|
|
|
+ else if (record.sleep.status == 'NOT_COMPLETED') {
|
|
|
+ realRing.durationArc = 0.01
|
|
|
+ return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} realRing={realRing} />
|
|
|
+ }
|
|
|
+ else if (record.sleep.status == 'COMPLETED') {
|
|
|
+ realRing = getReal(record, false, true)
|
|
|
+ return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} realRing={realRing} />
|
|
|
+ }
|
|
|
+ return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} />
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+
|
|
|
+ var currentDot = getDot(record, false)
|
|
|
+ var targetRing = getTarget(record, false)
|
|
|
+ if (record.status == 'ONGOING2') {
|
|
|
+ var realRing = getReal(record, false, false)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId={props.type + props.time + 'small'} />
|
|
|
+ }
|
|
|
+ if (record.status == 'ONGOING3') {
|
|
|
+ currentDot.color = 'rgba(0, 255, 255, 0.5)'
|
|
|
+ }
|
|
|
+ return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + props.time + 'small'} />
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ function rings() {
|
|
|
+ return <View style={{ position: 'relative', zIndex: 1 }}>
|
|
|
+ {
|
|
|
+ bigRing()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ props.type == 'FAST_SLEEP' && <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
|
|
|
+ {
|
|
|
+ smallRing()
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function getArrowText() {
|
|
|
+ if (record.status == 'WAIT_FOR_START') {
|
|
|
+ return '去开始'
|
|
|
+ }
|
|
|
+ if (record.status == 'ONGOING1' && props.type == 'SLEEP') {
|
|
|
+ return '去开始'
|
|
|
+ }
|
|
|
+ return '去结束'
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDuration(obj) {
|
|
|
+ if (!obj) {
|
|
|
+ }
|
|
|
+ if (obj.status == 'NOT_STARTED' || obj.status == 'NOT_COMPLETED') {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ var start = obj.real_start_time
|
|
|
+ var end = obj.real_end_time
|
|
|
+ if (!end) {
|
|
|
+ end = (new Date()).getTime()
|
|
|
+ }
|
|
|
+ if (obj.status == 'WAIT_FOR_START') {
|
|
|
+ start = obj.target_start_time
|
|
|
+ end = obj.target_end_time
|
|
|
+ }
|
|
|
+ return TimeFormatter.durationFormate(start, end)
|
|
|
+ // return TimeFormatter.calculateTimeDifference(start, end)
|
|
|
+ }
|
|
|
+
|
|
|
+ function fastDuration() {
|
|
|
+ if (record.fast.status == 'WAIT_FOR_END') {
|
|
|
+ return TimeFormatter.formateTimeDifference(record.fast.real_start_time, new Date().getTime(), true)
|
|
|
+ }
|
|
|
+ return getDuration(record.fast)
|
|
|
+ }
|
|
|
+
|
|
|
+ function sleepDuration() {
|
|
|
+ if (record.sleep.status == 'WAIT_FOR_END') {
|
|
|
+ return TimeFormatter.formateTimeDifference(record.sleep.real_start_time, new Date().getTime(), true)
|
|
|
+ }
|
|
|
+ return getDuration(record.sleep)
|
|
|
+ }
|
|
|
+
|
|
|
+ function goClock() {
|
|
|
+ jumpPage('/pages/clock/Clock', 'Clock', navigation)
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View className="time_operate_item" onClick={goClock}>
|
|
|
+ <View className="fast_sleep_item">
|
|
|
+ {
|
|
|
+ rings()
|
|
|
+ }
|
|
|
+ <View className="duration_bg">
|
|
|
+ {
|
|
|
+ (props.type == 'FAST' || props.type == 'FAST_SLEEP') && <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ (props.type == 'FAST' || props.type == 'FAST_SLEEP') && <Text className="duration_value" style={{ color: global.fastColor ? global.fastColor : ColorType.fast }}>{fastDuration()}</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ (props.type == 'SLEEP' || props.type == 'FAST_SLEEP') && <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ (props.type == 'SLEEP' || props.type == 'FAST_SLEEP') && <Text className="duration_value" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep }}>{sleepDuration()}</Text>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ {/* <Image className="arrow1" src={require('@/assets/images/arrow.png')} /> */}
|
|
|
+ <View className="record_arrow_bg" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <Text className='recordTime'>{getArrowText()}</Text>
|
|
|
+ <Image className="arrow2" src={require('@/assets/images/arrow3.png')} />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+}
|