add.html 4.4 KB

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