mirror of https://gitee.com/stylefeng/roses
【7.2.3】角色分配菜单,增加选中状态的半开状态
parent
9751d611d5
commit
49286b3935
|
@ -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.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.SysMenu;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
|
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.entity.SysMenuResource;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.menu.factory.AntdMenusFactory;
|
import cn.stylefeng.roses.kernel.system.modular.menu.factory.*;
|
||||||
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.mapper.SysMenuMapper;
|
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.SysMenuButtonService;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuResourceService;
|
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);
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue