Leon 1 năm trước cách đây
mục cha
commit
421af74399

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 10 - 1
src/components/basic/Icons.tsx


+ 100 - 112
src/features/trackSomething/components/DayNightCard.tsx

@@ -9,7 +9,8 @@ import { useDispatch, useSelector } from 'react-redux'
 import { useTranslation } from 'react-i18next'
 import { TimeFormatter } from '@/utils/time_format'
 import { systemLocation } from '@/services/common'
-import { setDayRingData, setNightRingData, updateMember } from '@/store/day_night'
+import { setDayRingData, showDay } from '@/store/day'
+import { setNightRingData, showNight, updateMember } from '@/store/night'
 import Modal from '@/components/layout/Modal.weapp'
 import { rpxToPx } from '@/utils/tools'
 import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
@@ -38,16 +39,21 @@ sunriseB.setMinutes(0)
 sunriseB.setSeconds(0)
 sunriseB.setMilliseconds(0)
 
-
-export default function DayNightCard(props: { isNight: boolean, switchChanged: Function }) {
-    const [expand, setExpand] = useState(false)
+let lastDayInfo: any = null;
+let lastNightInfo: any = null;
+export default function DayNightCard(props: { isNight: boolean, count: number }) {
     const user = useSelector((state: any) => state.user);
-    const [authInfo, setAuthInfo] = useState(null)
-    const [count, setCount] = useState(0)
+    const dayStore = useSelector((state: any) => state.day);
+    const nightStore = useSelector((state: any) => state.night);
+    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)
@@ -68,10 +74,13 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
     }
 
     useEffect(() => {
+        
+        
         if (user.isLogin) {
-            getPerm({}).then(res => {
-                setExpand(props.isNight ? (res as any).show_night_ring : (res as any).show_day_ring)
-            })
+            if (global.locationDetail){
+                locationDetail = global.locationDetail
+                setAuthInfo(locationDetail)
+            }
 
             var today = new Date()
             var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
@@ -81,19 +90,22 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             latestLocation({
                 date_start: strYesterday, date_end: strTomorrow
             }).then(data => {
-                debugger
                 setAuthInfo(data as any)
                 updateDate(data)
                 locationDetail = data
-                console.log(data)
-                // setLocationDetail(data as any)
+                global.locationDetail = locationDetail
+                Taro.setStorage({
+                    key: 'gps',
+                    data: JSON.stringify(data as any)
+                })
             })
 
         }
-        getContent()
     }, [user.isLogin])
 
     useEffect(() => {
+        if (locationDetail)
+            updateDate(locationDetail)
         if (props.isNight) {
             global.clearNightLocation = () => {
                 clearCacheData()
@@ -104,28 +116,21 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                 clearCacheData()
             }
         }
-        setInterval(() => {
-            setCount((prevCounter) => prevCounter + 1)
-
-            if (locationDetail) {
-                var detail: any = locationDetail
-                var now = new Date()
-                if (now.getHours() == 0 && now.getMinutes() == 0 && now.getSeconds() == 0) {
-                    detail.daylights.splice(0, 1)
-                }
-                locationDetail = detail
+    }, [])
 
-                // setLocationDetail(detail)
-                updateDate(detail)
-            }
-            else {
+    useEffect(() => {
+        if (locationDetail) {
+            var detail: any = locationDetail
+            var now = new Date()
+            if (now.getHours() == 0 && now.getMinutes() == 0 && now.getSeconds() == 0) {
+                detail.daylights.splice(0, 1)
             }
-        }, 1000)
-    }, [])
+            locationDetail = detail
 
-    // useDidShow(() => {
-    //     getContent()
-    // })
+            // setLocationDetail(detail)
+            updateDate(detail)
+        }
+    }, [props.count])
 
     function updateDate(data) {
 
@@ -159,17 +164,8 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                     setSunriseDate(todaySunriseDate)
                     setSunsetDate(todaySunsetDate)
                 }
-
-                dispatch(setNightRingData({
-                    date: yesterdayDate.getTime(),
-                    sunrise: data.daylights[1].sunrise,
-                    sunset: data.daylights[0].sunset
-                }))
-                dispatch(setDayRingData({
-                    date: today.getTime(),
-                    sunrise: data.daylights[1].sunrise,
-                    sunset: data.daylights[1].sunset
-                }))
+                updateNightStore(yesterdayDate, data.daylights[1].sunrise, data.daylights[0].sunset)
+                updateDayStore(today, data.daylights[1].sunrise, data.daylights[1].sunset)
             }
             //今天白天(今天出日后-日落前)
             else if (todaySunriseDate.getTime() < today.getTime() && today.getTime() < todaySunsetDate.getTime()) {
@@ -187,16 +183,8 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                     setSunsetDate(todaySunsetDate)
                     setSunriseDate(todaySunriseDate)
                 }
-                dispatch(setNightRingData({
-                    date: today.getTime(),
-                    sunrise: data.daylights[2].sunrise,
-                    sunset: data.daylights[1].sunset
-                }))
-                dispatch(setDayRingData({
-                    date: today.getTime(),
-                    sunrise: data.daylights[1].sunrise,
-                    sunset: data.daylights[1].sunset
-                }))
+                updateNightStore(today, data.daylights[2].sunrise, data.daylights[1].sunset)
+                updateDayStore(today, data.daylights[1].sunrise, data.daylights[1].sunset)
             }
             //今天夜晚
             else if (today.getTime() > todaySunsetDate.getTime() && today.getTime() < tomorrowSunriseDate.getTime()) {
@@ -214,16 +202,8 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                     setSunriseDate(tomorrowSunriseDate)
                     setSunsetDate(tomorrowSunsetDate)
                 }
-                dispatch(setNightRingData({
-                    date: today.getTime(),
-                    sunrise: data.daylights[2].sunrise,
-                    sunset: data.daylights[1].sunset
-                }))
-                dispatch(setDayRingData({
-                    date: tomorrowSunriseDate.getTime(),
-                    sunrise: data.daylights[2].sunrise,
-                    sunset: data.daylights[2].sunset
-                }))
+                updateNightStore(today, data.daylights[2].sunrise, data.daylights[1].sunset)
+                updateDayStore(tomorrowSunriseDate, data.daylights[2].sunrise, data.daylights[2].sunset)
             }
         }
         else {
@@ -231,32 +211,42 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
 
     }
 
-    async function getContent() {
-        const isShow = await getStorage(props.isNight ? 'showNightRing' : 'showDayRing') || false
-        setExpand(isShow)
-
-        // const gpsInfo = await getStorage('gps') || null
-        // if (gpsInfo) {
-        //     var data = JSON.parse(gpsInfo)
-        //     setAuthInfo(data)
-        //     setSunriseTime((data as any).daylights[0].sunrise)
-        //     setSunriseTmrTime((data as any).daylights[1].sunrise)
-        //     setSunsetTime((data as any).daylights[0].sunset)
-        //     dispatch(updateMember({ isMember: user.test_user, gpsInfo: data }))
-        // }
-        // else {
-        //     setSunriseTime('06:00')
-        //     setSunriseTmrTime('06:00')
-        //     setSunsetTime('18:00')
-        //     setAuthInfo(null)
-        // }
-        if (props.isNight) {
-            global.showNightRing = isShow
-            global.refreshIndex()
+    function updateNightStore(date, sunrise, sunset) {
+        if (lastNightInfo && lastNightInfo.date.getDate() == new Date(date).getDate() &&
+            lastNightInfo.sunrise == sunrise &&
+            lastNightInfo.sunset == sunset
+        ) {
+            return
         }
-        else {
-            props.switchChanged(isShow)
+        lastNightInfo = {
+            date,
+            sunrise,
+            sunset
+        }
+        dispatch(setNightRingData({
+            date: date.getTime(),
+            sunrise: sunrise,
+            sunset: sunset
+        }))
+    }
+
+    function updateDayStore(date, sunrise, sunset) {
+        if (lastDayInfo && lastDayInfo.date.getDate() == new Date(date).getDate() &&
+            lastDayInfo.sunrise == sunrise &&
+            lastDayInfo.sunset == sunset
+        ) {
+            return
         }
+        lastDayInfo = {
+            date,
+            sunrise,
+            sunset
+        }
+        dispatch(setDayRingData({
+            date: date.getTime(),
+            sunrise: sunrise,
+            sunset: sunset
+        }))
     }
 
     async function getStorage(key: string) {
@@ -289,7 +279,7 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
             jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
             return
         }
-        if (!expand) {
+        if (props.isNight && !nightStore.showNightRing || !props.isNight && !dayStore.showDayRing) {
             return
         }
         var list = ['Current location Info',
@@ -317,20 +307,16 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
     function auth() {
         Taro.chooseLocation({
             success: function (res) {
-                console.log(res)
                 var today = new Date()
-                var yesterday = new Date(today.getTime())
+                var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
                 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(data);
                     updateDate(data);
                     locationDetail = data;
-                    // setLocationDetail(data as any);
-                    // (data as any).latitude = res.latitude;
-                    // (data as any).longitude = res.longitude;
+                    global.locationDetail = locationDetail
                     setAuthInfo(data as any)
                     setSunriseTime((data as any).daylights[0].sunrise)
                     setSunriseTmrTime((data as any).daylights[1].sunrise)
@@ -367,16 +353,16 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
 
     }
 
-    function lowTimeColor(){
+    function lowTimeColor() {
         var now = new Date()
         if (props.isNight) {
-            if (now.getTime() < sunsetDate.getTime() && now.getTime()>sunriseDate.getTime()) {
+            if (now.getTime() < sunsetDate.getTime() && now.getTime() > sunriseDate.getTime()) {
                 return true
             }
             return false
         } else {
 
-            if (now.getTime() > sunriseDate.getTime() && now.getTime()<sunsetDate.getTime()) {
+            if (now.getTime() > sunriseDate.getTime() && now.getTime() < sunsetDate.getTime()) {
                 return false
             }
             return true
@@ -633,33 +619,33 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
     function nightDurationDesc() {
         if (!authInfo || !(authInfo as any).lat) {
             if (new Date().getHours() >= 6) {
-                return `${t('feature.day_night.tonight',{time:sunsetTime})} - ${t('feature.day_night.tomorrow_morning',{time:sunriseTmrTime})}`
+                return `${t('feature.day_night.tonight', { time: sunsetTime })} - ${t('feature.day_night.tomorrow_morning', { time: sunriseTmrTime })}`
             }
-            return `${t('feature.day_night.last_night',{time:sunsetTime})} - ${t('feature.day_night.this_morning',{time:sunriseTmrTime})}`
+            return `${t('feature.day_night.last_night', { time: sunsetTime })} - ${t('feature.day_night.this_morning', { time: sunriseTmrTime })}`
             // return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
         }
         if (nightDate.getDate() == new Date().getDate()) {
-            return `${t('feature.day_night.tonight',{time:sunsetTime})} - ${t('feature.day_night.tomorrow_morning',{time:sunriseTmrTime})}`
+            return `${t('feature.day_night.tonight', { time: sunsetTime })} - ${t('feature.day_night.tomorrow_morning', { time: sunriseTmrTime })}`
         }
-        return `${t('feature.day_night.last_night',{time:sunsetTime})} - ${t('feature.day_night.this_morning',{time:sunriseTmrTime})}`
+        return `${t('feature.day_night.last_night', { time: sunsetTime })} - ${t('feature.day_night.this_morning', { time: sunriseTmrTime })}`
         //`Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
     }
 
     function dayDurationDesc() {
         if (!authInfo || !(authInfo as any).lat) {
             if (new Date().getHours() >= 18) {
-                return `${t('feature.day_night.tomorrow',{time:sunriseTime})} - ${sunsetTime}`
+                return `${t('feature.day_night.tomorrow', { time: sunriseTime })} - ${sunsetTime}`
 
                 // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
             }
-            return `${t('feature.day_night.today',{time:sunriseTime})} - ${sunsetTime}`
+            return `${t('feature.day_night.today', { time: sunriseTime })} - ${sunsetTime}`
             // return `Today ${sunriseTime} - ${sunsetTime}`
         }
         if (dayDate.getDate() == new Date().getDate()) {
-            return `${t('feature.day_night.today',{time:sunriseTime})} - ${sunsetTime}`
+            return `${t('feature.day_night.today', { time: sunriseTime })} - ${sunsetTime}`
             // return `Today ${sunriseTime} - ${sunsetTime}`
         }
-        return `${t('feature.day_night.tomorrow',{time:sunriseTime})} - ${sunsetTime}`
+        return `${t('feature.day_night.tomorrow', { time: sunriseTime })} - ${sunsetTime}`
         // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
     }
 
@@ -675,18 +661,20 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                     }
 
                     <View style={{ flex: 1 }} />
-                    <Switch checked={expand}
+                    <Switch checked={props.isNight ? nightStore.showNightRing : dayStore.showDayRing}
                         color={props.isNight ? ColorType.night : ColorType.day}
                         onClick={(e) => { e.stopPropagation() }}
                         onChange={(e) => {
-                            props.switchChanged(e.detail.value)
                             e.stopPropagation()
-                            setExpand(e.detail.value)
+                            // setExpand(e.detail.value)
                             if (props.isNight) {
-                                global.showNightRing = e.detail.value
-                                global.refreshIndex()
+                                dispatch(showNight(e.detail.value))
+                            }
+                            else {
+                                dispatch(showDay(e.detail.value))
                             }
 
+
                             Taro.setStorage({
                                 key: props.isNight ? 'showNightRing' : 'showDayRing',
                                 data: e.detail.value
@@ -706,13 +694,13 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
                     />
                 </View>
                 {
-                    user.isLogin && expand && <View>
+                    user.isLogin && ((props.isNight && nightStore.showNightRing) || (!props.isNight && dayStore.showDayRing)) && <View>
                         <View style={{ display: 'flex', flexDirection: 'column' }}>
                             <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? nightDurationDesc() : dayDurationDesc()}</Text>
                             <Text className='day_night_desc'>{props.isNight ? t('feature.day_night.sunset_to_sunrise') : t('feature.day_night.sunrise_to_sunset')}</Text>
                             <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(32) }}>
                                 <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
-                                    <Text className='day_night_value' style={{ color: lowTimeColor()?ColorType.ring:props.isNight ? ColorType.night : ColorType.day, }}>{timeCount()}</Text>
+                                    <Text className='day_night_value' style={{ color: lowTimeColor() ? ColorType.ring : props.isNight ? ColorType.night : ColorType.day, }}>{timeCount()}</Text>
                                     <Text className='day_night_desc'>{timeDesc()}</Text>
                                 </View>
                                 {

+ 1 - 1
src/features/trackTimeDuration/components/DayLight.tsx

@@ -3,7 +3,7 @@ import './DayLight.scss'
 import { View, Text, Switch, Image } from '@tarojs/components'
 import Taro from '@tarojs/taro'
 import { useDispatch, useSelector } from 'react-redux'
-import { updateMember } from '@/store/day_night'
+import { updateMember } from '@/store/day'
 import { systemLocation } from '@/services/common'
 import { clearLocation, getPerm, latestLocation, uploadPerm } from '@/services/user'
 import { TimeFormatter } from '@/utils/time_format'

+ 46 - 82
src/features/trackTimeDuration/components/Discovery.tsx

@@ -7,7 +7,7 @@ import Rings from "@/features/trackTimeDuration/components/Rings";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import { rpxToPx } from "@/utils/tools";
 import { useEffect, useState } from "react";
-import Taro from "@tarojs/taro";
+import Taro, { useDidHide, useDidShow } from "@tarojs/taro";
 import './Discovery.scss'
 import { useTranslation } from "react-i18next";
 import { TimeFormatter } from "@/utils/time_format";
@@ -22,11 +22,14 @@ if (process.env.TARO_ENV == 'rn') {
     useNavigation = require("@react-navigation/native").useNavigation
 }
 
+let pauseTimer = false
+
 export default function Discovery() {
     const user = useSelector((state: any) => state.user);
-    const dayNight = useSelector((state: any) => state.dayNight);
-    const [showRing, setShowRing] = useState(false)
+    const dayNight = useSelector((state: any) => state.day);
     const [schedule, setSchedule] = useState(null)
+    const [count, setCount] = useState(0)
+    const [loaded,setLoaded] = useState(false)
     const { t } = useTranslation()
 
     let navigation;
@@ -34,11 +37,29 @@ export default function Discovery() {
     if (useNavigation) {
         navigation = useNavigation()
     }
+    console.log('discovery')
 
     useEffect(() => {
-        getContent()
+
+        setInterval(() => {
+            if (global.pauseIndexTimer  || pauseTimer) {
+                return
+            }
+            setCount((prevCounter) => prevCounter + 1)
+
+        }, 1000)
     }, [])
 
+    useDidShow(() => {
+        //resume timer
+        pauseTimer = false
+    })
+
+    useDidHide(()=>{
+        //pause timer
+        pauseTimer = true
+    })
+
     // useEffect(() => {
     //     setSchedule(global.homeData.scenarios)
     // }, [global.homeData])
@@ -46,28 +67,10 @@ export default function Discovery() {
     useEffect(() => {
         getPlans().then(res => {
             setSchedule((res as any).scenarios)
+            setLoaded(true)
         })
-        if (user.isLogin) {
-            getPerm({}).then(res => {
-                setShowRing((res as any).show_day_ring)
-            })
-        }
     }, [user.isLogin])
 
-    async function getStorage(key: string) {
-        try {
-            const res = await Taro.getStorage({ key });
-            return res.data;
-        } catch {
-            return '';
-        }
-    }
-
-    async function getContent() {
-        const isShow = await getStorage('showDayRing') || false
-        setShowRing(isShow)
-    }
-
     function getFoodTime() {
         var obj;
         (schedule as any).map(item => {
@@ -135,7 +138,7 @@ export default function Discovery() {
             durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
 
-        if (!user.isLogin){
+        if (!user.isLogin) {
             currentDot = null
             realRing = null
         }
@@ -184,7 +187,7 @@ export default function Discovery() {
             durationArc: (duration2 * 60) / (24 * 3600) * 2 * Math.PI
         }
 
-        if (!user.isLogin){
+        if (!user.isLogin) {
             currentDot = null
             realRing = null
         }
@@ -239,13 +242,13 @@ 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 (dayNight.dayRingDate) {
+            if (new Date(dayNight.dayRingDate).getDate() != new Date().getDate()) {
                 realRing = null;
             }
         }
 
-        if (!user.isLogin){
+        if (!user.isLogin) {
             currentDot = null
             realRing = null
         }
@@ -308,7 +311,7 @@ export default function Discovery() {
     function rings() {
         return <View style={{
             position: 'relative', zIndex: 1,
-            marginLeft: showRing ? -6 : 0,
+            marginLeft: dayNight.showDayRing ? -6 : 0,
         }}>
             {
                 bigRing()
@@ -321,7 +324,7 @@ export default function Discovery() {
                 </View>
             }
             {
-                showRing && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
+                dayNight.showDayRing && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
                     {
                         dayRing()
                     }
@@ -330,6 +333,11 @@ export default function Discovery() {
 
         </View>
     }
+
+    if (!loaded){
+        return <View />
+    }
+
     return <View style={{ display: 'flex', flexDirection: 'column' }}>
         <Box>
             <View>
@@ -337,28 +345,27 @@ export default function Discovery() {
                     marginLeft: rpxToPx(-40),
                     marginRight: rpxToPx(-40),
                     marginTop: rpxToPx(-40),
-                    padding: rpxToPx(48),
-                    // backgroundColor: 'red'
+                    padding: rpxToPx(48)
                 }}>
 
                     <View style={{
                         display: 'flex',
                         flexDirection: 'row',
-                        marginTop: showRing ? -6 : 0,
-                        marginBottom: showRing ? -6 : 0,
-                        padding: showRing ? 14 : 0,
+                        marginTop: dayNight.showDayRing ? -6 : 0,
+                        marginBottom: dayNight.showDayRing ? -6 : 0,
+                        padding: dayNight.showDayRing ? 14 : 0,
                         alignItems: 'center'
                     }}>
                         {
                             schedule && rings()
                         }
                         {schedule && <View className="duration_bg3"
-                            style={{ marginLeft: showRing ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
+                            style={{ marginLeft: dayNight.showDayRing ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
                             {
-                                showRing && <Text className="duration_title2">{t('feature.common.day')}</Text>
+                                dayNight.showDayRing && <Text className="duration_title2">{t('feature.common.day')}</Text>
                             }
                             {
-                                showRing &&
+                                dayNight.showDayRing &&
                                 <Text className="duration_value2" style={{ color: ColorType.day }}>{dayDuration()}</Text>
                             }
                             {
@@ -387,50 +394,7 @@ export default function Discovery() {
             </View>
         </Box>
 
-        <DayNightCard isNight={false} switchChanged={(e) => {
-            setShowRing(e)
-        }} />
-
-
-        {/* <View className="cell_bg" style={{ marginTop: 20 }}>
-            <View className="cell_full">
-                <Text className="cell_title">{t('feature.common.day')}</Text>
-                <Switch checked={showRing}
-                    color={ColorType.day}
-                    onChange={(e) => {
-                        setShowRing(e.detail.value)
-                        uploadPerm({ show_day_ring: e.detail.value })
-                        Taro.setStorage({
-                            key: 'showDayRing',
-                            data: e.detail.value
-                        })
-                    }}
-                />
-            </View>
-            {
-                showRing && <View className="cell_line" style={{ height: 1 }} />
-            }
-            {
-                showRing && <View className="cell_full">
-                    <Text className="cell_title">{t('feature.track_time_duration.third_ring.sunrise_today')}</Text>
-                    <Text className="cell_value" style={{ color: '#fff' }}>{
-                        dayNight.isMember && dayNight.gpsInfo ? dayNight.gpsInfo.daylights[0].sunrise : '06:00'
-                    }</Text>
-                </View>
-            }
-            {
-                showRing && <View className="cell_line" style={{ height: 1 }} />
-            }
-            {
-                showRing && <View className="cell_full">
-                    <Text className="cell_title">{t('feature.track_time_duration.third_ring.sunset_today')}</Text>
-                    <Text className="cell_value" style={{ color: '#fff' }}>{
-                        dayNight.isMember && dayNight.gpsInfo ? dayNight.gpsInfo.daylights[0].sunset : '18:00'
-                    }</Text>
-                </View>
-            }
-
-        </View> */}
+        <DayNightCard isNight={false} count={count}/>
 
     </View>
 }

+ 2 - 0
src/features/trackTimeDuration/components/IndexConsole.tsx

@@ -160,6 +160,7 @@ export default function IndexConsole(props: { record: any }) {
                 title={title}
                 onCancel={hidePicker} onChange={(e) => {
                     pickerConfirm(e)
+                    global.pauseIndexTimer = false
                     // hidePicker()
                 }} />
         </View>
@@ -183,6 +184,7 @@ export default function IndexConsole(props: { record: any }) {
                 }
                 onCancel={hidePicker} onChange={(e) => {
                     pickerConfirm(e)
+                    global.pauseIndexTimer = false
                     // hidePicker()
                 }} />
         </View>

+ 34 - 59
src/features/trackTimeDuration/components/IndexItem.tsx

@@ -1,5 +1,5 @@
 import { View, Text, Image, PageContainer } from "@tarojs/components";
-import { bigRingRadius, dotIsOuterRange, getBgRing, getCommon, getDot, getReal, getSchedule, getTarget, ringWidth, smallRingRadius, thirdRingRadius, timeTotimestamp } from "../hooks/RingData";
+import { bigRingRadius, getBgRing, getCommon, getDot, getReal, getSchedule, getTarget, ringWidth, smallRingRadius, thirdRingRadius, timeTotimestamp } from "../hooks/RingData";
 import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
 import Rings from "./Rings";
 import './IndexItem.scss'
@@ -25,7 +25,7 @@ export default function Component(props: { type: string, data: any, time: any, s
     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 dayNight = useSelector((state: any) => state.night);
     const [stageList, setStageList] = useState([true, false, false])
     const [isStageMode, setIsStageMode] = useState(false)
     const [showDetailModal, setShowDetailModal] = useState(false)
@@ -41,19 +41,17 @@ export default function Component(props: { type: string, data: any, time: any, s
 
     useEffect(() => {
         setCount((pre) => pre + 1)
-        console.log(dayNight.nightRingSunrise, dayNight.nightRingSunset)
     }, [dayNight.nightRingSunrise, dayNight.nightRingSunset])
 
+
     useEffect(() => {
         if (props.type == 'FAST_SLEEP') {
             global.updateMixItem = (data) => {
                 setStageList(data)
-
             }
 
             global.changeMixIndex = (index) => {
                 setIsStageMode(index == 1)
-
             }
         }
     }, [])
@@ -86,15 +84,26 @@ export default function Component(props: { type: string, data: any, time: any, s
             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.data.scenario.name != 'SLEEP', true, true)//getSchedule(record, props.type != 'SLEEP', true)
+            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
+                }
+                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 (props.data.scenario.name == 'FAST_SLEEP') {
+            if (scenario.name == 'FAST_SLEEP') {
                 realRing1.color = ColorType.fast + '66'
 
-                if (dotIsOuterRange(true, record.fast)) {
-                    currentDot1.color = ColorType.ring
-                }
-                var detail = timeTotimestamp(props.data.scenario)
+                var detail = timeTotimestamp(scenario)
 
                 if (stageList[0]) {
 
@@ -125,7 +134,7 @@ export default function Component(props: { type: string, data: any, time: any, s
                     list.push(realRingBig)
                 }
             }
-            else if (props.data.scenario.name == 'SLEEP') {
+            else if (scenario.name == 'SLEEP') {
                 realRing1.color = ColorType.sleep + '66'
             }
             else {
@@ -193,7 +202,6 @@ export default function Component(props: { type: string, data: any, time: any, s
                 var currentDot = getDot(record, false)
                 return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={props.type + props.time + 'small'} />
             }
-            debugger
             return <Rings common={common} bgRing={bgRing} canvasId={props.type + props.time + 'small'} />
         }
         else {
@@ -287,7 +295,7 @@ export default function Component(props: { type: string, data: any, time: any, s
                 </View>
             }
             {
-                !props.showStage && global.showNightRing === true && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
+                !props.showStage && dayNight.showNightRing === true && <View style={{ display: 'flex', position: 'absolute', left: -14, top: -14, right: -14, bottom: -14 }}>
                     {
                         dayRing()
                     }
@@ -364,17 +372,6 @@ export default function Component(props: { type: string, data: any, time: any, s
         return getDuration(record.sleep)
     }
 
-    function goClock() {
-        if (!user.isLogin) {
-            jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
-            return
-        }
-        if (props.showStage) {
-            return
-        }
-        global.showSegmentPop()
-    }
-
     function nightDuration() {
 
             var sunRiseObj = dayNight.nightRingSunrise
@@ -390,25 +387,6 @@ export default function Component(props: { type: string, data: any, time: any, s
             return TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + duration);
     }
 
-    function fastPicker() {
-        if (!user.isLogin) {
-            jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
-            return
-        }
-        global.showFastPicker()
-    }
-
-    function sleepPicker(e) {
-        if (!user.isLogin) {
-            jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
-            return
-        }
-        if (record.status == 'ONGOING3') {
-            return;
-        }
-        global.showSleepPicker()
-    }
-
 
     function goDetail(e) {
         if (process.env.TARO_ENV == 'weapp') {
@@ -426,6 +404,7 @@ export default function Component(props: { type: string, data: any, time: any, s
             return <Modal
                 testInfo={null}
                 dismiss={() => {
+                    global.pauseIndexTimer = false
                     setShowDetailModal(false)
                 }}
                 confirm={() => { }}>
@@ -451,7 +430,7 @@ export default function Component(props: { type: string, data: any, time: any, s
                 }}
                 onClick={() => { alert('b') }}
                 onClickOverlay={() => { alert('a') }}
-                onAfterLeave={() => { setShowDetailModal(false) }}
+                onAfterLeave={() => { setShowDetailModal(false);global.pauseIndexTimer = false; }}
                 show={showDetailModal} round={true} overlay={true} position='bottom'
             >
                 {
@@ -468,26 +447,27 @@ export default function Component(props: { type: string, data: any, time: any, s
         marginLeft: rpxToPx(-40),
         marginRight: rpxToPx(-40),
         marginTop: rpxToPx(-40),
-        padding: rpxToPx(48),
-        // backgroundColor:'pink'
+        padding: rpxToPx(48)
     }}>
         <View className="time_operate_item1" onClick={goDetail}>
             <View className="fast_sleep_item" style={{
-                marginTop: !props.showStage && global.showNightRing === true ? -6 : 0,
-                marginBottom: !props.showStage && global.showNightRing === true ? -6 : 0,
-                padding: !props.showStage && global.showNightRing === true ? 14 : 0,
-                paddingRight: 0
+                marginTop: !props.showStage && dayNight.showNightRing === true ? -6 : 0,
+                marginBottom: !props.showStage && dayNight.showNightRing === true ? -6 : 0,
+                marginLeft: !props.showStage && dayNight.showNightRing === true ? -6 : 0,
+                padding: !props.showStage && dayNight.showNightRing === true ? 14 : 0,
+                paddingRight: 0,
+                
             }}>
                 {
                     rings()
                 }
-                <View className="duration_bg2" style={{ marginLeft: !props.showStage && global.showNightRing === true ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
+                <View className="duration_bg2" style={{ marginLeft: !props.showStage && dayNight.showNightRing === true ? rpxToPx(68) : rpxToPx(52), height: bigRingRadius * 2, overflow: 'visible' }}>
                     {
-                        !props.showStage && global.showNightRing === true &&
+                        !props.showStage && dayNight.showNightRing === true &&
                         <Text className="duration_title2">{t('feature.common.overnight')}</Text>
                     }
                     {
-                        !props.showStage && global.showNightRing === true &&
+                        !props.showStage && dayNight.showNightRing === true &&
                         <Text className="duration_value2" style={{ color: ColorType.night }}>{nightDuration()}</Text>
                     }
                     {
@@ -504,11 +484,6 @@ export default function Component(props: { type: string, data: any, time: any, s
                     }
                 </View>
                 <Image className="arrow2" src={require('@/assets/images/arrow3.png')} />
-                {/* {
-                !props.showStage && <View className="record_arrow_bg" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>
-                    <View style={{ flex: 1 }} />
-                    
-                </View>} */}
 
 
             </View>

+ 23 - 12
src/features/trackTimeDuration/components/Rings.weapp.tsx

@@ -35,6 +35,8 @@ export type BgRing = {
     color: string;
 }
 
+let arrowImg;
+
 export default function Rings(props: {
     common: RingCommon; 
     currentDot?: CurrentDot;
@@ -238,27 +240,36 @@ export default function Rings(props: {
                 ctx.fill();
             }
 
-            //绘制终点图标
-            ctx.save()
-            ctx.beginPath()
-            // ctx.translate(xPrime, yPrime)
-            // ctx.rotate(arc)
-            // ctx.translate(-xPrime, -xPrime)
+            
     
-            if (global.canvas_start_icon2) {
-                ctx.drawImage(global.canvas_start_icon2, xPrime - lineWidth/2, yPrime - lineWidth/2, lineWidth, lineWidth)
+            if (arrowImg) {
+                //绘制终点图标
+                ctx.save()
+                ctx.beginPath()
+                ctx.translate(xPrime, yPrime)
+                ctx.rotate(arc)
+                ctx.translate(-xPrime, -yPrime)
+                ctx.drawImage(arrowImg, xPrime - lineWidth/2, yPrime - lineWidth/2, lineWidth, lineWidth)
+                ctx.restore()
+                ctx.closePath()
             }
             else {
                 let tempImage = global.canvas2.createImage()
                 tempImage.src = require('@/assets/images/dot_arrow.png')//'./watch_line.png'//'..//assets/images/watch_line.png'
                 tempImage.onload = () => {
-                    global.canvas_start_icon2 = tempImage
-                    drawContent(ctx)
+                    arrowImg = tempImage
+                    ctx.save()
+                    ctx.beginPath()
+                    ctx.translate(xPrime, yPrime)
+                    ctx.rotate(arc)
+                    ctx.translate(-xPrime, -yPrime)
+                    ctx.drawImage(arrowImg, xPrime - lineWidth/2, yPrime - lineWidth/2, lineWidth, lineWidth)
+                    ctx.restore()
+                    ctx.closePath()
                 }
             }
     
-            ctx.restore()
-            ctx.closePath()
+            
 
             
         

+ 5 - 5
src/features/trackTimeDuration/components/StageSelector.tsx

@@ -1,4 +1,4 @@
-import { IconPlus } from "@/components/basic/Icons";
+import { IconCheck, IconPlus } from "@/components/basic/Icons";
 import { ColorType } from "@/context/themes/color";
 import { View, Text, Image, Switch } from "@tarojs/components";
 import { useState } from "react";
@@ -41,7 +41,7 @@ export default function () {
                         }}>
                             <Text className={item.checked ? "single_check_text_sel" : "single_check_text_nor"}>{item.title}</Text>
                             {
-                                item.checked ? <Image src={require('@assets/images/check_fast.png')} className="single_checked" /> :
+                                item.checked ? <IconCheck width={rpxToPx(48)} height={rpxToPx(48)} color={ColorType.fast}/> :
                                     <IconPlus color={ColorType.fast} />
                             }
                         </View>
@@ -52,19 +52,19 @@ export default function () {
                 <View className={selIndex == 0 ? "single_check_sel1" : "single_check_nor1"} onClick={() => { setSelIndex(0); global.updateMixItem([true, false, false]); }}>
                     <Text className={selIndex == 0 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.a')}</Text>
                     {
-                        selIndex == 0 && <Image src={require('@assets/images/check_fast.png')} className="single_checked" />
+                        selIndex == 0 && <IconCheck width={rpxToPx(48)} height={rpxToPx(48)} color={ColorType.fast}/>//<Image src={require('@assets/images/check_fast.png')} className="single_checked" />
                     }
                 </View>
                 <View className={selIndex == 1 ? "single_check_sel1" : "single_check_nor1"} onClick={() => { setSelIndex(1); global.updateMixItem([false, true, false]); }}>
                     <Text className={selIndex == 1 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.b')}</Text>
                     {
-                        selIndex == 1 && <Image src={require('@assets/images/check_fast.png')} className="single_checked" />
+                        selIndex == 1 && <IconCheck width={rpxToPx(48)} height={rpxToPx(48)} color={ColorType.fast}/>//<Image src={require('@assets/images/check_fast.png')} className="single_checked" />
                     }
                 </View>
                 <View className={selIndex == 2 ? "single_check_sel1" : "single_check_nor1"} onClick={() => { setSelIndex(2); global.updateMixItem([false, false, true]); }}>
                     <Text className={selIndex == 2 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.c')}</Text>
                     {
-                        selIndex == 2 && <Image src={require('@assets/images/check_fast.png')} className="single_checked" />
+                        selIndex == 2 && <IconCheck width={rpxToPx(48)} height={rpxToPx(48)} color={ColorType.fast}/>//<Image src={require('@assets/images/check_fast.png')} className="single_checked" />
                     }
                 </View>
             </View>

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

@@ -4,7 +4,7 @@ import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
 import Rings from "@/features/trackTimeDuration/components/Rings";
 import './Index.scss'
 import { useDispatch, useSelector } from "react-redux";
-import { useDidShow, useReady } from "@tarojs/taro";
+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";
@@ -36,11 +36,14 @@ 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 { showDay } from "@/store/day";
+import { clientInfo } from "@/services/common";
 
 let GradientText
 let useNavigation;
-let isPause = false;
 let timer
+let pauseTimer = false;
 
 if (process.env.TARO_ENV == 'rn') {
     GradientText = require('@/components/basic/GradientText').default
@@ -61,7 +64,6 @@ export default function Page() {
     const [count, setCount] = useState(0)
     const [homeData, setHomeData] = useState(null)
     const [loaded, setLoaded] = useState(false)
-    const [selIndex, setSelIndex] = useState(0)
 
 
     const [showModal, setShowModal] = useState(false)
@@ -72,14 +74,14 @@ export default function Page() {
 
     const [debugInfo, setDebugInfo] = useState(null)
 
-    const [isMulti, setIsMulti] = useState(false)
     const [records, setRecords] = useState([])
 
 
+
+
     useEffect(() => {
-        global.showNightRing = false;
         timer = setInterval(() => {
-            if (isPause || global.pauseIndexTimer) {
+            if (global.pauseIndexTimer || pauseTimer) {
                 return
             }
             setCount((prevCounter) => prevCounter + 1)
@@ -87,17 +89,26 @@ export default function Page() {
         }, 1000)
     }, [])
 
-    useEffect(()=>{
-        getDatas()
-    },[])
+    useEffect(() => {
+        if (process.env.TARO_ENV == 'weapp') {
+            loadWXCache()
+        }
+        else {
+            loadRNCache()
+        }
+    }, [])
 
     useEffect(() => {
         getCheckData()
+        global.pauseIndexTimer = !user.isLogin
+
+        if (user.isLogin) {
+            uploadUserClient();
+        }
     }, [user.isLogin, time.status])
 
     useReady(async () => {
         const userData = await getStorage('userData');
-        debugger
         if (userData) {
             dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
             // setTimeout(() => {
@@ -113,8 +124,13 @@ export default function Page() {
     })
 
     useDidShow(() => {
-        // if (user.isLogin)
-        //     refresh()
+        //resume timer
+        pauseTimer = false
+    })
+
+    useDidHide(() => {
+        //pause timer
+        pauseTimer = true
     })
 
     global.refreshIndex = () => {
@@ -122,27 +138,65 @@ export default function Page() {
         setCount((prevCounter) => prevCounter + 1)
     }
 
-    async function getDatas() {
-        const userData = await getStorage('userData');
-        dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
-
-        var today = new Date()
-        var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
-        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())}`
+    function uploadUserClient() {
+        var systemInfo = Taro.getSystemInfoSync();
+        var split = new Date().toString().split(' ');
+        var timeZoneFormatted = split[split.length - 2];
+        clientInfo({
+            client: {
+                client_type: process.env.TARO_ENV == 'weapp' ? 'MP' : 'APP',
+                client_version: '1.0'
+            },
+            meta: {
+                language: systemInfo.language,
+                time_zone: {
+                    id: Intl.DateTimeFormat().resolvedOptions().timeZone,
+                    name: timeZoneFormatted
+                },
+            },
+            device: {
+                brand: systemInfo.brand,
+                model: systemInfo.model,
+                platform: systemInfo.platform,
+                system: systemInfo.system
+            },
+            perm: {
+                wifiEnabled: systemInfo.wifiEnabled,
+                location: systemInfo.locationAuthorized
+            }
+        })
+    }
 
+    function loadWXCache() {
+        var showDayRing = Taro.getStorageSync('showDayRing') || false;
+        var showNightRing = Taro.getStorageSync('showNightRing') || false;
+        dispatch(showDay(showDayRing))
+        dispatch(showNight(showNightRing))
+        var gps = Taro.getStorageSync('gps')
+        if (gps) {
+            global.locationDetail = JSON.parse(gps)
+        }
+        var userData = Taro.getStorageSync('userData')
         if (userData) {
-            Promise.all([getClocks(),latestLocation({
-                date_start: strYesterday, date_end: strTomorrow
-            })]).then(res=>{
-                setLoaded(true)
-                console.log(res)
-            })
+            dispatch(getInfoSuccess(JSON.parse(userData)));
         }
-        else {
+        getCheckData()
+    }
 
+    async function loadRNCache() {
+        var showDayRing = await getStorage('showDayRing') || false;
+        var showNightRing = await getStorage('showNightRing') || false;
+        dispatch(showDay(showDayRing))
+        dispatch(showNight(showNightRing))
+        var gps = await getStorage('gps')
+        if (gps) {
+            global.locationDetail = JSON.parse(gps)
         }
+        var userData = await getStorage('userData')
+        if (userData) {
+            dispatch(getInfoSuccess(JSON.parse(userData)));
+        }
+        getCheckData()
     }
 
 
@@ -167,7 +221,6 @@ export default function Page() {
             setHomeData(res as any)
             global.homeData = res
             if (user.isLogin) {
-                isPause = (res as any).current_record.status == 'WAIT_FOR_START'
                 dispatch(updateScenario((res as any).current_record))
                 dispatch(setConfigs((res as any).time_input_schema));
                 dispatch(setScenario((res as any).scenario));
@@ -241,6 +294,7 @@ export default function Page() {
                         setDebugInfo(null)
                         setShowModal(false);
                         setShowModal2(false);
+                        global.pauseIndexTimer = false
                     }}
                     confirm={() => { }}>
                     {
@@ -263,7 +317,7 @@ export default function Page() {
                     }}
                     onClick={() => { alert('b') }}
                     onClickOverlay={() => { alert('a') }}
-                    onAfterLeave={() => { setShowModal(false); setShowModal2(false) }}
+                    onAfterLeave={() => { setShowModal(false); setShowModal2(false); global.pauseIndexTimer = false }}
                     show={showModal || showModal2} round={true} overlay={true} position='bottom'
                 >
                     {
@@ -326,10 +380,7 @@ export default function Page() {
                     </View>
                 </Box>
 
-                {/* {
-                    user.isLogin && <DayLight />
-                } */}
-                <DayNightCard isNight={true} switchChanged={(e) => { }} />
+                <DayNightCard isNight={true} count={count} />
                 {
                     user.isLogin && records.length > 0 && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginTop: rpxToPx(40), }}>
                         {

+ 0 - 1
src/pages/clock/Index的副本.tsx

@@ -86,7 +86,6 @@ export default function Page() {
     ])
 
     useEffect(() => {
-        global.showNightRing = false;
         setInterval(() => {
             if (isPause) {
                 return

+ 10 - 1
src/services/common.tsx

@@ -1,5 +1,5 @@
 import { setResources, setConfigs } from "@/store/common";
-import { API_CONFIGS, API_DEL_SESSION, API_GLOBAL_CONFIGS, API_STATIC_RESOURCES, API_SYSTEM_LOCATION, API_UPLOAD_SESSION, API_USER_LOCATION } from "./http/api";
+import { API_CONFIGS, API_DEL_SESSION, API_GLOBAL_CONFIGS, API_STATIC_RESOURCES, API_SYSTEM_LOCATION, API_UPLOAD_SESSION, API_USER_CLIENT, API_USER_LOCATION } from "./http/api";
 import { request } from "./http/request";
 import Taro from "@tarojs/taro";
 
@@ -25,6 +25,15 @@ export const gobalConfigs = () => (dispatch: any) => {
     })
 }
 
+export const clientInfo = (params) => {
+    request({
+        url: API_USER_CLIENT, method: 'POST', data: {
+            ...params
+        }
+    }).then(res => {
+    })
+}
+
 export const getConfigs = (params) => (dispatch: any) => {
     request({
         url: API_CONFIGS, method: 'GET', data: {

+ 1 - 0
src/services/http/api.js

@@ -17,6 +17,7 @@ export const API_GLOBAL_CONFIGS = `${baseUrl}/api/system/global-configs`
 export const API_CONFIGS = `${baseUrl}/api/system/configs`
 export const API_USER_INFO = `${baseUrl}/api/user/info`
 export const API_CLIENT_ID = `${baseUrl}/api/user/client-id`
+export const API_USER_CLIENT = `${baseUrl}/api/user/client`
 export const API_CLEAR_FAST = `${baseUrl}/api/clear/fasting`
 export const API_CLEAR_SLEEP = `${baseUrl}/api/sleep/clear-my-data`
 export const API_CLEAR_MIX = `${baseUrl}/api/clear-data/FAST_SLEEP`

+ 66 - 0
src/store/day.tsx

@@ -0,0 +1,66 @@
+import { createSlice } from "@reduxjs/toolkit";
+
+
+interface dayNightState {
+    sunRise: string | '06:00',
+    sunSet: string | '18:00',
+    sunRiseTomorrow: string | '06:00',
+    sunSetTomorrow: string | '18:00',
+    showDayRing: boolean | false,
+    isMember: boolean | false,
+    gpsInfo: Object | null,
+    dayRingSunrise: string | '06:00',
+    dayRingSunset: string | '18:00',
+    dayRingDate: any | null,
+}
+
+const initialState: dayNightState = {
+    sunRise: '06:00',
+    sunSet: '18:00',
+    sunRiseTomorrow: '06:00',
+    sunSetTomorrow: '18:00',
+    showDayRing: false,
+    isMember: false,
+    gpsInfo: null,
+    dayRingSunrise: '06:00',
+    dayRingSunset: '18:00',
+    dayRingDate: 0,
+}
+
+const dayNightSlice = createSlice({
+    name: 'day_night',
+    initialState,
+    reducers: {
+        showDay(state, action) {
+            state.showDayRing = action.payload;
+        },
+        setDayRingData(state, action) {
+            const { sunrise, sunset, date } = action.payload
+            state.dayRingDate = date;
+            state.dayRingSunrise = sunrise
+            state.dayRingSunset = sunset
+        },
+        updateMember(state, action) {
+            var isMember = action.payload.isMember;
+            var gpsInfo = action.payload.gpsInfo;
+            state.isMember = isMember;
+            if (isMember && gpsInfo) {
+                state.sunRise = '07:00'
+                state.sunSet = '19:00'
+                state.sunRiseTomorrow = '07:00'
+                state.sunSetTomorrow = '19:00'
+                state.gpsInfo = gpsInfo
+            }
+            else {
+                state.sunRise = '06:00'
+                state.sunSet = '18:00'
+                state.sunRiseTomorrow = '06:00'
+                state.sunSetTomorrow = '18:00'
+                state.gpsInfo = gpsInfo ? gpsInfo : null
+            }
+        },
+    }
+});
+
+export default dayNightSlice.reducer;
+export const { showDay, updateMember, setDayRingData } = dayNightSlice.actions;

+ 2 - 19
src/store/day_night.tsx → src/store/night.tsx

@@ -6,15 +6,11 @@ interface dayNightState {
     sunSet: string | '18:00',
     sunRiseTomorrow: string | '06:00',
     sunSetTomorrow: string | '18:00',
-    showDayRing: boolean | false,
     showNightRing: boolean | false,
     isMember: boolean | false,
     gpsInfo: Object | null,
-    dayRingSunrise: string | '06:00',
-    dayRingSunset: string | '18:00',
     nightRingSunset: string | '18:00',
     nightRingSunrise: string | '06:00',
-    dayRingDate: any | null,
     nightRingDate: any | null
 }
 
@@ -23,34 +19,21 @@ const initialState: dayNightState = {
     sunSet: '18:00',
     sunRiseTomorrow: '06:00',
     sunSetTomorrow: '18:00',
-    showDayRing: false,
     showNightRing: false,
     isMember: false,
     gpsInfo: null,
-    dayRingSunrise: '06:00',
-    dayRingSunset: '18:00',
-    dayRingDate: null,
     nightRingSunset: '18:00',
     nightRingSunrise: '06:00',
-    nightRingDate: null,
+    nightRingDate: 0,
 }
 
 const dayNightSlice = createSlice({
     name: 'day_night',
     initialState,
     reducers: {
-        showDay(state, action) {
-            state.showDayRing = action.payload;
-        },
         showNight(state, action) {
             state.showNightRing = action.payload;
         },
-        setDayRingData(state, action) {
-            const { sunrise, sunset, date } = action.payload
-            state.dayRingDate = date;
-            state.dayRingSunrise = sunrise
-            state.dayRingSunset = sunset
-        },
         setNightRingData(state, action) {
             const { sunrise, sunset, date } = action.payload
             state.nightRingDate = date;
@@ -80,4 +63,4 @@ const dayNightSlice = createSlice({
 });
 
 export default dayNightSlice.reducer;
-export const { showDay, showNight, updateMember, setDayRingData, setNightRingData } = dayNightSlice.actions;
+export const { showNight, updateMember, setNightRingData } = dayNightSlice.actions;

+ 4 - 2
src/store/store.tsx

@@ -8,7 +8,8 @@ import timeReducer from './time';
 import modalReducer from './modal';
 import consoleReducer from './console';
 import workoutReducer from './workout';
-import dayNightReducer from './day_night';
+import dayReducer from './day';
+import nightReducer from './night';
 
 const store = configureStore({
   reducer: {
@@ -23,7 +24,8 @@ const store = configureStore({
     modal: modalReducer,
     console: consoleReducer,
     workout: workoutReducer,
-    dayNight: dayNightReducer
+    night: nightReducer,
+    day: dayReducer
   },
 });
 

+ 1 - 1
src/utils/time_format.ts

@@ -592,7 +592,7 @@ export class TimeFormatter {
   //hh:mm转换成秒数
   static timestringToSeconds = (strTime: string) => {
     var list = strTime.split(':')
-    return parseInt(list[0]) * 3600 + parseInt(list[1])
+    return parseInt(list[0]) * 3600 + parseInt(list[1])*60
   }
 
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác