Leon il y a 1 an
Parent
commit
695b56fb68
2 fichiers modifiés avec 114 ajouts et 27 suppressions
  1. 11 7
      src/pages/clock/ClockMain.tsx
  2. 103 20
      src/pages/notification/setting.tsx

+ 11 - 7
src/pages/clock/ClockMain.tsx

@@ -120,7 +120,7 @@ export default function Page() {
     const common = useSelector((state: any) => state.common);
     const [access, setAccess] = useState<any>(null)
 
-    const [buildVersion,setBuildVersion] = useState('')
+    const [buildVersion, setBuildVersion] = useState('')
 
     const scrollRef = useRef(null);
 
@@ -421,7 +421,7 @@ export default function Page() {
         if (process.env.TARO_ENV == 'rn') {
             var NativeModules = require('react-native').NativeModules;
             var DeviceInfo = require('react-native-device-info').default
-            console.log('jslfspodgfsdfopgs',DeviceInfo.getBuildNumber())
+            console.log('jslfspodgfsdfopgs', DeviceInfo.getBuildNumber())
             setBuildVersion(DeviceInfo.getBuildNumber())
             if (kIsIOS) {
                 // language = NativeModules.SettingsManager.settings.AppleLocale
@@ -602,7 +602,7 @@ export default function Page() {
             global.swiperDayNightRefresh()
         }
 
-        if (global.refrehWeekly){
+        if (global.refrehWeekly) {
             global.refrehWeekly()
         }
 
@@ -921,7 +921,11 @@ export default function Page() {
                         </View>
                         <WeekCalendar isFastSleep={true} />
                         <View className="vip_calendar" onClick={() => setShowEatCalendar(true)}>
-                            <Text className="eat_calendar_text">{t('feature.track_time_duration.weekly.show_eating_window')}</Text>
+                            {
+                                process.env.TARO_ENV == 'weapp' ? <Text className="eat_calendar_text">{t('feature.track_time_duration.weekly.show_eating_window')}</Text> :
+                                    <GradientText style={{ fontSize: rpxToPx(28), color: 'black' }} colors={[ColorType.food, ColorType.activity]}>{t('feature.track_time_duration.weekly.show_eating_window')}</GradientText>
+                            }
+
                         </View>
                     </View>
                 }
@@ -983,11 +987,11 @@ export default function Page() {
                     user.isLogin && user.test_user && homeData && access && <View style={{ display: 'flex', flexDirection: 'column' }}>
                         <Text style={{ color: '#fff', fontSize: 15 }}>member status:{access && access.member && access.member.status}</Text>
                         {
-                            access && access.member && access.member.status=='MEMBER' &&
+                            access && access.member && access.member.status == 'MEMBER' &&
                             <Text style={{ color: '#fff', fontSize: 15 }}>会员过期时间:{dayjs(access.member.expire).format('YYYY-MM-DD HH:mm:ss')}</Text>
                         }
                         {
-                            access && access.member && access.member.status=='MEMBER' &&
+                            access && access.member && access.member.status == 'MEMBER' &&
                             <Text style={{ color: '#fff', fontSize: 15 }}>会员过期倒计时:{TimeFormatter.countdown(access.member.expire)}</Text>
                         }
                         <Text style={{ color: '#fff', fontSize: 15 }}>current status:{access.fast_sleep.current.qualification.status}</Text>
@@ -996,7 +1000,7 @@ export default function Page() {
                         <Text style={{ color: '#fff', fontSize: 15 }}>lost_access_total:{access.fast_sleep.current.qualification.condition.lost_access_total}</Text>
                         <Text style={{ color: '#fff', fontSize: 15 }}>streak_fast_min_required:{access.fast_sleep.current.qualification.condition.streak_fast_min_required}</Text>
                         {
-                            process.env.TARO_ENV=='rn' && <Text style={{ color: '#fff', fontSize: 15 }}>App build version:{buildVersion}</Text>
+                            process.env.TARO_ENV == 'rn' && <Text style={{ color: '#fff', fontSize: 15 }}>App build version:{buildVersion}</Text>
                         }
                     </View>
                 }

+ 103 - 20
src/pages/notification/setting.tsx

@@ -1,4 +1,4 @@
-import { View, Text, Switch, ScrollView } from "@tarojs/components";
+import { View, Text, ScrollView } from "@tarojs/components";
 import Metric from "@/features/trackSomething/components/Metric";
 import { useDidShow, usePullDownRefresh, useShareAppMessage } from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
@@ -12,11 +12,13 @@ import { getLocalPush } from "@/features/trackTimeDuration/actions/TrackTimeActi
 import { useSelector } from "react-redux";
 import ProductList from "../store/product_list";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
+import { userAccess } from "@/services/user";
 
 let useNavigation;
-let AppState;
+let AppState, Switch;
 if (process.env.TARO_ENV == 'rn') {
     AppState = require("react-native").AppState
+    Switch = require("react-native").Switch
     useNavigation = require("@react-navigation/native").useNavigation
 }
 export default function Page() {
@@ -32,6 +34,7 @@ export default function Page() {
     const [systemFast, setSystemFast] = useState(true)
     const [systemExtra, setSystemExtra] = useState(true)
     const [systemSun, setSystemSun] = useState(true)
+    const [access, setAccess] = useState<any>(null)
     const user = useSelector((state: any) => state.user);
 
     let navigation;
@@ -40,12 +43,13 @@ export default function Page() {
     }
 
     // useEffect(() => {
-        
+
     // }, [])
 
-    useEffect(()=>{
+    useEffect(() => {
         checkSetting()
         getSettings()
+        getMemberStatus()
         if (process.env.TARO_ENV == 'rn') {
             AppState.addEventListener('change', handleAppStateChange);
             // AppState.addEventListener('change', handleAppStateChange);
@@ -59,7 +63,19 @@ export default function Page() {
             // });
 
         }
-    },[user.isLogin])
+
+        if (process.env.TARO_ENV == 'rn') {
+            // AppState.addEventListener('change', handleAppStateChange);
+            navigation.addListener('focus', () => {
+                getMemberStatus()
+            });
+
+            // 当页面即将消失时执行
+            navigation.addListener('blur', () => {
+            });
+
+        }
+    }, [user.isLogin])
 
     const handleAppStateChange = (nextAppState) => {
         console.log(nextAppState)
@@ -68,10 +84,39 @@ export default function Page() {
         }
         if (nextAppState == 'active') {
             checkSetting()
+            getMemberStatus()
         }
 
     };
 
+    function getMemberStatus() {
+        userAccess().then(res => {
+            setAccess(res)
+            if ((res as any).member.status == 'NON_MEMBER') {
+                postNotifySettings({
+                    notification: {
+                        follow_sun: {
+                            sunrise: {
+                                in_app: 'OFF'
+                            },
+                            sunset: {
+                                in_app: 'OFF'
+                            },
+                            solar_noon: {
+                                in_app: 'OFF'
+                            }
+                        }
+                    }
+                }).then(res => {
+                    setIsSolarNoon(false)
+                    setIsSunset(false)
+                    setIsSunrise(false)
+                    global.swiperDayNightRefresh()
+                })
+            }
+        })
+    }
+
     useDidShow(() => {
         console.log('notfication setting user did show')
     })
@@ -84,6 +129,7 @@ export default function Page() {
             setIsSunrise(dt.follow_sun.sunrise.in_app == 'ON')
             setIsSunset(dt.follow_sun.sunset.in_app == 'ON')
             setIsSolarNoon(dt.follow_sun.solar_noon.in_app == 'ON')
+
             setLoaded(true)
         })
     }
@@ -168,8 +214,8 @@ export default function Page() {
         </View>
     }
 
-    function iap(){
-        jumpPage('','ProductList',navigation)
+    function iap() {
+        jumpPage('', 'ProductList', navigation)
     }
 
     function pro() {
@@ -189,18 +235,20 @@ export default function Page() {
                 <Text className="setting_header">Extra Reminders</Text>
                 <View className="setting_cell">
                     <Text className="setting_cell_title" style={{ flex: 1 }}>If I missed previous action</Text>
-                    <Switch className="myswitch" checked={isExtra} color={ColorType.fast} onChange={(e) => {
-                        // setIsMulti(e.detail.value)
+                    <Switch className="myswitch" value={isExtra} color={ColorType.fast} trackColor={{ true: ColorType.fast }} onChange={(e) => {
+                        debugger
+                        // setIsMulti(e.nativeEvent.value)
+                        const value = e.nativeEvent.value
                         postNotifySettings({
                             notification: {
                                 fast_sleep: {
                                     extra_reminders: {
-                                        in_app: e.detail.value ? 'ON' : 'OFF'
+                                        in_app: value ? 'ON' : 'OFF'
                                     }
                                 }
                             }
                         }).then(res => {
-                            setIsExtra(e.detail.value)
+                            setIsExtra(value)
                             getLocalPush()
                         })
                     }} />
@@ -214,17 +262,30 @@ export default function Page() {
                     <View className="setting_cell_group_item">
                         <Text className="setting_cell_title" style={{ flex: 1 }}>Sunrise</Text>
                         <Switch className="myswitch" checked={isSunrise} color={ColorType.fast} onChange={(e) => {
-                            // setIsMulti(e.detail.value)
+                            // setIsMulti(e.nativeEvent.value)
+                            const value = e.nativeEvent.value
+                            if (e.nativeEvent.value) {
+                                if (access.member.status == 'NON_MEMBER') {
+                                    setTimeout(() => {
+                                        setIsSunrise(false)
+                                    }, 1000)
+
+                                    jumpPage('', 'ProductList', navigation)
+                                    return
+                                }
+
+                            }
                             postNotifySettings({
                                 notification: {
                                     follow_sun: {
                                         sunrise: {
-                                            in_app: e.detail.value ? 'ON' : 'OFF'
+                                            in_app: value ? 'ON' : 'OFF'
                                         }
                                     }
                                 }
                             }).then(res => {
-                                setIsSunrise(e.detail.value)
+                                setIsExtra(value)
+                                // setIsSunrise(e.nativeEvent.value)
                                 global.swiperDayNightRefresh()
                             })
                         }} />
@@ -232,17 +293,28 @@ export default function Page() {
                     <View className="setting_cell_group_item">
                         <Text className="setting_cell_title" style={{ flex: 1 }}>Sunset</Text>
                         <Switch className="myswitch" checked={isSunset} color={ColorType.fast} onChange={(e) => {
-                            // setIsMulti(e.detail.value)
+                            // setIsMulti(e.nativeEvent.value)
+                            if (e.nativeEvent.value) {
+                                if (access.member.status == 'NON_MEMBER') {
+                                    setTimeout(() => {
+                                        setIsSunset(false)
+                                    }, 1000)
+
+                                    jumpPage('', 'ProductList', navigation)
+                                    return
+                                }
+
+                            }
                             postNotifySettings({
                                 notification: {
                                     follow_sun: {
                                         sunset: {
-                                            in_app: e.detail.value ? 'ON' : 'OFF'
+                                            in_app: e.nativeEvent.value ? 'ON' : 'OFF'
                                         }
                                     }
                                 }
                             }).then(res => {
-                                setIsSunset(e.detail.value)
+                                setIsSunset(e.nativeEvent.value)
                                 global.swiperDayNightRefresh()
                             })
                         }} />
@@ -250,17 +322,28 @@ export default function Page() {
                     <View className="setting_cell_group_item">
                         <Text className="setting_cell_title" style={{ flex: 1 }}>Solar Noon</Text>
                         <Switch className="myswitch" checked={isSolarNoon} color={ColorType.fast} onChange={(e) => {
-                            // setIsMulti(e.detail.value)
+                            // setIsMulti(e.nativeEvent.value)
+                            if (e.nativeEvent.value) {
+                                if (access.member.status == 'NON_MEMBER') {
+                                    setTimeout(() => {
+                                        setIsSolarNoon(false)
+                                    }, 1000)
+
+                                    jumpPage('', 'ProductList', navigation)
+                                    return
+                                }
+
+                            }
                             postNotifySettings({
                                 notification: {
                                     follow_sun: {
                                         solar_noon: {
-                                            in_app: e.detail.value ? 'ON' : 'OFF'
+                                            in_app: e.nativeEvent.value ? 'ON' : 'OFF'
                                         }
                                     }
                                 }
                             }).then(res => {
-                                setIsSolarNoon(e.detail.value)
+                                setIsSolarNoon(e.nativeEvent.value)
                                 global.swiperDayNightRefresh()
                             })
                         }} />