Browse Source

feat(cloud-sync): implement conventional expiration verification with verification page first, redirect to main business page after successful verification
close #32

sw 1 month ago
parent
commit
8a680020d0
3 changed files with 45 additions and 25 deletions
  1. 4 1
      src/app.config.ts
  2. 3 24
      src/app.tsx
  3. 38 0
      src/pages/security/cloud_sync_expired.tsx

+ 4 - 1
src/app.config.ts

@@ -1,5 +1,8 @@
 export default defineAppConfig({
-  pages: ['pages/index/index'],
+  pages: [
+    'pages/security/cloud_sync_expired',
+    'pages/index/index',
+  ],
   window: {
     backgroundTextStyle: 'light',
     navigationBarBackgroundColor: '#fff',

+ 3 - 24
src/app.tsx

@@ -5,7 +5,6 @@ import { ConfigProvider, Button } from 'antd';
 import { Provider } from 'react-redux';
 import store from './states/store';
 import { initializeProductState } from './states/productSlice';
-import { getQuota } from './API/security/quotaActions';
 import './app.css';
 import { lightTheme, darkTheme } from './themes';
 import ProductSelector from './components/ProductSelector';
@@ -39,23 +38,11 @@ function App({ children }: PropsWithChildren<React.ReactNode>) {
   });
 
   const [currentTheme, setCurrentTheme] = useState(lightTheme); // 默认使用 light 主题
-  const [quotaStatus, setQuotaStatus] = useState<boolean | null>(null);
   const changeTheme = (themeConfig: typeof lightTheme) => {
     setCurrentTheme(themeConfig);
   };
 
   useEffect(() => {
-    const checkQuota = async () => {
-      try {
-        const response = await getQuota();
-        console.error(`Quota response: ${JSON.stringify(response)}`);
-        setQuotaStatus(response.data.overdue);
-      } catch (error) {
-        console.error('Error fetching quota:', error);
-        setQuotaStatus(false); // Assume overdue if there's an error
-      }
-    };
-    checkQuota();
     store.dispatch(initializeProductState());
   }, []);
 
@@ -79,17 +66,9 @@ function App({ children }: PropsWithChildren<React.ReactNode>) {
               boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
             }}
           >
-            {quotaStatus === null ? (
-              <div>Loading...</div>
-            ) : quotaStatus === false ? (
-              <div>Please sync with the cloud to continue.</div>
-            ) : (
-              <>
-                <AcquisitionTracer />
-                <QuotaAlertModal />
-                {children}
-              </>
-            )}
+            <AcquisitionTracer />
+            <QuotaAlertModal />
+            {children}
             {process.env.NODE_ENV === 'development' && <ProductSelector />}
             <div
               style={{

+ 38 - 0
src/pages/security/cloud_sync_expired.tsx

@@ -0,0 +1,38 @@
+// src/pages/check.tsx
+import { useEffect, useState } from 'react';
+import Taro from '@tarojs/taro';
+import { View } from '@tarojs/components';
+import { getQuota } from '@/API/security/quotaActions';
+
+export default function Check() {
+  const [overdueStatus, setoverdueStatus] = useState<boolean | null>(null);
+  useEffect(() => {
+    const checkoverdue = async () => {
+      try {
+        const response = await getQuota();
+        setoverdueStatus(response.data.overdue);
+        console.error(`overdue response: ${JSON.stringify(response)}`);
+        if (!response.data.overdue) {
+          //overdue 为 false 说明没有过期
+          Taro.redirectTo({ url: '/pages/index/index' });
+        }
+      } catch (error) {
+        setoverdueStatus(false);
+        console.error('Error fetching overdue:', error);
+      }
+    };
+    checkoverdue();
+  }, []);
+
+  return (
+    <View style={{ paddingTop: '40vh', textAlign: 'center' }}>
+      {overdueStatus === null ? (
+        <div>checking...</div>
+      ) : overdueStatus === true ? (
+        <div>Please sync with the cloud to continue.</div>
+      ) : (
+        <div>overdue valid, redirecting...</div>
+      )}
+    </View>
+  );
+}