umi-tablayout
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Effect, Reducer } from 'umi';
|
||||
import { Effect, Reducer } from '@umijs/max';
|
||||
|
||||
import { queryCurrent, query as queryUsers } from '@/services/user';
|
||||
|
||||
@ -18,6 +18,8 @@ export interface CurrentUser {
|
||||
|
||||
export interface UserModelState {
|
||||
currentUser?: CurrentUser;
|
||||
menuData?: any[];
|
||||
pathKeyMap?: Map<string, {name: string, icon?: string}>;
|
||||
}
|
||||
|
||||
export interface UserModelType {
|
||||
@ -30,6 +32,7 @@ export interface UserModelType {
|
||||
reducers: {
|
||||
saveCurrentUser: Reducer<UserModelState>;
|
||||
changeNotifyCount: Reducer<UserModelState>;
|
||||
saveMenuData: Reducer<UserModelState>;
|
||||
};
|
||||
}
|
||||
|
||||
@ -38,6 +41,8 @@ const UserModel: UserModelType = {
|
||||
|
||||
state: {
|
||||
currentUser: {},
|
||||
menuData: [],
|
||||
pathKeyMap: new Map<string, {name: string, icon?: string}>(),
|
||||
},
|
||||
|
||||
effects: {
|
||||
@ -64,6 +69,27 @@ const UserModel: UserModelType = {
|
||||
currentUser: action.payload || {},
|
||||
};
|
||||
},
|
||||
saveMenuData(state, action) {
|
||||
const menuData = action.payload || [];
|
||||
const pathKeyMap = new Map<string, {name: string, icon?: string}>();
|
||||
// 将menuData转换为pathKeyMap 递归处理
|
||||
const convertToPathKeyMap = (menuData: any[]) => {
|
||||
menuData.forEach((item: any) => {
|
||||
const path = item.path ? item.path.toLowerCase() : '';
|
||||
pathKeyMap.set(path, {name: item.name, icon: item.icon});
|
||||
if (item.children) {
|
||||
convertToPathKeyMap(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
convertToPathKeyMap(menuData);
|
||||
pathKeyMap.set('/dashboard', { name: '首页' });
|
||||
return {
|
||||
...state,
|
||||
menuData: action.payload || [],
|
||||
pathKeyMap,
|
||||
};
|
||||
},
|
||||
changeNotifyCount(
|
||||
state = {
|
||||
currentUser: {},
|
||||
|
Reference in New Issue
Block a user