mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-06-29 07:32:50 +08:00
缓加载优化
This commit is contained in:
parent
bf19ea66a3
commit
6137916964
@ -49,7 +49,7 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
.video-title {
|
.video-title {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 36px;
|
height: auto;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: rgba(255, 255, 255, 0.88);
|
color: rgba(255, 255, 255, 0.88);
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { Outlet } from "react-router-dom";
|
import { Outlet } from "react-router-dom";
|
||||||
// import styles from "./index.module.scss";
|
|
||||||
import {
|
import {
|
||||||
SystemConfigStoreInterface,
|
SystemConfigStoreInterface,
|
||||||
saveConfigAction,
|
saveConfigAction,
|
||||||
} from "../../store/system/systemConfigSlice";
|
} from "../../store/system/systemConfigSlice";
|
||||||
import { loginAction } from "../../store/user/loginUserSlice";
|
import { loginAction } from "../../store/user/loginUserSlice";
|
||||||
import { Header, NoHeader, Footer } from "../../compenents";
|
|
||||||
import { useParams, useLocation } from "react-router-dom";
|
|
||||||
import { isMobile } from "../../utils/index";
|
import { isMobile } from "../../utils/index";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -17,30 +14,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const InitPage = (props: Props) => {
|
export const InitPage = (props: Props) => {
|
||||||
const pathname = useLocation().pathname;
|
|
||||||
const params = useParams();
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [showHeader, setShowHeader] = useState<boolean>(true);
|
|
||||||
const [showNoHeader, setShowNoHeader] = useState<boolean>(false);
|
|
||||||
const [showFooter, setShowFooter] = useState<boolean>(true);
|
|
||||||
const [init, setInit] = useState<boolean>(false);
|
const [init, setInit] = useState<boolean>(false);
|
||||||
useEffect(() => {
|
|
||||||
if (pathname) {
|
|
||||||
if (pathname === "/login") {
|
|
||||||
setShowNoHeader(true);
|
|
||||||
setShowHeader(false);
|
|
||||||
setShowFooter(false);
|
|
||||||
} else if (!params.hourId) {
|
|
||||||
setShowNoHeader(false);
|
|
||||||
setShowHeader(true);
|
|
||||||
setShowFooter(true);
|
|
||||||
} else {
|
|
||||||
setShowNoHeader(false);
|
|
||||||
setShowHeader(false);
|
|
||||||
setShowFooter(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [pathname, params]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.loginData) {
|
if (props.loginData) {
|
||||||
@ -84,11 +59,8 @@ export const InitPage = (props: Props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{init && (
|
{init && (
|
||||||
<div>
|
<div style={{ minHeight: 900 }}>
|
||||||
{showNoHeader && <NoHeader></NoHeader>}
|
|
||||||
{showHeader && <Header></Header>}
|
|
||||||
<Outlet />
|
<Outlet />
|
||||||
{showFooter && <Footer></Footer>}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
18
src/pages/layouts/with-header-with-footer/index.tsx
Normal file
18
src/pages/layouts/with-header-with-footer/index.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
import { Footer, Header } from "../../../compenents";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import LoadingPage from "../../loading";
|
||||||
|
|
||||||
|
const WithHeaderWithFooter = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header></Header>
|
||||||
|
<Suspense fallback={<LoadingPage height="100vh" />}>
|
||||||
|
<Outlet />
|
||||||
|
</Suspense>
|
||||||
|
<Footer></Footer>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default WithHeaderWithFooter;
|
17
src/pages/layouts/with-header-without-footer/index.tsx
Normal file
17
src/pages/layouts/with-header-without-footer/index.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
import { NoHeader } from "../../../compenents";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import LoadingPage from "../../loading";
|
||||||
|
|
||||||
|
const WithHeaderWithoutFooter = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<NoHeader></NoHeader>
|
||||||
|
<Suspense fallback={<LoadingPage height="100vh" />}>
|
||||||
|
<Outlet />
|
||||||
|
</Suspense>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default WithHeaderWithoutFooter;
|
17
src/pages/layouts/without-header-with-footer/index.tsx
Normal file
17
src/pages/layouts/without-header-with-footer/index.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
import { Footer } from "../../../compenents";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import LoadingPage from "../../loading";
|
||||||
|
|
||||||
|
const WithoutHeaderWithFooter = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Suspense fallback={<LoadingPage height="100vh" />}>
|
||||||
|
<Outlet />
|
||||||
|
</Suspense>
|
||||||
|
<Footer></Footer>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default WithoutHeaderWithFooter;
|
13
src/pages/layouts/without-header-without-footer/index.tsx
Normal file
13
src/pages/layouts/without-header-without-footer/index.tsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { Suspense } from "react";
|
||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
import LoadingPage from "../../loading";
|
||||||
|
|
||||||
|
const WithoutHeaderWithoutFooter = () => {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<LoadingPage height="100vh" />}>
|
||||||
|
<Outlet />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default WithoutHeaderWithoutFooter;
|
@ -1,10 +1,6 @@
|
|||||||
.loadingBox {
|
.loading-box {
|
||||||
position: fixed;
|
width: 100vw;
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
z-index: 99;
|
|
||||||
text-align: center;
|
|
||||||
line-height: 100vh;
|
line-height: 100vh;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #f4fafe;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
import { Spin } from "antd";
|
import { Spin } from "antd";
|
||||||
import styles from "./index.module.scss";
|
import styles from "./index.module.scss";
|
||||||
|
|
||||||
const LoadingPage = () => {
|
interface PropsInterface {
|
||||||
|
height?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LoadingPage = (props: PropsInterface) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.loadingBox}>
|
<>
|
||||||
<Spin />
|
<div
|
||||||
|
className={styles["loading-box"]}
|
||||||
|
style={{ height: props.height || "100vh" }}
|
||||||
|
>
|
||||||
|
<Spin size="large" />
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@ import { getToken } from "../utils";
|
|||||||
// 页面加载
|
// 页面加载
|
||||||
import { InitPage } from "../pages/init";
|
import { InitPage } from "../pages/init";
|
||||||
import LoginPage from "../pages/login";
|
import LoginPage from "../pages/login";
|
||||||
|
import WithHeaderWithFooter from "../pages/layouts/with-header-with-footer";
|
||||||
|
import WithHeaderWithoutFooter from "../pages/layouts/with-header-without-footer";
|
||||||
|
import WithoutHeaderWithFooter from "../pages/layouts/without-header-with-footer";
|
||||||
|
import WithoutHeaderWithoutFooter from "../pages/layouts/without-header-without-footer";
|
||||||
|
|
||||||
//主页
|
//主页
|
||||||
const IndexPage = lazy(() => import("../pages/index"));
|
const IndexPage = lazy(() => import("../pages/index"));
|
||||||
//课程相关
|
//课程相关
|
||||||
@ -48,39 +53,53 @@ if (getToken()) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 懒加载
|
|
||||||
// const LoginPage = lazy(() => import("../pages/login"));
|
|
||||||
// const IndexPage = lazy(() => import("../pages/index"));
|
|
||||||
// const CoursePage = lazy(() => import("../pages/course"));
|
|
||||||
// const LatestLearnPage = lazy(() => import("../pages/latest-learn"));
|
|
||||||
|
|
||||||
const routes: RouteObject[] = [
|
const routes: RouteObject[] = [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
element: RootPage,
|
element: RootPage,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
element: <WithHeaderWithFooter />,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
element: <PrivateRoute Component={<IndexPage />} />,
|
element: <PrivateRoute Component={<IndexPage />} />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/login",
|
|
||||||
element: <LoginPage />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/course/:courseId",
|
path: "/course/:courseId",
|
||||||
element: <PrivateRoute Component={<CoursePage />} />,
|
element: <PrivateRoute Component={<CoursePage />} />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/course/:courseId/hour/:hourId",
|
|
||||||
element: <PrivateRoute Component={<CoursePlayPage />} />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/latest-learn",
|
path: "/latest-learn",
|
||||||
element: <PrivateRoute Component={<LatestLearnPage />} />,
|
element: <PrivateRoute Component={<LatestLearnPage />} />,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
element: <WithHeaderWithoutFooter />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: "/login",
|
||||||
|
element: <LoginPage />,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
element: <WithoutHeaderWithoutFooter />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: "/course/:courseId/hour/:hourId",
|
||||||
|
element: <PrivateRoute Component={<CoursePlayPage />} />,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default routes;
|
export default routes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user