forked from wangziqi/gongxue-base
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
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;
|
||
}
|