9 changed files with 32 additions and 36 deletions
-
4src/App.tsx
-
4src/components/Header.tsx
-
9src/pages/measure/components/MeasureAction.tsx
-
6src/pages/measure/components/MeasureConfig.tsx
-
8src/pages/measure/components/MeasureDetail.tsx
-
9src/pages/measure/components/graph/ResultLayer.tsx
-
19src/store/features/contextSlice.ts
-
3src/store/index.ts
-
6src/utils/hooks.ts
@ -1,32 +1,29 @@ |
|||
// counterSlice.ts 文件
|
|||
|
|||
import { createSlice } from "@reduxjs/toolkit"; |
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; |
|||
import { ContextMessage } from "../../services/wsTypes"; |
|||
|
|||
const initialState: ContextMessage["data"] = { |
|||
loginFlag: false, |
|||
loginUser: {}, |
|||
|
|||
newMeasureAfterSave: false, |
|||
}; |
|||
|
|||
// 创建一个 Slice
|
|||
export const contextSlice = createSlice({ |
|||
name: "context", |
|||
initialState, |
|||
// 定义 reducers 并生成关联的操作
|
|||
|
|||
reducers: { |
|||
// 定义一个加的方法
|
|||
updateUser: (state, { payload }) => { |
|||
state.loginFlag = payload.loginFlag; |
|||
state.loginUser = payload.loginUser; |
|||
updateUser: (state, action: PayloadAction<ContextMessage["data"]>) => { |
|||
state.loginFlag = action.payload.loginFlag; |
|||
state.loginUser = action.payload.loginUser; |
|||
}, |
|||
switchMeasureAfterSave: (state, { payload }) => { |
|||
state.newMeasureAfterSave = payload; |
|||
switchMeasureAfterSave: (state, action: PayloadAction<boolean>) => { |
|||
state.newMeasureAfterSave = action.payload; |
|||
}, |
|||
}, |
|||
}); |
|||
// 导出加减的方法
|
|||
|
|||
export const { updateUser, switchMeasureAfterSave } = contextSlice.actions; |
|||
|
|||
// 默认导出
|
|||
|
@ -0,0 +1,6 @@ |
|||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' |
|||
import type { RootState, AppDispatch } from '../store' |
|||
|
|||
// 在整个应用程序中使用,而不是简单的 `useDispatch` 和 `useSelector`
|
|||
export const useAppDispatch: () => AppDispatch = useDispatch |
|||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector |
Write
Preview
Loading…
Cancel
Save
Reference in new issue