|
|
@@ -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>
|
|
|
{
|