system-copyright-react/src/App.tsx

58 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-31 16:00:30 +08:00
// 引入Provider
import { Provider } from 'react-redux';
// 引入仓库
import store from './store';
2024-03-11 19:13:42 +08:00
import Head from './layout/head/Head.tsx';
2024-03-12 18:53:51 +08:00
import Body from './layout/body/Body.tsx';
2024-05-07 17:00:32 +08:00
// import Foot from './layout/foot/Foot.tsx';
2024-03-26 21:09:41 +08:00
import {
GlobalContext,
GlobalData,
GlobalDataAction,
GlobalDataActionType,
2024-04-02 18:45:46 +08:00
GlobalDispatchContext,
2024-03-26 21:09:41 +08:00
} from "./context/GlobalContext.ts";
2024-07-31 16:00:30 +08:00
import React, { Reducer, useReducer } from "react";
2024-03-16 23:12:49 +08:00
2024-03-11 19:13:42 +08:00
const App: React.FC = () => {
2024-04-02 18:45:46 +08:00
2024-03-26 21:09:41 +08:00
const globalDataReducer = (state: GlobalData, action: GlobalDataAction) => {
if (action.type == GlobalDataActionType.REFRESH_SELF) {
2024-04-19 18:20:51 +08:00
if (action.user) {
2024-03-26 21:09:41 +08:00
state.user.balance = action.user.balance;
2024-04-19 18:20:51 +08:00
state.user.userId = action.user.userId;
2024-03-26 21:09:41 +08:00
state.user.nickname = action.user.nickname;
state.user.username = action.user.username;
state.user.hasUserInfo = action.user.hasUserInfo;
}
}
return {
...state
}
2024-03-26 11:54:30 +08:00
}
2024-03-26 21:09:41 +08:00
const [globalData, dispatch] = useReducer<Reducer<GlobalData, GlobalDataAction>>(globalDataReducer, {
user: {
balance: '0',
2024-04-19 18:20:51 +08:00
userId: '',
2024-03-26 21:09:41 +08:00
username: '',
nickname: '',
hasUserInfo: false
}
});
2024-03-26 11:54:30 +08:00
2024-03-11 19:13:42 +08:00
return (
2024-03-14 18:33:58 +08:00
<>
2024-07-31 16:00:30 +08:00
<Provider store={store}>
<GlobalContext.Provider value={globalData}>
<GlobalDispatchContext.Provider value={dispatch}>
<Head />
<Body />
{/* <Foot/> */}
</GlobalDispatchContext.Provider>
</GlobalContext.Provider>
</Provider>
2024-03-14 18:33:58 +08:00
</>
2024-03-11 19:13:42 +08:00
);
};
export default App;