| | |
| | | import React, { useState, useRef, useEffect, useMemo } from "react"; |
| | | import { Route } from 'react-router-dom' |
| | | import { Route } from "react-router-dom"; |
| | | import { |
| | | Admin, |
| | | Resource, |
| | |
| | | StoreContextProvider, |
| | | resolveBrowserLocale, |
| | | } from "react-admin"; |
| | | import polyglotI18nProvider from 'ra-i18n-polyglot'; |
| | | import englishMessages from './i18n/en'; |
| | | import polyglotI18nProvider from "ra-i18n-polyglot"; |
| | | import englishMessages from "./i18n/en"; |
| | | import zhMessages from "./i18n/zh"; |
| | | import { Layout } from "./layout"; |
| | | import AuthProvider from "./config/authProvider"; |
| | | import DataProvider from "./config/dataProvider"; |
| | | import Dashboard from "./page/dashboard"; |
| | | import Settings from "./page/settings"; |
| | | import Login from "./page/login"; |
| | | import * as Common from './utils/common' |
| | | import { themes } from './themes/themes'; |
| | | import { SPA_NAME, SPA_VERSION, DEFAULT_THEME_NAME, DEFAULT_THEME_MODE, DATA_PROVIDER_SPRING } from "./config/setting"; |
| | | import * as Common from "./utils/common"; |
| | | import { themes } from "./themes/themes"; |
| | | import { |
| | | SPA_NAME, |
| | | SPA_VERSION, |
| | | DEFAULT_THEME_NAME, |
| | | DEFAULT_THEME_MODE, |
| | | DATA_PROVIDER_SPRING, |
| | | } from "./config/setting"; |
| | | import ResourceContent from "./page/ResourceContent"; |
| | | import { getSystemInfo, getSystemDicts, tenants } from "@/api/auth"; |
| | | import chineseMessages from 'ra-language-chinese'; |
| | | import { createTheme, ThemeProvider } from '@mui/material/styles'; |
| | | import { zhCN } from '@mui/material/locale'; |
| | | |
| | | const i18nProvider = polyglotI18nProvider( |
| | | locale => { |
| | | if (locale === 'zh') { |
| | | return import('./i18n/zh').then(messages => messages.default); |
| | | (locale) => { |
| | | if (locale === "en") { |
| | | return import("./i18n/en").then((messages) => messages.default); |
| | | } |
| | | // fallback |
| | | return englishMessages; |
| | | return { ...chineseMessages, ...zhMessages }; |
| | | }, |
| | | // default |
| | | // 'en', |
| | | resolveBrowserLocale('en', { fullLocale: true }), |
| | | "zh", |
| | | [ |
| | | { locale: 'en', name: 'English' }, |
| | | { locale: 'zh', name: '简体中文' }, |
| | | { locale: "en", name: "English" }, |
| | | { locale: "zh", name: "简体中文" }, |
| | | ], |
| | | { |
| | | // msg in console |
| | | allowMissing: true, |
| | | } |
| | | }, |
| | | ); |
| | | |
| | | |
| | | const theme = createTheme( |
| | | { |
| | | palette: { main: '#1976d2' }, |
| | | }, |
| | | zhCN |
| | | ) |
| | | |
| | | |
| | | const store = localStorageStore(SPA_VERSION, SPA_NAME); |
| | | |
| | | const App = () => { |
| | | const [themeName] = useStore('themeName', DEFAULT_THEME_NAME); |
| | | const lightTheme = themes.find(theme => theme.name === themeName)?.light; |
| | | const darkTheme = themes.find(theme => theme.name === themeName)?.dark; |
| | | const [themeName] = useStore("themeName", DEFAULT_THEME_NAME); |
| | | const lightTheme = themes.find((theme) => theme.name === themeName)?.light; |
| | | const darkTheme = themes.find((theme) => theme.name === themeName)?.dark; |
| | | |
| | | useEffect(() => { |
| | | getSystemInfo().then((data) => { |
| | | localStorage.setItem("system", JSON.stringify(data)); |
| | | }) |
| | | }, []); |
| | | |
| | | return ( |
| | | <> |
| | |
| | | loginPage={Login} |
| | | dashboard={Dashboard} |
| | | > |
| | | {permissions => ( |
| | | {(permissions) => ( |
| | | <> |
| | | { |
| | | Common.extractNavMenus(permissions)?.map(node => { |
| | | return ( |
| | | <Resource |
| | | key={node.id} |
| | | name={node.component} |
| | | {...ResourceContent(node)} |
| | | /> |
| | | ) |
| | | }) |
| | | } |
| | | {Common.extractNavMenus(permissions)?.map((node) => { |
| | | return ( |
| | | <Resource |
| | | key={node.id} |
| | | name={node.component} |
| | | {...ResourceContent(node)} |
| | | /> |
| | | ); |
| | | })} |
| | | </> |
| | | )} |
| | | {/* CustomRoutes don't trigger checkAuth */} |
| | |
| | | </CustomRoutes> |
| | | </Admin> |
| | | </> |
| | | ) |
| | | ); |
| | | }; |
| | | |
| | | const AppWrapper = () => ( |
| | | <StoreContextProvider value={store}> |
| | | <App /> |
| | | </StoreContextProvider> |
| | | <ThemeProvider theme={theme}> |
| | | <StoreContextProvider value={store}> |
| | | <App /> |
| | | </StoreContextProvider> |
| | | </ThemeProvider> |
| | | |
| | | ); |
| | | |
| | | export default AppWrapper; |