|
|
@@ -12,7 +12,7 @@ import { getLocalPush } from "@/features/trackTimeDuration/actions/TrackTimeActi
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import ProductList from "../store/product_list";
|
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
-import { getPerm, userAccess } from "@/services/user";
|
|
|
+import { getPerm, latestLocation, userAccess } from "@/services/user";
|
|
|
import '@/features/trackTimeDuration/components/CheckAccess.scss';
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
import Layout from "@/components/layout/layout";
|
|
|
@@ -23,6 +23,8 @@ import Tabbar from "@/components/navigation/TabBar";
|
|
|
import FSwitch from "@/components/input/FSwitch";
|
|
|
import { wxPubFollow } from "@/services/permission";
|
|
|
import { setWXFollow } from "@/store/permission";
|
|
|
+import { TimeFormatter } from "@/utils/time_format";
|
|
|
+import DayNightSwiperPopup from "@/features/daynight/DayNightSwiperPopup";
|
|
|
|
|
|
let useNavigation;
|
|
|
let AppState;
|
|
|
@@ -57,28 +59,45 @@ export default function Page() {
|
|
|
const [systemSun, setSystemSun] = useState(true)
|
|
|
const [isAuthorized, setIsAuthorized] = useState(false)
|
|
|
const [showMemberAlert, setShowMemberAlert] = useState(false)
|
|
|
+ const [errorCode, setErrorCode] = useState(-1)
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const accessObj = useSelector((state: any) => state.access);
|
|
|
const common = useSelector((state: any) => state.common);
|
|
|
+ const [authInfo, setAuthInfo] = useState<any>(null)
|
|
|
+ const [hasAddress, setHasAddress] = useState(false)
|
|
|
const permission = useSelector((state: any) => state.permission);
|
|
|
+ const [index,setIndex] = useState(0)
|
|
|
+
|
|
|
+
|
|
|
+ const [switching0, setSwitching0] = useState(false)
|
|
|
+ const [switching1, setSwitching1] = useState(false)
|
|
|
+ const [switching2, setSwitching2] = useState(false)
|
|
|
+ const [switching3, setSwitching3] = useState(false)
|
|
|
|
|
|
let navigation;
|
|
|
if (useNavigation) {
|
|
|
navigation = useNavigation()
|
|
|
}
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
-
|
|
|
- // }, [])
|
|
|
+ useEffect(() => {
|
|
|
+ setInterval(()=>{
|
|
|
+ setIndex(index=>index+1)
|
|
|
+ },1000)
|
|
|
+ }, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (!user.isLogin) {
|
|
|
return;
|
|
|
}
|
|
|
- checkSetting()
|
|
|
- getSettings()
|
|
|
- getMemberStatus()
|
|
|
+ // checkSetting()
|
|
|
+ // getSettings()
|
|
|
+ // getMemberStatus()
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
+ checkSetting()
|
|
|
+ getSettings()
|
|
|
+ getMemberStatus()
|
|
|
+ getLatestLocation()
|
|
|
+
|
|
|
navigation.setOptions({
|
|
|
headerTitle: '',
|
|
|
});
|
|
|
@@ -92,6 +111,7 @@ export default function Page() {
|
|
|
navigation.addListener('focus', () => {
|
|
|
rnNotification()
|
|
|
getMemberStatus()
|
|
|
+ getLatestLocation()
|
|
|
});
|
|
|
|
|
|
// 当页面即将消失时执行
|
|
|
@@ -117,6 +137,7 @@ export default function Page() {
|
|
|
rnNotification()
|
|
|
checkSetting()
|
|
|
getMemberStatus()
|
|
|
+ getLatestLocation()
|
|
|
}
|
|
|
|
|
|
};
|
|
|
@@ -188,8 +209,16 @@ export default function Page() {
|
|
|
|
|
|
useDidShow(() => {
|
|
|
console.log('notfication setting user did show')
|
|
|
+ getSettings()
|
|
|
+ getMemberStatus()
|
|
|
+ checkSetting()
|
|
|
+ getLatestLocation()
|
|
|
})
|
|
|
|
|
|
+ global.swiperDayNightRefresh = ()=>{
|
|
|
+ getLatestLocation()
|
|
|
+ }
|
|
|
+
|
|
|
function getSettings() {
|
|
|
getNotifySettings().then(res => {
|
|
|
var dt = (res as any).notification
|
|
|
@@ -200,6 +229,42 @@ export default function Page() {
|
|
|
setIsSolarNoon(dt.follow_sun.solar_noon.in_app == 'ON')
|
|
|
|
|
|
setLoaded(true)
|
|
|
+
|
|
|
+ if ((res as any).push_errors && (res as any).push_errors.length > 0) {
|
|
|
+ setErrorCode((res as any).push_errors[0].code)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setErrorCode(-1)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function getLatestLocation() {
|
|
|
+ if (!user.isLogin) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var today = new Date()
|
|
|
+ var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
|
|
|
+ var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 50)
|
|
|
+ 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: strYesterday, date_end: strTomorrow
|
|
|
+ }).then(data => {
|
|
|
+ if (data && (data as any).daylights) {
|
|
|
+ (data as any).daylights.map(item => {
|
|
|
+ if (!item.sunrise_ts) {
|
|
|
+ item.sunrise_ts = new Date(item.date + 'T' + item.sunrise + ':00').getTime()
|
|
|
+ item.sunset_ts = new Date(item.date + 'T' + item.sunset + ':00').getTime()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setHasAddress((data as any).has_address)
|
|
|
+
|
|
|
+ setAuthInfo(data)
|
|
|
+ }).catch(e => {
|
|
|
+ setLoaded(true)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -297,7 +362,7 @@ export default function Page() {
|
|
|
|
|
|
|
|
|
function confirm() {
|
|
|
- jumpPage('', 'ProductList', navigation)
|
|
|
+ jumpPage('/pages/store/product_list', 'ProductList', navigation)
|
|
|
setShowMemberAlert(false)
|
|
|
}
|
|
|
|
|
|
@@ -334,12 +399,33 @@ export default function Page() {
|
|
|
cancel: () => {
|
|
|
},
|
|
|
confirm: () => {
|
|
|
- checkNotification()
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
+ followWxPub()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ checkNotification()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ else {
|
|
|
+ showAlert({
|
|
|
+ title: '关注公众号',
|
|
|
+ content: 'content',
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ showCancel: true,
|
|
|
+ cancel: () => {
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ followWxPub()
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function pro(isLogin: boolean) {
|
|
|
@@ -351,44 +437,109 @@ export default function Page() {
|
|
|
</ScrollView>
|
|
|
}
|
|
|
|
|
|
+ function sunSwitchStatus(type: string) {
|
|
|
+ if (type == 'sunrise' && switching1) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (type == 'sunset' && switching2) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type == 'solarnoon' && switching3) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if (type =='extra' && switching0){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!user.isLogin) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!isAuthorized) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (type == 'extra'){
|
|
|
+ return isExtra;
|
|
|
+ }
|
|
|
+ if (!hasAddress) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type == 'sunrise')
|
|
|
+ return isSunrise
|
|
|
+ if (type == 'sunset')
|
|
|
+ return isSunset
|
|
|
+ if (type == 'solarnoon')
|
|
|
+ return isSolarNoon
|
|
|
+ return true
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function openSwitch(index){
|
|
|
+ if (index==0){
|
|
|
+ setSwitching0(true)
|
|
|
+ setTimeout(()=>{
|
|
|
+ setSwitching0(false)
|
|
|
+ },500)
|
|
|
+ }
|
|
|
+ if (index==1){
|
|
|
+ setSwitching1(true)
|
|
|
+ setTimeout(()=>{
|
|
|
+ setSwitching1(false)
|
|
|
+ },500)
|
|
|
+ }
|
|
|
+ if (index==2){
|
|
|
+ setSwitching2(true)
|
|
|
+ setTimeout(()=>{
|
|
|
+ setSwitching2(false)
|
|
|
+ },500)
|
|
|
+ }
|
|
|
+ if (index==3){
|
|
|
+ setSwitching3(true)
|
|
|
+ setTimeout(()=>{
|
|
|
+ setSwitching3(false)
|
|
|
+ },500)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function proDetail(isLogin: boolean) {
|
|
|
return <View className="setting_container">
|
|
|
<View className="setting_section">
|
|
|
- <Text className="setting_section_title">Fast & Sleep</Text>
|
|
|
+ <Text className="setting_section_title">{t('page.reminders.fast_sleep')}</Text>
|
|
|
</View>
|
|
|
- <Text className="setting_header">Reminders</Text>
|
|
|
+ <Text className="setting_header">{t('page.reminders.base')}</Text>
|
|
|
<View className="setting_cell">
|
|
|
- <Text className="setting_cell_title" style={{ flex: 1 }}>At schedule time</Text>
|
|
|
+ <Text className="setting_cell_title" style={{ flex: 1 }}>{t('page.reminders.base_schedule_time')}</Text>
|
|
|
{
|
|
|
- isLogin ? <Text className="setting_cell_value1">{systemFast ? 'Always' : 'Off'}</Text> :
|
|
|
+ isLogin ? <Text className="setting_cell_value1">{systemFast ? t('page.reminders.always') : 'Off'}</Text> :
|
|
|
<Text className="setting_cell_value1">Off</Text>
|
|
|
}
|
|
|
|
|
|
</View>
|
|
|
- <Text className="setting_footer">A timely reminder so you never miss your schedule time for fasting and/or sleep.</Text>
|
|
|
- <Text className="setting_header">Extra Reminders (Pro)</Text>
|
|
|
+ <Text className="setting_footer">{t('page.reminders.base_footer')}</Text>
|
|
|
+ <Text className="setting_header">{t('page.reminders.extra')}</Text>
|
|
|
<View className="setting_cell">
|
|
|
- <Text className="setting_cell_title" style={{ flex: 1 }}>Missed previous action</Text>
|
|
|
+ <Text className="setting_cell_title" style={{ flex: 1 }}>{t('page.reminders.missed_action')}</Text>
|
|
|
<FSwitch color={ColorType.fast}
|
|
|
- checked={isLogin ? (isAuthorized ? isExtra : false) : false}
|
|
|
+ checked={sunSwitchStatus('extra')}
|
|
|
onChange={(value) => {
|
|
|
+ openSwitch(0)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
- debugger
|
|
|
|
|
|
if (!isAuthorized) {
|
|
|
notificationOpen()
|
|
|
return
|
|
|
}
|
|
|
- if (value) {
|
|
|
- if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
- setShowMemberAlert(true)
|
|
|
- return
|
|
|
- }
|
|
|
+ // if (value) {
|
|
|
+ // if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
+ // setShowMemberAlert(true)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
|
|
|
- }
|
|
|
+ // }
|
|
|
postNotifySettings({
|
|
|
notification: {
|
|
|
fast_sleep: {
|
|
|
@@ -404,18 +555,19 @@ export default function Page() {
|
|
|
}}
|
|
|
/>
|
|
|
</View>
|
|
|
- <Text className="setting_footer">In case you missed your previous action, receive another reminder to log it together with the current one. This gives you extra protection against any streak loss.</Text>
|
|
|
+ <Text className="setting_footer">{t('page.reminders.extra_footer')}</Text>
|
|
|
<View className="setting_section">
|
|
|
- <Text className="setting_section_title">The Sun (Pro)</Text>
|
|
|
+ <Text className="setting_section_title">{t('page.reminders.sun')}</Text>
|
|
|
</View>
|
|
|
- <Text className="setting_header">Reminders for Your Daily Local Solar Times</Text>
|
|
|
+ <Text className="setting_header">{t('page.reminders.sun_header')}</Text>
|
|
|
<View className="setting_cell_group">
|
|
|
<View className="setting_cell_group_item">
|
|
|
- <Text className="setting_cell_title" style={{ flex: 1 }}>Sunrise</Text>
|
|
|
+ <Text className="setting_cell_title" style={{ flex: 1 }}>{t('page.reminders.sunrise')}</Text>
|
|
|
<FSwitch
|
|
|
color={ColorType.fast}
|
|
|
- checked={isLogin ? (isAuthorized ? isSunrise : false) : false}
|
|
|
+ checked={sunSwitchStatus('sunrise')}
|
|
|
onChange={(value) => {
|
|
|
+ openSwitch(1)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
@@ -424,6 +576,11 @@ export default function Page() {
|
|
|
notificationOpen()
|
|
|
return
|
|
|
}
|
|
|
+ if (!hasAddress) {
|
|
|
+ global.showDayNightSwiperPop2(false, new Date(), new Date())
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
if (value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
setShowMemberAlert(true)
|
|
|
@@ -449,19 +606,25 @@ export default function Page() {
|
|
|
</View>
|
|
|
<View className="new_item_cell_line" />
|
|
|
<View className="setting_cell_group_item">
|
|
|
- <Text className="setting_cell_title" style={{ flex: 1 }}>Sunset</Text>
|
|
|
+ <Text className="setting_cell_title" style={{ flex: 1 }}>{t('page.reminders.sunset')}</Text>
|
|
|
<FSwitch
|
|
|
color={ColorType.fast}
|
|
|
- checked={isLogin ? (isAuthorized ? isSunset : false) : false}
|
|
|
+ checked={sunSwitchStatus('sunset')}
|
|
|
onChange={(value) => {
|
|
|
+ openSwitch(2)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
if (!isAuthorized) {
|
|
|
+
|
|
|
notificationOpen()
|
|
|
return
|
|
|
}
|
|
|
+ if (!hasAddress) {
|
|
|
+ global.showDayNightSwiperPop2(true, new Date(), new Date())
|
|
|
+ return
|
|
|
+ }
|
|
|
if (value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
// setTimeout(() => {
|
|
|
@@ -491,17 +654,23 @@ export default function Page() {
|
|
|
</View>
|
|
|
<View className="new_item_cell_line" />
|
|
|
<View className="setting_cell_group_item">
|
|
|
- <Text className="setting_cell_title" style={{ flex: 1 }}>Solar noon</Text>
|
|
|
+ <Text className="setting_cell_title" style={{ flex: 1 }}>{t('page.reminders.solarnoon')}</Text>
|
|
|
<FSwitch
|
|
|
color={ColorType.fast}
|
|
|
- checked={isLogin ? (isAuthorized ? isSolarNoon : false) : false}
|
|
|
+ checked={sunSwitchStatus('solarnoon')}
|
|
|
onChange={(value) => {
|
|
|
+ openSwitch(3)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
if (!isAuthorized) {
|
|
|
notificationOpen()
|
|
|
+ setIsAuthorized(false)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!hasAddress) {
|
|
|
+ global.showDayNightSwiperPop2(false, new Date(), new Date())
|
|
|
return
|
|
|
}
|
|
|
if (value) {
|
|
|
@@ -533,7 +702,11 @@ export default function Page() {
|
|
|
/>
|
|
|
</View>
|
|
|
</View>
|
|
|
- <Text className="setting_footer">Note for polar region, during Polar Day (Midnight Sun) when the Sun is up all day or Polar Night when the Sun is down all day, the only reminder available is the daily Solar Noon.</Text>
|
|
|
+ <Text className="setting_footer">{t('page.reminders.sun_footer')}</Text>
|
|
|
+ <Text style={{opacity:0}}>{index}</Text>
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <View style={{ height: 120 }} />
|
|
|
+ }
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
@@ -588,6 +761,7 @@ export default function Page() {
|
|
|
<Text className="setting_tip_text">Jump to App's Notifications settings{'>>'}</Text>
|
|
|
</View>
|
|
|
}
|
|
|
+
|
|
|
{
|
|
|
showMemberAlert && process.env.TARO_ENV == 'weapp' && alertPop()
|
|
|
}
|
|
|
@@ -600,6 +774,18 @@ export default function Page() {
|
|
|
}
|
|
|
</View>
|
|
|
</Layout>
|
|
|
+
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && user.isLogin && errorCode == 43101 && <View className="setting_tip_bg"><View className="setting_tip2" onClick={goSetting}>
|
|
|
+ <Text className="setting_tip_text">{'请前往公众号主页,点右上角「设置-通知消息管理」\n确认“接收通知”已开启。'}</Text>
|
|
|
+ </View></View>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && user.isLogin && errorCode == 43019 && <View className="setting_tip_bg"><View className="setting_tip2" onClick={goSetting}>
|
|
|
+ <Text className="setting_tip_text">{'您暂无该功能体验权限。'}</Text>
|
|
|
+ </View></View>
|
|
|
+ }
|
|
|
+ <DayNightSwiperPopup authInfo={authInfo} />
|
|
|
<Tabbar index={2} />
|
|
|
</View>
|
|
|
}
|