edit.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 ">角色名称:</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">权限字符:</label>
  19. <div class="col-sm-8">
  20. <input class="form-control" type="text" name="roleKey" id="roleKey" th:field="*{roleKey}" required>
  21. </div>
  22. </div>
  23. <div class="form-group">
  24. <label class="col-sm-3 control-label">显示顺序:</label>
  25. <div class="col-sm-8">
  26. <input class="form-control" type="text" name="roleSort" id="roleSort" th:field="*{roleSort}" required>
  27. </div>
  28. </div>
  29. <div class="form-group">
  30. <label class="col-sm-3 control-label">状态:</label>
  31. <div class="col-sm-8">
  32. <label class="toggle-switch switch-solid">
  33. <input type="checkbox" id="status" th:checked="${role.status == '0' ? true : false}">
  34. <span></span>
  35. </label>
  36. </div>
  37. </div>
  38. <div class="form-group">
  39. <label class="col-sm-3 control-label">备注:</label>
  40. <div class="col-sm-8">
  41. <input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
  42. </div>
  43. </div>
  44. <div class="form-group">
  45. <label class="col-sm-3 control-label">菜单权限</label>
  46. <div class="col-sm-8">
  47. <div id="menuTrees" class="ztree"></div>
  48. </div>
  49. </div>
  50. </form>
  51. </div>
  52. <th:block th:include="include :: footer" />
  53. <th:block th:include="include :: ztree-js" />
  54. <script type="text/javascript">
  55. $(function() {
  56. var url = ctx + "system/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
  57. var options = {
  58. id: "menuTrees",
  59. url: url,
  60. check: { enable: true },
  61. expandLevel: 0
  62. };
  63. $.tree.init(options);
  64. });
  65. $("#form-role-edit").validate({
  66. onkeyup: false,
  67. rules:{
  68. roleName:{
  69. remote: {
  70. url: ctx + "system/role/checkRoleNameUnique",
  71. type: "post",
  72. dataType: "json",
  73. data: {
  74. "roleId": function() {
  75. return $("#roleId").val();
  76. },
  77. "roleName": function() {
  78. return $.common.trim($("#roleName").val());
  79. }
  80. },
  81. dataFilter: function(data, type) {
  82. return $.validate.unique(data);
  83. }
  84. }
  85. },
  86. roleKey:{
  87. remote: {
  88. url: ctx + "system/role/checkRoleKeyUnique",
  89. type: "post",
  90. dataType: "json",
  91. data: {
  92. "roleId": function() {
  93. return $("#roleId").val();
  94. },
  95. "roleKey": function() {
  96. return $.common.trim($("#roleKey").val());
  97. }
  98. },
  99. dataFilter: function(data, type) {
  100. return $.validate.unique(data);
  101. }
  102. }
  103. },
  104. roleSort:{
  105. digits:true
  106. },
  107. },
  108. messages: {
  109. "roleName": {
  110. remote: "角色名称已经存在"
  111. },
  112. "roleKey": {
  113. remote: "角色权限已经存在"
  114. }
  115. },
  116. focusCleanup: true
  117. });
  118. function edit() {
  119. var roleId = $("input[name='roleId']").val();
  120. var roleName = $("input[name='roleName']").val();
  121. var roleKey = $("input[name='roleKey']").val();
  122. var roleSort = $("input[name='roleSort']").val();
  123. var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
  124. var remark = $("input[name='remark']").val();
  125. var menuIds = $.tree.getCheckedNodes();
  126. $.ajax({
  127. cache : true,
  128. type : "POST",
  129. url : ctx + "system/role/edit",
  130. data : {
  131. "roleId": roleId,
  132. "roleName": roleName,
  133. "roleKey": roleKey,
  134. "roleSort": roleSort,
  135. "status": status,
  136. "remark": remark,
  137. "menuIds": menuIds
  138. },
  139. async : false,
  140. error : function(request) {
  141. $.modal.alertError("系统错误");
  142. },
  143. success : function(data) {
  144. $.operate.successCallback(data);
  145. }
  146. });
  147. }
  148. function submitHandler() {
  149. if ($.validate.form()) {
  150. edit();
  151. }
  152. }
  153. </script>
  154. </body>
  155. </html>