Leon há 2 anos atrás
pai
commit
9c08f23e58

+ 8 - 0
src/features/trackTimeDuration/components/IndexItem.tsx

@@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next";
 import { ColorType } from "@/context/themes/color";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import { TimeFormatter } from "@/utils/time_format";
+import { useSelector } from "react-redux";
 
 let useNavigation;
 if (process.env.TARO_ENV == 'rn') {
@@ -14,6 +15,7 @@ if (process.env.TARO_ENV == 'rn') {
 export default function Component(props: { type: string, data: any, time: any }) {
     const { t } = useTranslation()
     const record = props.data.current_record;
+    const user = useSelector((state: any) => state.user);
     let navigation;
     if (useNavigation) {
         navigation = useNavigation()
@@ -164,6 +166,12 @@ export default function Component(props: { type: string, data: any, time: any })
     }
 
     function goClock() {
+        if (!user.isLogin){
+            jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
+            return
+        }
+        global.selectData = props.data
+        global.scenario = props.type
         jumpPage('/pages/clock/Clock', 'Clock', navigation)
     }
 

+ 52 - 7
src/pages/clock/Clock.tsx

@@ -56,7 +56,7 @@ if (process.env.TARO_ENV == 'rn') {
 
 export default function IndexPage() {
   const dispatch = useDispatch();
-  const { t,i18n } = useTranslation()
+  const { t, i18n } = useTranslation()
   const [checkData, setCheckData] = useState(null)
   const user = useSelector((state: any) => state.user);
   const time = useSelector((state: any) => state.time);
@@ -95,10 +95,10 @@ export default function IndexPage() {
   }
 
   useEffect(() => {
-    if (process.env.TARO_ENV=='rn'){
+    if (process.env.TARO_ENV == 'rn') {
       AppState.addEventListener('change', handleAppStateChange);
     }
-    
+
     global.consoleType = 'idle'
     dispatch(staticResources() as any);
     // dispatch(gobalConfigs() as any);
@@ -119,10 +119,10 @@ export default function IndexPage() {
   }, [])
 
   useEffect(() => {
-    
+
     const currentLanguage = i18n.language;
     global.language = currentLanguage
-    console.log('current language',currentLanguage)
+    console.log('current language', currentLanguage)
   }, [])
 
   const handleAppStateChange = (nextAppState) => {
@@ -319,6 +319,51 @@ export default function IndexPage() {
   }
 
   function getCheckData() {
+    var res = global.selectData
+    setErrorPage(false)
+    dispatch(updateScenario((res as any).current_record))
+    dispatch(setConfigs((res as any).time_input_schema));
+    dispatch(setScenario((res as any).scenario));
+
+    if ((res as any).theme_color) {
+      global.fastColor = (res as any).theme_color.fast
+      global.sleepColor = (res as any).theme_color.sleep
+    }
+    machine.context.checkData = res as any;
+
+    global.scenario = (res as any).current_record.scenario;
+    const currentState = trackTimeService.getSnapshot();
+    let json = {};
+    var key = (res as any).current_record.scenario
+    var status = (res as any).current_record.status
+    json[key] = status
+    currentState.value = json;
+    machine.context.currentStatus = `${key}.${status}`;//'mixed.ON_GOING2'
+    setCheckData(res as any)
+
+    setLoaded(true)
+
+    if ((res as any).current_record.status != 'ONGOING1') {
+      setSwiperIndex(0)
+    }
+    else {
+      if (global.consoleType == 'going') {
+        setShowSingleFastEnd(true)
+        setTimeout(() => {
+          setShowSingleFastEnd(false)
+          setSwiperIndex(1)
+          setAutoPlay(true)
+          global.consoleType = 'end'
+          dispatch(changeConsoleStatus({ status: ConsoleType.end }))
+          setTimeout(() => {
+            global.consoleType = 'idle'
+          }, 2000)
+        }, 500)
+      }
+      else {
+      }
+    }
+    return
     getClocks().then(res => {
       debugger
       setErrorPage(false)
@@ -520,7 +565,7 @@ export default function IndexPage() {
           onBeforeLeave={() => {
             Taro.showTabBar();
           }}
-          onClick={()=>{alert('b')}}
+          onClick={() => { alert('b') }}
           onClickOverlay={() => { alert('a') }}
           onAfterLeave={() => { setShowModal(false); setShowModal2(false) }}
           show={showModal || showModal2} round={true} overlay={true} position='bottom'
@@ -581,7 +626,7 @@ export default function IndexPage() {
             user.isLogin && checkData && (checkData as any).latest_record &&
             <RecordFastSleep type='latest' data={(checkData as any).latest_record} delSuccess={getCheckData} />
           }
-          <View style={{ height: process.env.TARO_ENV=='rn'?0:100 }} />
+          <View style={{ height: process.env.TARO_ENV == 'rn' ? 0 : 100 }} />
         </View>
 
         {

+ 14 - 12
src/pages/clock/Index.tsx

@@ -23,6 +23,7 @@ export default function Page() {
     const [showErrorPage, setErrorPage] = useState(false)
     const [data, setData] = useState(null)
     const [count, setCount] = useState(0)
+    const [homeData, setHomeData] = useState(null)
 
     const [selIndex, setSelIndex] = useState(0)
 
@@ -48,9 +49,9 @@ export default function Page() {
     }, [])
 
     useEffect(() => {
-        if (user.isLogin) {
+        // if (user.isLogin) {
             getCheckData()
-        }
+        // }
     }, [user.isLogin, time.status])
 
     useReady(async () => {
@@ -64,15 +65,16 @@ export default function Page() {
             // }, 200)
 
         }
+
     })
 
     function getCheckData() {
         getClocks().then(res => {
-            setErrorPage(false)
-            setData(res as any)
-            dispatch(updateScenario((res as any).current_record))
-            dispatch(setConfigs((res as any).time_input_schema));
-            dispatch(setScenario((res as any).scenario));
+            // setErrorPage(false)
+            // setData(res as any)
+            // dispatch(updateScenario((res as any).current_record))
+            // dispatch(setConfigs((res as any).time_input_schema));
+            // dispatch(setScenario((res as any).scenario));
 
             if ((res as any).theme_color) {
                 global.fastColor = (res as any).theme_color.fast
@@ -81,7 +83,7 @@ export default function Page() {
         })
 
         clockHome().then(res => {
-
+            setHomeData(res as any)
         })
     }
 
@@ -93,7 +95,7 @@ export default function Page() {
             return '';
         }
     }
-    if (!data) {
+    if (!homeData) {
         return <View>
             <Tabbar index={0} />
         </View>
@@ -102,10 +104,10 @@ export default function Page() {
     var timestamp = new Date().getTime()
     return <View className="index_container">
         <Text className="count">{count}</Text>
-        <IndexItem type="FAST" data={data} time={timestamp} />
-        <IndexItem type='SLEEP' data={data} time={timestamp} />
+        <IndexItem type="FAST" data={(homeData as any).fast} time={timestamp} />
+        <IndexItem type='SLEEP' data={(homeData as any).sleep} time={timestamp} />
         <Text className="discovery">探索</Text>
-        <IndexItem type="FAST_SLEEP" data={data} time={timestamp} />
+        <IndexItem type="FAST_SLEEP" data={(homeData as any).fast_sleep} time={timestamp} />
         <Tabbar index={0} />
 
         <View>

+ 2 - 2
src/services/trackTimeDuration.tsx

@@ -32,7 +32,7 @@ export const setPlan = (params: Record<string, any> | undefined) => {
 export const getChecks = () => {
     return new Promise((resolve) => {
         request({
-            url: API_FAST_CHECKS, method: 'GET', data: {}
+            url: API_FAST_CHECKS+`?scenario=${global.scenario}`, method: 'GET', data: {}
         }).then(res => {
             resolve(res);
         })
@@ -84,7 +84,7 @@ export const recordCheck = (params: Record<string, any>) => {
     }
     return new Promise((resolve) => {
         request({
-            url: API_FAST_CLOCKS, method: 'POST', data: { ...params }
+            url: API_FAST_CLOCKS+`?scenario=${global.scenario}`, method: 'POST', data: { ...params }
         }).then(res => {
             resolve(res);
         }).catch(e => {