mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-06-10 04:34:10 +08:00
退出登录逻辑优化
This commit is contained in:
parent
76d3a939d2
commit
a67db5dbfc
12
src/App.tsx
12
src/App.tsx
@ -4,10 +4,6 @@ import { useLocation, useRoutes } from "react-router-dom";
|
|||||||
import routes from "./routes";
|
import routes from "./routes";
|
||||||
import "./App.scss";
|
import "./App.scss";
|
||||||
import LoadingPage from "./pages/loading";
|
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 || "";
|
const G_ID = import.meta.env.VITE_G_ID || "";
|
||||||
if (G_ID) {
|
if (G_ID) {
|
||||||
@ -15,16 +11,8 @@ if (G_ID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const dispatch = useDispatch();
|
|
||||||
const Views = () => useRoutes(routes);
|
const Views = () => useRoutes(routes);
|
||||||
|
|
||||||
if (getToken()) {
|
|
||||||
user.detail().then((res: any) => {
|
|
||||||
const data = res.data;
|
|
||||||
dispatch(loginAction(data));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!G_ID) {
|
if (!G_ID) {
|
||||||
|
@ -8,7 +8,12 @@ import {
|
|||||||
logoutAction,
|
logoutAction,
|
||||||
saveCurrentDepId,
|
saveCurrentDepId,
|
||||||
} from "../../store/user/loginUserSlice";
|
} 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 { ChangePasswordModel } from "../change-password";
|
||||||
import { UserInfoModel } from "../user-info";
|
import { UserInfoModel } from "../user-info";
|
||||||
import { ExclamationCircleFilled } from "@ant-design/icons";
|
import { ExclamationCircleFilled } from "@ant-design/icons";
|
||||||
@ -68,6 +73,7 @@ export const Header: React.FC = () => {
|
|||||||
cancelText: "取消",
|
cancelText: "取消",
|
||||||
onOk() {
|
onOk() {
|
||||||
dispatch(logoutAction());
|
dispatch(logoutAction());
|
||||||
|
clearToken();
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
},
|
},
|
||||||
onCancel() {
|
onCancel() {
|
||||||
|
@ -1,17 +1,48 @@
|
|||||||
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 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 { Header, NoHeader, Footer } from "../../compenents";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
config: Map<string, string>;
|
loginData?: any;
|
||||||
|
configData?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InitPage = (props: Props) => {
|
export const InitPage = (props: Props) => {
|
||||||
const dispatch = useDispatch();
|
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;
|
const pathname = useLocation().pathname;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,57 +1,38 @@
|
|||||||
import { lazy } from "react";
|
import { lazy } from "react";
|
||||||
import { RouteObject } from "react-router-dom";
|
import { RouteObject } from "react-router-dom";
|
||||||
import { system } from "../api";
|
import { system, user } from "../api";
|
||||||
import { SystemConfigStoreInterface } from "../store/system/systemConfigSlice";
|
import { SystemConfigStoreInterface } from "../store/system/systemConfigSlice";
|
||||||
|
|
||||||
|
import { getToken } from "../utils";
|
||||||
import { InitPage } from "../pages/init";
|
import { InitPage } from "../pages/init";
|
||||||
import CoursePage from "../pages/course";
|
import CoursePage from "../pages/course";
|
||||||
import IndexPage from "../pages/index";
|
import IndexPage from "../pages/index";
|
||||||
import LatestLearnPage from "../pages/latest-learn";
|
import LatestLearnPage from "../pages/latest-learn";
|
||||||
import LoginPage from "../pages/login";
|
import LoginPage from "../pages/login";
|
||||||
|
|
||||||
let config: SystemConfigStoreInterface = {
|
let RootPage: any = null;
|
||||||
systemApiUrl: "",
|
if (getToken()) {
|
||||||
systemPcUrl: "",
|
RootPage = lazy(async () => {
|
||||||
systemH5Url: "",
|
return new Promise<any>(async (resolve) => {
|
||||||
systemLogo: "",
|
try {
|
||||||
systemName: "",
|
let configRes: any = await system.config();
|
||||||
pcIndexFooterMsg: "",
|
let userRes: any = await user.detail();
|
||||||
playerPoster: "",
|
|
||||||
playerIsEnabledBulletSecret: false,
|
|
||||||
playerBulletSecretText: "",
|
|
||||||
playerBulletSecretColor: "",
|
|
||||||
playerBulletSecretOpacity: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
const Init = lazy(async () => {
|
|
||||||
return new Promise<any>((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({
|
resolve({
|
||||||
default: InitPage,
|
default: (
|
||||||
|
<InitPage configData={configRes.data} loginData={userRes.data} />
|
||||||
|
),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("系统初始化失败", e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
});
|
if (window.location.pathname !== "/login") {
|
||||||
|
window.location.href = "/login";
|
||||||
|
}
|
||||||
|
RootPage = <InitPage />;
|
||||||
|
}
|
||||||
|
|
||||||
// 懒加载
|
// 懒加载
|
||||||
// const LoginPage = lazy(() => import("../pages/login"));
|
// const LoginPage = lazy(() => import("../pages/login"));
|
||||||
@ -62,7 +43,7 @@ const Init = lazy(async () => {
|
|||||||
const routes: RouteObject[] = [
|
const routes: RouteObject[] = [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
element: <Init config={config} />,
|
element: RootPage,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user