Пример #1
0
        /// <summary>
        /// 生产  三个平台的集合
        /// </summary>
        /// <returns></returns>
        public static List <MenuTreeModel> InitData()
        {
            List <MenuTreeModel> list = new List <MenuTreeModel>();
            MenuTreeModel        tree = new MenuTreeModel();

            tree.text         = "安卓终端";
            tree.id           = "1";
            tree.value        = "1";
            tree.platformType = 1;
            list.Add(tree);
            MenuTreeModel tree1 = new MenuTreeModel();

            tree1.text         = "Windows终端";
            tree1.id           = "0";
            tree1.value        = "0";
            tree1.platformType = 0;
            list.Add(tree1);
            MenuTreeModel tree2 = new MenuTreeModel();

            tree2.text         = "手机APP";
            tree2.id           = "2";
            tree2.value        = "2";
            tree2.platformType = 2;
            list.Add(tree2);
            return(list);
        }
Пример #2
0
        /// <summary>
        /// 创建树数据
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="data"></param>
        /// <param name="showCheckBox"></param>
        /// <param name="showRemark"></param>
        private static void BuildTree(MenuTreeModel parentNode, List <MenuConfigEntity> data, bool showCheckBox = false, bool showRemark = false)
        {
            var childList = data.Where(x => x.ParentId == parentNode.id).ToList();

            childList.ForEach(x =>
            {
                parentNode.AddChild(new MenuTreeModel(x, parentNode.id, showCheckBox, 0, showRemark));
                //加入到上一级级树下面
            });
            parentNode.ChildNodes.ForEach(x =>
            {
                BuildTree(x, data, showCheckBox, showRemark);
            });
        }
Пример #3
0
        /// <summary>
        /// 创建树数据,根据传入的授权菜单的ID,来判断数据是否需要被勾上 (checkbox)
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="data"></param>
        /// <param name="authIds"></param>
        /// <param name="showCheckBox"></param>
        /// <param name="showReamrk"></param>
        private static void BuildTree(MenuTreeModel parentNode, List <MenuConfigEntity> data, List <string> authIds, bool showCheckBox, bool showReamrk)
        {
            var childList = data.Where(x => x.ParentId == parentNode.id).ToList();

            childList.ForEach(x =>
            {
                bool has = authIds.Any(p => p == x.ModuleId);
                parentNode.AddChild(new MenuTreeModel(x, parentNode.id, showCheckBox, has ? 1 : 0, showReamrk));
                //加入到上一级级树下面
            });
            parentNode.ChildNodes.ForEach(x =>
            {
                x.showcheck = true;
                BuildTree(x, data, authIds, showCheckBox, showReamrk);
            });
        }
Пример #4
0
        /// <summary>
        /// 生产无限级菜单
        /// </summary>
        /// <param name="firstLevel"></param>
        /// <param name="data"></param>
        /// <param name="showCheckBox">是否显示复选框</param>
        /// <param name="firstlevelShowCheckBox">第一级的复选框是否显示</param>
        /// <param name="showRemark">是否在菜单项上显示备注</param>
        public static void FomateTree(MenuTreeModel firstLevel, List <MenuConfigEntity> data, bool showCheckBox = false, bool firstlevelShowCheckBox = false, bool showRemark = false)
        {
            firstLevel.showcheck = firstlevelShowCheckBox;
            var childList = data.Where(x => x.ParentId == firstLevel.id).ToList();

            childList.ForEach(p =>
            {
                firstLevel.AddChild(new MenuTreeModel(p, firstLevel.id, showCheckBox, 0, showRemark));
                //加入到一级树下面
            });
            firstLevel.ChildNodes.ForEach(x =>
            {
                x.showcheck = showCheckBox;
                BuildTree(x, data, showCheckBox, showRemark);
            });
        }
Пример #5
0
        public static List <MenuTreeModel> BuildMenuTree(List <MenuConfigEntity> menus, bool showCheckBox = false)
        {
            var menuIds  = menus.Select(x => x.ModuleId).ToList();
            var noParent = menus.Where(p => !menuIds.Contains(p.ParentId)).ToList();
            List <MenuTreeModel> list = new List <MenuTreeModel>();

            foreach (var firstLevel in noParent)
            {
                MenuTreeModel tree = new MenuTreeModel(firstLevel, "0", showCheckBox);

                if (menus.Any(p => p.ParentId == firstLevel.ModuleId))
                {
                    BuildTree(tree, menus, showCheckBox, false);
                }
                list.Add(tree);
            }
            return(list);
        }
Пример #6
0
        /// <summary>
        /// 生产无限级菜单 ,根据传入的授权菜单的ID,来判断数据是否需要被勾上 (checkbox)
        /// </summary>
        /// <param name="firstLevel"></param>
        /// <param name="data"></param>
        /// <param name="AuthIds">已经授权过的菜单的ID,用来判断页面上的checkbox是不是应该勾上</param>
        /// <param name="firstlevelShowCheckBox">是否显示第一级菜单的复选框 默认false</param>
        /// <param name="showRemark">是否在菜单后面显示备注 默认false</param>
        /// <param name="showChildrenCheckBox">子集是否显示复选框</param>
        public static void FomateTree(MenuTreeModel firstLevel, List <MenuConfigEntity> data, List <string> AuthIds, bool firstlevelShowCheckBox = false, bool showRemark = false, bool showChildrenCheckBox = false)
        {
            var childList = data.Where(x => x.ParentId == firstLevel.id).ToList();

            firstLevel.showcheck = firstlevelShowCheckBox;
            bool firstHas = AuthIds.Any(x => x == firstLevel.id);

            firstLevel.checkstate = firstHas ? 1 : 0;
            childList.ForEach(p =>
            {
                bool has = AuthIds.Any(x => x == p.ModuleId);
                firstLevel.AddChild(new MenuTreeModel(p, firstLevel.id, true, has ? 1 :0, showRemark));
                //加入到一级树下面
            });
            firstLevel.ChildNodes.ForEach(x =>
            {
                x.showcheck = true;
                BuildTree(x, data, AuthIds, showChildrenCheckBox, showRemark);
            });
        }
Пример #7
0
 public void AddChild(MenuTreeModel menuTreeModel)
 {
     this.hasChildren = true;
     this.isexpand    = true;
     this.ChildNodes.Add(menuTreeModel);
 }