mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-06-08 06:48:38 +08:00
added: 系统初始化
This commit is contained in:
parent
0fabdf7da7
commit
c97a2529a8
@ -1,9 +1,9 @@
|
||||
import client from "./internal/httpClient";
|
||||
|
||||
export function config() {
|
||||
return client.post("/api/v1/system/config", {});
|
||||
return client.get("/api/v1/system/config", {});
|
||||
}
|
||||
|
||||
export function imageCaptcha() {
|
||||
return client.post("/api/v1/system/image-captcha", {});
|
||||
return client.get("/api/v1/system/image-captcha", {});
|
||||
}
|
||||
|
@ -1,8 +1,15 @@
|
||||
import { useDispatch } from "react-redux";
|
||||
import { Outlet } from "react-router-dom";
|
||||
import { saveConfigAction } from "../../store/system/systemConfigSlice";
|
||||
|
||||
interface Props {}
|
||||
interface Props {
|
||||
config: Map<string, string>;
|
||||
}
|
||||
|
||||
export const InitPage = (props: Props) => {
|
||||
const dispatch = useDispatch();
|
||||
dispatch(saveConfigAction(props.config));
|
||||
|
||||
return (
|
||||
<>
|
||||
<Outlet />
|
||||
|
@ -1,7 +1,33 @@
|
||||
import { lazy } from "react";
|
||||
import { RouteObject } from "react-router-dom";
|
||||
import { system } from "../api";
|
||||
|
||||
import { InitPage } from "../pages/init";
|
||||
import { SystemConfigStoreInterface } from "../store/system/systemConfigSlice";
|
||||
|
||||
let config: SystemConfigStoreInterface = {
|
||||
systemApiUrl: "",
|
||||
systemPcUrl: "",
|
||||
systemH5Url: "",
|
||||
systemLogo: "",
|
||||
systemName: "",
|
||||
};
|
||||
|
||||
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"];
|
||||
|
||||
resolve({
|
||||
default: InitPage,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 懒加载
|
||||
const LoginPage = lazy(() => import("../pages/login"));
|
||||
@ -10,7 +36,7 @@ const IndexPage = lazy(() => import("../pages/index"));
|
||||
const routes: RouteObject[] = [
|
||||
{
|
||||
path: "/",
|
||||
element: <InitPage />,
|
||||
element: <Init config={config} />,
|
||||
children: [
|
||||
{
|
||||
path: "/",
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import systemConfigReducer from "./system/systemConfigSlice";
|
||||
import loginUserReducer from "./user/loginUserSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
loginUser: loginUserReducer,
|
||||
systemConfig: systemConfigReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
34
src/store/system/systemConfigSlice.ts
Normal file
34
src/store/system/systemConfigSlice.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
type SystemConfigStoreInterface = {
|
||||
systemApiUrl: string;
|
||||
systemPcUrl: string;
|
||||
systemH5Url: string;
|
||||
systemLogo: string;
|
||||
systemName: string;
|
||||
};
|
||||
|
||||
let defaultValue: SystemConfigStoreInterface = {
|
||||
systemApiUrl: "",
|
||||
systemPcUrl: "",
|
||||
systemH5Url: "",
|
||||
systemLogo: "",
|
||||
systemName: "",
|
||||
};
|
||||
|
||||
const systemConfigSlice = createSlice({
|
||||
name: "systemConfig",
|
||||
initialState: {
|
||||
value: defaultValue,
|
||||
},
|
||||
reducers: {
|
||||
saveConfigAction(stage, e) {
|
||||
stage.value = e.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default systemConfigSlice.reducer;
|
||||
export const { saveConfigAction } = systemConfigSlice.actions;
|
||||
|
||||
export type { SystemConfigStoreInterface };
|
Loading…
x
Reference in New Issue
Block a user