源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
楼主: ttx9n

[ASP.NET] EasyUI Tree+Asp.net实现权限树或目录树导航的简单实例

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2014-2-13 09:30:23 | 显示全部楼层 |阅读模式
本篇文章主要是对EasyUI Tree+Asp.net实现权限树或目录树导航的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Manage_Main" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>网站后台通用管理系统,<%=adminname%>,您好!</title>
    <link href="Css/default.css" rel="stylesheet" type="text/css" />
    <!--easyui-->
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/tree.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
    <script type="text/javascript" src="easyui/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src='EasyUI/JQLoader.js'> </script>
    <script type="text/javascript" src='EasyUI/outlook.js'> </script>
    <script type="text/javascript">
        $(function () {
            $('#lefttree').tree({
                animate: true,
                checkbox: false,
                url: 'GetTreeDataFromDB.ashx?father=0',
                onClick: function (node) {
                    if (node.attributes != "") {
                        addTab(node.text, node.attributes, node.id);
                    }
                },
                onLoadSuccess: function (node, data) {
                    $('#lefttree').show();
                }
            });

            $('#loginOut').click(function () {
                $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
                    if (r) {
                        location.href = 'LoginExit.ashx';
                    }
                });
            })
        });
    </script>
    </head>
    <body class="easyui-layout" style="overflow-y: hidden"  scroll="no">
    <form id="form1" runat="server">
      <noscript>
      <div style=" position:absolute; z-index:100000; height:2046px;top:0px;left:0px; width:100%; background:white; text-align:center;"> <img src="images/noscript.gif" alt='抱歉,请开启脚本支持!' /> </div>
      </noscript>
      <div region="north" split="true" border="false" style="overflow: hidden; height: 60px;
        background: url(images/layout-browser-hd-bg.gif) #7f99be repeat-x center 50%;
        line-height: 20px;color: #fff; font-family: Verdana, 微软雅黑,黑体">
        <div style="float:right;padding-top:5px;padding-right:20px;text-align:right;"> <span class="head">       </span>
          <div style=" margin-top:6px;" class="head"> <span class="icon icon-quit"> </span><a href="#" id="loginOut">安全退出</a> </div>
        </div>
        <span style="padding-left:10px; font-size: 16px; "><img src="images/blocks.gif" width="20" height="20" align="absmiddle" />网站后台通用管理系统 V1.0</span> </div>
      <div region="south" split="true" style="height: 30px; background: #D2E0F2; ">
        <div class="footer"> 网站后台通用管理系统 <%=adminname%>,您好! 版权所有@2012</div>
      </div>
      <div region="west" hide="true" split="true" title="导航菜单" style="width:180px;" id="west">
        <div id="nav" class="easyui-accordion" fit="true" border="false">
          <!--  导航内容 -->
          <div id="lefttree" style="margin:5px;"></div>
        </div>
      </div>
      <div id="mainPanle" region="center" style="background: #eee; overflow-y:hidden">
        <div id="tabs" class="easyui-tabs"  fit="true" border="false" >
          <div title="欢迎使用" style="padding:20px;overflow:hidden; " > <span style="font-size:18px;">欢迎进入系统</span> </div>
        </div>
      </div>
      <div id="mm" class="easyui-menu" style="width:150px;">
        <div id="mm-tabupdate">刷新</div>
        <div class="menu-sep"></div>
        <div id="mm-tabclose">关闭</div>
        <div id="mm-tabcloseall">全部关闭</div>
        <div id="mm-tabcloseother">除此之外全部关闭</div>
        <div class="menu-sep"></div>
        <div id="mm-tabcloseright">当前页右侧全部关闭</div>
        <div id="mm-tabcloseleft">当前页左侧全部关闭</div>
        <div class="menu-sep"></div>
        <div id="mm-exit">退出</div>
      </div>
    </form>
</body>
</html>

复制代码 代码如下:
<%@ WebHandler Language="C#" Class="GetTreeDataFromDB" %>

using System;
using System.Web;
using System.Configuration;
using System.Data;
using System.Text;
using System.Collections.Generic;
//add
using System.Web.Script.Serialization;

public class GetTreeDataFromDB : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        //获取数据库中的分类数据
        string fatherid = context.Request.QueryString["father"];
        DataTable dt = createDT();

        string json = GetTreeJsonByTable(dt, "module_id", "module_name","module_url", "module_fatherid", "0");
        context.Response.Write(json);
        context.Response.End();       
    }

    #region 根据DataTable生成EasyUI Tree Json树结构
    StringBuilder result = new StringBuilder();
    StringBuilder sb = new StringBuilder();   
    /// <summary>
    /// 根据DataTable生成EasyUI Tree Json树结构
    /// </summary>
    /// <param name="tabel">数据源</param>
    /// <param name="idCol">ID列</param>
    /// <param name="txtCol">Text列</param>
    /// <param name="url">节点Url</param>
    /// <param name="rela">关系字段</param>
    /// <param name="pId">父ID</param>
    private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string url, string rela, object pId)
    {
        result.Append(sb.ToString());
        sb.Clear();
        if (tabel.Rows.Count > 0)
        {
            sb.Append("[");
            string filer = string.Format("{0}='{1}'", rela, pId);
            DataRow[] rows = tabel.Select(filer);
            if (rows.Length > 0)
            {
                foreach (DataRow row in rows)
                {
                    sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"attributes\":\"" + row[url] + "\",\"state\":\"open\"");
                    if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                    {
                        sb.Append(",\"children\":");
                        GetTreeJsonByTable(tabel, idCol, txtCol,url, rela, row[idCol]);
                        result.Append(sb.ToString());
                        sb.Clear();
                    }
                    result.Append(sb.ToString());
                    sb.Clear();
                    sb.Append("},");
                }
                sb = sb.Remove(sb.Length - 1, 1);
            }
            sb.Append("]");
            result.Append(sb.ToString());
            sb.Clear();
        }
        return result.ToString();
    }
    #endregion


    #region 创建数据
    protected static DataTable createDT()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("module_id");
        dt.Columns.Add("module_name");
        dt.Columns.Add("module_fatherid");
        dt.Columns.Add("module_url");
        dt.Columns.Add("module_order");

        dt.Rows.Add("C1", "全国", "0", "1.aspx", "1");
        dt.Rows.Add("M01", "广东", "C1", "2.aspx", "1");

        dt.Rows.Add("M0101", "深圳", "M01", "3.aspx", "100");
        dt.Rows.Add("M010101", "南山区", "M0101", "4.aspx", "1000");
        dt.Rows.Add("M010102", "罗湖区", "M0101", "", "1001");
        dt.Rows.Add("M010103", "福田区", "M0101", "", "1002");
        dt.Rows.Add("M010104", "宝安区", "M0101", "", "1003");
        dt.Rows.Add("M010105", "龙岗区", "M0101", "", "1004");

        dt.Rows.Add("M01010301", "上梅林", "M010103", "", "1002001");
        dt.Rows.Add("M01010302", "下梅林", "M010103", "", "1002002");
        dt.Rows.Add("M01010303", "车公庙", "M010103", "", "1002003");
        dt.Rows.Add("M01010304", "竹子林", "M010103", "", "1002004");
        dt.Rows.Add("M01010305", "八卦岭", "M010103", "", "1002005");
        dt.Rows.Add("M01010306", "华强北", "M010103", "", "1002006");

        dt.Rows.Add("M0102", "广州", "M01", "", "101");
        dt.Rows.Add("M010201", "越秀区", "M0102", "", "1105");
        dt.Rows.Add("M010202", "海珠区", "M0102", "", "1106");
        dt.Rows.Add("M010203", "天河区", "M0102", "", "1107");
        dt.Rows.Add("M010204", "白云区", "M0102", "", "1108");
        dt.Rows.Add("M010205", "黄埔区", "M0102", "", "1109");
        dt.Rows.Add("M010206", "荔湾区", "M0102", "", "1110");
        dt.Rows.Add("M010207", "罗岗区", "M0102", "", "1111");
        dt.Rows.Add("M010208", "南沙区", "M0102", "", "1112");
        return dt;
    }
    #endregion


    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

复制代码 代码如下:
    #region 根据DataTable生成EasyUI Tree Json树结构 
    StringBuilder result = new StringBuilder(); 
    StringBuilder sb = new StringBuilder();     
    /// <summary> 
    /// 根据DataTable生成EasyUI Tree Json树结构 
    /// </summary> 
    /// <param name="tabel">数据源</param> 
    /// <param name="idCol">ID列</param> 
    /// <param name="txtCol">Text列</param> 
    /// <param name="url">节点Url</param> 
    /// <param name="rela">关系字段</param> 
    /// <param name="pId">父ID</param> 
    private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string url, string rela, object pId) 
    { 
        result.Append(sb.ToString()); 
        sb.Clear(); 
        if (tabel.Rows.Count > 0) 
        { 
            sb.Append("["); 
            string filer = string.Format("{0}='{1}'", rela, pId); 
            DataRow[] rows = tabel.Select(filer); 
            if (rows.Length > 0) 
            { 
                foreach (DataRow row in rows) 
                { 
                    sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"attributes\":\"" + row[url] + "\""); 
                    if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0) 
                    { 
                        //点击展开
                        sb.Append(",\"state\":\"closed\",\"children\":"); 
                        GetTreeJsonByTable(tabel, idCol, txtCol,url, rela, row[idCol]); 
                        result.Append(sb.ToString()); 
                        sb.Clear(); 
                    } 
                    result.Append(sb.ToString()); 
                    sb.Clear(); 
                    sb.Append("},"); 
                } 
                sb = sb.Remove(sb.Length - 1, 1); 
            } 
            sb.Append("]"); 
            result.Append(sb.ToString()); 
            sb.Clear(); 
        } 
        return result.ToString(); 
    } 
    #endregion  

回复

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2022-8-28 06:18:52 | 显示全部楼层
来看看怎么样
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

347

积分

中级会员

Rank: 3Rank: 3

积分
347
发表于 2022-9-12 11:14:05 | 显示全部楼层
554411515451555
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

194

积分

注册会员

Rank: 2

积分
194
发表于 2022-9-13 04:50:26 | 显示全部楼层
我要金豆金豆金豆
回复 支持 反对

使用道具 举报

1

主题

2万

回帖

69

积分

注册会员

Rank: 2

积分
69
发表于 2023-8-20 14:39:36 | 显示全部楼层
看看看看
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2023-10-25 06:11:22 | 显示全部楼层
啊啊啊啊啊啊啊啊啊啊啊啊啊啊
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

194

积分

注册会员

Rank: 2

积分
194
发表于 2023-11-9 01:02:34 | 显示全部楼层
飞飞飞飞飞飞飞飞飞飞飞飞飞
回复 支持 反对

使用道具 举报

6

主题

2万

回帖

425

积分

中级会员

Rank: 3Rank: 3

积分
425
发表于 2023-11-17 22:08:44 | 显示全部楼层
谢谢您的分享!
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-3-23 13:21:57 | 显示全部楼层
管灌灌灌灌灌灌灌灌灌灌
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

67

积分

注册会员

Rank: 2

积分
67
发表于 2024-4-4 20:46:55 | 显示全部楼层
笑纳了老板
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2024-11-23 22:16 , Processed in 0.071329 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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