Skip to content

Commit

Permalink
feat: try bundle empty project
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 18, 2024
1 parent 734008b commit 1b64e15
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions cases/arco-pro/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
import './style/global.less';
import { useEffect } from 'react';
import * as ReactDOM from 'react-dom/client';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { ConfigProvider } from '@arco-design/web-react';
import zhCN from '@arco-design/web-react/es/locale/zh-CN';
import enUS from '@arco-design/web-react/es/locale/en-US';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import axios from 'axios';
import rootReducer from './store';
import PageLayout from './layout';
import { GlobalContext } from './context';
import Login from './pages/login';
import checkLogin from './utils/checkLogin';
import changeTheme from './utils/changeTheme';
import useStorage from './utils/useStorage';
import './mock';
import "@arco-design/web-react/dist/css/arco.css";
// import './style/global.less';
// import { useEffect } from 'react';
// import * as ReactDOM from 'react-dom/client';
// import { createStore } from 'redux';
// import { Provider } from 'react-redux';
// import { ConfigProvider } from '@arco-design/web-react';
// import zhCN from '@arco-design/web-react/es/locale/zh-CN';
// import enUS from '@arco-design/web-react/es/locale/en-US';
// import { BrowserRouter, Switch, Route } from 'react-router-dom';
// import axios from 'axios';
// import rootReducer from './store';
// import PageLayout from './layout';
// import { GlobalContext } from './context';
// import Login from './pages/login';
// import checkLogin from './utils/checkLogin';
// import changeTheme from './utils/changeTheme';
// import useStorage from './utils/useStorage';
// import './mock';
// import "@arco-design/web-react/dist/css/arco.css";

const store = createStore(rootReducer);
// const store = createStore(rootReducer);

function Index() {
const [lang, setLang] = useStorage('arco-lang', 'en-US');
const [theme, setTheme] = useStorage('arco-theme', 'light');
// function Index() {
// const [lang, setLang] = useStorage('arco-lang', 'en-US');
// const [theme, setTheme] = useStorage('arco-theme', 'light');

function getArcoLocale() {
switch (lang) {
case 'zh-CN':
return zhCN;
case 'en-US':
return enUS;
default:
return zhCN;
}
}
// function getArcoLocale() {
// switch (lang) {
// case 'zh-CN':
// return zhCN;
// case 'en-US':
// return enUS;
// default:
// return zhCN;
// }
// }

function fetchUserInfo() {
axios.get('/api/user/userInfo').then((res) => {
store.dispatch({
type: 'update-userInfo',
payload: { userInfo: res.data },
});
});
}
// function fetchUserInfo() {
// axios.get('/api/user/userInfo').then((res) => {
// store.dispatch({
// type: 'update-userInfo',
// payload: { userInfo: res.data },
// });
// });
// }

useEffect(() => {
if (checkLogin()) {
fetchUserInfo();
} else if (window.location.pathname.replace(/\//g, '') !== 'login') {
window.location.pathname = '/login';
}
}, []);
// useEffect(() => {
// if (checkLogin()) {
// fetchUserInfo();
// } else if (window.location.pathname.replace(/\//g, '') !== 'login') {
// window.location.pathname = '/login';
// }
// }, []);

useEffect(() => {
changeTheme(theme);
}, [theme]);
// useEffect(() => {
// changeTheme(theme);
// }, [theme]);

const contextValue = {
lang,
setLang,
theme,
setTheme,
};
// const contextValue = {
// lang,
// setLang,
// theme,
// setTheme,
// };

return (
<BrowserRouter>
<ConfigProvider
locale={getArcoLocale()}
componentConfig={{
Card: {
bordered: false,
},
List: {
bordered: false,
},
Table: {
border: false,
},
}}
>
<Provider store={store}>
<GlobalContext.Provider value={contextValue}>
<Switch>
<Route path="/login" component={Login} />
<Route path="/" component={PageLayout} />
</Switch>
</GlobalContext.Provider>
</Provider>
</ConfigProvider>
</BrowserRouter>
);
}
// return (
// <BrowserRouter>
// <ConfigProvider
// locale={getArcoLocale()}
// componentConfig={{
// Card: {
// bordered: false,
// },
// List: {
// bordered: false,
// },
// Table: {
// border: false,
// },
// }}
// >
// <Provider store={store}>
// <GlobalContext.Provider value={contextValue}>
// <Switch>
// <Route path="/login" component={Login} />
// <Route path="/" component={PageLayout} />
// </Switch>
// </GlobalContext.Provider>
// </Provider>
// </ConfigProvider>
// </BrowserRouter>
// );
// }

ReactDOM.createRoot(document.getElementById('root')).render(<Index />);
// ReactDOM.createRoot(document.getElementById('root')).render(<Index />);

0 comments on commit 1b64e15

Please sign in to comment.