username@email.com
2022-08-27 6e2b929cf381e2320ba6e7dec56c0371124d2b51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@using DTO;
@{
    ViewBag.Title = "Search";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
    var listRole = ViewBag.listRole == null ? new List<PltRoleDTO>() : (List<PltRoleDTO>)ViewBag.listRole;//获取所有角色
}
<link href="~/css/font-awesome.min.css" rel="stylesheet">
<link href="~/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="~/css/animate.min.css" rel="stylesheet">
<link href="~/css/style.min.css" rel="stylesheet">
 
<link rel="stylesheet" href="~/css/ztree/demo.css" type="text/css">
<link rel="stylesheet" href="~/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="~/js/ztree/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="~/js/ztree/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript" src="~/js/ztree/jquery.ztree.excheck-3.4.js"></script>
 
<style>
    #add {
        margin-left: 30%;
    }
 
    .ibox-title {
        margin-top: 0;
    }
 
    span.icon {
        margin-right: 5px;
    }
 
    .list-group-item {
        padding: 7px 15px;
    }
</style>
<div style="width:20%;height:100%;float:left;">
    <div id="tree">
        <ul class="list-group rolesearch" style="margin-bottom:0px;">
            <li class="list-group-item" style="font-weight: bold;text-align: center;">角色列表</li>
            <li class="list-group-item">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="input-group" style="width:100%">
                            <input type="text" class="form-control" placeholder="检索角色名称" id="rolesearch">
                            <!-- /btn-group -->
                        </div>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="list-group" id="listrole" style="overflow-y:scroll;">
            @foreach (var item in listRole)
            {
                <li class="list-group-item node-tree" data-roleid="@item.Id" data-name="@item.RoleName" style="cursor:pointer;" data-nodeid="0">
                    <span class="icon"><i class="glyphicon glyphicon-globe"></i></span>@item.RoleName
                </li>
            }
 
        </ul>
    </div>
</div>
<div style="width:80%;height:100%;float:right;background-color:black;">
    <div class="ibox-title">
        <div class="row">
            <div class="col-sm-12 col-md-12" style="text-align:center;">
                <h3>权限列表</h3>
            </div>
        </div>
    </div>
    <div id="authlist" class="ibox-content" style="overflow-y:scroll;">
        <div class="row">
            <div class="col-sm-12 col-md-12">
                <div class="left">
                    <ul id="treeDemo" class="ztree" style="width:100%; margin-top:0px; background:#fff; border:#ddd solid 1px; padding-left:30px;"></ul>
                </div>
 
            </div>
 
        </div>
    </div>
</div>
<div class="ibox-content" id="top" style="z-index:100; position:fixed;height:50px; width:100%;bottom:0; text-align:right; padding-top:8px ">
    <div class="" style="float:right;" data-bootstro-width="500px" data-bootstro-content="功能按钮:“停用”,“保存”,“新增”等操作">
 
        <a style="text-decoration:none;" class="btn btn-success " onclick="SaveAuth()">
            <i class="glyphicon glyphicon-ok"></i>&nbsp;&nbsp;<span class="bold">保存设置</span>
        </a>
    </div>
</div>
<script>
    $(function () {
        $('#authlist').css('height', document.body.clientHeight - 85);
        $('#treeDemo').css('height', document.body.clientHeight - 135);
        $('#listrole').css('height', document.body.clientHeight - $('.rolesearch').height() - 50);
        $('.node-tree').bind('click', function () {
            var nRoleID = $(this).attr('data-roleid');
            $('.node-tree').removeClass('text-navy');
            $(this).addClass('text-navy');
            GetTree(nRoleID);
        });
 
        $('#rolesearch').bind('keyup',function () {
            var sRoleName = $.trim($(this).val());
            if (sRoleName == '')
            {
                $('.node-tree').show();
            }
            else
            {
                $('.node-tree').each(function () {
                    var sName = $(this).attr('data-name');
                    if (sName.indexOf(sRoleName) != -1) {
                        $(this).show();
                    }
                    else {
                        $(this).hide();
                    }
                });
            }
        });
    });
 
    var SaveAuth = function () {
        var nRoleID = $('#tree .text-navy').attr('data-roleid');
        var aryPageId = [];
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        $.each(treeObj.getCheckedNodes(true), function (i, r) {
            aryPageId.push(r.id);
        });
        var error = "";
        if (aryPageId.length == 0) {
            toastr.warning("请选择权限");
            return;
        }
        if (nRoleID == undefined || parseInt(nRoleID) == 0) {
            toastr.warning("请选择权限角色");
            return;
        }
 
        var mAuth = {
            roleid: nRoleID,
            pageid: aryPageId.join(',')
        };
        $.ajax({
            url: "/PltAuth/Save",
            data: mAuth,
            type: 'Post',
            dataType:'json',
            success: function (data) {
                if (data.Result) {
                    toastr.success("保存成功");
                    parent.layer.closeAll('loading');
                }
                else {
                    toastr.warning(data.Message);
                }
            },
            error: function () {
 
            },
            complete: function () {
 
            }
        });
 
    }
</script>
<SCRIPT type="text/javascript">
 
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var GetTree = function (nroleid) {
        $.ajax({
            url: "/PltAuth/GetPageByRole",
            data: { roleid: nroleid },
            type: 'Post',
            dataType: 'json',
            success: function (data) {
              
                var sJson = data.sJson.replace(/True/g, true);
                sJson = sJson.replace(/False/g, false);
                var Json = eval("(" + sJson + ")");
                $.fn.zTree.init($("#treeDemo"), setting, Json);
                parent.layer.closeAll('loading');
            },
            error: function () {
 
            },
            complete: function () {
 
            }
        });
    }
</SCRIPT>