edit.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. dataFilter: function(data, type) {
  89. return $.validate.unique(data);
  90. }
  91. }
  92. },
  93. roleKey:{
  94. remote: {
  95. url: ctx + "system/role/checkRoleKeyUnique",
  96. type: "post",
  97. dataType: "json",
  98. data: {
  99. "roleId": function() {
  100. return $("#roleId").val();
  101. },
  102. "roleKey": function() {
  103. return $.common.trim($("#roleKey").val());
  104. }
  105. },
  106. dataFilter: function(data, type) {
  107. return $.validate.unique(data);
  108. }
  109. }
  110. },
  111. roleSort:{
  112. digits:true
  113. },
  114. },
  115. messages: {
  116. "roleName": {
  117. remote: "角色名称已经存在"
  118. },
  119. "roleKey": {
  120. remote: "角色权限已经存在"
  121. }
  122. },
  123. focusCleanup: true
  124. });
  125. $('input').on('ifChanged', function(obj){
  126. var type = $(this).val();
  127. var checked = obj.currentTarget.checked;
  128. if (type == 1) {
  129. if (checked) {
  130. $._tree.expandAll(true);
  131. } else {
  132. $._tree.expandAll(false);
  133. }
  134. } else if (type == "2") {
  135. if (checked) {
  136. $._tree.checkAllNodes(true);
  137. } else {
  138. $._tree.checkAllNodes(false);
  139. }
  140. } else if (type == "3") {
  141. if (checked) {
  142. $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
  143. } else {
  144. $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
  145. }
  146. }
  147. })
  148. function edit() {
  149. var roleId = $("input[name='roleId']").val();
  150. var roleName = $("input[name='roleName']").val();
  151. var roleKey = $("input[name='roleKey']").val();
  152. var roleSort = $("input[name='roleSort']").val();
  153. var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
  154. var remark = $("input[name='remark']").val();
  155. var menuIds = $.tree.getCheckedNodes();
  156. $.ajax({
  157. cache : true,
  158. type : "POST",
  159. url : ctx + "system/role/edit",
  160. data : {
  161. "roleId": roleId,
  162. "roleName": roleName,
  163. "roleKey": roleKey,
  164. "roleSort": roleSort,
  165. "status": status,
  166. "remark": remark,
  167. "menuIds": menuIds
  168. },
  169. async : false,
  170. error : function(request) {
  171. $.modal.alertError("系统错误");
  172. },
  173. success : function(data) {
  174. $.operate.successCallback(data);
  175. }
  176. });
  177. }
  178. function submitHandler() {
  179. if ($.validate.form()) {
  180. edit();
  181. }
  182. }
  183. </script>
  184. </body>
  185. </html>