Leon vor 1 Jahr
Ursprung
Commit
d73862bb7f

+ 31 - 17
src/features/trackSomething/components/DayNightCard.tsx

@@ -45,17 +45,11 @@ export default function DayNightCard(props: { isNight: boolean, count: number })
     const user = useSelector((state: any) => state.user);
     const dayStore = useSelector((state: any) => state.day);
     const nightStore = useSelector((state: any) => state.night);
-    const [authInfo, setAuthInfo] = useState(global.locationDetail?global.locationDetail:null)
+    const [authInfo, setAuthInfo] = useState(global.locationDetail ? global.locationDetail : null)
     const [sunriseTime, setSunriseTime] = useState('06:00')
     const [sunriseTmrTime, setSunriseTmrTime] = useState('06:00')
     const [sunsetTime, setSunsetTime] = useState('18:00')
 
-    if (!props.isNight){
-        console.log('aaassss')
-    }
-
-
-
     const [sunriseDate, setSunriseDate] = useState<any>(sunriseA)
     const [sunriseTmrDate, setSunriseTmrDate] = useState<any>(new Date(sunriseB.getTime() + 24 * 3600 * 1000))
     const [sunsetDate, setSunsetDate] = useState<any>(sunsetA)
@@ -74,10 +68,10 @@ export default function DayNightCard(props: { isNight: boolean, count: number })
     }
 
     useEffect(() => {
-        
-        
+
+
         if (user.isLogin) {
-            if (global.locationDetail){
+            if (global.locationDetail) {
                 locationDetail = global.locationDetail
                 setAuthInfo(locationDetail)
             }
@@ -100,6 +94,13 @@ export default function DayNightCard(props: { isNight: boolean, count: number })
                 })
             })
 
+        } else {
+            setSunriseTime('06:00');
+            setSunriseTmrTime('06:00')
+            setSunsetTime('18:00')
+            setSunriseDate(sunriseA)
+            setSunriseTmrDate(new Date(sunriseB.getTime() + 24 * 3600 * 1000))
+            setSunsetDate(sunsetA)
         }
     }, [user.isLogin])
 
@@ -312,8 +313,16 @@ export default function DayNightCard(props: { isNight: boolean, count: number })
                 var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
                 var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
                 var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
-
-                systemLocation({ lat: res.latitude, lng: res.longitude, date_start: strYesterday, date_end: strTomorrow }).then(data => {
+                console.log(res)
+                systemLocation({
+                    lat: res.latitude,
+                    lng: res.longitude,
+                    name: res.name,
+                    address: res.address,
+                    date_start: strYesterday,
+                    date_end: strTomorrow,
+                    coordinate_system_standard:'GCJ-02'
+                }).then(data => {
                     updateDate(data);
                     locationDetail = data;
                     global.locationDetail = locationDetail
@@ -667,18 +676,23 @@ export default function DayNightCard(props: { isNight: boolean, count: number })
                         onChange={(e) => {
                             e.stopPropagation()
                             // setExpand(e.detail.value)
-                            if (props.isNight) {
+                            // if (props.isNight) {
                                 dispatch(showNight(e.detail.value))
-                            }
-                            else {
+                            // }
+                            // else {
                                 dispatch(showDay(e.detail.value))
-                            }
+                            // }
 
 
                             Taro.setStorage({
-                                key: props.isNight ? 'showNightRing' : 'showDayRing',
+                                key:  'showNightRing',
+                                data: e.detail.value
+                            })
+                            Taro.setStorage({
+                                key:  'showDayRing',
                                 data: e.detail.value
                             })
+                            
 
                             if (user.isLogin) {
                                 if (props.isNight) {

+ 16 - 10
src/features/trackTimeDuration/components/CircadianDetailPopup.tsx

@@ -102,12 +102,12 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
 
     function getTitle() {
         if (props.record.status == 'COMPLETED') {
-            return TimeFormatter.getDayOfWeek(new Date().getDay(),true)
+            return TimeFormatter.getDayOfWeek(new Date().getDay(), true)
         }
         return 'Schedule'
     }
 
-    function getSubTitle(){
+    function getSubTitle() {
         if (props.record.status == 'COMPLETED') {
             return TimeFormatter.getMonthAndDayByTimestamp(props.record.first_real_check_time)
         }
@@ -219,6 +219,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
     function tapDuration(isFast: boolean) {
         if (isFast) {
             setIsFast(true)
+            global.pauseIndexTimer = true
             if (props.record.status == 'WAIT_FOR_START') {
                 setShowDurationPicker(true)
             }
@@ -228,13 +229,14 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
         }
         else {
             setIsFast(false)
-            if (props.record.status == 'WAIT_FOR_START') {
+            if (props.record.status == 'WAIT_FOR_START' && props.record.scenario == 'FAST_SLEEP') {
                 Taro.showToast({
                     title: t('feature.track_time_duration.common.start_fasting_first'),
                     icon: 'none'
                 })
                 return;
             }
+            global.pauseIndexTimer = true
             if (props.record.status == 'WAIT_FOR_START' || props.record.status == 'ONGOING1') {
                 setShowDurationPicker(true)
             }
@@ -263,7 +265,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
 
         }
         else {
-            if (props.record.status == 'WAIT_FOR_START') {
+            if (props.record.status == 'WAIT_FOR_START' && props.record.scenario == 'FAST_SLEEP') {
                 Taro.showToast({
                     title: t('feature.track_time_duration.common.start_fasting_first'),
                     icon: 'none'
@@ -306,7 +308,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
             setFastPickerValue(durationIndex(detail.fast.target_start_time, detail.fast.target_end_time, common))
         }
         else {
-            if (props.record.status == 'WAIT_FOR_START') {
+            if (props.record.status == 'WAIT_FOR_START' && props.record.scenario == 'FAST_SLEEP') {
                 Taro.showToast({
                     title: t('feature.track_time_duration.common.start_fasting_first'),
                     icon: 'none'
@@ -341,8 +343,8 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                 <Text className='pop_duration_title'>{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
                 <View style={{ flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(8), display: 'flex', width: '100%' }}>
                     <Text onClick={() => tapDuration(true)} className='pop_duration_txt' style={{ color: ColorType.fast }}>{TimeFormatter.durationFormate(detail.fast.target_start_time, detail.fast.target_end_time)}</Text>
-                    <View onClick={() => tapMinus(true)} className='minus' style={{ backgroundColor: ColorType.fast, opacity: 0.6 }}><IconMinus color='#090909'/></View>
-                    <View onClick={() => tapPlus(true)} className='plus' style={{ backgroundColor: ColorType.fast }}><IconPlus color='#090909'/></View>
+                    <View onClick={() => tapMinus(true)} className='minus' style={{ backgroundColor: ColorType.fast, opacity: 0.6 }}><IconMinus color='#090909' /></View>
+                    <View onClick={() => tapPlus(true)} className='plus' style={{ backgroundColor: ColorType.fast }}><IconPlus color='#090909' /></View>
                 </View>
             </View>
         }
@@ -382,8 +384,8 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                 <Text className='pop_duration_title'>{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
                 <View style={{ flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(8), display: 'flex', width: '100%' }}>
                     <Text onClick={() => tapDuration(false)} className='pop_duration_txt' style={{ color: ColorType.sleep }}>{TimeFormatter.durationFormate(detail.sleep.target_start_time, detail.sleep.target_end_time)}</Text>
-                    <View onClick={() => tapMinus(false)} className='minus' style={{ backgroundColor: ColorType.sleep, opacity: 0.6 }}><IconMinus color='#090909'/></View>
-                    <View onClick={() => tapPlus(false)} className='plus' style={{ backgroundColor: ColorType.sleep }}><IconPlus color='#090909'/></View>
+                    <View onClick={() => tapMinus(false)} className='minus' style={{ backgroundColor: ColorType.sleep, opacity: 0.6 }}><IconMinus color='#090909' /></View>
+                    <View onClick={() => tapPlus(false)} className='plus' style={{ backgroundColor: ColorType.sleep }}><IconPlus color='#090909' /></View>
                 </View>
             </View>
         }
@@ -506,6 +508,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                 showBtns={true}
                 onCancel={() => {
                     setShowDurationPicker(false)
+                    global.pauseIndexTimer = false
                 }} />
         </View>
     }
@@ -522,11 +525,13 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                 showBtns={true}
                 onCancel={() => {
                     setShowEditPicker(false)
+                    global.pauseIndexTimer = false
                 }} />
         </View>
     }
 
     function durationChange(e) {
+        global.pauseIndexTimer = false
         // debugger
         var count = (e[0] + common.duration.min) * 60 + e[1] * common.duration.step
         // var count = (e[0] + 1) * 60 + e[1] * 5
@@ -576,6 +581,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                     dismiss={() => {
                         setShowDurationPicker(false)
                         setShowEditPicker(false)
+                        global.pauseIndexTimer = false
                     }}
                     confirm={() => { }}>
                     {
@@ -597,7 +603,7 @@ export default function CircadianDetailPopup(props: { record: any, schedule?: an
                     }}
                     onClick={() => { alert('b') }}
                     onClickOverlay={() => { alert('a') }}
-                    onAfterLeave={() => { setShowDurationPicker(false); setShowEditPicker(false) }}
+                    onAfterLeave={() => { setShowDurationPicker(false); setShowEditPicker(false);global.pauseIndexTimer = false }}
                     show={showDurationPicker} round={true} overlay={true} position='bottom'
                 >
                     {

+ 169 - 37
src/features/trackTimeDuration/components/Discovery.tsx

@@ -2,7 +2,7 @@ import { View, Text, Image, Switch } from "@tarojs/components";
 import { bigRingRadius, dotIsOuterRange, getBgRing, getCommon, getDot, getReal, getSchedule, getTarget, ringWidth, smallRingRadius, thirdRingRadius } from "@/features/trackTimeDuration/hooks/RingData";
 import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
 import { ColorType } from "@/context/themes/color";
-import { useSelector } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
 import Rings from "@/features/trackTimeDuration/components/Rings";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import { rpxToPx } from "@/utils/tools";
@@ -15,6 +15,7 @@ import { getPerm, uploadPerm } from "@/services/user";
 import Box from "@/components/layout/Box";
 import { getPlans } from "@/services/trackTimeDuration";
 import DayNightCard from "@/features/trackSomething/components/DayNightCard";
+import { clearDayStore } from "@/store/day";
 
 
 let useNavigation;
@@ -26,10 +27,12 @@ let pauseTimer = false
 
 export default function Discovery() {
     const user = useSelector((state: any) => state.user);
-    const dayNight = useSelector((state: any) => state.day);
+    const day = useSelector((state: any) => state.day);
+    const ring = useSelector((state: any) => state.ring);
     const [schedule, setSchedule] = useState(null)
     const [count, setCount] = useState(0)
-    const [loaded,setLoaded] = useState(false)
+    const [loaded, setLoaded] = useState(false)
+    const dispatch = useDispatch();
     const { t } = useTranslation()
 
     let navigation;
@@ -37,12 +40,11 @@ export default function Discovery() {
     if (useNavigation) {
         navigation = useNavigation()
     }
-    console.log('discovery')
 
     useEffect(() => {
 
         setInterval(() => {
-            if (global.pauseIndexTimer  || pauseTimer) {
+            if (global.pauseIndexTimer || pauseTimer) {
                 return
             }
             setCount((prevCounter) => prevCounter + 1)
@@ -51,15 +53,22 @@ export default function Discovery() {
     }, [])
 
     useDidShow(() => {
+        setCount(pre=>pre+1)
         //resume timer
         pauseTimer = false
     })
 
-    useDidHide(()=>{
+    useDidHide(() => {
         //pause timer
         pauseTimer = true
     })
 
+    useEffect(()=>{
+        if (!user.isLogin) {
+            dispatch(clearDayStore());
+        }
+    },[user.isLogin])
+
     // useEffect(() => {
     //     setSchedule(global.homeData.scenarios)
     // }, [global.homeData])
@@ -69,9 +78,13 @@ export default function Discovery() {
             setSchedule((res as any).scenarios)
             setLoaded(true)
         })
+        setCount(pre=>pre+1)
     }, [user.isLogin])
 
     function getFoodTime() {
+        if (ring.schedule) {
+            return [ring.schedule.fast.end_time, ring.schedule.fast.start_time]
+        }
         var obj;
         (schedule as any).map(item => {
             if (item.name == 'FAST') {
@@ -86,6 +99,9 @@ export default function Discovery() {
     }
 
     function getActivityTime() {
+        if (ring.schedule) {
+            return [ring.schedule.sleep.end_time, ring.schedule.sleep.start_time]
+        }
         var obj;
         (schedule as any).map(item => {
             if (item.name == 'SLEEP') {
@@ -101,13 +117,36 @@ export default function Discovery() {
         common.lineWidth = ringWidth;
         var bgRing = getBgRing()
         const targetRing: RealRing = {
-            color: ColorType.food + '66',
+            color: (ring.current_record && ring.current_record.scenario == 'SLEEP') ? ColorType.activity + '66' : ColorType.food + '66',
             startArc: 0,
             durationArc: 2
         }
         var list = getFoodTime()
-        var start = parseInt(list[0].split(':')[0]) * 60 + parseInt(list[0].split(':')[1])
-        var end = parseInt(list[1].split(':')[0]) * 60 + parseInt(list[1].split(':')[1])
+        var start;
+        var end;
+
+        if (ring.current_record && ring.current_record.scenario == 'SLEEP') {
+            var list2 = getActivityTime()
+            start = parseInt(list2[0].split(':')[0]) * 60 + parseInt(list2[0].split(':')[1])
+            end = parseInt(list2[1].split(':')[0]) * 60 + parseInt(list2[1].split(':')[1])
+            if (ring.current_record.status != 'WAIT_FOR_START') {
+                var startDate = new Date(ring.current_record.sleep.target_start_time)
+                var endDate = new Date(ring.current_record.sleep.target_end_time)
+                end = startDate.getHours() * 60 + startDate.getMinutes()
+                start = endDate.getHours() * 60 + endDate.getMinutes()
+            }
+        }
+        else {
+            start = parseInt(list[0].split(':')[0]) * 60 + parseInt(list[0].split(':')[1])
+            end = parseInt(list[1].split(':')[0]) * 60 + parseInt(list[1].split(':')[1])
+            if (ring.current_record && ring.current_record.status != 'WAIT_FOR_START') {
+                var startDate = new Date(ring.current_record.fast.target_start_time)
+                var endDate = new Date(ring.current_record.fast.target_end_time)
+                end = startDate.getHours() * 60 + startDate.getMinutes()
+                start = endDate.getHours() * 60 + endDate.getMinutes()
+            }
+        }
+
         if (end < start) {
             end += 24 * 60
         }
@@ -143,7 +182,11 @@ export default function Discovery() {
             realRing = null
         }
 
-        return <Rings common={common} bgRing={bgRing} targetRing={targetRing} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_big'} />
+        if (ring.current_record.status == 'ONGOING1') {
+            realRing = null
+        }
+
+        return <Rings common={common} bgRing={bgRing} targetRing={targetRing} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={'day_big'} />
     }
     function smallRing() {
         var common = getCommon(null, false)
@@ -158,6 +201,45 @@ export default function Discovery() {
         var list = getActivityTime()
         var start = parseInt(list[0].split(':')[0]) * 60 + parseInt(list[0].split(':')[1])
         var end = parseInt(list[1].split(':')[0]) * 60 + parseInt(list[1].split(':')[1])
+        if (ring.current_record) {
+            if (ring.current_record.scenario == 'SLEEP') {
+                if (ring.current_record.status == 'ONGOING') {
+                    var startDate = new Date(ring.current_record.sleep.target_start_time)
+                    var endDate = new Date(ring.current_record.sleep.target_end_time)
+                    end = startDate.getHours() * 60 + startDate.getMinutes()
+                    start = endDate.getHours() * 60 + endDate.getMinutes()
+                }
+            }
+            else {
+                if (ring.current_record.status == 'ONGOING2') {
+                    var startDate = new Date(ring.current_record.sleep.target_start_time)
+                    var endDate = new Date(ring.current_record.sleep.target_end_time)
+                    end = startDate.getHours() * 60 + startDate.getMinutes()
+                    start = endDate.getHours() * 60 + endDate.getMinutes()
+                }
+                else if (ring.current_record.status == 'ONGOING3') {
+                    //睡眠已完成时,睡眠小于24小时,使用真实的real_end_time-real_start_time
+                    //大于24小时,使用real_end_time+sleep_duration
+                    if (ring.current_record.sleep.real_end_time - ring.current_record.sleep.real_start_time < 24 * 3600 * 1000) {
+                        var startDate = new Date(ring.current_record.sleep.real_start_time)
+                        var endDate = new Date(ring.current_record.sleep.real_end_time)
+                        end = startDate.getHours() * 60 + startDate.getMinutes()
+                        start = endDate.getHours() * 60 + endDate.getMinutes()
+                    }
+                    else {
+                        var startDate = new Date(ring.current_record.sleep.real_end_time)
+                        var durationTemp = end - start//ring.current_record.sleep.target_end_time-ring.current_record.sleep.target_start_time
+                        if (durationTemp < 0) {
+                            durationTemp += 24 * 60
+                        }
+                        var endDate = new Date(startDate.getTime() + durationTemp * 60 * 1000)
+                        start = startDate.getHours() * 60 + startDate.getMinutes()
+                        end = endDate.getHours() * 60 + endDate.getMinutes()
+                    }
+                }
+            }
+
+        }
         if (end < start) {
             end += 24 * 60
         }
@@ -192,7 +274,11 @@ export default function Discovery() {
             realRing = null
         }
 
-        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_small'} />
+        if (ring.current_record.status == 'ONGOING2') {
+            realRing = null
+        }
+
+        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={'day_small'} />
     }
     function dayRing() {
         var common = getCommon(null, true)
@@ -210,8 +296,8 @@ export default function Discovery() {
 
 
 
-        var sunRiseObj = dayNight.dayRingSunrise
-        var sunSetObj = dayNight.dayRingSunset
+        var sunRiseObj = day.dayRingSunrise
+        var sunSetObj = day.dayRingSunset
         sunRise = parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
         sunSet = parseInt(sunSetObj.split(':')[0]) * 60 + parseInt(sunSetObj.split(':')[1])
 
@@ -242,8 +328,8 @@ export default function Discovery() {
             startArc: (sunRise * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0,
             durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
-        if (dayNight.dayRingDate) {
-            if (new Date(dayNight.dayRingDate).getDate() != new Date().getDate()) {
+        if (day.dayRingDate) {
+            if (new Date(day.dayRingDate).getDate() != new Date().getDate()) {
                 realRing = null;
             }
         }
@@ -253,7 +339,7 @@ export default function Discovery() {
             realRing = null
         }
 
-        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_day'} />
+        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={'day_day'} />
     }
 
     function goAcitivity() {
@@ -273,8 +359,8 @@ export default function Discovery() {
     }
 
     function dayDuration() {
-        var sunRiseObj = dayNight.dayRingSunrise
-        var sunSetObj = dayNight.dayRingSunset
+        var sunRiseObj = day.dayRingSunrise
+        var sunSetObj = day.dayRingSunset
         var sunRise = 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) {
@@ -290,6 +376,12 @@ export default function Discovery() {
         var list = getFoodTime()
         var start = parseInt(list[0].split(':')[0]) * 60 + parseInt(list[0].split(':')[1])
         var end = parseInt(list[1].split(':')[0]) * 60 + parseInt(list[1].split(':')[1])
+        if (ring.current_record && ring.current_record.status != 'WAIT_FOR_START' && ring.current_record.scenario != 'SLEEP') {
+            var startDate = new Date(ring.current_record.fast.target_start_time)
+            var endDate = new Date(ring.current_record.fast.target_end_time)
+            end = startDate.getHours() * 60 + startDate.getMinutes()
+            start = endDate.getHours() * 60 + endDate.getMinutes()
+        }
         if (end < start) {
             end += 24 * 60
         }
@@ -299,32 +391,72 @@ export default function Discovery() {
 
     function activityDuration() {
         var list = getActivityTime()
-        var start = parseInt(list[0].split(':')[0]) * 60 + parseInt(list[0].split(':')[1])
-        var end = parseInt(list[1].split(':')[0]) * 60 + parseInt(list[1].split(':')[1])
+        var start = parseInt(list[0].split(':')[0]) * 3600 + parseInt(list[0].split(':')[1])*60
+        var end = parseInt(list[1].split(':')[0]) * 3600 + parseInt(list[1].split(':')[1])*60
+        if (ring.current_record) {
+            if (ring.current_record.scenario == 'SLEEP') {
+                if (ring.current_record.status == 'ONGOING') {
+                    var startDate = new Date(ring.current_record.sleep.target_start_time)
+                    var endDate = new Date(ring.current_record.sleep.target_end_time)
+                    end = startDate.getHours() * 3600 + startDate.getMinutes()*60+startDate.getSeconds()
+                    start = endDate.getHours() * 3600 + endDate.getMinutes()*60+endDate.getSeconds()
+                }
+            }
+            else {
+                if (ring.current_record.status == 'ONGOING2') {
+                    var startDate = new Date(ring.current_record.sleep.target_start_time)
+                    var endDate = new Date(ring.current_record.sleep.target_end_time)
+                    end = startDate.getHours() * 3600 + startDate.getMinutes()*60+startDate.getSeconds()
+                    start = endDate.getHours() * 3600 + endDate.getMinutes()*60+endDate.getSeconds()
+                }
+                else if (ring.current_record.status == 'ONGOING3') {
+                    //睡眠已完成时,睡眠小于24小时,使用真实的real_end_time-real_start_time
+                    //大于24小时,使用real_end_time+sleep_duration
+                    if (ring.current_record.sleep.real_end_time - ring.current_record.sleep.real_start_time < 24 * 3600 * 1000) {
+                        var startDate = new Date(ring.current_record.sleep.real_start_time)
+                        var endDate = new Date(ring.current_record.sleep.real_end_time)
+                        end = startDate.getHours() * 3600 + startDate.getMinutes()*60+startDate.getSeconds()
+                        start = endDate.getHours() * 3600 + endDate.getMinutes()*60+endDate.getSeconds()
+                    }
+                    else {
+                        var startDate = new Date(ring.current_record.sleep.real_end_time)
+                        var durationTemp = start - end//ring.current_record.sleep.target_end_time-ring.current_record.sleep.target_start_time
+                        if (durationTemp < 0) {
+                            durationTemp += 24 * 3600
+                        }
+                        var endDate = new Date(startDate.getTime() + durationTemp )
+                        end = startDate.getHours() * 3600 + startDate.getMinutes()*60+startDate.getSeconds()
+                        start = endDate.getHours() * 3600 + endDate.getMinutes()*60+endDate.getSeconds()
+                        console.log('active', end, start, durationTemp)
+                    }
+                }
+            }
+
+        }
         if (end < start) {
-            end += 24 * 60
+            end += 24 * 3600
         }
-        var duration = (end - start) * 60 * 1000
+        var duration = (end - start)*1000
         return TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + duration);
     }
 
     function rings() {
         return <View style={{
             position: 'relative', zIndex: 1,
-            marginLeft: dayNight.showDayRing ? -6 : 0,
+            marginLeft: day.showDayRing ? -6 : 0,
         }}>
             {
                 bigRing()
             }
             {
-                <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
+                ring.current_record && ring.current_record.scenario == 'FAST_SLEEP' && <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
                     {
                         smallRing()
                     }
                 </View>
             }
             {
-                dayNight.showDayRing && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
+                day.showDayRing && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
                     {
                         dayRing()
                     }
@@ -334,7 +466,7 @@ export default function Discovery() {
         </View>
     }
 
-    if (!loaded){
+    if (!loaded) {
         return <View />
     }
 
@@ -351,34 +483,34 @@ export default function Discovery() {
                     <View style={{
                         display: 'flex',
                         flexDirection: 'row',
-                        marginTop: dayNight.showDayRing ? -6 : 0,
-                        marginBottom: dayNight.showDayRing ? -6 : 0,
-                        padding: dayNight.showDayRing ? 14 : 0,
+                        marginTop: day.showDayRing ? -6 : 0,
+                        marginBottom: day.showDayRing ? -6 : 0,
+                        padding: day.showDayRing ? 14 : 0,
                         alignItems: 'center'
                     }}>
                         {
                             schedule && rings()
                         }
                         {schedule && <View className="duration_bg3"
-                            style={{ marginLeft: dayNight.showDayRing ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
+                            style={{ marginLeft: day.showDayRing ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
                             {
-                                dayNight.showDayRing && <Text className="duration_title2">{t('feature.common.day')}</Text>
+                                day.showDayRing && <Text className="duration_title2">{t('feature.common.day')}</Text>
                             }
                             {
-                                dayNight.showDayRing &&
+                                day.showDayRing &&
                                 <Text className="duration_value2" style={{ color: ColorType.day }}>{dayDuration()}</Text>
                             }
                             {
-                                <Text className="duration_title2">进食</Text>
+                                ring.current_record && ring.current_record.scenario != 'SLEEP' && <Text className="duration_title2">进食</Text>
                             }
                             {
-                                <Text className="duration_value2" style={{ color: ColorType.food }}>{eatDuration()}</Text>
+                                ring.current_record && ring.current_record.scenario != 'SLEEP' && <Text className="duration_value2" style={{ color: ColorType.food }}>{eatDuration()}</Text>
                             }
                             {
-                                <Text className="duration_title2">活动</Text>
+                                ring.current_record && ring.current_record.scenario != 'FAST' && <Text className="duration_title2">活动</Text>
                             }
                             {
-                                <Text className="duration_value2" style={{ color: ColorType.activity, marginBottom: 0 }}>{activityDuration()}</Text>
+                                ring.current_record && ring.current_record.scenario != 'FAST' && <Text className="duration_value2" style={{ color: ColorType.activity, marginBottom: 0 }}>{activityDuration()}</Text>
                             }
                         </View>
                         }
@@ -394,7 +526,7 @@ export default function Discovery() {
             </View>
         </Box>
 
-        <DayNightCard isNight={false} count={count}/>
+        <DayNightCard isNight={false} count={count} />
 
     </View>
 }

+ 92 - 52
src/features/trackTimeDuration/components/IndexItem.tsx

@@ -26,6 +26,7 @@ export default function Component(props: { type: string, data: any, time: any, s
     const [record, setRecord] = useState(props.data.current_record);
     const user = useSelector((state: any) => state.user);
     const dayNight = useSelector((state: any) => state.night);
+    const ring = useSelector((state: any) => state.ring);
     const [stageList, setStageList] = useState([true, false, false])
     const [isStageMode, setIsStageMode] = useState(false)
     const [showDetailModal, setShowDetailModal] = useState(false)
@@ -56,7 +57,7 @@ export default function Component(props: { type: string, data: any, time: any, s
         }
     }, [])
 
-    
+
     function durationArc(start_time: number, end_time: number) {
         var duration = (end_time - start_time) / 1000;
         return duration / (24 * 3600) * 2 * Math.PI;
@@ -81,23 +82,42 @@ export default function Component(props: { type: string, data: any, time: any, s
         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'} />
+            return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId={props.type + 'index_big'} />
         }
         if (record.status == 'WAIT_FOR_START') {
             var scenario = JSON.parse(JSON.stringify(props.data.scenario))
-            var countduration = (props.data.current_record.fast.target_end_time-props.data.current_record.fast.target_start_time)/60000
-            var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.start_time)/60
-            var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.end_time)/60
-            var leftMinutes = min1<min2?min2-min1:min2+24*60-min1
-            if (leftMinutes != countduration) {
-                min2 = min1+countduration
-                if (min2>1440){
-                    min2 -=1440
+
+            if (scenario.name == 'SLEEP') {
+                var countduration = (props.data.current_record.sleep.target_end_time - props.data.current_record.sleep.target_start_time) / 60000
+                var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.start_time) / 60
+                var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.end_time) / 60
+                var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
+                if (leftMinutes != countduration) {
+                    min2 = min1 + countduration
+                    if (min2 > 1440) {
+                        min2 -= 1440
+                    }
+                    var hour = Math.floor(min2 / 60)
+                    var minute = min2 % 60
+                    scenario.schedule.sleep.end_time = `${hour}:${minute}`
+                }
+            }
+            else {
+                var countduration = (props.data.current_record.fast.target_end_time - props.data.current_record.fast.target_start_time) / 60000
+                var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.start_time) / 60
+                var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.fast.end_time) / 60
+                var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
+                if (leftMinutes != countduration) {
+                    min2 = min1 + countduration
+                    if (min2 > 1440) {
+                        min2 -= 1440
+                    }
+                    var hour = Math.floor(min2 / 60)
+                    var minute = min2 % 60
+                    scenario.schedule.fast.end_time = `${hour}:${minute}`
                 }
-                var hour = Math.floor(min2/60)
-                var minute = min2%60
-                scenario.schedule.fast.end_time = `${hour}:${minute}`
             }
+
             var realRing1 = getSchedule(scenario, scenario.name != 'SLEEP', true, true)//getSchedule(record, props.type != 'SLEEP', true)
             var list: any = []
             if (scenario.name == 'FAST_SLEEP') {
@@ -144,14 +164,14 @@ export default function Component(props: { type: string, data: any, time: any, s
             if (user.isLogin) {
                 list = []
             }
-            if (!user.isLogin){
+            if (!user.isLogin) {
                 currentDot1 = null
                 // realRing1 = null
             }
-            return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot1} stageList={list} realRing={realRing1} canvasId={props.type + props.time + 'big'} />
+            return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot1} stageList={list} realRing={realRing1} canvasId={props.type + 'index_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'} />
+        return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId={props.type + 'index_big'} />
 
     }
 
@@ -171,38 +191,57 @@ export default function Component(props: { type: string, data: any, time: any, s
                 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} />
+                return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + 'index_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 scenario = JSON.parse(JSON.stringify(props.data.scenario))
+                if (record.status == 'ONGOING1') {
+                    var countduration = (props.data.current_record.sleep.target_end_time - props.data.current_record.sleep.target_start_time) / 60000
+                    var min1 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.start_time) / 60
+                    var min2 = TimeFormatter.timestringToSeconds(scenario.schedule.sleep.end_time) / 60
+                    var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
+                    if (leftMinutes != countduration) {
+                        min2 = min1 + countduration
+                        if (min2 > 1440) {
+                            min2 -= 1440
+                        }
+                        var hour = Math.floor(min2 / 60)
+                        var minute = min2 % 60
+                        scenario.schedule.sleep.end_time = `${hour}:${minute}`
+                    }
+                }
+
+
+                realRing = getSchedule(scenario, false, true, true)//getSchedule(record, false, true)
 
                 realRing.color = ColorType.sleep + '66'
 
                 var currentDot = getDot(record, false)
-                if (!user.isLogin){
+                if (!user.isLogin) {
                     currentDot = null
                 }
 
-                return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot} realRing={realRing} canvasId={props.type + props.time + 'small'} />
+                return <Rings common={common} bgRing={bgRing} currentDot={isStageMode ? null : currentDot} realRing={realRing} canvasId={props.type + 'index_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} />
+                return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + 'index_small'} realRing={realRing} />
             }
             else if (record.sleep.status == 'COMPLETED') {
                 realRing = getReal(record, false, true)
                 var currentDot = getDot(record, false)
-                if (record.status == 'ONGOING3'){
+                if (record.status == 'ONGOING3') {
                     currentDot.color = '#ffffffff'
                 }
-                return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + props.time + 'small'} realRing={realRing} />
+                return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + 'index_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} currentDot={currentDot} canvasId={props.type + 'index_small'} />
             }
-            return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} />
+            return <Rings common={common} bgRing={bgRing} canvasId={props.type + 'index_small'} />
         }
         else {
 
@@ -211,12 +250,12 @@ export default function Component(props: { type: string, data: any, time: any, s
             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'} />
+                return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId={props.type + 'index_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 <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + 'index_small'} />
         }
 
     }
@@ -263,20 +302,20 @@ export default function Component(props: { type: string, data: any, time: any, s
             durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
 
-        if (dayNight.nightRingDate){
-            if (new Date(dayNight.nightRingDate).getDate()== new Date().getDate() && new Date().getHours()<12){
-                
+        if (dayNight.nightRingDate) {
+            if (new Date(dayNight.nightRingDate).getDate() == new Date().getDate() && new Date().getHours() < 12) {
+
                 realRing = null;
             }
         }
 
-        if (!user.isLogin){
+        if (!user.isLogin) {
             currentDot = null;
             realRing = null;
         }
 
 
-        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 > duration ? null : realRing} currentDot={currentDot} canvasId={props.type + props.time + 'day'} />
+        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 > duration ? null : realRing} currentDot={currentDot} canvasId={props.type + 'index_day'} />
     }
 
     function rings() {
@@ -328,21 +367,22 @@ export default function Component(props: { type: string, data: any, time: any, s
         if (!record.fast) {
             return ''
         }
-        if (!user.isLogin){
+        if (!user.isLogin) {
             var count = 0
-            if (stageList[0]){
-                count += 6
+            if (stageList[0]) {
+
+                count = record.sleep.target_start_time - record.fast.target_start_time
             }
-            if (stageList[1]){
-                count+=8
+            if (stageList[1]) {
+                count += record.sleep.target_end_time - record.sleep.target_start_time
             }
-            if (stageList[2]){
-                count+=2
+            if (stageList[2]) {
+                count += record.fast.target_end_time - record.sleep.target_end_time
             }
-            if (count == 0){
+            if (count == 0) {
                 return t('feature.track_time_duration.stage.no_stage_selected')
             }
-            return `${count}小时`
+            return TimeFormatter.durationFormate(new Date().getTime(), new Date().getTime()+count)//`${count}小时`
         }
         if (record.fast.status == 'WAIT_FOR_END') {
             return TimeFormatter.countdown(record.fast.real_start_time)
@@ -374,17 +414,17 @@ export default function Component(props: { type: string, data: any, time: any, s
 
     function nightDuration() {
 
-            var sunRiseObj = dayNight.nightRingSunrise
-            var sunSetObj = dayNight.nightRingSunset
-            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 sunRiseObj = dayNight.nightRingSunrise
+        var sunSetObj = dayNight.nightRingSunset
+        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
+        var duration = (sunRise - sunSet) * 60 * 1000
 
-            return TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + duration);
+        return TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + duration);
     }
 
 
@@ -430,7 +470,7 @@ export default function Component(props: { type: string, data: any, time: any, s
                 }}
                 onClick={() => { alert('b') }}
                 onClickOverlay={() => { alert('a') }}
-                onAfterLeave={() => { setShowDetailModal(false);global.pauseIndexTimer = false; }}
+                onAfterLeave={() => { setShowDetailModal(false); global.pauseIndexTimer = false; }}
                 show={showDetailModal} round={true} overlay={true} position='bottom'
             >
                 {
@@ -456,7 +496,7 @@ export default function Component(props: { type: string, data: any, time: any, s
                 marginLeft: !props.showStage && dayNight.showNightRing === true ? -6 : 0,
                 padding: !props.showStage && dayNight.showNightRing === true ? 14 : 0,
                 paddingRight: 0,
-                
+
             }}>
                 {
                     rings()

+ 6 - 0
src/features/trackTimeDuration/components/Rings.weapp.tsx

@@ -119,13 +119,19 @@ export default function Rings(props: {
 
     
 
+    var retryCount = 0;
     function drawCircle() {
         
         const query = Taro.createSelectorQuery();
         query.select(`.${canvasId}`).fields({ node: true, size: true });
         query.exec((res) => {
             if (res[0] == null) {
+                retryCount++;
+                if (retryCount>5){
+                    return;
+                }
                 drawCircle()
+                // console.log(canvasId)
                 return;
             }
             const _canvas = res[0].node;

+ 36 - 2
src/features/trackTimeDuration/components/StageSelector.scss

@@ -4,13 +4,17 @@
     margin-bottom: 32px;
     height: 88px;
     border-radius: 44px;
-    border: solid 2px $fastColor;
     box-sizing: border-box;
     display: flex;
     flex-direction: row;
     align-items: center;
     padding-left: 44px;
     padding-right: 44px;
+
+    color: #fff;
+    border-width: 2px;
+    border-style: solid;
+    border-color: #fff;
     opacity: 0.4;
 }
 
@@ -19,7 +23,6 @@
     height: 88px;
     border-radius: 44px;
     border: solid 2px $fastColor;
-    // background-color: $fastColor;
     display: flex;
     flex-direction: row;
     align-items: center;
@@ -27,13 +30,44 @@
     padding-right: 44px;
     box-sizing: border-box;
     opacity: 1;
+
+    
+
+
+
+
+}
+
+
+/*
+.stage_btn {
+    height: 88px;
+    border-radius: 44px;
+    position: relative;
+    // margin-left: 46px;
+    // margin-right: 46px;
+    // margin-bottom: 36px;
+    align-items: center;
+    justify-content: center;
+    flex-direction: row;
+    display: flex;
+    color: #fff;
+    border-width: 2px;
+    border-style: solid;
+    border-color: #fff;
+    opacity: 0.4;
+    box-sizing: border-box;
+    padding-left: 44px;
+    padding-right: 44px;
 }
+*/
 
 .single_check_text_nor{
     color: $fastColor;
     font-weight: bold;
     font-size: 32px;
     flex: 1;
+    color: #fff;
 }
 
 .single_check_text_sel{

+ 54 - 34
src/pages/clock/Index.tsx

@@ -7,7 +7,7 @@ import { useDispatch, useSelector } from "react-redux";
 import { useDidHide, useDidShow, useReady } from "@tarojs/taro";
 import Taro from "@tarojs/taro";
 import { getInfoSuccess } from "@/store/user";
-import { clockHome, clockSummaryRecords, clockSummaryStats, getClockRecords, getClocks } from "@/services/trackTimeDuration";
+import { clockHome, clockSummaryRecords, clockSummaryStats, getClockRecords, getClocks, getPlans } from "@/services/trackTimeDuration";
 import { updateScenario } from "@/store/time";
 import { setConfigs } from "@/store/common";
 import { setScenario, setStep } from "@/store/scenario";
@@ -36,9 +36,10 @@ import Box from "@/components/layout/Box";
 import DayNightCard from "@/features/trackSomething/components/DayNightCard";
 import StageSelector from "@/features/trackTimeDuration/components/StageSelector";
 import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
-import { showNight } from "@/store/night";
+import { clearNightStore, showNight } from "@/store/night";
 import { showDay } from "@/store/day";
 import { clientInfo } from "@/services/common";
+import { changeFastDuration, changeSleepDuration, setCurrentRecord, setSchedule } from "@/store/ring";
 
 let GradientText
 let useNavigation;
@@ -105,17 +106,16 @@ export default function Page() {
         if (user.isLogin) {
             uploadUserClient();
         }
+        else {
+            dispatch(clearNightStore());
+        }
+        
     }, [user.isLogin, time.status])
 
     useReady(async () => {
         const userData = await getStorage('userData');
         if (userData) {
             dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
-            // setTimeout(() => {
-            //     // checkWXPubFollow()
-            //     getCheckData()
-
-            // }, 200)
             getHistory()
 
 
@@ -124,6 +124,7 @@ export default function Page() {
     })
 
     useDidShow(() => {
+        setCount(pre=>pre+1)
         //resume timer
         pauseTimer = false
     })
@@ -161,8 +162,9 @@ export default function Page() {
                 system: systemInfo.system
             },
             perm: {
-                wifiEnabled: systemInfo.wifiEnabled,
-                location: systemInfo.locationAuthorized
+                wifi_enabled: systemInfo.wifiEnabled,
+                location_authorized: systemInfo.locationAuthorized,
+                location_enabled: systemInfo.locationEnabled
             }
         })
     }
@@ -180,7 +182,7 @@ export default function Page() {
         if (userData) {
             dispatch(getInfoSuccess(JSON.parse(userData)));
         }
-        getCheckData()
+        // getCheckData()
     }
 
     async function loadRNCache() {
@@ -196,36 +198,32 @@ export default function Page() {
         if (userData) {
             dispatch(getInfoSuccess(JSON.parse(userData)));
         }
-        getCheckData()
+        // getCheckData()
     }
 
 
     function getCheckData() {
-        // clockHome().then(res => {
-        //     setHomeData(res as any)
-        //     global.homeData = res
-
-        //     if (user.isLogin) {
-        //         isPause = (res as any).fast_sleep.current_record.status == 'WAIT_FOR_START'
-        //         dispatch(updateScenario((res as any).fast_sleep.current_record))
-        //         dispatch(setConfigs((res as any).time_input_schema));
-        //         dispatch(setScenario((res as any).fast_sleep.scenario));
-        //     }
-        // })
-
-        // if (!user.isLogin){
-        //     return;
-        // }
-
-        getClocks().then(res => {
-            setHomeData(res as any)
-            global.homeData = res
+        Promise.all([getClocks(), getPlans()]).then((list) => {
+            setHomeData(list[0] as any)
+            global.homeData = list[0]
+            var array = (list[1] as any).scenarios
+            var schedule = null
+            array.map(item => {
+                if (item.name == 'FAST_SLEEP') {
+                    schedule = item.schedule;
+                }
+            })
             if (user.isLogin) {
-                dispatch(updateScenario((res as any).current_record))
-                dispatch(setConfigs((res as any).time_input_schema));
-                dispatch(setScenario((res as any).scenario));
-                global.scenario = (res as any).scenario.name;
+                dispatch(updateScenario((list[0] as any).current_record))
+                dispatch(setConfigs((list[0] as any).time_input_schema));
+                dispatch(setScenario((list[0] as any).scenario));
+
+
+
+                global.scenario = (list[0] as any).scenario.name;
             }
+            dispatch(setCurrentRecord((list[0] as any).current_record))
+            dispatch(setSchedule(schedule))
             setLoaded(true)
         })
 
@@ -283,6 +281,28 @@ export default function Page() {
             setHomeData(obj)
         }
 
+        switch (data.scenario) {
+            case 'FAST':
+                if (data.status == 'WAIT_FOR_START') {
+                    dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
+                }
+                break;
+            case 'SLEEP':
+                if (data.status == 'WAIT_FOR_START') {
+                    dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
+                }
+                break;
+            case 'FAST_SLEEP':
+                if (data.status == 'WAIT_FOR_START') {
+                    dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
+                }
+                else if (data.status == 'ONGOING1') {
+                    debugger
+                    dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
+                }
+                break;
+        }
+
     }
 
     function modalContent() {

+ 13 - 2
src/store/day.tsx

@@ -28,7 +28,7 @@ const initialState: dayNightState = {
 }
 
 const dayNightSlice = createSlice({
-    name: 'day_night',
+    name: 'day',
     initialState,
     reducers: {
         showDay(state, action) {
@@ -59,8 +59,19 @@ const dayNightSlice = createSlice({
                 state.gpsInfo = gpsInfo ? gpsInfo : null
             }
         },
+        clearDayStore(state) {
+            state.sunRise = '06:00'
+            state.sunSet = '18:00'
+            state.sunRiseTomorrow = '06:00'
+            state.sunSetTomorrow = '18:00'
+            state.gpsInfo = null
+            state.dayRingSunrise = '06:00'
+            state.dayRingSunset = '18:00'
+            state.dayRingDate = 0
+            state.showDayRing = false
+        }
     }
 });
 
 export default dayNightSlice.reducer;
-export const { showDay, updateMember, setDayRingData } = dayNightSlice.actions;
+export const { showDay, updateMember, setDayRingData, clearDayStore } = dayNightSlice.actions;

+ 13 - 2
src/store/night.tsx

@@ -28,7 +28,7 @@ const initialState: dayNightState = {
 }
 
 const dayNightSlice = createSlice({
-    name: 'day_night',
+    name: 'night',
     initialState,
     reducers: {
         showNight(state, action) {
@@ -59,8 +59,19 @@ const dayNightSlice = createSlice({
                 state.gpsInfo = gpsInfo ? gpsInfo : null
             }
         },
+
+        clearNightStore(state) {
+            state.sunRise = '06:00'
+            state.sunSet = '18:00'
+            state.sunRiseTomorrow = '06:00'
+            state.sunSetTomorrow = '18:00'
+            state.nightRingSunset = '18:00'
+            state.nightRingSunrise = '06:00'
+            state.showNightRing= false
+            state.nightRingDate = 0
+        }
     }
 });
 
 export default dayNightSlice.reducer;
-export const { showNight, updateMember, setNightRingData } = dayNightSlice.actions;
+export const { showNight, updateMember, setNightRingData, clearNightStore } = dayNightSlice.actions;

+ 67 - 0
src/store/ring.tsx

@@ -0,0 +1,67 @@
+import { TimeFormatter } from "@/utils/time_format";
+import { createSlice } from "@reduxjs/toolkit";
+
+
+interface RingState {
+    // scenario: null,
+    schedule: any,
+    current_record: any,
+    // status: 'WAIT_FOR_START' //READY_FOR_ONGOING READY_FOR_ONGOING1 READY_FOR_ONGOING2
+}
+
+const initialState: RingState = {
+    // scenario: null,
+    schedule: null,
+    current_record: null,
+    // status: 'WAIT_FOR_START'
+}
+
+const ringSlice = createSlice({
+    name: 'ring',
+    initialState,
+    reducers: {
+
+        setSchedule(state, action) {
+            state.schedule = action.payload
+        },
+        setCurrentRecord(state, action) {
+            state.current_record = action.payload
+        },
+        changeFastDuration(state, action) {
+            const  duration  = action.payload
+            var countduration = duration/60000
+            var min1 = TimeFormatter.timestringToSeconds(state.schedule.fast.start_time) / 60
+            var min2 = TimeFormatter.timestringToSeconds(state.schedule.fast.end_time) / 60
+            var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
+            if (leftMinutes != countduration) {
+                min2 = min1 + countduration
+                if (min2 > 1440) {
+                    min2 -= 1440
+                }
+                var hour = Math.floor(min2 / 60)
+                var minute = min2 % 60
+                state.schedule.fast.end_time = `${hour}:${minute}`
+            }
+        },
+        changeSleepDuration(state, action) {
+            const  duration  = action.payload
+            var countduration = duration/60000
+            var min1 = TimeFormatter.timestringToSeconds(state.schedule.sleep.start_time) / 60
+            var min2 = TimeFormatter.timestringToSeconds(state.schedule.sleep.end_time) / 60
+            var leftMinutes = min1 < min2 ? min2 - min1 : min2 + 24 * 60 - min1
+            if (leftMinutes != countduration) {
+                min2 = min1 + countduration
+                if (min2 > 1440) {
+                    min2 -= 1440
+                }
+                var hour = Math.floor(min2 / 60)
+                var minute = min2 % 60
+                state.schedule.sleep.end_time = `${hour}:${minute}`
+            }
+        }
+
+    }
+});
+
+export default ringSlice.reducer;
+export const { setSchedule, setCurrentRecord, changeFastDuration, changeSleepDuration } = ringSlice.actions;

+ 3 - 1
src/store/store.tsx

@@ -10,6 +10,7 @@ import consoleReducer from './console';
 import workoutReducer from './workout';
 import dayReducer from './day';
 import nightReducer from './night';
+import ringReducer from './ring';
 
 const store = configureStore({
   reducer: {
@@ -25,7 +26,8 @@ const store = configureStore({
     console: consoleReducer,
     workout: workoutReducer,
     night: nightReducer,
-    day: dayReducer
+    day: dayReducer,
+    ring: ringReducer
   },
 });