2026-04-08 06:34:59 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { ConfigProvider, theme, App as AntdApp } from "antd";
|
2026-02-26 08:27:45 +00:00
|
|
|
import AppRoutes from "./routes";
|
|
|
|
|
import { getOpenPlatformConfig } from "./api";
|
2026-03-17 07:31:09 +00:00
|
|
|
import {useThemeStore} from "./store/themeStore";
|
2026-02-26 08:27:45 +00:00
|
|
|
import type { SysPlatformConfig } from "./types";
|
2026-02-10 09:48:44 +00:00
|
|
|
|
|
|
|
|
export default function App() {
|
2026-02-26 08:27:45 +00:00
|
|
|
const [config, setConfig] = useState<SysPlatformConfig | null>(null);
|
2026-03-17 07:31:09 +00:00
|
|
|
const { colorPrimary, themeMode, initTheme } = useThemeStore();
|
2026-02-26 08:27:45 +00:00
|
|
|
useEffect(() => {
|
2026-03-17 07:31:09 +00:00
|
|
|
initTheme();
|
2026-02-26 08:27:45 +00:00
|
|
|
const fetchConfig = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await getOpenPlatformConfig();
|
|
|
|
|
setConfig(data);
|
|
|
|
|
if (data.projectName) {
|
|
|
|
|
document.title = data.projectName;
|
|
|
|
|
}
|
|
|
|
|
if (data.iconUrl) {
|
|
|
|
|
let link: HTMLLinkElement | null = document.querySelector("link[rel~='icon']");
|
|
|
|
|
if (!link) {
|
|
|
|
|
link = document.createElement('link');
|
|
|
|
|
link.rel = 'icon';
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(link);
|
|
|
|
|
}
|
|
|
|
|
link.href = data.iconUrl;
|
|
|
|
|
}
|
|
|
|
|
// Save to sessionStorage for other components
|
|
|
|
|
sessionStorage.setItem("platformConfig", JSON.stringify(data));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error("Failed to load platform config", e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
fetchConfig();
|
2026-03-17 07:31:09 +00:00
|
|
|
}, [initTheme]);
|
2026-02-26 08:27:45 +00:00
|
|
|
|
2026-03-17 07:31:09 +00:00
|
|
|
return (
|
|
|
|
|
<ConfigProvider
|
|
|
|
|
theme={{
|
|
|
|
|
algorithm: themeMode === 'tech' ? theme.darkAlgorithm : theme.defaultAlgorithm,
|
|
|
|
|
token: {
|
|
|
|
|
colorPrimary: colorPrimary,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
colorBgLayout: 'transparent',
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
Card: {
|
|
|
|
|
borderRadiusLG: 16
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-04-08 06:34:59 +00:00
|
|
|
<AntdApp>
|
|
|
|
|
<AppRoutes />
|
|
|
|
|
</AntdApp>
|
2026-03-17 07:31:09 +00:00
|
|
|
</ConfigProvider>
|
|
|
|
|
);
|
2026-02-10 09:48:44 +00:00
|
|
|
}
|