Leon 1 anno fa
parent
commit
8f528fce65
1 ha cambiato i file con 42 aggiunte e 24 eliminazioni
  1. 42 24
      src/pages/clock/Index.tsx

+ 42 - 24
src/pages/clock/Index.tsx

@@ -41,6 +41,8 @@ import { showDay } from "@/store/day";
 import { clientInfo } from "@/services/common";
 import { changeFastDuration, changeSleepDuration, setCurrentRecord, setSchedule } from "@/store/ring";
 import { checkAuthorized } from "@/utils/check_authorized";
+import NoData from "@/components/view/NoData";
+import { AtActivityIndicator } from "taro-ui";
 
 let GradientText
 let useNavigation;
@@ -70,7 +72,7 @@ export default function Page() {
     const [count, setCount] = useState(0)
     const [homeData, setHomeData] = useState(null)
     const [loaded, setLoaded] = useState(false)
-
+    const [showErrorPage, setErrorPage] = useState(false)
 
     const [showModal, setShowModal] = useState(false)
     const [modalDetail, setModalDetail] = useState<any>(null)
@@ -85,6 +87,7 @@ export default function Page() {
 
 
 
+
     useEffect(() => {
         timer = setInterval(() => {
             if (global.pauseIndexTimer || pauseTimer) {
@@ -256,33 +259,40 @@ export default function Page() {
 
     function getCheckData() {
         Promise.all([getClocks(), getPlans()]).then((list) => {
-            setHomeData(list[0] as any)
-            global.homeData = list[0]
-            global.currentStatus = (list[0] as any).current_record.status;
-            var array = (list[1] as any).scenarios
-            var schedule = null
-            array.map(item => {
-                if (item.name == 'FAST_SLEEP') {
-                    schedule = item.schedule;
-                }
-            })
-            if (user.isLogin) {
-                dispatch(updateScenario((list[0] as any).current_record))
-                dispatch(setConfigs((list[0] as any).time_input_schema));
-                dispatch(setScenario((list[0] as any).scenario));
-
+            setErrorPage(false)
+            setCheckData(list)
+        }).catch((e) => {
+            setErrorPage(true)
+            var list = JSON.parse(defaultValue)
+            setCheckData(list)
+        })
 
+        getHistory()
+    }
 
-                global.scenario = (list[0] as any).scenario.name;
+    function setCheckData(list: any) {
+        setHomeData(list[0])
+        global.homeData = list[0]
+        global.currentStatus = list[0].current_record.status;
+        var array = list[1].scenarios
+        var schedule = null
+        array.map(item => {
+            if (item.name == 'FAST_SLEEP') {
+                schedule = item.schedule;
             }
-            dispatch(setCurrentRecord((list[0] as any).current_record))
-            dispatch(setSchedule(schedule))
-            setLoaded(true)
-        }).catch((e)=>{
-            console.log('9527',e)
         })
+        if (user.isLogin) {
+            dispatch(updateScenario(list[0].current_record))
+            dispatch(setConfigs(list[0].time_input_schema));
+            dispatch(setScenario(list[0].scenario));
 
-        getHistory()
+
+
+            global.scenario = list[0].scenario.name;
+        }
+        dispatch(setCurrentRecord(list[0].current_record))
+        dispatch(setSchedule(schedule))
+        setLoaded(true)
     }
 
 
@@ -439,6 +449,11 @@ export default function Page() {
     var timestamp = new Date().getTime()
 
     function render() {
+        if (!loaded) {
+            return <View style={{ width: rpxToPx(750), height: rpxToPx(900), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
+                <AtActivityIndicator size={40} color="#fff"/>
+            </View>
+        }
         return <Layout type={TemplateType.customHeader} header={headerView()} title={t('page.clock.title')} titleShowStyle={NaviBarTitleShowType.scrollToShow}>
 
             <View className="index_container">
@@ -480,9 +495,12 @@ export default function Page() {
                         <ChooseScenarioBtn title={t('feature.auth.login.login_now')} background={ColorType.fast} onClick={tapLogin} />
                     </View>
                 }
+                {
+                    showErrorPage && <NoData refresh={() => { getCheckData() }} />
+                }
 
                 {
-                    user.isLogin && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
+                    user.isLogin && !showErrorPage && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
                         <Text className="discovery1" >周统计</Text>
                         <WeekCalendar />
                     </View>