Leon 1 year ago
parent
commit
c81c485b5b

+ 171 - 5
src/features/trackSomething/components/DayNightCard.tsx

@@ -46,9 +46,6 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
 
     useEffect(() => {
         setInterval(() => {
-            if (!expand) {
-                return
-            }
             setCount((prevCounter) => prevCounter + 1)
         }, 1000)
     }, [])
@@ -199,6 +196,20 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             now.setHours(hour)
             now.setMinutes(min)
             now.setSeconds(second)
+
+            var sunriseDate = new Date()
+            var list2 = sunriseTmrTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunriseDate.setHours(hour2)
+            sunriseDate.setMinutes(min2)
+            sunriseDate.setSeconds(second2)
+
+            if (new Date().getTime()<sunriseDate.getTime()){
+                return TimeFormatter.countdown(now.getTime()-24*3600*1000)
+            }
+
             return TimeFormatter.countdown(now.getTime())
         } else {
             var list = sunriseTime.split(':')
@@ -208,10 +219,119 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             now.setHours(hour)
             now.setMinutes(min)
             now.setSeconds(second)
+
+            var sunsetDate = new Date()
+            var list2 = sunsetTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunsetDate.setHours(hour2)
+            sunsetDate.setMinutes(min2)
+            sunsetDate.setSeconds(second2)
+            if (new Date().getTime() < sunsetDate.getTime()) {
+                return TimeFormatter.countdown(now.getTime())
+            }
+
+            var sunriseTDate = new Date()
+            var list3 = sunriseTmrTime.split(':')
+            var hour3 = parseInt(list3[0])
+            var min3 = parseInt(list3[1])
+            var second3 = list3.length == 3 ? parseInt(list3[2]) : 0
+            sunriseTDate.setHours(hour3)
+            sunriseTDate.setMinutes(min3)
+            sunriseTDate.setSeconds(second3)
+            return TimeFormatter.countdown(sunriseTDate.getTime() + 24 * 3600 * 1000)
+
+        }
+    }
+
+    function timeCount2() {
+        var now = new Date()
+        if (props.isNight) {
+            var list = sunriseTmrTime.split(':')
+            var hour = parseInt(list[0])
+            var min = parseInt(list[1])
+            var second = list.length == 3 ? parseInt(list[2]) : 0
+            now.setHours(hour)
+            now.setMinutes(min)
+            now.setSeconds(second)
+
+            var sunsetDate = new Date()
+            var list2 = sunsetTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunsetDate.setHours(hour2)
+            sunsetDate.setMinutes(min2)
+            sunsetDate.setSeconds(second2)
+            if (new Date().getTime() < sunsetDate.getTime()) {
+                return TimeFormatter.countdown(now.getTime())
+            }
+
+            return TimeFormatter.countdown(now.getTime() + 24 * 3600 * 1000)
+        } else {
+            var list = sunsetTime.split(':')
+            var hour = parseInt(list[0])
+            var min = parseInt(list[1])
+            var second = list.length == 3 ? parseInt(list[2]) : 0
+            now.setHours(hour)
+            now.setMinutes(min)
+            now.setSeconds(second)
             return TimeFormatter.countdown(now.getTime())
         }
     }
 
+    function showExtraData() {
+        var now = new Date()
+        if (props.isNight) {
+            var list = sunsetTime.split(':')
+            var hour = parseInt(list[0])
+            var min = parseInt(list[1])
+            var second = list.length == 3 ? parseInt(list[2]) : 0
+            now.setHours(hour)
+            now.setMinutes(min)
+            now.setSeconds(second)
+
+            var sunriseDate = new Date()
+            var list2 = sunriseTmrTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunriseDate.setHours(hour2)
+            sunriseDate.setMinutes(min2)
+            sunriseDate.setSeconds(second2)
+            if (sunriseDate.getTime()>new Date().getTime()){
+                return true
+            }
+
+            if (now.getTime() > new Date().getTime()) {
+                return false
+            }
+            return true
+        }
+        var list = sunriseTime.split(':')
+        var hour = parseInt(list[0])
+        var min = parseInt(list[1])
+        var second = list.length == 3 ? parseInt(list[2]) : 0
+        now.setHours(hour)
+        now.setMinutes(min)
+        now.setSeconds(second)
+
+        var sunsetDate = new Date()
+        var list2 = sunsetTime.split(':')
+        var hour2 = parseInt(list2[0])
+        var min2 = parseInt(list2[1])
+        var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+        sunsetDate.setHours(hour2)
+        sunsetDate.setMinutes(min2)
+        sunsetDate.setSeconds(second2)
+
+        if (now.getTime() < new Date().getTime() && new Date().getTime() < sunsetDate.getTime()) {
+            return true
+        }
+        return false
+    }
+
     function timeDesc() {
         var now = new Date()
         if (props.isNight) {
@@ -222,6 +342,19 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             now.setHours(hour)
             now.setMinutes(min)
             now.setSeconds(second)
+
+            var sunriseDate = new Date()
+            var list2 = sunriseTmrTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunriseDate.setHours(hour2)
+            sunriseDate.setMinutes(min2)
+            sunriseDate.setSeconds(second2)
+            if (sunriseDate.getTime()>new Date().getTime()){
+                return 'Time past Sunset'
+            }
+
             if (now.getTime() < new Date().getTime()) {
                 return 'Time past Sunset'
             }
@@ -235,6 +368,19 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             now.setHours(hour)
             now.setMinutes(min)
             now.setSeconds(second)
+
+            var sunsetDate = new Date()
+            var list2 = sunsetTime.split(':')
+            var hour2 = parseInt(list2[0])
+            var min2 = parseInt(list2[1])
+            var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
+            sunsetDate.setHours(hour2)
+            sunsetDate.setMinutes(min2)
+            sunsetDate.setSeconds(second2)
+
+            if (new Date().getTime() > sunsetDate.getTime()) {
+                return 'Time to Sunrise'
+            }
             if (now.getTime() < new Date().getTime()) {
                 return 'Time past Sunrise'
             }
@@ -242,6 +388,13 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
         }
     }
 
+    function timeDesc2() {
+        if (props.isNight) {
+            return 'Time to Sunrise'
+        }
+        return 'Time to Sunset'
+    }
+
     function clearData() {
         Taro.showModal({
             title: '提示',
@@ -352,6 +505,8 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
         }
     }
 
+
+
     return <View style={{ color: '#fff' }}>
         <Box onClick={tapCard}>
             <View>
@@ -394,8 +549,19 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                         <View style={{ display: 'flex', flexDirection: 'column' }}>
                             <Text style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? `Today ${sunsetTime} - Tomorrow ${sunriseTmrTime}` : `${sunriseTime} - ${sunsetTime}`}</Text>
                             <Text>{props.isNight ? 'Sunset to Sunrise' : 'Sunrise to Sunset'}</Text>
-                            <Text style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
-                            <Text>{timeDesc()}</Text>
+                            <View style={{ display: 'flex', flexDirection: 'row' }}>
+                                <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
+                                    <Text style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
+                                    <Text>{timeDesc()}</Text>
+                                </View>
+                                {
+                                    showExtraData() && <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
+                                        <Text style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount2()}</Text>
+                                        <Text>{timeDesc2()}</Text>
+                                    </View>
+                                }
+                            </View>
+
                         </View>
                         {
                             footer()

+ 52 - 29
src/features/trackTimeDuration/components/Discovery.tsx

@@ -44,7 +44,7 @@ export default function Discovery() {
     // }, [global.homeData])
 
     useEffect(() => {
-        getPlans().then(res=>{
+        getPlans().then(res => {
             setSchedule((res as any).scenarios)
         })
         if (user.isLogin) {
@@ -93,8 +93,8 @@ export default function Discovery() {
         common.radius = 42;
         common.lineWidth = 9;
         var bgRing = getBgRing()
-        const realRingBig: RealRing = {
-            color: ColorType.food,
+        const targetRing: RealRing = {
+            color: ColorType.food + '66',
             startArc: 0,
             durationArc: 2
         }
@@ -105,8 +105,8 @@ export default function Discovery() {
             end += 24 * 60
         }
         var duration = end - start
-        realRingBig.startArc = (start * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
-        realRingBig.durationArc = (duration * 60) / (24 * 3600) * 2 * Math.PI;
+        targetRing.startArc = (start * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
+        targetRing.durationArc = (duration * 60) / (24 * 3600) * 2 * Math.PI;
 
         var currentDot = getDot(null, false)
         var date = new Date()
@@ -115,13 +115,23 @@ export default function Discovery() {
             minutes += 1440
         }
 
-        if (start <= minutes && end > minutes) {
-            currentDot.color = ColorType.food
+        currentDot.color = ColorType.food
+
+
+        var now = new Date()
+        var t = now.getHours() * 60 + now.getMinutes()
+        var duration2 = t - start
+        if (duration2 < 0) {
+            duration2 += 24 * 60
         }
-        else {
-            currentDot.color = ColorType.ring
+
+        const realRing: RealRing = {
+            color: ColorType.food,
+            startArc: (start * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0,
+            durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
-        return <Rings common={common} bgRing={bgRing} realRing={realRingBig} currentDot={currentDot} canvasId={timeStamp + '_big'} />
+
+        return <Rings common={common} bgRing={bgRing} targetRing={targetRing} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_big'} />
     }
     function smallRing() {
         var common = getCommon(null, false)
@@ -129,7 +139,7 @@ export default function Discovery() {
         common.lineWidth = 9;
         var bgRing = getBgRing()
         const realRingBig: RealRing = {
-            color: ColorType.activity,
+            color: ColorType.activity + '66',
             startArc: 0,
             durationArc: 2
         }
@@ -150,13 +160,21 @@ export default function Discovery() {
             minutes += 1440
         }
 
-        if (start <= minutes && end > minutes) {
-            currentDot.color = ColorType.activity
+        currentDot.color = ColorType.activity
+
+
+        var now = new Date()
+        var t = now.getHours() * 60 + now.getMinutes()
+        var duration2 = t - start
+        if (duration2 < 0) {
+            duration2 += 24 * 60
         }
-        else {
-            currentDot.color = ColorType.ring
+        const realRing: RealRing = {
+            color: ColorType.activity,
+            startArc: (start * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0,
+            durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
-        return <Rings common={common} bgRing={bgRing} realRing={realRingBig} currentDot={currentDot} canvasId={timeStamp + '_small'} />
+        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_small'} />
     }
     function dayRing() {
         var common = getCommon(null, true)
@@ -165,7 +183,7 @@ export default function Discovery() {
         var bgRing = getBgRing()
 
         const realRingBig: RealRing = {
-            color: ColorType.day,
+            color: ColorType.day + '66',
             startArc: 0,
             durationArc: 2
         }
@@ -178,9 +196,6 @@ export default function Discovery() {
             var sunSetObj = dayNight.gpsInfo.daylights[0].sunset
             sunRise = 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 = sunSet - sunRise
@@ -195,14 +210,22 @@ export default function Discovery() {
             minutes += 1440
         }
 
-        if (sunRise <= minutes && sunSet > minutes) {
-            currentDot.color = ColorType.day
+        currentDot.color = ColorType.day
+
+
+        var now = new Date()
+        var t = now.getHours() * 60 + now.getMinutes()
+        var duration2 = t - sunRise
+        if (duration2<0){
+            duration2+=24*60
         }
-        else {
-            currentDot.color = ColorType.ring
+        const realRing: RealRing = {
+            color: ColorType.day,
+            startArc: (sunRise * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0,
+            durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
 
-        return <Rings common={common} bgRing={bgRing} realRing={realRingBig} currentDot={currentDot} canvasId={timeStamp + '_day'} />
+        return <Rings common={common} bgRing={bgRing} targetRing={realRingBig} realRing={duration2 <= duration ? realRing : null} currentDot={currentDot} canvasId={timeStamp + '_day'} />
     }
 
     function goAcitivity() {
@@ -286,7 +309,7 @@ export default function Discovery() {
     return <View style={{ display: 'flex', flexDirection: 'column' }}>
         <Box>
             <View>
-                <View style={{ display: 'flex', flexDirection: 'row',  marginBottom: rpxToPx(60), alignItems: 'center' }}>
+                <View style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(60), alignItems: 'center' }}>
                     {
                         schedule && rings()
                     }
@@ -316,15 +339,15 @@ export default function Discovery() {
                 <View className="food_btn1" style={{ backgroundColor: ColorType.food }} onClick={goFood}>
                     <Text style={{ fontWeight: 'bold' }}>食物日记</Text>
                 </View>
-                <View className="food_btn1" style={{ backgroundColor: ColorType.activity,marginBottom:0 }} onClick={goAcitivity}>
+                <View className="food_btn1" style={{ backgroundColor: ColorType.activity, marginBottom: 0 }} onClick={goAcitivity}>
                     <Text style={{ fontWeight: 'bold' }}>运动训练</Text>
                 </View>
             </View>
         </Box>
 
-        <DayNightCard isNight={false} switchChanged={(e)=>{
+        <DayNightCard isNight={false} switchChanged={(e) => {
             setShowRing(e)
-        }}/>
+        }} />
 
 
         {/* <View className="cell_bg" style={{ marginTop: 20 }}>

+ 29 - 10
src/features/trackTimeDuration/components/IndexItem.tsx

@@ -115,6 +115,12 @@ export default function Component(props: { type: string, data: any, time: any, s
                     list.push(realRingBig)
                 }
             }
+            else if (props.data.scenario.name == 'SLEEP') {
+                realRing1.color = ColorType.sleep + '66'
+            }
+            else {
+                realRing1.color = ColorType.fast + '66'
+            }
 
             if (!isStageMode) {
                 list = []
@@ -134,6 +140,9 @@ export default function Component(props: { type: string, data: any, time: any, s
         var bgRing = getBgRing()
         var realRing = getReal(record, false, false)
         if (props.type == 'SLEEP' || props.data.scenario.name == 'FAST_SLEEP') {
+            if (!record.sleep) {
+                return null
+            }
             if (record.sleep.status == 'WAIT_FOR_END') {
                 var targetBigRing1 = getTarget(record, false)
                 targetBigRing1.color = ColorType.sleep + '66'
@@ -143,6 +152,8 @@ export default function Component(props: { type: string, data: any, time: any, s
             }
             else if (record.status == 'WAIT_FOR_START' || record.status == 'ONGOING1') {
                 realRing = getSchedule(props.data.scenario, false, true, true)//getSchedule(record, false, true)
+                realRing.color = ColorType.sleep + '66'
+
                 var currentDot = getDot(record, false)
                 if (dotIsOuterRange(true, record.sleep)) {
                     currentDot.color = ColorType.ring
@@ -211,14 +222,22 @@ export default function Component(props: { type: string, data: any, time: any, s
         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
+        currentDot.color = ColorType.night
+
+        var now = new Date()
+        var t = now.getHours() * 60 + now.getMinutes()
+        var duration2 = t - sunSet
+        if (duration2 < 0) {
+            duration2 += 24 * 60
         }
-        else {
-            currentDot.color = ColorType.night + '66'
+        const realRing: RealRing = {
+            color: ColorType.night,
+            startArc: (sunSet * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0,
+            durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
 
-        return <Rings common={common} bgRing={bgRing} realRing={realRingBig} 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 + props.time + 'day'} />
     }
 
     function rings() {
@@ -264,7 +283,7 @@ export default function Component(props: { type: string, data: any, time: any, s
     }
 
     function fastDuration() {
-        if (!record.fast){
+        if (!record.fast) {
             return ''
         }
         if (record.fast.status == 'WAIT_FOR_END') {
@@ -286,7 +305,7 @@ export default function Component(props: { type: string, data: any, time: any, s
     }
 
     function sleepDuration() {
-        if (!record.sleep){
+        if (!record.sleep) {
             return ''
         }
         if (record.sleep.status == 'WAIT_FOR_END') {
@@ -345,7 +364,7 @@ export default function Component(props: { type: string, data: any, time: any, s
 
 
     function goDetail(e) {
-        if (process.env.TARO_ENV=='weapp'){
+        if (process.env.TARO_ENV == 'weapp') {
             e.stopPropagation()
         }
         if (!user.isLogin) {
@@ -405,11 +424,11 @@ export default function Component(props: { type: string, data: any, time: any, s
             }
             <View className="duration_bg">
                 {
-                     !props.showStage  && global.showNightRing === true &&
+                    !props.showStage && global.showNightRing === true &&
                     <Text className="duration_title">{t('feature.common.overnight')}</Text>
                 }
                 {
-                     !props.showStage  && global.showNightRing === true &&
+                    !props.showStage && global.showNightRing === true &&
                     <Text className="duration_value" style={{ color: ColorType.night }}>{nightDuration()}</Text>
                 }
                 {

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

@@ -229,6 +229,11 @@ export default function Rings(props: {
             ctx.strokeStyle = '#1C1C1C';
             ctx.lineCap = 'round'; // 设置为圆角
             ctx.stroke();
+
+            ctx.beginPath();
+            ctx.arc(xPrime, yPrime, lineWidth / 2, 0, 2 * Math.PI, false);
+            ctx.fillStyle = props.currentDot.color;
+            ctx.fill();
         
             // ctx.beginPath();
             // ctx.arc(center, center, radius, arc,

+ 3 - 0
src/features/trackTimeDuration/hooks/RingData.tsx

@@ -332,6 +332,9 @@ export const getReal = (data: any, isBigRing: boolean, isRecord: boolean) => {
         return realRingBig
     }
     else {
+        if (!data.sleep){
+            return realRingSmall
+        }
         if (data.sleep.real_end_time_zone && data.status == 'COMPLETED') {
             // alert(data.fast.real_end_time_zone)
             var timestamp = TimeFormatter.transferTimestamp(data.sleep.real_start_time, data.fast.real_end_time_zone ? data.fast.real_end_time_zone : data.sleep.real_end_time_zone)