import trackTimeService, { machine } from "@/store/trackTimeMachine"; import { View, Text, CoverView } from "@tarojs/components"; import { useEffect, useState } from "react"; import { TimeFormatter } from "@/utils/time_format"; import Rings, { BgRing, CurrentDot, RealRing, RingCommon } from './Rings'; import { getBgRing, getCommon, getDot, getReal, getTarget } from "../hooks/RingData"; import './Clock.scss' import { ColorType } from "@/context/themes/color"; import { useSelector } from "react-redux"; import { jumpPage } from "../hooks/Common"; export default function Component(props: { showCoverView: boolean }) { const [checkData, setCheckData] = useState(null) const time = useSelector((state: any) => state.time); const user = useSelector((state: any) => state.user); const [showCover, setShowCover] = useState(props.showCoverView) useEffect(() => { if (!user.isLogin) { setCheckData(null) } }, [user.isLogin]) useEffect(() => { if (machine.context.checkData) { setCheckData(machine.context.checkData as any); } }, [machine.context.checkData]); useEffect(() => { trackTimeService.onTransition(_ => { if (machine.context.checkData) { setCheckData(machine.context.checkData as any); } }); }, []); useEffect(() => { setShowCover(props.showCoverView) }, [props.showCoverView]) //外环 function bigRing() { var common = getCommon(null, true) common.radius = 126; common.lineWidth = 28; var bgRing = getBgRing() if (!checkData) { var currentDot1 = getDot(null, true) return } var current_record = (checkData as any).current_record var currentDot1 = getDot((checkData as any).current_record, true) var targetBigRing1 = getTarget((checkData as any).current_record, true) targetBigRing1.color = global.fastColor ? global.fastColor + '66' : ColorType.fast + '66'//'rgba(170,255,0,0.4)' if ((checkData as any).current_record.scenario == 'SLEEP') { targetBigRing1.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'//'rgba(170,255,0,0.4)' } // console.log(targetBigRing1.color) if (current_record.status == 'ONGOING') { var realRing1 = getReal((checkData as any).current_record, true, false) return } if (current_record.status == 'WAIT_FOR_START') { return } var realRing1 = getReal((checkData as any).current_record, true, false) return } //内环 function smallRing() { var current_record = (checkData as any).current_record if (current_record.scenario == 'FAST_SLEEP') { var common = getCommon(null, false) common.radius = 90; common.lineWidth = 28; var bgRing = getBgRing() var realRing = getReal((checkData as any).current_record, false, false) var currentDot = getDot((checkData as any).current_record, false) var targetRing = getTarget((checkData as any).current_record, false) targetRing.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66'//'rgba(0, 255, 255, 0.4)' if (current_record.status == 'ONGOING2') { return } //ongoing3时,睡眠点整理亮度降低 if (current_record.status == 'ONGOING3') { currentDot.color = global.sleepColor ? global.sleepColor + '66' : ColorType.sleep + '66' } return } return null; } function tapCover(){ if (user.isLogin){ } else { jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', null) } } if (!checkData) return { bigRing() } { {TimeFormatter.getCurrentHourAndMinute()} } { showCover && } return ( { bigRing() } { smallRing() } { (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario == 'FAST_SLEEP' && {TimeFormatter.getCurrentHourAndMinute()} } { (checkData as any).current_record.status == 'WAIT_FOR_START' && time.scenario != 'FAST_SLEEP' && {TimeFormatter.getCurrentHourAndMinute()} } { (checkData as any).current_record.status == 'ONGOING' && {TimeFormatter.formateTimeNow((checkData as any).current_record.fast ? (checkData as any).current_record.fast.real_start_time : (checkData as any).current_record.sleep.real_start_time)} } { (checkData as any).current_record.status == 'ONGOING1' && {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)} } { (checkData as any).current_record.status == 'ONGOING2' && {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)} {TimeFormatter.formateTimeNow((checkData as any).current_record.sleep.real_start_time)} } { (checkData as any).current_record.status == 'ONGOING3' && {TimeFormatter.formateTimeNow((checkData as any).current_record.fast.real_start_time)} } { showCover && } ) }