menu grant
This commit is contained in:
@@ -37,10 +37,14 @@ export const MenuCategory = ({
|
||||
const [favoriteItems, setFavoriteItems] = useState<Array<UserFavorite>>([]);
|
||||
const [menuIds, setMenuIds] = useState<Array<number | undefined>>([]);
|
||||
|
||||
const onClickToNavigate = (path?: string) => {
|
||||
if(!!path && !!setMenuOn && !editMode){
|
||||
const onClickToNavigate = (path?: string, menuId?: number) => {
|
||||
if(!!path && !!setMenuOn && !editMode && !!menuId){
|
||||
setMenuOn(false);
|
||||
navigate(path);
|
||||
navigate(path, {
|
||||
state: {
|
||||
menuId: menuId
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -121,7 +125,7 @@ export const MenuCategory = ({
|
||||
rs.push(
|
||||
<li
|
||||
key={ `menu-item-key-${menuId}-${i}` }
|
||||
onClick={ () => onClickToNavigate(subMenu[i]?.programPath) }
|
||||
onClick={ () => onClickToNavigate(subMenu[i]?.programPath, subMenu[i]?.menuId) }
|
||||
>
|
||||
<span>{ displayName }</span>
|
||||
<div className="check_box_scrap">
|
||||
|
||||
@@ -7,6 +7,8 @@ export interface UserInfoState {
|
||||
userInfo: UserInfo;
|
||||
setUserInfo: (update: SetStateAction<Partial<UserInfo>>) => void;
|
||||
resetUserInfo: () => void;
|
||||
menuGrantsByKey: Record<string, Array<string>>;
|
||||
setMenuGrantsByKey: (update: SetStateAction<Record<string, Array<string>>>) => void;
|
||||
businessInfo: BusinessInfo;
|
||||
setBusinessInfo: (update: SetStateAction<Partial<BusinessInfo>>) => void;
|
||||
|
||||
@@ -32,6 +34,7 @@ export interface UserInfoState {
|
||||
|
||||
const initialUserInfoState = {
|
||||
userInfo: {} as UserInfo,
|
||||
menuGrantsByKey: {} as Record<string, Array<string>>,
|
||||
businessInfo: {} as BusinessInfo,
|
||||
userFavorite: [] as Array<UserFavorite>,
|
||||
userMids: [] as Array<string>,
|
||||
@@ -59,6 +62,18 @@ export const createUserInfoStore = lens<UserInfoState>((set, get) => ({
|
||||
};
|
||||
});
|
||||
},
|
||||
setMenuGrantsByKey: (update) => {
|
||||
set((state: UserInfoState) => {
|
||||
const newMenuGrantsByKey = (typeof update === 'function')
|
||||
? update(state.menuGrantsByKey): update;
|
||||
return {
|
||||
...state,
|
||||
menuGrantsByKey: {
|
||||
...newMenuGrantsByKey
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
setBusinessInfo: (update) => {
|
||||
set((state: UserInfoState) => {
|
||||
const newBusinessInfo = (typeof update === 'function')
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
BusinessPropertyParams,
|
||||
BusinessPropertyResponse,
|
||||
LoginResponse,
|
||||
MenuGrantsItem,
|
||||
ShortcutUserParams,
|
||||
ShortcutUserResponse,
|
||||
UserFindAuthMethodParams
|
||||
@@ -257,7 +258,7 @@ export const SubLayout = () => {
|
||||
});
|
||||
callCodesSelect({ codeCl: '0325' });
|
||||
callCodesSelect({ codeCl: '0074' });
|
||||
|
||||
onSetGrant();
|
||||
}).catch((error: any) => {
|
||||
setLoginSuccess(false);
|
||||
});
|
||||
@@ -284,6 +285,50 @@ export const SubLayout = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const onSetGrant = () => {
|
||||
let userInfo = useStore.getState().UserStore.userInfo;
|
||||
const menuGrants = userInfo.menuGrants;
|
||||
let grantObj: Record<string, Array<string>> = {};
|
||||
let grantKeys = [8, 4, 2, 1];
|
||||
if(!!menuGrants){
|
||||
for(let i=0;i<menuGrants.length;i++){
|
||||
let menuGrantItem = menuGrants[i];
|
||||
if(menuGrantItem){
|
||||
let menuId: number = menuGrantItem.menuId;
|
||||
let grant: number = menuGrantItem.grant;
|
||||
if(!grantObj.hasOwnProperty(''+menuId)){
|
||||
grantObj[''+menuId] = [];
|
||||
}
|
||||
for(let j=0;j<grantKeys.length;j++){
|
||||
let grantKey = grantKeys[j];
|
||||
if(!!grantKey){
|
||||
//grant = grant - grantKey;
|
||||
if((grant - grantKey) >= 0){
|
||||
grant = grant - grantKey;
|
||||
if(j === 0){
|
||||
grantObj[''+menuId]?.push('D');
|
||||
}
|
||||
else if(j === 1){
|
||||
grantObj[''+menuId]?.push('X');
|
||||
}
|
||||
else if(j === 2){
|
||||
grantObj[''+menuId]?.push('W');
|
||||
}
|
||||
else if(j === 3){
|
||||
grantObj[''+menuId]?.push('R');
|
||||
}
|
||||
}
|
||||
else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
useStore.getState().UserStore.setMenuGrantsByKey(grantObj);
|
||||
};
|
||||
|
||||
const onSetCommonCodes = ({
|
||||
data,
|
||||
codeCl,
|
||||
@@ -330,7 +375,6 @@ export const SubLayout = () => {
|
||||
updateUserData(token);
|
||||
};
|
||||
const alarmLink = (options: AlarmLinkOptions) => {
|
||||
console.log(options);
|
||||
if(options?.linkUrl){
|
||||
setAlarmRoutesOn(true);
|
||||
setAlarmOptions(options);
|
||||
|
||||
Reference in New Issue
Block a user