|
|
@@ -9,7 +9,7 @@ import { useDispatch, useSelector } from 'react-redux'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import { TimeFormatter } from '@/utils/time_format'
|
|
|
import { systemLocation } from '@/services/common'
|
|
|
-import { updateMember } from '@/store/day_night'
|
|
|
+import { setDayRingData, setNightRingData, updateMember } from '@/store/day_night'
|
|
|
import Modal from '@/components/layout/Modal.weapp'
|
|
|
import { rpxToPx } from '@/utils/tools'
|
|
|
import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
|
|
|
@@ -18,6 +18,8 @@ let useNavigation;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
}
|
|
|
+
|
|
|
+let locationDetail;
|
|
|
export default function DayNightCard(props: { isNight: boolean, switchChanged: Function }) {
|
|
|
const [expand, setExpand] = useState(false)
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
@@ -27,6 +29,10 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
const [sunriseTmrTime, setSunriseTmrTime] = useState('06:00')
|
|
|
const [sunsetTime, setSunsetTime] = useState('18:00')
|
|
|
const [showDetailModal, setShowDetailModal] = useState(false)
|
|
|
+ // const [locationDetail, setLocationDetail] = useState(null)
|
|
|
+
|
|
|
+ const [nightDate, setNightDate] = useState(new Date())
|
|
|
+ const [dayDate, setDayDate] = useState(new Date())
|
|
|
const dispatch = useDispatch();
|
|
|
const { t } = useTranslation()
|
|
|
let navigation;
|
|
|
@@ -41,12 +47,19 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
})
|
|
|
|
|
|
var today = new Date()
|
|
|
+ var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
|
|
|
var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
|
|
|
- var strToday = `${today.getFullYear()}-${TimeFormatter.padZero(today.getMonth() + 1)}-${TimeFormatter.padZero(today.getDate())}`
|
|
|
+ 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())}`
|
|
|
latestLocation({
|
|
|
- date_start: strToday, date_end: strTomorrow
|
|
|
- }).then(data => { })
|
|
|
+ date_start: strYesterday, date_end: strTomorrow
|
|
|
+ }).then(data => {
|
|
|
+ setAuthInfo(data as any)
|
|
|
+ updateDate(data)
|
|
|
+ locationDetail = data
|
|
|
+ console.log(data)
|
|
|
+ // setLocationDetail(data as any)
|
|
|
+ })
|
|
|
|
|
|
}
|
|
|
getContent()
|
|
|
@@ -55,12 +68,130 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
useEffect(() => {
|
|
|
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) {
|
|
|
+ console.log('9527')
|
|
|
+ detail.daylights.splice(0, 1)
|
|
|
+ }
|
|
|
+ locationDetail = detail
|
|
|
+
|
|
|
+ // setLocationDetail(detail)
|
|
|
+ updateDate(detail)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log('apple')
|
|
|
+ }
|
|
|
}, 1000)
|
|
|
}, [])
|
|
|
|
|
|
- useDidShow(() => {
|
|
|
- getContent()
|
|
|
- })
|
|
|
+ // useDidShow(() => {
|
|
|
+ // getContent()
|
|
|
+ // })
|
|
|
+
|
|
|
+ function updateDate(data) {
|
|
|
+
|
|
|
+ var today = new Date()
|
|
|
+ // var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
|
|
|
+ var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000)
|
|
|
+ // 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())}`
|
|
|
+ if (data.daylights.length > 0) {
|
|
|
+ var yesterdayDate = new Date(data.daylights[0].date + 'T' + data.daylights[0].sunset)
|
|
|
+ var todaySunriseDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunrise)
|
|
|
+ var todaySunsetDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunset)
|
|
|
+ var tomorrowSunriseDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunrise)
|
|
|
+
|
|
|
+ // var tomorrowSunsetDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunset)
|
|
|
+ //今天凌晨日出前
|
|
|
+ if (yesterdayDate.getTime() < today.getTime() && today.getTime() < todaySunriseDate.getTime()) {
|
|
|
+ setNightDate(yesterdayDate)
|
|
|
+ setDayDate(today)
|
|
|
+ if (props.isNight) {
|
|
|
+ setSunsetTime(data.daylights[0].sunset)
|
|
|
+ setSunriseTmrTime(data.daylights[1].sunrise)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setSunriseTime(data.daylights[1].sunrise)
|
|
|
+ setSunsetTime(data.daylights[1].sunset)
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ //今天白天(今天出日后-日落前)
|
|
|
+ else if (todaySunriseDate.getTime() < today.getTime() && today.getTime() < todaySunsetDate.getTime()) {
|
|
|
+ console.log('2')
|
|
|
+ setNightDate(today)
|
|
|
+ setDayDate(today)
|
|
|
+ if (props.isNight) {
|
|
|
+ setSunsetTime(data.daylights[1].sunset)
|
|
|
+ setSunriseTmrTime(data.daylights[2].sunrise)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setSunriseTime(data.daylights[1].sunrise)
|
|
|
+ setSunsetTime(data.daylights[1].sunset)
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ //今天夜晚
|
|
|
+ else if (today.getTime() > todaySunsetDate.getTime() && today.getTime() < tomorrowSunriseDate.getTime()) {
|
|
|
+ console.log('3')
|
|
|
+ setNightDate(today)
|
|
|
+ setDayDate(tomorrow)
|
|
|
+ if (props.isNight) {
|
|
|
+ setSunsetTime(data.daylights[1].sunset)
|
|
|
+ setSunriseTmrTime(data.daylights[2].sunrise)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setSunriseTime(data.daylights[2].sunrise)
|
|
|
+ setSunsetTime(data.daylights[2].sunset)
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // for (var i=0;i<data.daylights.length;i++){
|
|
|
+ // var obj = data[i]
|
|
|
+ // var str = obj.date+' '+obj.sunrise
|
|
|
+ // var date = new Date(str)
|
|
|
+ // var str2 = obj.date+' '+obj.sunset
|
|
|
+ // var date2 = new Date(str2)
|
|
|
+ // if (date2)
|
|
|
+ // }
|
|
|
+ // data.daylights.map(item=>{
|
|
|
+ // var str = item.date+' '+item.sunrise
|
|
|
+ // var date = new Date(str)
|
|
|
+ // debugger
|
|
|
+ // })
|
|
|
+ }
|
|
|
|
|
|
async function getContent() {
|
|
|
const isShow = await getStorage(props.isNight ? 'showNightRing' : 'showDayRing') || false
|
|
|
@@ -156,8 +287,11 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
|
|
|
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;
|
|
|
+ updateDate(data);
|
|
|
+ locationDetail = data;
|
|
|
+ // setLocationDetail(data as any);
|
|
|
+ // (data as any).latitude = res.latitude;
|
|
|
+ // (data as any).longitude = res.longitude;
|
|
|
setAuthInfo(data as any)
|
|
|
setSunriseTime((data as any).daylights[0].sunrise)
|
|
|
setSunriseTmrTime((data as any).daylights[1].sunrise)
|
|
|
@@ -410,6 +544,7 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
clearLocation().then(res => {
|
|
|
+ locationDetail = null
|
|
|
Taro.removeStorage({ key: 'gps' })
|
|
|
setAuthInfo(null)
|
|
|
setSunriseTime('06:00')
|
|
|
@@ -448,7 +583,7 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
<View className="cell_full" >
|
|
|
<Text className="cell_title">{t('feature.track_time_duration.third_ring.latitude')}</Text>
|
|
|
|
|
|
- <Text className="cell_value">{(authInfo as any).latitude}</Text>
|
|
|
+ <Text className="cell_value">{(authInfo as any).lat}</Text>
|
|
|
|
|
|
|
|
|
</View>
|
|
|
@@ -458,7 +593,7 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
<View className="cell_full">
|
|
|
<Text className="cell_title" >{t('feature.track_time_duration.third_ring.longitude')}</Text>
|
|
|
|
|
|
- <Text className="cell_value">{(authInfo as any).longitude}</Text>
|
|
|
+ <Text className="cell_value">{(authInfo as any).lng}</Text>
|
|
|
|
|
|
</View>
|
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
|
@@ -513,6 +648,20 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function nightDurationDesc() {
|
|
|
+ if (nightDate.getDate() == new Date().getDate()) {
|
|
|
+ return `Today ${sunsetTime} - Tomorrow ${sunriseTmrTime}`
|
|
|
+ }
|
|
|
+ return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
|
|
|
+ }
|
|
|
+
|
|
|
+ function dayDurationDesc() {
|
|
|
+ if (dayDate.getDate() == new Date().getDate()) {
|
|
|
+ return `${sunriseTime} - ${sunsetTime}`
|
|
|
+ }
|
|
|
+ return `Tomorrow ${sunriseTime} - Tomorrow ${sunsetTime}`
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
return <View style={{ color: '#fff' }}>
|
|
|
@@ -555,7 +704,7 @@ export default function DayNightCard(props: { isNight: boolean, switchChanged: F
|
|
|
{
|
|
|
expand && <View>
|
|
|
<View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
- <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? `Today ${sunsetTime} - Tomorrow ${sunriseTmrTime}` : `${sunriseTime} - ${sunsetTime}`}</Text>
|
|
|
+ <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 ? 'Sunset to Sunrise' : 'Sunrise to Sunset'}</Text>
|
|
|
<View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(32) }}>
|
|
|
<View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
|