author.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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="${user}">
  10. <input id="userId" name="userId" type="hidden" th:field="*{userId}"/>
  11. <div class="form-group">
  12. <label class="col-sm-3 control-label">菜单权限</label>
  13. <div class="col-sm-8">
  14. <div id="menuTrees" class="ztree"></div>
  15. </div>
  16. </div>
  17. </form>
  18. </div>
  19. <th:block th:include="include :: footer" />
  20. <th:block th:include="include :: ztree-js" />
  21. <script type="text/javascript">
  22. $(function() {
  23. var url = ctx + "system/author/tree/" + $("#userId").val();
  24. var options = {
  25. id: "menuTrees",
  26. url: url,
  27. check: { enable: true},
  28. expandLevel: 0,
  29. onCheck:function (event,treeId,treeNode) {
  30. // console.log(treeNode);
  31. // console.log(treeNode.getParentNode());
  32. }
  33. };
  34. $.tree.init(options);
  35. });
  36. $("#form-role-edit").validate({
  37. onkeyup: false,
  38. rules:{
  39. roleName:{
  40. remote: {
  41. url: ctx + "system/role/checkRoleNameUnique",
  42. type: "post",
  43. dataType: "json",
  44. data: {
  45. "roleId": function() {
  46. return $("#roleId").val();
  47. },
  48. "roleName": function() {
  49. return $.common.trim($("#roleName").val());
  50. }
  51. },
  52. dataFilter: function(data, type) {
  53. return $.validate.unique(data);
  54. }
  55. }
  56. },
  57. roleKey:{
  58. remote: {
  59. url: ctx + "system/role/checkRoleKeyUnique",
  60. type: "post",
  61. dataType: "json",
  62. data: {
  63. "roleId": function() {
  64. return $("#roleId").val();
  65. },
  66. "roleKey": function() {
  67. return $.common.trim($("#roleKey").val());
  68. }
  69. },
  70. dataFilter: function(data, type) {
  71. return $.validate.unique(data);
  72. }
  73. }
  74. },
  75. roleSort:{
  76. digits:true
  77. },
  78. },
  79. messages: {
  80. "roleName": {
  81. remote: "角色名称已经存在"
  82. },
  83. "roleKey": {
  84. remote: "角色权限已经存在"
  85. }
  86. },
  87. focusCleanup: true
  88. });
  89. function edit() {
  90. var userId = $("input[name='userId']").val();
  91. // console.log($.tree)
  92. // console.log($.tree.getNodes()[0].getCheckStatus())
  93. var authorIds = $.tree.getCheckedNodesRole();
  94. $.ajax({
  95. cache : true,
  96. type : "POST",
  97. url : ctx + "system/author/tree/edit",
  98. data : {
  99. "userId": userId,
  100. "authorIds": authorIds
  101. },
  102. async : false,
  103. error : function(request) {
  104. $.modal.alertError("系统错误");
  105. },
  106. success : function(data) {
  107. $.operate.successCallback(data);
  108. }
  109. });
  110. }
  111. function submitHandler() {
  112. if ($.validate.form()) {
  113. edit();
  114. }
  115. }
  116. </script>
  117. </body>
  118. </html>