Skip to content

Commit 5c696fc

Browse files
committed
feat: 添加tab的相关store
1 parent fab0cc7 commit 5c696fc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/store/slice/tab/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { RoutePath } from '@elegant-router/types';
2+
import { createSlice } from '@reduxjs/toolkit';
3+
import type { PayloadAction } from '@reduxjs/toolkit';
4+
5+
interface InitialStateType {
6+
activeFirstLevelMenuKey: string;
7+
activeTabId: string;
8+
homeTab: App.Global.Tab | null;
9+
removeCacheKey: RoutePath | null;
10+
tabs: App.Global.Tab[];
11+
}
12+
13+
const initialState: InitialStateType = {
14+
/** - 当前一级菜单 */
15+
activeFirstLevelMenuKey: '',
16+
/** - 当前标签页 */
17+
activeTabId: '',
18+
/** - 首页标签页 */
19+
homeTab: null,
20+
/** - 需要删除的缓存页面 */
21+
removeCacheKey: null,
22+
/** - 标签页 */
23+
tabs: []
24+
};
25+
26+
export const tabSlice = createSlice({
27+
initialState,
28+
name: 'tab',
29+
reducers: {
30+
setActiveFirstLevelMenuKey: (state, action: PayloadAction<string>) => {
31+
state.activeFirstLevelMenuKey = action.payload;
32+
}
33+
},
34+
selectors: {
35+
selectActiveFirstLevelMenuKey: tab => tab.activeFirstLevelMenuKey,
36+
selectTabs: tab => tab.tabs
37+
}
38+
});
39+
40+
export const { setActiveFirstLevelMenuKey } = tabSlice.actions;
41+
42+
export const { selectActiveFirstLevelMenuKey, selectTabs } = tabSlice.selectors;

0 commit comments

Comments
 (0)