Leon 2 years ago
parent
commit
a77295876d

+ 1 - 0
src/features/trackTimeDuration/components/DayLight.scss

@@ -53,4 +53,5 @@
     -webkit-line-clamp: 1;
     white-space: normal;
     width: 240px;
+    text-align: right;
 }

+ 22 - 10
src/features/trackTimeDuration/components/DayLight.tsx

@@ -4,6 +4,7 @@ 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 { systemLocation } from '@/services/common'
 export default function DayLight() {
     const [showRing, setShowRing] = useState(false)
     const [isTomorrow, setIsTomorrow] = useState(false)
@@ -20,16 +21,16 @@ export default function DayLight() {
 
     useEffect(() => {
         setIsMember(user.test_user)
-        dispatch(updateMember({ isMember: user.test_user,authInfo }))
+        dispatch(updateMember({ isMember: user.test_user, authInfo }))
         if (user.test_user && authInfo) {
-            setSunriseTime('07:00')
-            setSunsetTime('19:00')
+            setSunriseTime((authInfo as any).daylights[0].sunrise)
+            setSunsetTime((authInfo as any).daylights[0].sunset)
         }
         else {
             setSunriseTime('06:00')
             setSunsetTime('18:00')
         }
-    }, [user.test_user,authInfo])
+    }, [user.test_user, authInfo])
 
     async function getStorage(key: string) {
         try {
@@ -90,12 +91,21 @@ export default function DayLight() {
         Taro.chooseLocation({
             success: function (res) {
                 console.log(res)
-                setAuthInfo(res as any)
-                Taro.setStorage({
-                    key: 'gps',
-                    data: JSON.stringify(res as any)
+
+                systemLocation({ lat: res.latitude, lng: res.longitude }).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)
+                    setSunsetTime((data as any).daylights[0].sunset)
+                    Taro.setStorage({
+                        key: 'gps',
+                        data: JSON.stringify(data as any)
+                    })
+                    dispatch(updateMember({ isMember: user.test_user, gpsInfo: (data as any) }))
                 })
-                dispatch(updateMember({ isMember: user.test_user, gpsInfo: (res as any) }))
+
             },
             fail(res) {
                 Taro.showToast({
@@ -107,6 +117,8 @@ export default function DayLight() {
 
     }
 
+
+
     var split = new Date().toString().split(' ');
     var timezone = split[split.length - 2];
 
@@ -143,7 +155,7 @@ export default function DayLight() {
                         <View className='daylight_item' onClick={auth}>
                             <Text style={{ flex: 1 }}>Location</Text>
                             {
-                                authInfo ? <Text className='address'>{(authInfo as any).address}</Text> :
+                                authInfo ? <Text className='address'>{(authInfo as any).address.city}</Text> :
                                     <Text>Enter</Text>
                             }
                             <Image className="daylight_arrow" src={require('@/assets/images/arrow3.png')} />

+ 31 - 3
src/features/trackTimeDuration/components/IndexItem.tsx

@@ -204,8 +204,18 @@ export default function Component(props: { type: string, data: any, time: any })
             startArc: 0,
             durationArc: 2
         }
-        var sunRise = 24 * 60 + (dayNight.gpsInfo && dayNight.isMember ? 7 * 60 : 6 * 60)
-        var sunSet = dayNight.gpsInfo && dayNight.isMember ? 19 * 60 : 18 * 60
+        var sunRise = 24 * 60 +  6 * 60
+        var sunSet = 18 * 60
+
+        if (dayNight.gpsInfo && dayNight.isMember){
+            var sunRiseObj = dayNight.gpsInfo.daylights[0].sunrise
+            var sunSetObj = dayNight.gpsInfo.daylights[0].sunset
+            sunRise = 24*60+parseInt(sunRiseObj.split(':')[0])*60+parseInt(sunRiseObj.split(':')[1])
+            sunSet = parseInt(sunSetObj.split(':')[0])*60+parseInt(sunSetObj.split(':')[1])
+            if (sunSetObj.indexOf('PM')!=-1){
+                sunSet+=12*60
+            }
+        }
         var duration = sunRise - sunSet
         realRingBig.startArc = (sunSet * 60) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
         realRingBig.durationArc = (duration * 60) / (24 * 3600) * 2 * Math.PI;
@@ -297,6 +307,24 @@ export default function Component(props: { type: string, data: any, time: any })
         jumpPage('/pages/clock/Clock', 'Clock', navigation)
     }
 
+    function nightDuration(){
+        if (dayNight.gpsInfo && dayNight.isMember){
+            var sunRiseObj = dayNight.gpsInfo.daylights[0].sunrise
+            var sunSetObj = dayNight.gpsInfo.daylights[0].sunset
+            var sunRise = 24*60+parseInt(sunRiseObj.split(':')[0])*60+parseInt(sunRiseObj.split(':')[1])
+            var sunSet = parseInt(sunSetObj.split(':')[0])*60+parseInt(sunSetObj.split(':')[1])
+            if (sunSetObj.indexOf('PM')!=-1){
+                sunSet+=12*60
+            }
+
+            var duration = (sunRise-sunSet)*60*1000
+
+            return TimeFormatter.calculateTimeDifference(new Date().getTime(),new Date().getTime()+duration);
+        }else {
+            return '12小时'
+        }
+    }
+
     return <View className="time_operate_item" onClick={goClock}>
         <View className="fast_sleep_item">
             {
@@ -309,7 +337,7 @@ export default function Component(props: { type: string, data: any, time: any })
                 }
                 {
                     props.type == 'FAST_SLEEP' && user.isLogin && global.showNightRing === true &&
-                    <Text className="duration_value" style={{ color: ColorType.night }}>12小时</Text>
+                    <Text className="duration_value" style={{ color: ColorType.night }}>{nightDuration()}</Text>
                 }
                 {
                     (props.type == 'FAST' || props.type == 'FAST_SLEEP') && <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>

+ 19 - 0
src/features/trackTimeDuration/components/WeekCalendarItem.scss

@@ -36,3 +36,22 @@
     width: 86px;
     margin-left: 8px;
 }
+
+.verticalLine{
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    background-color: #5A5A5A;
+    -webkit-transform: scaleX(0.5);
+    transform: scaleX(0.5);
+    width: 2px;
+}
+.horizontalLine{
+    position: absolute;
+    left: 0;
+    right: 0;
+    background-color: #5A5A5A;
+    -webkit-transform: scaleY(0.5);
+    transform: scaleY(0.5);
+    height: 2px;
+}

+ 12 - 1
src/features/trackTimeDuration/components/WeekCalendarItem.tsx

@@ -1,5 +1,6 @@
 import { View, Text } from "@tarojs/components";
 import './WeekCalendarItem.scss'
+import { rpxToPx } from "@/utils/tools";
 export default function WeekCalendarItem() {
     return <View className="chart_content">
         <View className="chart_top_week">
@@ -11,7 +12,17 @@ export default function WeekCalendarItem() {
             <Text className="chart_week_text">周五</Text>
             <Text className="chart_week_text">周六</Text>
         </View>
-        <View className="chart_detail"></View>
+        <View className="chart_detail">
+            <View className="verticalLine" style={{left:rpxToPx(94)}}/>
+            <View className="verticalLine" style={{left:rpxToPx(94*2)}}/>
+            <View className="verticalLine" style={{left:rpxToPx(94*3)}}/>
+            <View className="verticalLine" style={{left:rpxToPx(94*4)}}/>
+            <View className="verticalLine" style={{left:rpxToPx(94*5)}}/>
+            <View className="verticalLine" style={{left:rpxToPx(94*6)}}/>
+            <View className="horizontalLine" style={{top:rpxToPx(100),backgroundColor:'#262626'}}/>
+            <View className="horizontalLine" style={{top:rpxToPx(200),backgroundColor:'#383838'}}/>
+            <View className="horizontalLine" style={{top:rpxToPx(300),backgroundColor:'#262626'}}/>
+        </View>
         <View className="chart_bottom_week">
             <Text className="chart_week_text">周一</Text>
             <Text className="chart_week_text">周二</Text>

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

@@ -92,6 +92,9 @@ export const dotIsOuterRange = (isTargetRange: boolean, scheduleData?: any, dayL
         var scheduleEnd = new Date(scheduleData!.target_end_time)
         var startMinute = scheduleStart.getHours() * 60 + scheduleStart.getMinutes()
         var endMinute = scheduleEnd.getHours() * 60 + scheduleStart.getMinutes()
+        if (endMinute<startMinute){
+            endMinute+=1440
+        }
         if (startMinute <= minutes && endMinute > minutes) {
             return false;
         }

+ 17 - 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_UPLOAD_SESSION } from "./http/api";
+import { API_CONFIGS, API_DEL_SESSION, API_GLOBAL_CONFIGS, API_STATIC_RESOURCES, API_SYSTEM_LOCATION, API_UPLOAD_SESSION } from "./http/api";
 import { request } from "./http/request";
 import Taro from "@tarojs/taro";
 
@@ -45,6 +45,22 @@ export const uploadSessionKey = (params) => {
     })
 }
 
+export const systemLocation = (params) => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_SYSTEM_LOCATION, method: 'GET', data: {
+                ...params
+            }
+        }).then(res => {
+            resolve(res)
+            // dispatch(loginSuccess(res));
+        }).catch(e => {
+            reject(e)
+        })
+    })
+
+}
+
 export const delSession = (params) => {
     request({
         url: API_DEL_SESSION + '?type=WX_MP', method: 'DELETE', data: {

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

@@ -24,6 +24,7 @@ export const API_CHECK_UNIQUE = `${baseUrl}/api/user/check-unique`
 export const API_UPLOAD_SESSION = `${baseUrl}/api/thirdparty/wx/session`
 export const API_DEL_SESSION = `${baseUrl}/api/thirdparty/wx/session`
 export const API_USER_PERMS =  `${baseUrl}/api/user/perms`
+export const API_SYSTEM_LOCATION =  `${baseUrl}/api/system/location`
 
 //track time duration
 export const API_FAST_PLANS = `${baseUrl}/api/fast/plans`