leon před 1 rokem
rodič
revize
47d40985c1

+ 3 - 1
src/features/trackTimeDuration/components/CheckAccess.tsx

@@ -79,6 +79,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
     function viewWillAppear() {
         if (checkChooseMixed && chooseMixedSuccess) {
             upgradeSuccess()
+            confirmAction = null
         }
         setCheckChooseMixed(false)
         setChooseMixedSuccess(false)
@@ -112,6 +113,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
 
 
             setSubConfirmText('')
+            confirmAction = null
             // setAccess(acccessData)
 
             if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
@@ -321,7 +323,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
             dispatch(updateStep({ step: 2 }))
             dispatch(chooseMode({ isMixed: true }))
             setCheckChooseMixed(true)
-            jumpPage(`/pages/clock/SetGoal?upgrade=true`, 'SetGoal', navigation, {})
+            jumpPage(`/pages/clock/SetGoal?upgrade=true&isSelf=1`, 'SetGoal', navigation, {})
             confirmAction = goSetting
         })
 

+ 45 - 12
src/features/trackTimeDuration/components/ClockHeader.tsx

@@ -11,8 +11,9 @@ import { PageContainer, View } from "@tarojs/components";
 import PickerViews from "@/components/input/PickerViews";
 import Modal from "@/components/layout/Modal.weapp";
 import { ColorType } from "@/context/themes/color";
-import { updateRecord } from "@/services/trackTimeDuration";
+import { getPlans, updateRecord } from "@/services/trackTimeDuration";
 import showActionSheet from "@/components/basic/ActionSheet";
+import { chooseMode, initTarget, updateStep } from "@/store/set_target";
 
 
 let GradientText
@@ -28,6 +29,7 @@ if (process.env.TARO_ENV == 'rn') {
 export default function ClockHeader(props: { homeData: any }) {
     const user = useSelector((state: any) => state.user);
     const time = useSelector((state: any) => state.time);
+    const ring = useSelector((state: any) => state.ring);
     const [fastPickerValue, setFastPickerValue] = useState([0, 0])
     const [sleepPickerValue, setSleepPickerValue] = useState([0, 0])
     const [fastDuration, setFastDuration] = useState<number>(0);
@@ -101,6 +103,27 @@ export default function ClockHeader(props: { homeData: any }) {
                             })
                             return;
                         }
+                        getPlans().then(res => {
+                            const data = res as { scenarios: any[] };
+                            console.log(data)
+                            var targets: any = {}
+                            data.scenarios.forEach((item) => {
+                                if (item.name == 'FAST') {
+                                    if (item.schedule.fast.duration.prev_input) {
+                                        item.schedule.fast.duration.last_value = item.schedule.fast.duration.init_value
+                                    }
+                                    targets.fast = item
+                                }
+                                else if (item.name == 'SLEEP') {
+                                    targets.sleep = item
+                                }
+                            })
+                            dispatch(initTarget(targets))
+                            dispatch(updateStep({ step: 0 }))
+                            dispatch(chooseMode({ isMixed: ring.current_record.scenario=='FAST_SLEEP' }))
+                            jumpPage(`/pages/clock/Suggest`, 'Suggest', navigation, {})
+                        })
+
                         break;
                     case 2:
                         if (time.status != 'WAIT_FOR_START') {
@@ -110,16 +133,26 @@ export default function ClockHeader(props: { homeData: any }) {
                             })
                             return;
                         }
-                        if (time.scenario == 'FAST_SLEEP') {
-                            dispatch(setStep(isFastFirst ? 'fast' : 'sleep'))
-                        }
-                        else if (time.scenario == 'SLEEP') {
-                            dispatch(setStep('sleep'))
-                        }
-                        else {
-                            dispatch(setStep('fast'))
-                        }
-                        jumpPage('/pages/clock/SetSchedule', 'SetSchedule', navigation)
+                        getPlans().then(res => {
+                            const data = res as { scenarios: any[] };
+                            console.log(data)
+                            var targets: any = {}
+                            data.scenarios.forEach((item) => {
+                                if (item.name == 'FAST') {
+                                    if (item.schedule.fast.duration.prev_input) {
+                                        item.schedule.fast.duration.last_value = item.schedule.fast.duration.init_value
+                                    }
+                                    targets.fast = item
+                                }
+                                else if (item.name == 'SLEEP') {
+                                    targets.sleep = item
+                                }
+                            })
+                            dispatch(initTarget(targets))
+                            dispatch(updateStep({ step: 2 }))
+                            dispatch(chooseMode({ isMixed: ring.current_record.scenario=='FAST_SLEEP' }))
+                            jumpPage(`/pages/clock/SetGoal?upgrade=true&isSelf=1`, 'SetGoal', navigation, {})
+                        })
                         break;
                 }
             }
@@ -228,4 +261,4 @@ export default function ClockHeader(props: { homeData: any }) {
             modalContent()
         }
     </View>
-}
+}

+ 21 - 0
src/features/trackTimeDuration/components/Streaks.tsx

@@ -9,9 +9,11 @@ import { TimeFormatter } from '@/utils/time_format'
 import { rpxToPx } from '@/utils/tools'
 
 let GradientText
+let useNavigation;
 
 if (process.env.TARO_ENV == 'rn') {
     GradientText = require('@/components/basic/GradientText').default
+    useNavigation = require("@react-navigation/native").useNavigation
 }
 
 export default function Streaks(props: { count: number }) {
@@ -19,9 +21,25 @@ export default function Streaks(props: { count: number }) {
     const [fastStreaks, setFastStreaks] = useState<any>(null)
     const [sleepStreaks, setSleepStreaks] = useState<any>(null)
     const [isLoading, setIsLoading] = useState(false)
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
 
     useEffect(() => {
         getDatas()
+
+        if (process.env.TARO_ENV == 'rn') {
+            // AppState.addEventListener('change', handleAppStateChange);
+            navigation.addListener('focus', () => {
+                getDatas()
+            });
+
+            // 当页面即将消失时执行
+            navigation.addListener('blur', () => {
+            });
+
+        }
     }, [])
 
     useEffect(() => {
@@ -38,6 +56,9 @@ export default function Streaks(props: { count: number }) {
         }
     }, [props.count])
 
+
+
+
     global.refreshStreaks = () => {
         getDatas()
     }

+ 2 - 2
src/pages/clock/ChooseScenario.scss

@@ -12,7 +12,7 @@
     padding-top: 48px;
     padding-bottom: 40px;
     border-radius: 24px;
-    background-color: #1c1c1c;
+    background-color: #767676;
     color: #fff;
     position: relative;
     box-sizing: border-box;
@@ -32,7 +32,7 @@
     padding-top: 48px;
     padding-bottom: 40px;
     border-radius: 24px;
-    background-color: #1c1c1c;
+    background-color: #767676;
     color: #fff;
     position: relative;
     box-sizing: border-box;

+ 3 - 0
src/pages/clock/Clock.tsx

@@ -51,6 +51,7 @@ import dayjs from 'dayjs'
 import DayNightSwiper from "@/features/daynight/DayNightSwiper";
 import showAlert from "@/components/basic/Alert";
 import { APP_VERSION, WX_VERSION } from "@/services/http/api";
+import { wxPubFollow } from "@/services/permission";
 
 const utc = require('dayjs/plugin/utc')
 const timezone = require('dayjs/plugin/timezone')
@@ -219,6 +220,7 @@ export default function Page() {
             checkAuthorized();
             //检查用户是否添加过小程序
             checkAddToMini();
+            wxPubFollow({force_refresh:true});
 
 
 
@@ -525,6 +527,7 @@ export default function Page() {
 
 
     function getCheckData() {
+        
         Promise.all([getClocks(), getPlans()]).then((list) => {
             setErrorPage(false)
             setCheckData(list)

+ 1 - 1
src/pages/clock/SetGoal.tsx

@@ -193,7 +193,7 @@ export default function SetGoal() {
         }
 
         if (router.params.upgrade) {
-            params.trigger_event = 'PROVISIONAL UPGRADE SET'
+            params.trigger_event = 'PROVISIONAL_UPGRADE_SET'
         }
         else {
             params.trigger_event = 'SET'

+ 96 - 37
src/pages/clock/Suggest.tsx

@@ -102,7 +102,8 @@ export default function Suggest() {
             setFastLastIndex(lastIndex)
             setSuggestItem(array)
             setSuggestIndex(currentIndex)
-            setScrollTop(currentIndex * rpxToPx(160))
+            setScrollTop(currentIndex * rpxToPx(160) + 50)
+            // setScrollTop(currentIndex * 100-30)
         }
         else if (pageStep == 3) {
             var obj = target.sleep.schedule.sleep
@@ -402,14 +403,33 @@ export default function Suggest() {
         }
     }
 
-    function targetRing(start, end, isFast) {
+    function targetRing(start, end, isFast, isHighLight) {
+        var color: any = isFast ? ColorType.fast + '66' : ColorType.sleep + '66'
+        if (!isHighLight) {
+            color = isFast ? ColorType.fast + '0D' : ColorType.sleep + '0D'
+        }
         return {
-            color: isFast ? ColorType.fast : ColorType.sleep,
+            color: color,
             startArc: timeToArc(start),
             durationArc: durationToArc(start, end)
         }
     }
 
+    function point(isFast: boolean, isShow: boolean) {
+        if (!isShow) return null;
+
+        var now = new Date()
+        var t = suggestItems[suggestIndex].time
+        now.setHours(parseInt(t.split(':')[0]))
+        now.setMinutes(parseInt(t.split(':')[1]))
+
+        return [{
+            color: isFast ? ColorType.fast : ColorType.sleep,
+            borderColor: 'transparent',
+            timestamp: now.getTime()
+        }]
+    }
+
     function timeToArc(time: string) {
         var count: number = parseInt(time.split(':')[1]) + parseInt(time.split(':')[0]) * 60
         // count = count>720?count-720:count
@@ -432,32 +452,64 @@ export default function Suggest() {
                 <View style={{ flexDirection: 'column', display: 'flex' }}>
                     {
                         suggestItems.map((item: any, index: number) => {
-                            return <View onClick={() => {
-                                setSuggestIndex(index)
-                            }} key={index} className={index == suggestIndex ? 'item_choose_selected' : 'item_choose'}>
-                                <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
-                                    <View className="suggest_item_title">{item.hours} hours</View>
-                                    <View style={{ flex: 1 }} />
-                                    {
-                                        index == fastRecommendIndex &&
-                                        <View style={{ color: '#fff' }}>Recommended</View>
-                                    }
-                                    {
-                                        index == fastLastIndex &&
-                                        <View style={{ color: '#fff', marginLeft: 5 }}>Last</View>
-                                    }
+                            return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} onClick={() => setSuggestIndex(index)}>
+                                <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
+                                    <Rings2 common={ringCommon()}
+                                        bgRing={bgRing}
+                                        targetRing={targetRing(item.time, target.fast.schedule.fast.end_time, true, suggestIndex == index)}
+                                        dotList={point(true, index == suggestIndex)}
+                                        canvasId={new Date().getTime() + index * 5} />
                                 </View>
-
-                                <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
-                                {
-                                    index == suggestIndex &&
-                                    <View className="suggest_choose">
-                                        <View style={{ color: ColorType.fast }}>Start fasting at  {item.time}</View>
-                                        <IconCheck color={ColorType.fast} width={38} height={26} />
+                                <View>
+                                    <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
+                                        <View className="suggest_item_title">{item.hours} hours</View>
+                                        <View style={{ flex: 1 }} />
+                                        {
+                                            index == fastRecommendIndex &&
+                                            <View style={{ color: '#fff' }}>Popular</View>
+                                        }
+                                        {
+                                            index == fastLastIndex &&
+                                            <View style={{ color: '#fff', marginLeft: 5 }}>Recent</View>
+                                        }
                                     </View>
-                                }
 
+                                    <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
+                                    {
+                                        index == suggestIndex &&
+                                        <View className="suggest_choose">
+                                            <View style={{ color: ColorType.fast }}>Start fasting at  {item.time}</View>
+                                            <IconCheck color={ColorType.fast} width={38} height={26} />
+                                        </View>
+                                    }
+                                </View>
                             </View>
+                            // return <View onClick={() => {
+                            //     setSuggestIndex(index)
+                            // }} key={index} className={index == suggestIndex ? 'item_choose_selected' : 'item_choose'}>
+                            //     <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
+                            //         <View className="suggest_item_title">{item.hours} hours</View>
+                            //         <View style={{ flex: 1 }} />
+                            //         {
+                            //             index == fastRecommendIndex &&
+                            //             <View style={{ color: '#fff' }}>Popular</View>
+                            //         }
+                            //         {
+                            //             index == fastLastIndex &&
+                            //             <View style={{ color: '#fff', marginLeft: 5 }}>Recent</View>
+                            //         }
+                            //     </View>
+
+                            //     <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
+                            //     {
+                            //         index == suggestIndex &&
+                            //         <View className="suggest_choose">
+                            //             <View style={{ color: ColorType.fast }}>Start fasting at  {item.time}</View>
+                            //             <IconCheck color={ColorType.fast} width={38} height={26} />
+                            //         </View>
+                            //     }
+
+                            // </View>
                         })
                     }
                 </View>
@@ -466,19 +518,26 @@ export default function Suggest() {
         return <View style={{ flex: 1, overflow: 'scroll' }}>
             {
                 suggestItems.map((item: any, index: number) => {
-                    return <View onClick={() => {
-                        setSuggestIndex(index)
-                    }} key={index} className={index == suggestIndex ? 'item_sel2' : 'item1'}>
-
-                        <View className="suggest_item_title">{item.hours} hrs {item.minutes} mins</View>
-                        <View className="suggest_item_desc">{item.number} sleep cycles</View>
-                        {
-                            index == suggestIndex && <View className="suggest_choose">
-                                <View style={{ color: ColorType.sleep }}>Go to bed at {item.time}</View>
-                                <IconCheck color={ColorType.sleep} width={38} height={26} />
-                            </View>
-                        }
+                    return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} onClick={() => setSuggestIndex(index)}>
+                        <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
+                            <Rings2 common={ringCommon()}
+                                bgRing={bgRing}
+                                dotList={point(false, index == suggestIndex)}
+                                targetRing={targetRing(item.time, target.sleep.schedule.sleep.end_time, false, suggestIndex == index)}
+                                canvasId={new Date().getTime() + index * 5} />
+                        </View>
+                        <View>
+
+                            <View className="suggest_item_title">{item.hours} hrs {item.minutes} mins</View>
+                            <View className="suggest_item_desc">{item.number} sleep cycles</View>
+                            {
+                                index == suggestIndex && <View className="suggest_choose">
+                                    <View style={{ color: ColorType.sleep }}>Go to bed at {item.time}</View>
+                                    <IconCheck color={ColorType.sleep} width={38} height={26} />
+                                </View>
+                            }
 
+                        </View>
                     </View>
                 })
             }

+ 0 - 1
src/store/ring.tsx

@@ -24,7 +24,6 @@ const ringSlice = createSlice({
     reducers: {
 
         setSchedule(state, action) {
-            debugger
             state.count = new Date().getTime()
             state.schedule = action.payload
         },