Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建树数据
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="data"></param>
        /// <param name="showCheckBox"></param>
        private static void BuildTree(MenuTreeModel parentNode, List <MenuConfigEntity> data, bool showCheckBox)
        {
            var childList = data.Where(x => x.ParentId == parentNode.id).ToList();

            childList.ForEach(x =>
            {
                parentNode.AddChild(new MenuTreeModel(x, parentNode.id, showCheckBox));
                //加入到上一级级树下面
            });
            parentNode.ChildNodes.ForEach(x =>
            {
                BuildTree(x, data, showCheckBox);
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建树数据,根据传入的授权菜单的ID,来判断数据是否需要被勾上 (checkbox)
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="data"></param>
        /// <param name="authIds"></param>
        private static void BuildTree(MenuTreeModel parentNode, List <MenuConfigEntity> data, List <string> authIds)
        {
            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, true, has ? 1 : 0));
                //加入到上一级级树下面
            });
            parentNode.ChildNodes.ForEach(x =>
            {
                x.showcheck = true;
                BuildTree(x, data, authIds);
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 生产无限级菜单
        /// </summary>
        /// <param name="firstLevel"></param>
        /// <param name="data"></param>
        /// <param name="showCheckBox">是否显示复选框</param>
        /// <param name="firstlevelShowCheckBox">第一级的复选框是否显示</param>
        public static void FomateTree(MenuTreeModel firstLevel, List <MenuConfigEntity> data, bool showCheckBox = false, bool firstlevelShowCheckBox = 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));
                //加入到一级树下面
            });
            firstLevel.ChildNodes.ForEach(x =>
            {
                x.showcheck = showCheckBox;
                BuildTree(x, data, showCheckBox);
            });
        }
Ejemplo n.º 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);
                }
                list.Add(tree);
            }
            return(list);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 生产无限级菜单 ,根据传入的授权菜单的ID,来判断数据是否需要被勾上 (checkbox)
        /// </summary>
        /// <param name="firstLevel"></param>
        /// <param name="data"></param>
        /// <param name="AuthIds">已经授权过的菜单的ID,用来判断页面上的checkbox是不是应该勾上</param>
        public static void FomateTree(MenuTreeModel firstLevel, List <MenuConfigEntity> data, List <string> AuthIds, bool firstlevelShowCheckBox = 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));
                //加入到一级树下面
            });
            firstLevel.ChildNodes.ForEach(x =>
            {
                x.showcheck = true;
                BuildTree(x, data, AuthIds);
            });
        }
Ejemplo n.º 7
0
 public void AddChild(MenuTreeModel menuTreeModel)
 {
     this.hasChildren = true;
     this.isexpand    = true;
     this.ChildNodes.Add(menuTreeModel);
 }