dataScope.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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">角色名称:</label>
  13. <div class="col-sm-8">
  14. <input class="form-control" type="text" name="roleName" id="roleName" th:field="*{roleName}" readonly="true"/>
  15. </div>
  16. </div>
  17. <div class="form-group">
  18. <label class="col-sm-3 control-label">权限字符:</label>
  19. <div class="col-sm-8">
  20. <input class="form-control" type="text" name="roleKey" id="roleKey" th:field="*{roleKey}" readonly="true">
  21. </div>
  22. </div>
  23. <div class="form-group">
  24. <label class="col-sm-3 control-label">数据范围:</label>
  25. <div class="col-sm-8">
  26. <select id="dataScope" name="dataScope" class="form-control m-b">
  27. <option value="1" th:field="*{dataScope}">全部数据权限</option>
  28. <option value="2" th:field="*{dataScope}">自定数据权限</option>
  29. <option value="3" th:field="*{dataScope}">本部门数据权限</option>
  30. <option value="4" th:field="*{dataScope}">本部门及以下数据权限</option>
  31. <option value="5" th:field="*{dataScope}">仅本人数据权限</option>
  32. </select>
  33. <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 特殊情况下,设置为“自定数据权限”</span>
  34. </div>
  35. </div>
  36. <div class="form-group" id="authDataScope" th:style="'display:' + @{(*{dataScope=='2'} ? 'block' : 'none')} + ''">
  37. <label class="col-sm-3 control-label">数据权限:</label>
  38. <div class="col-sm-8">
  39. <label class="check-box">
  40. <input type="checkbox" value="1" checked>展开/折叠</label>
  41. <label class="check-box">
  42. <input type="checkbox" value="2">全选/全不选</label>
  43. <label class="check-box">
  44. <input type="checkbox" value="3" checked>父子联动</label>
  45. <div id="deptTrees" class="ztree ztree-border"></div>
  46. </div>
  47. </div>
  48. </form>
  49. </div>
  50. <th:block th:include="include :: footer" />
  51. <th:block th:include="include :: ztree-js" />
  52. <script type="text/javascript">
  53. $(function() {
  54. var url = ctx + "system/dept/roleDeptTreeData?roleId=" + $("#roleId").val();
  55. var options = {
  56. id: "deptTrees",
  57. url: url,
  58. check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
  59. expandLevel: 2
  60. };
  61. $.tree.init(options);
  62. });
  63. $('input').on('ifChanged', function(obj){
  64. var type = $(this).val();
  65. var checked = obj.currentTarget.checked;
  66. if (type == 1) {
  67. if (checked) {
  68. $._tree.expandAll(true);
  69. } else {
  70. $._tree.expandAll(false);
  71. }
  72. } else if (type == "2") {
  73. if (checked) {
  74. $._tree.checkAllNodes(true);
  75. } else {
  76. $._tree.checkAllNodes(false);
  77. }
  78. } else if (type == "3") {
  79. if (checked) {
  80. $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
  81. } else {
  82. $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
  83. }
  84. }
  85. })
  86. function submitHandler() {
  87. if ($.validate.form()) {
  88. edit();
  89. }
  90. }
  91. function edit() {
  92. var roleId = $("input[name='roleId']").val();
  93. var roleName = $("input[name='roleName']").val();
  94. var roleKey = $("input[name='roleKey']").val();
  95. var dataScope = $("#dataScope").val();
  96. var deptIds = $.tree.getCheckedNodes();
  97. $.ajax({
  98. cache : true,
  99. type : "POST",
  100. url : ctx + "system/role/authDataScope",
  101. data : {
  102. "roleId": roleId,
  103. "roleName": roleName,
  104. "roleKey": roleKey,
  105. "dataScope": dataScope,
  106. "deptIds": deptIds
  107. },
  108. async : false,
  109. error : function(request) {
  110. $.modal.alertError("系统错误");
  111. },
  112. success : function(data) {
  113. $.operate.successCallback(data);
  114. }
  115. });
  116. }
  117. $("#dataScope").change(function(event){
  118. var dataScope = $(event.target).val();
  119. dataScopeVisible(dataScope);
  120. });
  121. function dataScopeVisible(dataScope) {
  122. if (dataScope == 2) {
  123. $("#authDataScope").show();
  124. } else {
  125. $._tree.checkAllNodes(false);
  126. $("#authDataScope").hide();
  127. }
  128. }
  129. </script>
  130. </body>
  131. </html>