Files
gongxue-base/apps/taro/src/app.tsx
2026-07-02 01:55:07 +08:00

73 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PropsWithChildren, useEffect, useState } from 'react';
import { Text, View } from '@tarojs/components';
import { useDidShow } from '@tarojs/taro';
import 'katex/dist/katex.min.css';
import { appEnv } from '@/env';
import { currentPagePath, guardCurrentRoute, shouldGuardPath } from '@/services/routeGuard';
import './app.css';
export default function App({ children }: PropsWithChildren) {
const [routeReady, setRouteReady] = useState(() => !shouldGuardPath(currentPagePath()));
function verifyCurrentRoute() {
const path = currentPagePath();
const protectedRoute = shouldGuardPath(path);
setRouteReady(!protectedRoute);
guardCurrentRoute()
.then(ok => setRouteReady(Boolean(ok)))
.catch(() => setRouteReady(false));
}
useEffect(() => {
verifyCurrentRoute();
}, []);
useDidShow(() => {
verifyCurrentRoute();
});
if (!routeReady && appEnv.portal === 'tenant-admin') {
return (
<View className='route-guard-page'>
<View className='route-guard-shell'>
<View className='route-guard-panel'>
<Text className='route-guard-kicker'>Tenant Admin</Text>
<Text className='route-guard-title'></Text>
<Text className='route-guard-subtitle'></Text>
</View>
</View>
</View>
);
}
if (!routeReady && appEnv.portal === 'platform-admin') {
return (
<View className='route-guard-page'>
<View className='route-guard-shell'>
<View className='route-guard-panel'>
<Text className='route-guard-kicker'>Platform Admin</Text>
<Text className='route-guard-title'></Text>
<Text className='route-guard-subtitle'></Text>
</View>
</View>
</View>
);
}
if (!routeReady) {
return (
<View className='route-guard-page'>
<View className='route-guard-shell'>
<View className='route-guard-panel'>
<Text className='route-guard-kicker'>Student</Text>
<Text className='route-guard-title'></Text>
<Text className='route-guard-subtitle'></Text>
</View>
</View>
</View>
);
}
return children;
}