added: 系统初始化

This commit is contained in:
none 2023-03-23 11:32:38 +08:00
parent 0fabdf7da7
commit c97a2529a8
5 changed files with 73 additions and 4 deletions

View File

@ -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", {});
}

View File

@ -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 />

View File

@ -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: "/",

View File

@ -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,
},
});

View 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 };