【7.2.3】角色分配菜单,增加选中状态的半开状态

pull/30/head
fengshuonan 2022-06-24 18:48:57 +08:00
parent 9751d611d5
commit 49286b3935
2 changed files with 81 additions and 5 deletions

View File

@ -0,0 +1,77 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.system.modular.menu.factory;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2022/6/24 18:35
*/
public class IndeterminateFactory {
/**
*
*
* @author fengshuonan
* @date 2022/6/24 18:36
*/
public static void fillIndeterminate(List<MenuAndButtonTreeResponse> menuAndButtonTreeResponses) {
for (MenuAndButtonTreeResponse menuAndButtonTreeRespons : menuAndButtonTreeResponses) {
List<MenuAndButtonTreeResponse> children = menuAndButtonTreeRespons.getChildren();
if (ObjectUtil.isEmpty(children)) {
continue;
}
// 获取选中状态子节点数量
long selectedCount = children.stream().filter(MenuAndButtonTreeResponse::getChecked).count();
// 获取子节点数量
int childrenSize = children.size();
// 统计选中的数量
if (selectedCount == childrenSize) {
menuAndButtonTreeRespons.setChecked(true);
menuAndButtonTreeRespons.setIndeterminate(false);
} else if (selectedCount == 0) {
menuAndButtonTreeRespons.setChecked(false);
menuAndButtonTreeRespons.setIndeterminate(false);
} else {
menuAndButtonTreeRespons.setChecked(false);
menuAndButtonTreeRespons.setIndeterminate(true);
}
// 继续遍历子节点并填充
IndeterminateFactory.fillIndeterminate(children);
}
}
}

View File

@ -59,10 +59,7 @@ import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuResource;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.AntdMenusFactory;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.Antdv3MenusFactory;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.LayuiMenusFactory;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.MenuTypeFactory;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.*;
import cn.stylefeng.roses.kernel.system.modular.menu.mapper.SysMenuMapper;
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuButtonService;
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuResourceService;
@ -474,7 +471,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
AntdMenusFactory.fillButtons(menuAndButtonTreeResponses, buttonList, roleMenuButtonList);
// 菜单列表转化为一棵树
return new DefaultTreeBuildFactory<MenuAndButtonTreeResponse>().doTreeBuild(menuAndButtonTreeResponses);
List<MenuAndButtonTreeResponse> menuAndButtonTreeResponses1 = new DefaultTreeBuildFactory<MenuAndButtonTreeResponse>().doTreeBuild(menuAndButtonTreeResponses);
IndeterminateFactory.fillIndeterminate(menuAndButtonTreeResponses1);
return menuAndButtonTreeResponses1;
}
@Override