From df2ab806c66c8c6012c58a62aae75c4962d069cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com>
Date: Mon, 17 Apr 2023 11:20:54 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BB=9A=E5=88=B0?=
=?UTF-8?q?=E5=88=B0=E9=A1=B6=E9=83=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/AutoTop.ts | 12 ++++++++++++
src/main.tsx | 5 ++++-
src/pages/index/index.tsx | 1 +
src/pages/latest-learn/index.tsx | 1 +
4 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 src/AutoTop.ts
diff --git a/src/AutoTop.ts b/src/AutoTop.ts
new file mode 100644
index 0000000..f3a29ea
--- /dev/null
+++ b/src/AutoTop.ts
@@ -0,0 +1,12 @@
+import { useLayoutEffect } from "react";
+import { useLocation } from "react-router-dom";
+
+const AutoScorllTop = ({ children }) => {
+ const location = useLocation();
+ useLayoutEffect(() => {
+ document.documentElement.scrollTo(0, 0);
+ }, [location.pathname]);
+ return children;
+};
+
+export default AutoScorllTop;
diff --git a/src/main.tsx b/src/main.tsx
index eca299d..462a531 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -8,6 +8,7 @@ import { ConfigProvider } from "antd";
import zhCN from "antd/locale/zh_CN";
import App from "./App";
import "./index.scss"; //全局样式
+import AutoScorllTop from "./AutoTop";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
@@ -16,7 +17,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
theme={{ token: { colorPrimary: "#ff4d4f" } }}
>
-
+
+
+
diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx
index 3308fda..5fb956b 100644
--- a/src/pages/index/index.tsx
+++ b/src/pages/index/index.tsx
@@ -12,6 +12,7 @@ import iconRoute from "../../assets/images/commen/icon-route.png";
import { studyTimeFormat } from "../../utils/index";
const IndexPage = () => {
+ document.title = "首页";
const systemConfig = useSelector((state: any) => state.systemConfig.value);
const [loading, setLoading] = useState(false);
const [tabKey, setTabKey] = useState(0);
diff --git a/src/pages/latest-learn/index.tsx b/src/pages/latest-learn/index.tsx
index 7a679a8..6df6a91 100644
--- a/src/pages/latest-learn/index.tsx
+++ b/src/pages/latest-learn/index.tsx
@@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
const LatestLearnPage = () => {
+ document.title = "最近学习";
const navigate = useNavigate();
const systemConfig = useSelector((state: any) => state.systemConfig.value);
const [loading, setLoading] = useState(false);
From a0754cde00f12c0a499fe6f459181a48299a5c2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com>
Date: Mon, 17 Apr 2023 11:34:14 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E5=AD=98=E5=82=A8=E9=83=A8=E9=97=A8?=
=?UTF-8?q?=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/compenents/header/index.tsx | 5 ++++-
src/store/user/loginUserSlice.ts | 3 ++-
src/utils/index.ts | 23 +++++++++++++++++++++++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/compenents/header/index.tsx b/src/compenents/header/index.tsx
index 80e414a..3ea76a0 100644
--- a/src/compenents/header/index.tsx
+++ b/src/compenents/header/index.tsx
@@ -8,6 +8,7 @@ import {
logoutAction,
saveCurrentDepId,
} from "../../store/user/loginUserSlice";
+import { setDepKey, setDepName, getDepName } from "../../utils/index";
import { ChangePasswordModel } from "../change-password";
import { UserInfoModel } from "../user-info";
import { ExclamationCircleFilled } from "@ant-design/icons";
@@ -32,7 +33,7 @@ export const Header: React.FC = () => {
useEffect(() => {
if (departments.length > 0) {
- setCurrentDepartment(departments[0].name);
+ setCurrentDepartment(getDepName() || departments[0].name);
const arr: any = [
{
key: "1",
@@ -129,6 +130,8 @@ export const Header: React.FC = () => {
onOk() {
setCurrentDepartment(name);
dispatch(saveCurrentDepId(Number(key)));
+ setDepKey(key);
+ setDepName(name);
const box = [...departments];
const arr: any = [
{
diff --git a/src/store/user/loginUserSlice.ts b/src/store/user/loginUserSlice.ts
index ac24a80..237e761 100644
--- a/src/store/user/loginUserSlice.ts
+++ b/src/store/user/loginUserSlice.ts
@@ -1,4 +1,5 @@
import { createSlice } from "@reduxjs/toolkit";
+import { getDepKey } from "../../utils/index";
type UserStoreInterface = {
user: null;
@@ -10,7 +11,7 @@ type UserStoreInterface = {
let defaultValue: UserStoreInterface = {
user: null,
departments: [],
- currentDepId: 0,
+ currentDepId: Number(getDepKey()) || 0,
isLogin: false,
};
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 2ab988f..52657e3 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -72,3 +72,26 @@ export function inStrArray(array: string[], value: string): boolean {
}
return false;
}
+
+export function getDepKey(): string {
+ return window.localStorage.getItem("playedu-frontend-depatmentKey") || "";
+}
+
+export function setDepKey(token: string) {
+ window.localStorage.setItem("playedu-frontend-depatmentKey", token);
+}
+
+export function clearDepKey() {
+ window.localStorage.removeItem("playedu-frontend-depatmentKey");
+}
+export function getDepName(): string {
+ return window.localStorage.getItem("playedu-frontend-depatmentName") || "";
+}
+
+export function setDepName(token: string) {
+ window.localStorage.setItem("playedu-frontend-depatmentName", token);
+}
+
+export function clearDepName() {
+ window.localStorage.removeItem("playedu-frontend-depatmentName");
+}
From 76d3a939d2b6751148ad7be2191815cf64624931 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com>
Date: Mon, 17 Apr 2023 14:28:04 +0800
Subject: [PATCH 3/5] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BB=9A=E5=88=B0?=
=?UTF-8?q?=E5=88=B0=E9=A1=B6=E9=83=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/AutoTop.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/AutoTop.ts b/src/AutoTop.ts
index f3a29ea..fc8efa6 100644
--- a/src/AutoTop.ts
+++ b/src/AutoTop.ts
@@ -1,7 +1,8 @@
+import React from "react";
import { useLayoutEffect } from "react";
import { useLocation } from "react-router-dom";
-const AutoScorllTop = ({ children }) => {
+const AutoScorllTop: React.FC<{ children: any }> = ({ children }) => {
const location = useLocation();
useLayoutEffect(() => {
document.documentElement.scrollTo(0, 0);
From 7e16c748f56ab66da535f841c97b898b3ef82f83 Mon Sep 17 00:00:00 2001
From: none
Date: Mon, 17 Apr 2023 16:05:40 +0800
Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96dockerfile?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.dockerignore | 3 +++
Dockerfile | 12 ++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
create mode 100644 .dockerignore
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..57d3105
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,3 @@
+/node_modules
+/build
+/dist
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 6336b7b..c7ea6b3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,13 @@
+FROM node:lts-slim as builder
+
+WORKDIR /app
+
+COPY . /app
+
+RUN yarn config set registry https://registry.npm.taobao.org && yarn && yarn build
+
FROM nginx:1.23.4-alpine-slim
-COPY dist /usr/share/nginx/html
+COPY --from=builder /app/dist /usr/share/nginx/html
-COPY docker/nginx.conf /etc/nginx/nginx.conf
+COPY --from=builder /app/docker/nginx.conf /etc/nginx/nginx.conf
\ No newline at end of file
From a67db5dbfc56a99e75ca6e3ee66b9c830771594f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com>
Date: Mon, 17 Apr 2023 17:25:31 +0800
Subject: [PATCH 5/5] =?UTF-8?q?=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.tsx | 12 ------
src/compenents/header/index.tsx | 8 +++-
src/pages/init/index.tsx | 37 ++++++++++++++++--
src/routes/index.tsx | 67 ++++++++++++---------------------
4 files changed, 65 insertions(+), 59 deletions(-)
diff --git a/src/App.tsx b/src/App.tsx
index a4c2ce4..e91f9b2 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -4,10 +4,6 @@ import { useLocation, useRoutes } from "react-router-dom";
import routes from "./routes";
import "./App.scss";
import LoadingPage from "./pages/loading";
-import { user } from "./api/index";
-import { getToken } from "./utils/index";
-import { useDispatch } from "react-redux";
-import { loginAction } from "./store/user/loginUserSlice";
const G_ID = import.meta.env.VITE_G_ID || "";
if (G_ID) {
@@ -15,16 +11,8 @@ if (G_ID) {
}
const App = () => {
- const dispatch = useDispatch();
const Views = () => useRoutes(routes);
- if (getToken()) {
- user.detail().then((res: any) => {
- const data = res.data;
- dispatch(loginAction(data));
- });
- }
-
const location = useLocation();
useEffect(() => {
if (!G_ID) {
diff --git a/src/compenents/header/index.tsx b/src/compenents/header/index.tsx
index 3ea76a0..9c9bd77 100644
--- a/src/compenents/header/index.tsx
+++ b/src/compenents/header/index.tsx
@@ -8,7 +8,12 @@ import {
logoutAction,
saveCurrentDepId,
} from "../../store/user/loginUserSlice";
-import { setDepKey, setDepName, getDepName } from "../../utils/index";
+import {
+ setDepKey,
+ setDepName,
+ getDepName,
+ clearToken,
+} from "../../utils/index";
import { ChangePasswordModel } from "../change-password";
import { UserInfoModel } from "../user-info";
import { ExclamationCircleFilled } from "@ant-design/icons";
@@ -68,6 +73,7 @@ export const Header: React.FC = () => {
cancelText: "取消",
onOk() {
dispatch(logoutAction());
+ clearToken();
navigate("/login");
},
onCancel() {
diff --git a/src/pages/init/index.tsx b/src/pages/init/index.tsx
index 6668e2f..7347448 100644
--- a/src/pages/init/index.tsx
+++ b/src/pages/init/index.tsx
@@ -1,17 +1,48 @@
import { useDispatch } from "react-redux";
import { Outlet } from "react-router-dom";
// import styles from "./index.module.scss";
-import { saveConfigAction } from "../../store/system/systemConfigSlice";
+import {
+ SystemConfigStoreInterface,
+ saveConfigAction,
+} from "../../store/system/systemConfigSlice";
+import { loginAction } from "../../store/user/loginUserSlice";
import { Header, NoHeader, Footer } from "../../compenents";
import { useLocation } from "react-router-dom";
interface Props {
- config: Map;
+ loginData?: any;
+ configData?: any;
}
export const InitPage = (props: Props) => {
const dispatch = useDispatch();
- dispatch(saveConfigAction(props.config));
+ if (props.loginData) {
+ dispatch(loginAction(props.loginData));
+ }
+ if (props.configData) {
+ let config: SystemConfigStoreInterface = {
+ //系统配置
+ systemApiUrl: props.configData["system-api-url"],
+ systemH5Url: props.configData["system-h5-url"],
+ systemLogo: props.configData["system-logo"],
+ systemName: props.configData["system-name"],
+ systemPcUrl: props.configData["system-pc-url"],
+ pcIndexFooterMsg: props.configData["system-pc-index-footer-msg"],
+ //播放器配置
+ playerPoster: props.configData["player-poster"],
+ playerIsEnabledBulletSecret:
+ props.configData["player-is-enabled-bullet-secret"] &&
+ props.configData["player-is-enabled-bullet-secret"] === "1"
+ ? true
+ : false,
+ playerBulletSecretText: props.configData["player-bullet-secret-text"],
+ playerBulletSecretColor: props.configData["player-bullet-secret-color"],
+ playerBulletSecretOpacity:
+ props.configData["player-bullet-secret-opacity"],
+ };
+ dispatch(saveConfigAction(config));
+ }
+
const pathname = useLocation().pathname;
return (
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
index ea55cce..a05b7f9 100644
--- a/src/routes/index.tsx
+++ b/src/routes/index.tsx
@@ -1,57 +1,38 @@
import { lazy } from "react";
import { RouteObject } from "react-router-dom";
-import { system } from "../api";
+import { system, user } from "../api";
import { SystemConfigStoreInterface } from "../store/system/systemConfigSlice";
+import { getToken } from "../utils";
import { InitPage } from "../pages/init";
import CoursePage from "../pages/course";
import IndexPage from "../pages/index";
import LatestLearnPage from "../pages/latest-learn";
import LoginPage from "../pages/login";
-let config: SystemConfigStoreInterface = {
- systemApiUrl: "",
- systemPcUrl: "",
- systemH5Url: "",
- systemLogo: "",
- systemName: "",
- pcIndexFooterMsg: "",
- playerPoster: "",
- playerIsEnabledBulletSecret: false,
- playerBulletSecretText: "",
- playerBulletSecretColor: "",
- playerBulletSecretOpacity: "",
-};
-
-const Init = lazy(async () => {
- return new Promise((resolve) => {
- system.config().then((res: any) => {
- //系统配置
- config.systemApiUrl = res.data["system-api-url"];
- config.systemH5Url = res.data["system-h5-url"];
- config.systemLogo = res.data["system-logo"];
- config.systemName = res.data["system-name"];
- config.systemPcUrl = res.data["system-pc-url"];
- config.pcIndexFooterMsg = res.data["system-pc-index-footer-msg"];
-
- //播放器配置
- config.playerPoster = res.data["player-poster"];
- config.playerIsEnabledBulletSecret =
- res.data["player-is-enabled-bullet-secret"] &&
- res.data["player-is-enabled-bullet-secret"] === "1"
- ? true
- : false;
- config.playerBulletSecretText = res.data["player-bullet-secret-text"];
- config.playerBulletSecretColor = res.data["player-bullet-secret-color"];
- config.playerBulletSecretOpacity =
- res.data["player-bullet-secret-opacity"];
-
- resolve({
- default: InitPage,
- });
+let RootPage: any = null;
+if (getToken()) {
+ RootPage = lazy(async () => {
+ return new Promise(async (resolve) => {
+ try {
+ let configRes: any = await system.config();
+ let userRes: any = await user.detail();
+ resolve({
+ default: (
+
+ ),
+ });
+ } catch (e) {
+ console.error("系统初始化失败", e);
+ }
});
});
-});
+} else {
+ if (window.location.pathname !== "/login") {
+ window.location.href = "/login";
+ }
+ RootPage = ;
+}
// 懒加载
// const LoginPage = lazy(() => import("../pages/login"));
@@ -62,7 +43,7 @@ const Init = lazy(async () => {
const routes: RouteObject[] = [
{
path: "/",
- element: ,
+ element: RootPage,
children: [
{
path: "/",