Leon преди 1 година
родител
ревизия
136a6cb973

+ 34 - 7
src/features/trackTimeDuration/components/DayLight.tsx

@@ -5,7 +5,9 @@ import Taro from '@tarojs/taro'
 import { useDispatch, useSelector } from 'react-redux'
 import { updateMember } from '@/store/day_night'
 import { systemLocation } from '@/services/common'
-import { clearLocation, latestLocation } from '@/services/user'
+import { clearLocation, getPerm, latestLocation, uploadPerm } from '@/services/user'
+import { TimeFormatter } from '@/utils/time_format'
+import { ColorType } from '@/context/themes/color'
 export default function DayLight() {
     const [showRing, setShowRing] = useState(false)
     const [isTomorrow, setIsTomorrow] = useState(false)
@@ -23,9 +25,15 @@ export default function DayLight() {
     useEffect(() => {
         setIsMember(user.test_user)
         if (authInfo)
-            dispatch(updateMember({ isMember: user.test_user, gpsInfo:authInfo }))
+            dispatch(updateMember({ isMember: user.test_user, gpsInfo: authInfo }))
         if (user.test_user && authInfo) {
-            setSunriseTime((authInfo as any).daylights[0].sunrise)
+            if ((authInfo as any).daylights.length==1){
+                setSunriseTime((authInfo as any).daylights[0].sunrise)
+            }
+            else {
+                setSunriseTime((authInfo as any).daylights[1].sunrise)
+            }
+            
             setSunsetTime((authInfo as any).daylights[0].sunset)
         }
         else {
@@ -40,7 +48,13 @@ export default function DayLight() {
                 (data as any).latitude = (data as any).lat;
                 (data as any).longitude = (data as any).lng;
                 setAuthInfo(data as any)
-                setSunriseTime((data as any).daylights[0].sunrise)
+                
+                if ((data as any).daylights.length==1){
+                    setSunriseTime((data as any).daylights[0].sunrise)
+                }
+                else {
+                    setSunriseTime((data as any).daylights[1].sunrise)
+                }
                 setSunsetTime((data as any).daylights[0].sunset)
                 Taro.setStorage({
                     key: 'gps',
@@ -49,6 +63,12 @@ export default function DayLight() {
                 dispatch(updateMember({ isMember: user.test_user, gpsInfo: (data as any) }))
             }
         })
+
+        if (user.isLogin) {
+            getPerm({}).then(res => {
+                setShowRing((res as any).show_night_ring)
+            })
+        }
     }, [user.isLogin])
 
     async function getStorage(key: string) {
@@ -110,13 +130,17 @@ export default function DayLight() {
         Taro.chooseLocation({
             success: function (res) {
                 console.log(res)
+                var today = new Date()
+                var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000)
+                var strToday = `${today.getFullYear()}-${TimeFormatter.padZero(today.getMonth() + 1)}-${TimeFormatter.padZero(today.getDate())}`
+                var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
 
-                systemLocation({ lat: res.latitude, lng: res.longitude }).then(data => {
+                systemLocation({ lat: res.latitude, lng: res.longitude, date_start: strToday, date_end: strTomorrow }).then(data => {
                     console.log(data);
                     (data as any).latitude = res.latitude;
                     (data as any).longitude = res.longitude;
                     setAuthInfo(data as any)
-                    setSunriseTime((data as any).daylights[0].sunrise)
+                    setSunriseTime((data as any).daylights[1].sunrise)
                     setSunsetTime((data as any).daylights[0].sunset)
                     Taro.setStorage({
                         key: 'gps',
@@ -164,6 +188,7 @@ export default function DayLight() {
         <View className='daylight_row'>
             <Text>Night ring</Text>
             <Switch checked={showRing}
+                color={ColorType.night}
                 onChange={(e) => {
                     setShowRing(e.detail.value)
                     global.showNightRing = e.detail.value
@@ -172,6 +197,8 @@ export default function DayLight() {
                         key: 'showLightRing',
                         data: e.detail.value
                     })
+
+                    uploadPerm({ show_night_ring: e.detail.value })
                 }}
             />
         </View>
@@ -185,7 +212,7 @@ export default function DayLight() {
                     <Text>Sunrise tomororow</Text>
                     <Text>{sunriseTime}</Text>
                 </View>
-                <Text className='daylight_note'>{isMember ? 'Calculated based on your location.' : 'Sunset and sunrise times are global average. For actual times at your location, join our Pro program.'}</Text>
+                <Text className='daylight_note'>{isMember && authInfo ? 'Calculated based on your location.' : 'Sunset and sunrise times are global average. For actual times at your location, join our Pro program.'}</Text>
                 {
                     isMember ? <View>
                         <View className='daylight_item' onClick={auth}>

+ 36 - 3
src/features/trackTimeDuration/components/Discovery.tsx

@@ -11,6 +11,7 @@ import Taro from "@tarojs/taro";
 import './Discovery.scss'
 import { useTranslation } from "react-i18next";
 import { TimeFormatter } from "@/utils/time_format";
+import { getPerm, uploadPerm } from "@/services/user";
 
 
 let useNavigation;
@@ -39,6 +40,14 @@ export default function Discovery() {
         setSchedule(global.homeData.scenarios)
     }, [global.homeData])
 
+    useEffect(() => {
+        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 });
@@ -271,7 +280,7 @@ export default function Discovery() {
         </View>
     }
     return <View style={{ display: 'flex', flexDirection: 'column' }}>
-        <View style={{ display: 'flex', flexDirection: 'row', marginLeft: 50, marginBottom: 50,alignItems:'center' }}>
+        <View style={{ display: 'flex', flexDirection: 'row', marginLeft: 50, marginBottom: 50, alignItems: 'center' }}>
             {
                 schedule && rings()
             }
@@ -299,10 +308,10 @@ export default function Discovery() {
             }
         </View>
         <View className="food_btn1" style={{ backgroundColor: ColorType.food }} onClick={goFood}>
-            <Text style={{fontWeight:'bold'}}>食物日记</Text>
+            <Text style={{ fontWeight: 'bold' }}>食物日记</Text>
         </View>
         <View className="food_btn1" style={{ backgroundColor: ColorType.activity }} onClick={goAcitivity}>
-            <Text style={{fontWeight:'bold'}}>运动训练</Text>
+            <Text style={{ fontWeight: 'bold' }}>运动训练</Text>
         </View>
         <View style={{
             display: 'flex', flexDirection: 'row',
@@ -311,8 +320,10 @@ export default function Discovery() {
         }}>
             <Text style={{ color: '#fff' }}>白天</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
@@ -320,6 +331,28 @@ export default function Discovery() {
                 }}
             />
         </View>
+        <View>
+            <View style={{
+                display: 'flex', flexDirection: 'row',
+                justifyContent: 'space-between',
+                marginLeft: rpxToPx(46), marginRight: rpxToPx(46)
+            }}>
+                <Text style={{ color: '#fff' }}>Sunrise today</Text>
+                <Text style={{ color: '#fff' }}>{
+                    dayNight.isMember && dayNight.gpsInfo ? dayNight.gpsInfo.daylights[0].sunrise : '06:00'
+                }</Text>
+            </View>
+            <View style={{
+                display: 'flex', flexDirection: 'row',
+                justifyContent: 'space-between',
+                marginLeft: rpxToPx(46), marginRight: rpxToPx(46)
+            }}>
+                <Text style={{ color: '#fff' }}>Sunset today</Text>
+                <Text style={{ color: '#fff' }}>{
+                    dayNight.isMember && dayNight.gpsInfo ? dayNight.gpsInfo.daylights[0].sunset : '18:00'
+                }</Text>
+            </View>
+        </View>
 
     </View>
 }

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

@@ -32,7 +32,7 @@ export default function RecordFastSleep(props: { data: any, type: string, delSuc
     const [diffTimeZone, setDiffTimeZone] = useState(false)
     const [multiTimeZone, setMultiTimeZone] = useState(false)
     const { t } = useTranslation()
-    const canvasId = props.data.id
+    var canvasId = props.data.id+new Date().getTime()
     const record = props.data;
 
     const handleAppStateChange = (nextAppState) => {

+ 9 - 10
src/features/trackTimeDuration/components/TimelineStage.rn.tsx

@@ -15,10 +15,10 @@ import { useFocusEffect } from '@react-navigation/native';
 import React from 'react';
 import JPush from 'jpush-react-native';
 import { Linking } from 'react-native';
-import { uploadPushPerm } from '@/services/user';
+import { uploadPerm } from '@/services/user';
 
 
-export default function Component(props: { data: any, title?: string, subTitle?: string, isSchedule?: boolean,first_real_check_time?:number }) {
+export default function Component(props: { data: any, title?: string, subTitle?: string, isSchedule?: boolean, first_real_check_time?: number }) {
     // debugger
     const [segmentIndex, setSegmentIndex] = useState(0)
     const permission = useSelector((state: any) => state.permission);
@@ -55,12 +55,11 @@ export default function Component(props: { data: any, title?: string, subTitle?:
 
         JPush.isNotificationEnabled(obj => {
             setPushEnable(obj)
-
-            uploadPushPerm(obj)
+            uploadPerm({ push_enabled: obj })
         })
     }
 
-    function goSetting(){
+    function goSetting() {
         Linking.openURL('app-settings:notifications')
     }
 
@@ -72,8 +71,8 @@ export default function Component(props: { data: any, title?: string, subTitle?:
             return item.code == 'follow_wx_pub'
         })
 
-        const title = permission.wxPubFollow ?t('feature.track_time_duration.follow_wx_pub.h5_followed_title'):
-        t('feature.track_time_duration.follow_wx_pub.h5_unfollowed_title')
+        const title = permission.wxPubFollow ? t('feature.track_time_duration.follow_wx_pub.h5_followed_title') :
+            t('feature.track_time_duration.follow_wx_pub.h5_unfollowed_title')
 
         Taro.showModal({
             title: permission.wxPubFollow ? t('feature.track_time_duration.follow_wx_pub.modal_followed_title') :
@@ -99,11 +98,11 @@ export default function Component(props: { data: any, title?: string, subTitle?:
         <View className="box_header" style={{ backgroundColor: global.isDebug ? 'pink' : 'transparent' }}>
             <Text className="box_title" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>{props.title ? props.title : 'Title'}</Text>
             {
-                props.isSchedule && process.env.TARO_ENV=='weapp' &&
+                props.isSchedule && process.env.TARO_ENV == 'weapp' &&
                 <Switch isOn={permission.wxPubFollow} onClick={() => followWxPub()} />
             }
             {
-                props.isSchedule && process.env.TARO_ENV=='rn' &&
+                props.isSchedule && process.env.TARO_ENV == 'rn' &&
                 <Switch isOn={pushEnable} onClick={() => goSetting()} />
             }
         </View>
@@ -124,7 +123,7 @@ export default function Component(props: { data: any, title?: string, subTitle?:
 
                 <View style={{ position: 'relative' }}>
                     <View style={{ opacity: segmentIndex == 0 ? 1 : 0 }}>
-                        <TimelineFastSleep data={props.data} first_real_check_time={props.first_real_check_time}/>
+                        <TimelineFastSleep data={props.data} first_real_check_time={props.first_real_check_time} />
                     </View>
                     {props.data.scenario == 'FAST_SLEEP' && <View style={{
                         opacity: segmentIndex == 1 ? 1 : 0,

+ 13 - 10
src/pages/clock/Index.tsx

@@ -441,18 +441,21 @@ export default function Page() {
             {
                 user.isLogin && <DayLight />
             }
-            <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
-                {
-                    user.isLogin && <Text className="discovery">最近</Text>
-                }
-                {
-                    process.env.TARO_ENV == 'weapp' && <Text className="fast_sleep_more index_more" onClick={more}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
-                }
-            </View>
             {
-                process.env.TARO_ENV == 'rn' && <GradientText onClick={more} style={{ fontSize: rpxToPx(32), fontWeight: 'bold' }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</GradientText>
-                //<Text className="header_action fast_sleep_text"  onClick={() => { props.action!() }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
+                user.isLogin && records.length > 0 && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
+                    {
+                        <Text className="discovery">最近</Text>
+                    }
+                    {
+                        process.env.TARO_ENV == 'weapp' && <Text className="fast_sleep_more index_more" onClick={more}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
+                    }
+                    {
+                        process.env.TARO_ENV == 'rn' && <GradientText onClick={more} style={{ fontSize: rpxToPx(32), fontWeight: 'bold' }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</GradientText>
+                        //<Text className="header_action fast_sleep_text"  onClick={() => { props.action!() }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
+                    }
+                </View>
             }
+
             {
                 records.length > 0 && <View className="fast_sleep_item_bg">
                     <RecordFastSleep data={records[0]} type='record' delSuccess={() => { }} />

+ 15 - 2
src/services/user.tsx

@@ -30,10 +30,23 @@ export const login = (username: string, password: string) => {
     })
 }
 
-export const uploadPushPerm = (push_enable: boolean) => {
+export const uploadPerm = (params: any) => {
     return new Promise((resolve, reject) => {
         request({
-            url: API_USER_PERMS, method: 'POST', data: { push_enabled: push_enable }
+            url: API_USER_PERMS, method: 'POST', data: { ...params }//{ push_enabled: push_enable }
+        }).then(res => {
+            resolve(res)
+            // dispatch(loginSuccess(res));
+        }).catch(e => {
+            reject(e)
+        })
+    })
+}
+
+export const getPerm = (params: any) => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_USER_PERMS, method: 'GET', data: { ...params }//{ push_enabled: push_enable }
         }).then(res => {
             resolve(res)
             // dispatch(loginSuccess(res));