22.子权限

点查询子权限要过来要带一个父权限id过来:?也就是说点击【子权限】,子权限视图要放一个pid;

// <summary>
        /// 子权限列表视图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult PermissionSon()
        {
            //获取父权限id
            int pid = int.Parse(Request.QueryString["pid"]);
            return View();
        } 

查询子菜单列表数据的id怎么拿到:?

 /// <summary>
        /// 查询子权限列表数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [AjaxRequest]
        public ActionResult  GetSonPermData(FormCollection form)
        {
            //获取页容量
            int pageSize = int.Parse(Request.Form["rows"]);
            //获取请求的页面
            int pageIndex = int.Parse(Request.Form["page"]);
            //获取父权限id
            int parentMenid=int.Parse(Request.QueryString["pid"]);//这个父菜单id怎么拿到?
         //查询分页数据
            var list = OperateContext.Current.BLLSession.IOu_PermissionBLL.GetPagedList(pageIndex, pageSize,p=>p.pParent==parentMenid && p.pIsDel == false, p => p.pOrder).Select(p => p.ToPOCO());
            int rowCount = OperateContext.Current.BLLSession.IOu_PermissionBLL.GetListBy(p => p.pParent==parentMenid && p.pIsDel==false).Count();
           //2生成规定格式的 json字符串发回  给异步对象
            MODEL.EasyUIModel.DataGridModel dgModel = new MODEL.EasyUIModel.DataGridModel()
            { 
            total=rowCount,
            rows=list,
            footer=null
            };
            return Json(dgModel);
        }

查询子菜单列表数据的id怎么拿到:?很简单,查询的时候直接带上一个参数:

【子权限】按钮要带一个pid过去,PermissionSon视图接收。如: int pid = int.Parse(Request.QueryString["pid"]);

子菜单get到permissionSon,能接收到pid;子菜单post到permissionSon就接收不到父权限:  int parentMenid=int.Parse(Request.QueryString["pid"]);//获取父权限id   

所以就需求在点击子菜单permissionSon时候带上pid;如: url: '/admin/sys/PermissionSon?pid=@Request.QueryString["pid"]'

这样get和post都带一个id.
GetPermisson 
$(function () { $(
'#editWindow').window('close');//编辑默认关闭 $("#tbList").datagrid({ width: 'auto', height: 400, striped: true, singleSelect: true, url: '/admin/sys/PermissionSon?pid=@Request.QueryString["pid"]',//点击子菜单要带上pid,PermissionSon方法post用,//这样get和post都带一个id. 下图2:

loadMsg: '数据加载中请稍后……', pagination: true,//启用分页,默认每页10行 rownumbers: true,//显示页码,默认 提供 10 - 50 的页容量选择下拉框 pageSize: 10,//设置 页容量为 5 pageList: [10, 15, 20, 25, 30],//设置 页容量下拉框 fitColumns:true, columns: [[ { field: 'pIsShow', title: '显示', width: 20, formatter: function (value) { return value ? "" : "X"; }, }, { field: 'pid', title: 'ID', width: 100, align: "center" }, { field: 'pName', title: '权限名', width: 100, align: "center" }, { field: 'pAreaName', title: '区域名', width: 100, align: "center" }, { field: 'pControllerName', title: '控制名', width: 100, align: "center" }, { field: 'pActionName', title: 'Action', width: 100, align: "center" }, { field: 'pFormMethod', title: '请求方式', width: 100, align: "center", formatter: function (value) { switch (value.toString()) { case "1": return "Get"; case "2": return "Post"; case "3": return "Both"; } } }, { field: 'pOperationType', title: '操作类型', width: 100, align: "center", formatter: function (value) { switch (value.toString()) { case "0": return "无操作"; case "1": return "easyui连接"; case "2": return "打开新窗体"; break; } } } ]], toolbar: [{ iconCls: 'icon-add', text: "新增", handler: AddRow },'-', { iconCls: 'icon-remove', text: "删除", handler: Delperm }, '-', { iconCls: 'icon-edit', text: "编辑", handler: editRow }, '-', { iconCls: 'icon-edit', text: "查看子权限", handler: viewSon //查看子权限 }, //'-', { // iconCls: 'icon-search', // text: "返回", // handler: function(){window.location="/admin/sys/Permission";}, //} ], //设置选中行 onSelect: function (rowI, rD) { selectRowIndex = rowI;//1.1将中的行设置为全局变量 设置给全局变量 } }); initMoifyForm(); }) ////为表单 设置 参数 function initMoifyForm() { $('#modifyForm').form({ url: "/admin/sys/EditPermission", }); } //1.将中的行设置为全局变量 var selectRowIndex = -1; //编辑按钮方法 function editRow() { //1.获取选中行里的数据! var rowData = $("#tbList").datagrid("getSelected");//getSelected返回一个选中的行 if (rowData){ $('#editWindow').window('open');//打开 //load发送异步请求权限修改页面。并直接加载到 当前的 修改窗体中 //路径、data、回调函数 $.get("/admin/sys/EditPermission/" + rowData.pid, null, function (jsonObj) { //1.url,2.data,3.回调函数 if (jsonObj.Statu)//如果转了就是json对象,如果没转字符串就没有statu $.procAjaxData(jsonObj); else $('#editWindow').html(jsonObj); }); } }; //新增按钮方法 function AddRow() { $('#editWindow').window('open');//打开 $.get("/admin/sys/AddPermission/", null, function (jsonObj) { if (jsonObj.Statu) $.procAjaxData(jsonObj); else { $("#editWindow").html(jsonObj); } });//路径、data、回调函数 } //删除方法 function Delperm() { //1.获取选中行里的数据! var rowData = $("#tbList").datagrid("getSelected"); if (rowData) { //{id:rowData.pid} //$.post("/admin/sys/delpemission", rowData.pid, function () { }) $.post("/admin/sys/DelPermission", "id=" + rowData.pid, function (jsonObj) { $.procAjaxData(jsonObj, function () {//json统一处理方法:1.数据,2.删除成功后回调函数 $("#tbList").datagrid("reload");//删除成功后 刷新页面 }); //成功了 }, "JSON"); } } function viewSon() {//查看子权限 var rowData = $("#tbList").datagrid("getSelected");//获取选中行 window.location = "/admin/sys/PermissionSon?pid=" + rowData.pid;//查询的时候直接带上一个参数:pid
 }

 

permission权限管理

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>用户权限管理</title>
    <link href="~/EasyUI/themes/icon.css" rel="stylesheet" />

    <link href="~/EasyUI/themes/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script>

    
    @*自动为表单 添加验证功能的js文件---微软提供
        <script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
        *@
  
    <script type="text/javascript" src="~/Scripts/jquery.msgProcess.js"></script>
    <script type="text/javascript">
        //=====================1.加载数据======================
        $(function () {
            $('#editWindow').window('close');//编辑默认关闭
           
            $("#tbList").datagrid({
                width: 'auto',
                height: 400,
                striped: true,
                singleSelect: true,
                url: '/admin/sys/GetPermData',
                //queryParams:{},  
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页,默认每页10行
                rownumbers: true,//显示页码,默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 10,//设置 页容量为 5
                pageList: [10, 15, 20, 25, 30],//设置 页容量下拉框
                fitColumns:true,
                columns: [[
                     {
                         field: 'pIsShow', title: '显示', width: 20, formatter: function (value) {
                             return value ? "" : "X";
                         },
                     },
                    { field: 'pid', title: 'ID', width: 100, align: "center" },
                    { field: 'pName', title: '权限名', width: 100, align: "center" },
                    { field: 'pAreaName', title: '区域名', width: 100, align: "center" },
                    { field: 'pControllerName', title: '控制名', width: 100, align: "center" },
                    { field: 'pActionName', title: 'Action', width: 100, align: "center" },
                    {
                        field: 'pFormMethod', title: '请求方式', width: 100, align: "center", formatter: function (value) {
                          
                            switch (value.toString()) {
                                case "1":
                                    return "Get";
                                case "2":
                                    return "Post";
                                case "3":
                                    return "Both";
                            }
                        }
                    },
                    {
                        field: 'pOperationType', title: '操作类型', width: 100, align: "center", formatter: function (value) {
                            
                            switch (value.toString()) {
                                case "0":
                                    return "无操作";
                                case "1":
                                    return "easyui连接";
                                case "2":
                                    return "打开新窗体";
                                    break;
                            }
                        }
                    },
                     { field: 'pRemark', title: '备注', width: 100, align: "center" },
                    
                ]],
                toolbar: [{
                    iconCls: 'icon-add',
                    text: "新增",
                    handler: AddRow
                 },'-', {
                    iconCls: 'icon-remove',
                    text: "删除",
                    handler: Delperm
                }, '-', {
                    iconCls: 'icon-edit',
                    text: "编辑",
                    handler: editRow
                },  '-', {
                   iconCls: 'icon-search',
               text: "子权限",
               handler: viewSon //function () { window.location = "/admin/sys/PermissionSon"; },
            }
            ],
               //设置选中行
                onSelect: function (rowI, rD) {
                   
                    selectRowIndex = rowI;//1.1将中的行设置为全局变量 设置给全局变量
                }
            });
            initMoifyForm();
        })
        ////为表单 设置 参数
        function initMoifyForm() {
           $('#modifyForm').form({
               url: "/admin/sys/EditPermission",
              
            });
        }
        //1.将中的行设置为全局变量
        var selectRowIndex = -1;
       
        //编辑按钮方法
        function editRow() {
            //1.获取选中行里的数据!
            var rowData = $("#tbList").datagrid("getSelected");//getSelected返回一个选中的行
            if (rowData){
            $('#editWindow').window('open');//打开
            //load发送异步请求权限修改页面。并直接加载到 当前的 修改窗体中
            
              //路径、data、回调函数  
            $.get("/admin/sys/EditPermission/" + rowData.pid, null, function (jsonObj) {  //1.url,2.data,3.回调函数
                if (jsonObj.Statu)//如果转了就是json对象,如果没转字符串就没有statu
                    $.procAjaxData(jsonObj);
               else
                    $('#editWindow').html(jsonObj);
            });
            }
        };
        //新增按钮方法
        function AddRow() {
            $('#editWindow').window('open');//打开
            $.get("/admin/sys/AddPermission/", null, function (jsonObj) {
                if (jsonObj.Statu)
                    $.procAjaxData(jsonObj);
                else {
                    $("#editWindow").html(jsonObj);
                }
            });//路径、data、回调函数
        }
        //删除方法
        function Delperm() {
            //1.获取选中行里的数据!
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                //{id:rowData.pid}
                //$.post("/admin/sys/delpemission", rowData.pid, function () { })
                $.post("/admin/sys/DelPermission", "id=" + rowData.pid, function (jsonObj) {
                    $.procAjaxData(jsonObj, function () {//json统一处理方法:1.数据,2.删除成功后回调函数
                        $("#tbList").datagrid("reload");//删除成功后 刷新页面
                    });
                    //成功了 
                }, "JSON");
                
            }
        }
        function viewSon() {
            var rowData = $("#tbList").datagrid("getSelected");//获取选中行
            window.location = "/admin/sys/PermissionSon?pid=" + rowData.pid;//带上权限pid
        }
    </script>
</head>
<body>
    <table id="tbList" style="width:400px;height:250px">

      
    </table>
    <div id="editWindow" class="easyui-window" title="用户权限编辑" style="width:600px;height:400px;" resizable="true" data-options="iconCls:'icon-save',modal:true">

    </div>
</body>
</html>

 

permissionSon子权限

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>子权限管理</title>
    <link href="~/EasyUI/themes/icon.css" rel="stylesheet" />

    <link href="~/EasyUI/themes/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script>

    
   
  
    <script type="text/javascript" src="~/Scripts/jquery.msgProcess.js"></script>
    <script type="text/javascript">
    //=====================1.加载数据======================
    $(function () {
        $('#editWindow').window('close');//编辑默认关闭

        $("#tbList").datagrid({
            width: 'auto',
            height: 400,
            striped: true,
            singleSelect: true,
            url: '/admin/sys/PermissionSon?pid=@Request.QueryString["pid"]',//post用到这个参数
           //queryParams:{},
            loadMsg: '数据加载中请稍后……',
        pagination: true,//启用分页,默认每页10行
        rownumbers: true,//显示页码,默认 提供 10 - 50 的页容量选择下拉框
        pageSize: 10,//设置 页容量为 5
        pageList: [10, 15, 20, 25, 30],//设置 页容量下拉框
        fitColumns:true,
        columns: [[
             {
                 field: 'pIsShow', title: '显示', width: 20, formatter: function (value) {
                     return value ? "" : "X";
                 },
             },
             { field: 'pid', title: 'ID', width: 100, align: "center" },
            { field: 'pName', title: '权限名', width: 100, align: "center" },
            { field: 'pAreaName', title: '区域名', width: 100, align: "center" },
            { field: 'pControllerName', title: '控制名', width: 100, align: "center" },
            { field: 'pActionName', title: 'Action', width: 100, align: "center" },
            {
                field: 'pFormMethod', title: '请求方式', width: 100, align: "center", formatter: function (value) {

                    switch (value.toString()) {
                        case "1":
                            return "Get";
                        case "2":
                            return "Post";
                        case "3":
                            return "Both";
                    }
                }
            },
            {
                field: 'pOperationType', title: '操作类型', width: 100, align: "center", formatter: function (value) {

                    switch (value.toString()) {
                        case "0":
                            return "无操作";
                        case "1":
                            return "easyui连接";
                        case "2":
                            return "打开新窗体";
                            break;
                    }
                }
            }
        ]],
        toolbar: [{
            iconCls: 'icon-add',
            text: "新增",
            handler: AddRow
        },'-', {
            iconCls: 'icon-remove',
            text: "删除",
            handler: Delperm
        }, '-', {
            iconCls: 'icon-edit',
            text: "编辑",
            handler: editRow
        }, '-', {
            iconCls: 'icon-search',
            text: "返回",
            handler: function(){window.location="/admin/sys/Permission";},
        }
    ],
        //设置选中行
        onSelect: function (rowI, rD) {

            selectRowIndex = rowI;//1.1将中的行设置为全局变量 设置给全局变量
        }
    });
    initMoifyForm();
    })
    ////为表单 设置 参数
    function initMoifyForm() {
        $('#modifyForm').form({
            url: "/admin/sys/EditPermission",

        });
    }
    //1.将中的行设置为全局变量
    var selectRowIndex = -1;

    //编辑按钮方法
    function editRow() {
        //1.获取选中行里的数据!
        var rowData = $("#tbList").datagrid("getSelected");//getSelected返回一个选中的行
        if (rowData){
            $('#editWindow').window('open');//打开
            //load发送异步请求权限修改页面。并直接加载到 当前的 修改窗体中

            //路径、data、回调函数
            $.get("/admin/sys/EditPermission/" + rowData.pid, null, function (jsonObj) {  //1.url,2.data,3.回调函数
                if (jsonObj.Statu)//如果转了就是json对象,如果没转字符串就没有statu
                    $.procAjaxData(jsonObj);
                else
                    $('#editWindow').html(jsonObj);
            });
        }
    };
    //新增按钮方法
    function AddRow() {
        $('#editWindow').window('open');//打开
        $.get("/admin/sys/AddPermission/", null, function (jsonObj) {
            if (jsonObj.Statu)
                $.procAjaxData(jsonObj);
            else {
                $("#editWindow").html(jsonObj);
            }
        });//路径、data、回调函数
    }
    //删除方法
    function Delperm() {
        //1.获取选中行里的数据!
        var rowData = $("#tbList").datagrid("getSelected");
        if (rowData) {
            //{id:rowData.pid}
            //$.post("/admin/sys/delpemission", rowData.pid, function () { })
            $.post("/admin/sys/DelPermission", "id=" + rowData.pid, function (jsonObj) {
                $.procAjaxData(jsonObj, function () {//json统一处理方法:1.数据,2.删除成功后回调函数
                    $("#tbList").datagrid("reload");//删除成功后 刷新页面
                });
                //成功了
            }, "JSON");

        }
    }
    //function viewSon() {
    //    var rowData = $("#tbList").datagrid("getSelected");//获取选中行
    //    window.location = "/admin/sys/PermissionSon?pid=" + rowData.pid;
    //}
    </script>
</head>
<body>
    <table id="tbList" style="width:400px;height:250px">

      
    </table>
    <div id="editWindow" class="easyui-window" title="用户权限编辑" style="width:600px;height:400px;" resizable="true" data-options="iconCls:'icon-save',modal:true">

    </div>
</body>
</html>

子菜单控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MVCOA.Helper;
using Common.Attributes;

namespace MVCOA.Login.Admin
{
    /// <summary>
    /// 系统管理
    /// </summary>
    public class SysController : Controller
    {
 #region 1.2子权限列表 视图+PermissionSon()
        /// <summary>
        /// 子权限列表视图get
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AjaxRequest]
        public ActionResult PermissionSon()
        {
            //获取父权限id
            int pid = int.Parse(Request.QueryString["pid"]);
            return View();
        } 
        #endregion

        /// <summary>
        /// 查询子权限列表数据 post
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [AjaxRequest]
        public ActionResult PermissionSon(FormCollection form)
        {
            //获取页容量
            int pageSize = int.Parse(Request.Form["rows"]);
            //获取请求的页面
            int pageIndex = int.Parse(Request.Form["page"]);
            //获取父权限id
            int parentMenid=int.Parse(Request.QueryString["pid"]);
            //查询分页数据
            var list = OperateContext.Current.BLLSession.IOu_PermissionBLL.GetPagedList(pageIndex, pageSize,p=>p.pParent==parentMenid && p.pIsDel == false,p=>p.pid).Select(p => p.ToPOCO());
            int rowCount = OperateContext.Current.BLLSession.IOu_PermissionBLL.GetListBy(p => p.pParent==parentMenid && p.pIsDel==false).Count();
           //2生成规定格式的 json字符串发回  给异步对象
            MODEL.EasyUIModel.DataGridModel dgModel = new MODEL.EasyUIModel.DataGridModel()
            { 
            total=rowCount,
            rows=list,
            footer=null
            };
            return Json(dgModel);
        }
}
}

这样子菜单功能就完成了。

posted @ 2017-04-19 02:25  狼牙者.net  阅读(148)  评论(0编辑  收藏  举报