diff --git a/src/api/system.ts b/src/api/system.ts index c6c2186..f8dac4a 100644 --- a/src/api/system.ts +++ b/src/api/system.ts @@ -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", {}); } diff --git a/src/pages/init/index.tsx b/src/pages/init/index.tsx index e6c53dc..3733b77 100644 --- a/src/pages/init/index.tsx +++ b/src/pages/init/index.tsx @@ -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; +} export const InitPage = (props: Props) => { + const dispatch = useDispatch(); + dispatch(saveConfigAction(props.config)); + return ( <> diff --git a/src/routes/index.tsx b/src/routes/index.tsx index d220081..221a602 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -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((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: , + element: , children: [ { path: "/", diff --git a/src/store/index.ts b/src/store/index.ts index d8136b5..1d782a2 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -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, }, }); diff --git a/src/store/system/systemConfigSlice.ts b/src/store/system/systemConfigSlice.ts new file mode 100644 index 0000000..eab6dfe --- /dev/null +++ b/src/store/system/systemConfigSlice.ts @@ -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 };