feat(front): 覆盖 front 并完善登录快传入口与中文文案
This commit is contained in:
@@ -1,100 +1,58 @@
|
||||
import React, { Suspense } from 'react';
|
||||
import { BrowserRouter, HashRouter, Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
||||
import { Layout } from './components/layout/Layout';
|
||||
import { useAuth } from './auth/AuthProvider';
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation } from 'react-router-dom';
|
||||
import { AnimatePresence, motion } from 'motion/react';
|
||||
import AdminDashboard from './admin/dashboard';
|
||||
import AdminFilesList from './admin/files-list';
|
||||
import AdminStoragePoliciesList from './admin/storage-policies-list';
|
||||
import AdminUsersList from './admin/users-list';
|
||||
import Layout from './components/layout/Layout';
|
||||
import MobileLayout from './mobile-components/MobileLayout';
|
||||
import { useIsMobile } from './hooks/useIsMobile';
|
||||
import Login from './pages/Login';
|
||||
import Overview from './pages/Overview';
|
||||
import Files from './pages/Files';
|
||||
import RecycleBin from './pages/RecycleBin';
|
||||
import Shares from './pages/Shares';
|
||||
import Tasks from './pages/Tasks';
|
||||
import Transfer from './pages/Transfer';
|
||||
import FileShare from './pages/FileShare';
|
||||
import Games from './pages/Games';
|
||||
import GamePlayer from './pages/GamePlayer';
|
||||
import { FILE_SHARE_ROUTE_PREFIX } from './lib/file-share';
|
||||
import {
|
||||
getTransferRouterMode,
|
||||
LEGACY_PUBLIC_TRANSFER_ROUTE,
|
||||
PUBLIC_TRANSFER_ROUTE,
|
||||
} from './lib/transfer-links';
|
||||
import FilesPage from './pages/files/FilesPage';
|
||||
|
||||
const PortalAdminApp = React.lazy(() => import('./admin/AdminApp'));
|
||||
|
||||
function LegacyTransferRedirect() {
|
||||
function AnimatedRoutes({ isMobile }: { isMobile: boolean }) {
|
||||
const location = useLocation();
|
||||
return <Navigate to={`${PUBLIC_TRANSFER_ROUTE}${location.search}`} replace />;
|
||||
}
|
||||
|
||||
function AppRoutes() {
|
||||
const { ready, session } = useAuth();
|
||||
const location = useLocation();
|
||||
const isPublicTransferRoute = location.pathname === PUBLIC_TRANSFER_ROUTE || location.pathname === LEGACY_PUBLIC_TRANSFER_ROUTE;
|
||||
const isPublicFileShareRoute = location.pathname.startsWith(`${FILE_SHARE_ROUTE_PREFIX}/`);
|
||||
|
||||
if (!ready && !isPublicTransferRoute && !isPublicFileShareRoute) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-[#07101D] text-slate-300">
|
||||
正在检查登录状态...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const isAuthenticated = Boolean(session?.token);
|
||||
const AppLayout = isMobile ? MobileLayout : Layout;
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
<Route
|
||||
path={PUBLIC_TRANSFER_ROUTE}
|
||||
element={isAuthenticated ? <Layout><Transfer /></Layout> : <Transfer />}
|
||||
/>
|
||||
<Route path={`${FILE_SHARE_ROUTE_PREFIX}/:token`} element={<FileShare />} />
|
||||
<Route path={LEGACY_PUBLIC_TRANSFER_ROUTE} element={<LegacyTransferRedirect />} />
|
||||
<Route
|
||||
path="/login"
|
||||
element={isAuthenticated ? <Navigate to="/overview" replace /> : <Login />}
|
||||
/>
|
||||
<Route
|
||||
path="/"
|
||||
element={isAuthenticated ? <Layout /> : <Navigate to="/login" replace />}
|
||||
>
|
||||
<Route index element={<Navigate to="/overview" replace />} />
|
||||
<Route path="overview" element={<Overview />} />
|
||||
<Route path="files" element={<Files />} />
|
||||
<Route path="recycle-bin" element={<RecycleBin />} />
|
||||
<Route path="games" element={<Games />} />
|
||||
<Route path="games/:gameId" element={<GamePlayer />} />
|
||||
</Route>
|
||||
<Route
|
||||
path="/admin/*"
|
||||
element={
|
||||
isAuthenticated ? (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="min-h-screen flex items-center justify-center bg-white text-slate-700">
|
||||
正在加载后台管理台...
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<PortalAdminApp />
|
||||
</Suspense>
|
||||
) : (
|
||||
<Navigate to="/login" replace />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="*"
|
||||
element={<Navigate to={isAuthenticated ? '/overview' : '/login'} replace />}
|
||||
/>
|
||||
</Routes>
|
||||
<AnimatePresence mode="wait">
|
||||
<Routes location={location}>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/share/:token" element={<FileShare />} />
|
||||
<Route element={<AppLayout />}>
|
||||
<Route path="/" element={<Navigate to="/overview" replace />} />
|
||||
<Route path="/overview" element={<Overview />} />
|
||||
<Route path="/files" element={<FilesPage />} />
|
||||
<Route path="/tasks" element={<Tasks />} />
|
||||
<Route path="/shares" element={<Shares />} />
|
||||
<Route path="/recycle-bin" element={<RecycleBin />} />
|
||||
<Route path="/transfer" element={<Transfer />} />
|
||||
<Route path="/admin">
|
||||
<Route index element={<Navigate to="/admin/dashboard" replace />} />
|
||||
<Route path="dashboard" element={isMobile ? <Navigate to="/overview" replace /> : <AdminDashboard />} />
|
||||
<Route path="users" element={isMobile ? <Navigate to="/overview" replace /> : <AdminUsersList />} />
|
||||
<Route path="files" element={isMobile ? <Navigate to="/overview" replace /> : <AdminFilesList />} />
|
||||
<Route path="storage-policies" element={isMobile ? <Navigate to="/overview" replace /> : <AdminStoragePoliciesList />} />
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/overview" replace />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const Router = getTransferRouterMode() === 'hash' ? HashRouter : BrowserRouter;
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<AppRoutes />
|
||||
</Router>
|
||||
<BrowserRouter>
|
||||
<AnimatedRoutes isMobile={isMobile} />
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user