FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 3192|回复: 5
打印 上一主题 下一主题

如何设置带有权限的树控件?

[复制链接]
跳转到指定楼层
楼主
发表于 2017-1-21 12:23:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
例如:管理员,展示所有的树节点
某用户:没有某树节点的权限不显示
请教一下?怎么做
沙发
发表于 2017-1-21 12:58:42 | 只看该作者
读取相应的数据源,用递归的方法添加treeNode。
板凳
 楼主| 发表于 2017-1-21 13:39:14 | 只看该作者
也是我看了官方的动态添加菜单
地板
 楼主| 发表于 2017-1-21 16:32:49 | 只看该作者
使用不同的xml读取就行了
5#
发表于 2017-1-21 17:27:03 | 只看该作者
两种方式都可以,如果需要控制到具体的某个TreeNode节点的话,还是 zy32002 说的正确。

AppBox首页的菜单树,就是从数据库中读取后应用权限,然后递归生成 TreeNode 集合
6#
发表于 2017-2-5 17:56:01 | 只看该作者
发个我的代码供楼主参考
前台:

        /// <summary>
        /// 树型菜单
        /// </summary>
        /// <returns></returns>
        private FineUI.Tree GetTree(Guid rootId)
        {
            AccountEntity Me = Session["Account"] as AccountEntity;
            FineUI.Tree tree = new Tree();
            tree.AutoScroll = true;
            tree.EnableArrows = true;
            tree.EnableLines = false;
            tree.ShowBorder = false;
            tree.ShowHeader = false;
            //动态加载下级节点
            tree.AutoLeafIdentification = false;
            tree.NodeLazyLoad += Tree_NodeLazyLoad;

            //获取一级节点
            Menus menuBll = new Menus();
            bll.Roles bll = new abcebiz.bll.Roles();
            Collection<RolesViewEntity> roles = bll.SelectRolesByParentId(rootId, Me.GroupId);
            foreach (RolesViewEntity ro in roles)
            {
                FineUI.TreeNode node = new FineUI.TreeNode();
                node.Text = ro.Name;
                node.NodeID = ro.MenuId.ToString();
                if (menuBll.SelectByParentId(ro.MenuId).Count > 0)
                {
                    node.Leaf = false;

                }
                else
                {
                    node.Leaf = true;
                    node.NavigateUrl = ro.URL;
                    //node.OnClientClick = mainTabStrip.GetAddTabReference(menu.Name, menu.URL, menu.Name, true);
                }
                tree.Nodes.Add(node);
            }
            return tree;
        }

        /// <summary>
        /// 动态加载下级菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tree_NodeLazyLoad(object sender, FineUI.TreeNodeEventArgs e)
        {
            AccountEntity Me = Session["Account"] as AccountEntity;
            e.Node.Expanded = true;
            Menus menuBll = new Menus();
            Guid ParentId = ValidateHelper.GetNullableGuid(e.NodeID);
            bll.Roles bll = new abcebiz.bll.Roles();
            Collection<RolesViewEntity> roles = bll.SelectRolesByParentId(ParentId, Me.GroupId);
            foreach (RolesViewEntity ro in roles)
            {
                FineUI.TreeNode node = new FineUI.TreeNode();
                node.Text = ro.Name;
                node.NodeID = ro.MenuId.ToString();
                if (menuBll.SelectByParentId(ro.MenuId).Count > 0)
                {
                    node.Leaf = false;

                }
                else
                {
                    node.Leaf = true;
                    //node.OnClientClick = mainTabStrip.GetAddTabReference(menu.Name, menu.URL, menu.Name, true);
                    node.NavigateUrl = ro.URL;

                }
                e.Node.Nodes.Add(node);
            }
        }

BLL:
        /// <summary>
        /// 根据菜单父ID和用户组ID查询 Roles 视图中的指定记录
        /// </summary>
        /// <param name="ParentId">菜单父ID</param>
        /// <param name="GroupId">用户组ID</param>
        /// <returns></returns>
        public virtual Collection<RolesViewEntity> SelectRolesByParentId(Guid ParentId, Guid GroupId)
        {
            return dal.SelectRolesByParentId(ParentId, GroupId);
        }

DAL:
        public virtual Collection<RolesViewEntity> SelectRolesByParentId(Guid ParentId, Guid GroupId)
        {
            string sql = @"
SELECT *
FROM
        [RolesView]
WHERE
    [ParentId]=@ParentId
AND
    [AccountGroupId] = @AccountGroupId
AND
    [CanRead]=1
AND
    [visible]=1
ORDER BY Sequence
";

            SqlParameter[] args = new SqlParameter[]
                        {
                Parameter.Menus.ParentId,
                                Parameter.Roles.AccountGroupId
               
                        };
            args[0].Value = ParentId;
            args[1].Value = GroupId;

            return RolesViewEntity.FillCollection(SqlHelper.ExecuteReader(CommandType.Text, sql, args));
        }

SQL SERVER做个视图,把MENUS跟ROLES做到一起
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-4-26 15:00 , Processed in 0.046312 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表