edit.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
  3. <head>
  4. <th:block th:include="include :: header('修改角色')" />
  5. <th:block th:include="include :: ztree-css" />
  6. </head>
  7. <body class="white-bg">
  8. <div class="wrapper wrapper-content animated fadeInRight ibox-content">
  9. <form class="form-horizontal m" id="form-role-edit" th:object="${role}">
  10. <input id="roleId" name="roleId" type="hidden" th:field="*{roleId}"/>
  11. <div class="form-group">
  12. <label class="col-sm-3 control-label is-required">角色名称:</label>
  13. <div class="col-sm-8">
  14. <input class="form-control" type="text" name="roleName" id="roleName" th:field="*{roleName}" required>
  15. </div>
  16. </div>
  17. <div class="form-group">
  18. <label class="col-sm-3 control-label is-required">权限字符:</label>
  19. <div class="col-sm-8">
  20. <input class="form-control" type="text" name="roleKey" id="roleKey" th:field="*{roleKey}" required>
  21. <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限字符,如:@RequiresRoles("")</span>
  22. </div>
  23. </div>
  24. <div class="form-group">
  25. <label class="col-sm-3 control-label is-required">显示顺序:</label>
  26. <div class="col-sm-8">
  27. <input class="form-control" type="text" name="roleSort" id="roleSort" th:field="*{roleSort}" required>
  28. </div>
  29. </div>
  30. <div class="form-group">
  31. <label class="col-sm-3 control-label">状态:</label>
  32. <div class="col-sm-8">
  33. <label class="toggle-switch switch-solid">
  34. <input type="checkbox" id="status" th:checked="${role.status == '0' ? true : false}">
  35. <span></span>
  36. </label>
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-sm-3 control-label">备注:</label>
  41. <div class="col-sm-8">
  42. <input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-sm-3 control-label">菜单权限:</label>
  47. <div class="col-sm-8">
  48. <label class="check-box">
  49. <input type="checkbox" value="1">展开/折叠</label>
  50. <label class="check-box">
  51. <input type="checkbox" value="2">全选/全不选</label>
  52. <label class="check-box">
  53. <input type="checkbox" value="3" checked>父子联动</label>
  54. <div id="menuTrees" class="ztree ztree-border"></div>
  55. </div>
  56. </div>
  57. </form>
  58. </div>
  59. <th:block th:include="include :: footer" />
  60. <th:block th:include="include :: ztree-js" />
  61. <script type="text/javascript">
  62. $(function() {
  63. var url = ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
  64. var options = {
  65. id: "menuTrees",
  66. url: url,
  67. check: { enable: true },
  68. expandLevel: 0
  69. };
  70. $.tree.init(options);
  71. });
  72. $("#form-role-edit").validate({
  73. onkeyup: false,
  74. rules:{
  75. roleName:{
  76. remote: {
  77. url: ctx + "system/role/checkRoleNameUnique",
  78. type: "post",
  79. dataType: "json",
  80. data: {
  81. "roleId": function() {
  82. return $("#roleId").val();
  83. },
  84. "roleName": function() {
  85. return $.common.trim($("#roleName").val());
  86. }
  87. }
  88. }
  89. },
  90. roleKey:{
  91. remote: {
  92. url: ctx + "system/role/checkRoleKeyUnique",
  93. type: "post",
  94. dataType: "json",
  95. data: {
  96. "roleId": function() {
  97. return $("#roleId").val();
  98. },
  99. "roleKey": function() {
  100. return $.common.trim($("#roleKey").val());
  101. }
  102. }
  103. }
  104. },
  105. roleSort:{
  106. digits:true
  107. },
  108. },
  109. messages: {
  110. "roleName": {
  111. remote: "角色名称已经存在"
  112. },
  113. "roleKey": {
  114. remote: "角色权限已经存在"
  115. }
  116. },
  117. focusCleanup: true
  118. });
  119. $('input').on('ifChanged', function(obj){
  120. var type = $(this).val();
  121. var checked = obj.currentTarget.checked;
  122. if (type == 1) {
  123. if (checked) {
  124. $._tree.expandAll(true);
  125. } else {
  126. $._tree.expandAll(false);
  127. }
  128. } else if (type == "2") {
  129. if (checked) {
  130. $._tree.checkAllNodes(true);
  131. } else {
  132. $._tree.checkAllNodes(false);
  133. }
  134. } else if (type == "3") {
  135. if (checked) {
  136. $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
  137. } else {
  138. $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
  139. }
  140. }
  141. })
  142. function edit() {
  143. var roleId = $("input[name='roleId']").val();
  144. var roleName = $("input[name='roleName']").val();
  145. var roleKey = $("input[name='roleKey']").val();
  146. var roleSort = $("input[name='roleSort']").val();
  147. var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
  148. var remark = $("input[name='remark']").val();
  149. var menuIds = $.tree.getCheckedNodes();
  150. $.ajax({
  151. cache : true,
  152. type : "POST",
  153. url : ctx + "system/role/edit",
  154. data : {
  155. "roleId": roleId,
  156. "roleName": roleName,
  157. "roleKey": roleKey,
  158. "roleSort": roleSort,
  159. "status": status,
  160. "remark": remark,
  161. "menuIds": menuIds
  162. },
  163. async : false,
  164. error : function(request) {
  165. $.modal.alertError("系统错误");
  166. },
  167. success : function(data) {
  168. $.operate.successCallback(data);
  169. }
  170. });
  171. }
  172. function submitHandler() {
  173. if ($.validate.form()) {
  174. edit();
  175. }
  176. }
  177. </script>
  178. </body>
  179. </html>