双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改角色')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-role-edit" th:object="${role}">
            <input id="roleId" name="roleId" type="hidden" th:field="*{roleId}"/>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属公司:</label>
                <div class="col-sm-8">
                    <input id="companyName" name="companyName" placeholder="选择所属公司" th:field="*{company.companyName}" class="form-control" type="text" onclick="selectCompanyList()" maxlength="30" readonly="true" required>
                    <input id="companyId" name="companyId" th:field="*{companyId}" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">角色名称:</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="roleName" id="roleName" th:field="*{roleName}" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">权限字符:</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="roleKey" id="roleKey" th:field="*{roleKey}" required>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限字符,如:@RequiresRoles("")</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">显示顺序:</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="roleSort" id="roleSort" th:field="*{roleSort}" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态:</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" th:checked="${role.status == '0' ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注:</label>
                <div class="col-sm-8">
                    <input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">菜单权限</label>
                <div class="col-sm-8">
                    <div id="menuTrees" class="ztree"></div>
                </div>
            </div>
 
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">区域权限</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div id="regionTrees" name="regionTrees" class="ztree"></div>-->
<!--                </div>-->
<!--            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ztree-js" />
    <script type="text/javascript">
         $(function() {
             var menuUrl = ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
            var options = {
                id: "menuTrees",
                url: menuUrl,
                check: { enable: true },
                expandLevel: 0
            };
            $.tree.init(options);
 
 
             var regionUrl = ctx + "tr/region/roleRegionTreeData?roleId=" + $("#roleId").val();
             var regionOptions = {
                 id: "regionTrees",
                 url: regionUrl,
                 check: { enable: true },
                 expandLevel: 0
             };
             $.tree.init(regionOptions);
        });
    
        $("#form-role-edit").validate({
            onkeyup: false,
            rules:{
                roleName:{
                    remote: {
                        url: ctx + "system/role/checkRoleNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "roleId": function() {
                                return $("#roleId").val();
                            },
                            "roleName": function() {
                                return $.common.trim($("#roleName").val());
                            },
                            "companyId": function() {
                                return $.common.trim($("#companyId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                roleKey:{
                    remote: {
                        url: ctx + "system/role/checkRoleKeyUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "roleId": function() {
                                return $("#roleId").val();
                            },
                            "roleKey": function() {
                                return $.common.trim($("#roleKey").val());
                            },
                            "companyId": function() {
                                return $.common.trim($("#companyId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                roleSort:{
                    digits:true
                },
            },
            messages: {
                "roleName": {
                    remote: "角色名称已经存在"
                },
                "roleKey": {
                    remote: "角色权限已经存在"
                }
            },
            focusCleanup: true
        });
 
         //选择所属公司
         function selectCompanyList() {
             var url = "/system/company/selectCompanyList";
             $.modal.openNoConfirm("所属公司", url, '700', '500');
         }
 
         /**
          * 获取所有的id
          * @param nodes
          * @returns {*}
          */
         function getNodes(nodes) {
             return $.map(nodes, function (row) {
                 return row["id"];
             }).join();
         }
 
        function edit() {
            var roleId = $("input[name='roleId']").val();
            var companyId = $("input[name='companyId']").val();
            var roleName = $("input[name='roleName']").val();
            var roleKey = $("input[name='roleKey']").val();
            var roleSort = $("input[name='roleSort']").val();
            var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
            var remark = $("input[name='remark']").val();
 
            var menuTrees = $.fn.zTree.getZTreeObj("menuTrees");
            var menuIds = getNodes(menuTrees.getCheckedNodes());
 
            // var regionTrees = $.fn.zTree.getZTreeObj("regionTrees");
            // var regionIds = getNodes(regionTrees.getCheckedNodes());
 
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "system/role/edit",
                data : {
                    "roleId": roleId,
                    "companyId": companyId,
                    "roleName": roleName,
                    "roleKey": roleKey,
                    "roleSort": roleSort,
                    "status": status,
                    "remark": remark,
                    "menuIds": menuIds,
                    // "regionIds": regionIds
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }
        
        function submitHandler() {
            if ($.validate.form()) {
                edit();
            }
        }
    </script>
</body>
</html>