|
@@ -5,7 +5,9 @@ import Taro from '@tarojs/taro'
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
import { updateMember } from '@/store/day_night'
|
|
import { updateMember } from '@/store/day_night'
|
|
|
import { systemLocation } from '@/services/common'
|
|
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() {
|
|
export default function DayLight() {
|
|
|
const [showRing, setShowRing] = useState(false)
|
|
const [showRing, setShowRing] = useState(false)
|
|
|
const [isTomorrow, setIsTomorrow] = useState(false)
|
|
const [isTomorrow, setIsTomorrow] = useState(false)
|
|
@@ -23,9 +25,15 @@ export default function DayLight() {
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
setIsMember(user.test_user)
|
|
setIsMember(user.test_user)
|
|
|
if (authInfo)
|
|
if (authInfo)
|
|
|
- dispatch(updateMember({ isMember: user.test_user, gpsInfo:authInfo }))
|
|
|
|
|
|
|
+ dispatch(updateMember({ isMember: user.test_user, gpsInfo: authInfo }))
|
|
|
if (user.test_user && 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)
|
|
setSunsetTime((authInfo as any).daylights[0].sunset)
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -40,7 +48,13 @@ export default function DayLight() {
|
|
|
(data as any).latitude = (data as any).lat;
|
|
(data as any).latitude = (data as any).lat;
|
|
|
(data as any).longitude = (data as any).lng;
|
|
(data as any).longitude = (data as any).lng;
|
|
|
setAuthInfo(data as any)
|
|
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)
|
|
setSunsetTime((data as any).daylights[0].sunset)
|
|
|
Taro.setStorage({
|
|
Taro.setStorage({
|
|
|
key: 'gps',
|
|
key: 'gps',
|
|
@@ -49,6 +63,12 @@ export default function DayLight() {
|
|
|
dispatch(updateMember({ isMember: user.test_user, gpsInfo: (data as any) }))
|
|
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])
|
|
}, [user.isLogin])
|
|
|
|
|
|
|
|
async function getStorage(key: string) {
|
|
async function getStorage(key: string) {
|
|
@@ -110,13 +130,17 @@ export default function DayLight() {
|
|
|
Taro.chooseLocation({
|
|
Taro.chooseLocation({
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
console.log(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);
|
|
console.log(data);
|
|
|
(data as any).latitude = res.latitude;
|
|
(data as any).latitude = res.latitude;
|
|
|
(data as any).longitude = res.longitude;
|
|
(data as any).longitude = res.longitude;
|
|
|
setAuthInfo(data as any)
|
|
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)
|
|
setSunsetTime((data as any).daylights[0].sunset)
|
|
|
Taro.setStorage({
|
|
Taro.setStorage({
|
|
|
key: 'gps',
|
|
key: 'gps',
|
|
@@ -164,6 +188,7 @@ export default function DayLight() {
|
|
|
<View className='daylight_row'>
|
|
<View className='daylight_row'>
|
|
|
<Text>Night ring</Text>
|
|
<Text>Night ring</Text>
|
|
|
<Switch checked={showRing}
|
|
<Switch checked={showRing}
|
|
|
|
|
+ color={ColorType.night}
|
|
|
onChange={(e) => {
|
|
onChange={(e) => {
|
|
|
setShowRing(e.detail.value)
|
|
setShowRing(e.detail.value)
|
|
|
global.showNightRing = e.detail.value
|
|
global.showNightRing = e.detail.value
|
|
@@ -172,6 +197,8 @@ export default function DayLight() {
|
|
|
key: 'showLightRing',
|
|
key: 'showLightRing',
|
|
|
data: e.detail.value
|
|
data: e.detail.value
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ uploadPerm({ show_night_ring: e.detail.value })
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
@@ -185,7 +212,7 @@ export default function DayLight() {
|
|
|
<Text>Sunrise tomororow</Text>
|
|
<Text>Sunrise tomororow</Text>
|
|
|
<Text>{sunriseTime}</Text>
|
|
<Text>{sunriseTime}</Text>
|
|
|
</View>
|
|
</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>
|
|
isMember ? <View>
|
|
|
<View className='daylight_item' onClick={auth}>
|
|
<View className='daylight_item' onClick={auth}>
|