add.html 5.1 KB

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