| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- import { View, Text, Image } from "@tarojs/components";
- import { dotIsOuterRange, getBgRing, getCommon, getDot, getReal, getSchedule, getTarget, timeTotimestamp } from "../hooks/RingData";
- import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
- 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";
- import { useSelector } from "react-redux";
- import { useEffect, useState } from "react";
- import Taro from "@tarojs/taro";
- import Modal from "@/components/layout/Modal.weapp";
- import { ModalType } from "@/utils/types";
- import TimelineStage from "./TimelineStage";
- let useNavigation;
- if (process.env.TARO_ENV == 'rn') {
- useNavigation = require("@react-navigation/native").useNavigation
- }
- let popTimer;
- let currentRecordTemp;
- export default function Component(props: { type: string, data: any, time: any, showStage?: boolean }) {
- const { t } = useTranslation()
- const [record, setRecord] = useState(props.data.current_record);
- const user = useSelector((state: any) => state.user);
- const dayNight = useSelector((state: any) => state.dayNight);
- const [stageList, setStageList] = useState([true, false, false])
- const [isStageMode, setIsStageMode] = useState(false)
- let navigation;
- if (useNavigation) {
- navigation = useNavigation()
- }
- useEffect(() => {
- setRecord(props.data.current_record)
- currentRecordTemp = props.data.current_record
- }, [props.data])
- useEffect(() => {
- if (props.type == 'FAST_SLEEP') {
- global.updateMixItem = (data) => {
- setStageList(data)
- }
- global.changeMixIndex = (index) => {
- setIsStageMode(index == 1)
- }
- }
- }, [])
- function durationArc(start_time: number, end_time: number) {
- var duration = (end_time - start_time) / 1000;
- return duration / (24 * 3600) * 2 * Math.PI;
- }
- const startArc = (time: number) => {
- var date = new Date(time);
- var hour = date.getHours();
- var minute = date.getMinutes();
- var second = date.getSeconds();
- return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
- }
- function bigRing() {
- var common = getCommon(null, true)
- common.radius = 42;
- common.lineWidth = 9;
- var bgRing = getBgRing()
- 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(props.data.scenario, props.type != 'SLEEP', true, true)//getSchedule(record, props.type != 'SLEEP', true)
- var list: any = []
- if (props.type == 'FAST_SLEEP') {
- realRing1.color = ColorType.fast + '66'
- if (dotIsOuterRange(true, record.fast)) {
- currentDot1.color = ColorType.ring
- }
- var detail = timeTotimestamp(props.data.scenario)
- if (stageList[0]) {
- const realRingBig: RealRing = {
- color: global.fastColor ? global.fastColor : ColorType.fast,
- startArc: startArc(detail.fast.target_start_time),
- durationArc: durationArc(detail.fast.target_start_time, detail.sleep.target_start_time)
- }
- list.push(realRingBig)
- }
- if (stageList[1]) {
- const realRingBig: RealRing = {
- color: global.fastColor ? global.fastColor : ColorType.fast,
- startArc: startArc(detail.sleep.target_start_time),
- durationArc: durationArc(detail.sleep.target_start_time, detail.sleep.target_end_time)
- }
- list.push(realRingBig)
- }
- if (stageList[2]) {
- const realRingBig: RealRing = {
- color: global.fastColor ? global.fastColor : ColorType.fast,
- startArc: startArc(detail.sleep.target_end_time),
- durationArc: durationArc(detail.sleep.target_end_time, detail.fast.target_end_time)
- }
- list.push(realRingBig)
- }
- }
- if (!isStageMode) {
- list = []
- }
- return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot1} stageList={list} 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() {
- 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') {
- var targetBigRing1 = getTarget(record, false)
- targetBigRing1.color = ColorType.sleep + '66'
- var currentDot = getDot(record, false)
- realRing.durationArc = durationArc(record.sleep.target_start_time, (new Date()).getTime())
- return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + props.time + 'small'} targetRing={targetBigRing1} realRing={realRing} />
- }
- else if (record.status == 'WAIT_FOR_START' || record.status == 'ONGOING1') {
- realRing = getSchedule(props.data.scenario, false, true, true)//getSchedule(record, false, true)
- var currentDot = getDot(record, false)
- if (dotIsOuterRange(true, record.sleep)) {
- currentDot.color = ColorType.ring
- }
- return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot} realRing={realRing} canvasId={props.type + props.time + 'small'} />
- }
- else if (record.sleep.status == 'NOT_COMPLETED') {
- realRing.durationArc = 0.01
- var currentDot = getDot(record, false)
- return <Rings common={common} bgRing={bgRing} currentDot={currentDot} 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} />
- }
- else if (record.sleep.status == 'ONGOING2') {
- var currentDot = getDot(record, false)
- return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + props.time + 'small'} />
- }
- 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'} />
- }
- }
- function dayRing() {
- var common = getCommon(null, true)
- common.radius = 56;
- common.lineWidth = 9;
- var bgRing = getBgRing()
- const realRingBig: RealRing = {
- color: ColorType.night + '66',
- startArc: 0,
- durationArc: 2
- }
- var sunRise = 24 * 60 + 6 * 60
- var sunSet = 18 * 60
- if (dayNight.gpsInfo && user.test_user) {
- var sunRiseObj = dayNight.gpsInfo.daylights[0].sunrise
- var sunSetObj = dayNight.gpsInfo.daylights[0].sunset
- sunRise = 24 * 60 + parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
- sunSet = parseInt(sunSetObj.split(':')[0]) * 60 + parseInt(sunSetObj.split(':')[1])
- if (sunSetObj.indexOf('PM') != -1) {
- sunSet += 12 * 60
- }
- }
- var duration = sunRise - sunSet
- realRingBig.startArc = (sunSet * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
- realRingBig.durationArc = (duration * 60) / (24 * 3600) * 2 * Math.PI;
- var currentDot = getDot(record, false)
- if (dotIsOuterRange(false, null, { sunrise: dayNight.sunRise, sunset: dayNight.sunSet })) {
- currentDot.color = ColorType.ring
- }
- else {
- currentDot.color = ColorType.night + '66'
- }
- return <Rings common={common} bgRing={bgRing} realRing={realRingBig} currentDot={currentDot} canvasId={props.type + props.time + 'day'} />
- }
- 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>
- }
- {
- props.type == 'FAST_SLEEP' && !props.showStage && user.isLogin && global.showNightRing === true && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
- {
- dayRing()
- }
- </View>
- }
- </View>
- }
- 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(), false)
- }
- if (isStageMode && record.scenario == 'FAST_SLEEP') {
- if (stageList[0]) {
- return TimeFormatter.durationFormate(record.fast.target_start_time, record.sleep.target_start_time)
- }
- if (stageList[1]) {
- return TimeFormatter.durationFormate(record.sleep.target_start_time, record.sleep.target_end_time)
- }
- if (stageList[2]) {
- return TimeFormatter.durationFormate(record.sleep.target_end_time, record.fast.target_end_time)
- }
- }
- return getDuration(record.fast)
- }
- function sleepDuration() {
- if (record.sleep.status == 'WAIT_FOR_END') {
- return TimeFormatter.formateTimeDifference(record.sleep.real_start_time, new Date().getTime(), false)
- }
- return getDuration(record.sleep)
- }
- function goClock() {
- if (!user.isLogin) {
- jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
- return
- }
- if (props.showStage) {
- return
- }
- var node = schedules()
- global.showIndexModal3(true, node, null);
- popTimer = setInterval(() => {
- var node = schedules()
- global.showIndexModal3(true, node, null);
- }, 1000)
- global.popTimer = popTimer
- }
- function nightDuration() {
- if (dayNight.gpsInfo && dayNight.isMember) {
- var sunRiseObj = dayNight.gpsInfo.daylights[0].sunrise
- var sunSetObj = dayNight.gpsInfo.daylights[0].sunset
- var sunRise = 24 * 60 + parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
- var sunSet = parseInt(sunSetObj.split(':')[0]) * 60 + parseInt(sunSetObj.split(':')[1])
- if (sunSetObj.indexOf('PM') != -1) {
- sunSet += 12 * 60
- }
- var duration = (sunRise - sunSet) * 60 * 1000
- return TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + duration);
- } else {
- return '12小时'
- }
- }
- function schedules() {
- var timestamp = new Date().getTime()//props.data.first_real_check_time
- return <View style={{ display: 'flex', flexDirection: 'column' }}>
- <TimelineStage data={currentRecordTemp} title={t('feature.track_time_duration.record_fast_sleep.pop_title')}
- subTitle='今天' first_real_check_time={timestamp} />
- </View>
- }
- function fastPicker() {
- var node = schedules()
- global.showIndexModal2(true, node, null);
- popTimer = setInterval(() => {
- var node = schedules()
- global.showIndexModal2(true, node, null);
- }, 1000)
- global.popTimer = popTimer
- }
- function sleepPicker(e) {
- if (record.status == 'ONGOING3') {
- return;
- }
- if (record.status == 'WAIT_FOR_START') {
- Taro.showToast({
- title: t('feature.track_time_duration.common.start_fasting_first'),
- icon: 'none'
- })
- return;
- }
- var node = schedules()
- global.showIndexModal2(true, node, null);
- popTimer = setInterval(() => {
- var node = schedules()
- global.showIndexModal2(true, node, null);
- }, 1000)
- global.popTimer = popTimer
- }
- return <View className="time_operate_item">
- <View className="fast_sleep_item">
- {
- rings()
- }
- <View className="duration_bg">
- {
- props.type == 'FAST_SLEEP' && !props.showStage && user.isLogin && global.showNightRing === true &&
- <Text className="duration_title">{t('feature.common.overnight')}</Text>
- }
- {
- props.type == 'FAST_SLEEP' && !props.showStage && user.isLogin && global.showNightRing === true &&
- <Text className="duration_value" style={{ color: ColorType.night }}>{nightDuration()}</Text>
- }
- {
- (props.type == 'FAST' || props.type == 'FAST_SLEEP') && <Text className="duration_title" onClick={fastPicker}>{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
- }
- {
- (props.type == 'FAST' || props.type == 'FAST_SLEEP') && <Text className="duration_value" onClick={fastPicker} style={{ color: global.fastColor ? global.fastColor : ColorType.fast }}>{fastDuration()}</Text>
- }
- {
- (props.type == 'SLEEP' || props.type == 'FAST_SLEEP') && <Text className="duration_title" onClick={sleepPicker}>{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
- }
- {
- (props.type == 'SLEEP' || props.type == 'FAST_SLEEP') && <Text className="duration_value" onClick={sleepPicker} 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' }} onClick={goClock}>
- <View style={{ flex: 1 }} />
- {/* <Text className='recordTime'>{getArrowText()}</Text> */}
- <Image className="arrow2" src={require('@/assets/images/arrow3.png')} />
- </View>
- {/* <t-popup></t-popup> */}
- </View>
- </View>
- }
|