add.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. dataFilter: function(data, type) {
  85. return $.validate.unique(data);
  86. }
  87. }
  88. },
  89. roleKey:{
  90. remote: {
  91. url: ctx + "system/role/checkRoleKeyUnique",
  92. type: "post",
  93. dataType: "json",
  94. data: {
  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. $('input').on('ifChanged', function(obj){
  119. var type = $(this).val();
  120. var checked = obj.currentTarget.checked;
  121. if (type == 1) {
  122. if (checked) {
  123. $._tree.expandAll(true);
  124. } else {
  125. $._tree.expandAll(false);
  126. }
  127. } else if (type == "2") {
  128. if (checked) {
  129. $._tree.checkAllNodes(true);
  130. } else {
  131. $._tree.checkAllNodes(false);
  132. }
  133. } else if (type == "3") {
  134. if (checked) {
  135. $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
  136. } else {
  137. $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
  138. }
  139. }
  140. })
  141. function submitHandler() {
  142. if ($.validate.form()) {
  143. add();
  144. }
  145. }
  146. function add() {
  147. var roleName = $("input[name='roleName']").val();
  148. var roleKey = $("input[name='roleKey']").val();
  149. var roleSort = $("input[name='roleSort']").val();
  150. var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
  151. var remark = $("input[name='remark']").val();
  152. var menuIds = $.tree.getCheckedNodes();
  153. $.ajax({
  154. cache : true,
  155. type : "POST",
  156. url : ctx + "system/role/add",
  157. data : {
  158. "roleName": roleName,
  159. "roleKey": roleKey,
  160. "roleSort": roleSort,
  161. "status": status,
  162. "remark": remark,
  163. "menuIds": menuIds
  164. },
  165. async : false,
  166. error : function(request) {
  167. $.modal.alertError("系统错误");
  168. },
  169. success : function(data) {
  170. $.operate.successCallback(data);
  171. }
  172. });
  173. }
  174. </script>
  175. </body>
  176. </html>