permission.blade.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <div class="form-group">
  2. <label class="col-xs-12 col-sm-3 col-md-2 control-label">操作权限</label>
  3. <div class="col-sm-9 col-xs-12">
  4. <div class='panel panel-default'>
  5. <!-- 第一级-->
  6. @foreach($permissions as $keyOne=>$valueOne)
  7. @if(isset($valueOne['permit']) && $valueOne['permit'] === 1)
  8. <div class='panel-heading'>
  9. <label class='checkbox-inline'>
  10. <input type='checkbox'
  11. name='perms[]'
  12. value='{{$keyOne}}'
  13. class='perm-all'
  14. {{in_array($keyOne, $rolePermission) ? 'disabled' : ''}}
  15. data-group='{{$keyOne}}' {{in_array($keyOne, $userPermissions) ? 'checked' : ''}} />
  16. {{$valueOne['name'] ?? ''}}
  17. </label>
  18. </div>
  19. <!-- 第二级-->
  20. @if(isset($valueOne['child']))
  21. <div class='panel-body perm-group'>
  22. @foreach($valueOne['child'] as $keyTwo=>$valueTwo)
  23. @if(isset($valueTwo['permit']) && $valueTwo['permit'] === 1 && !in_array($keyTwo, \app\common\services\PermissionService::founderPermission()))
  24. <span>
  25. <label class='checkbox-inline' >
  26. <input type='checkbox'
  27. name='perms[]'
  28. value='{{$keyTwo}}'
  29. class='perm-all-item'
  30. data-group='{{$keyOne}}'
  31. data-child='{{$keyTwo}}'
  32. {{in_array($keyTwo, $rolePermission) ? 'disabled' : ''}}
  33. {{in_array($keyTwo, $userPermissions) ? 'checked' : ''}}/>
  34. <b>{{$valueTwo['name'] ?? ''}}</b>
  35. </label>
  36. <!-- 第三级-->
  37. @if(isset($valueTwo['child']))
  38. @foreach($valueTwo['child'] as $keyThird=>$valueThird)
  39. @if(isset($valueThird['permit']) && $valueThird['permit'] === 1)
  40. <label class="checkbox-inline" style="width: 117px;">
  41. <input type="checkbox"
  42. name="perms[]"
  43. value="{{$keyThird}}"
  44. class="perm-item"
  45. data-group="{{$keyOne}}"
  46. data-child="{{$keyTwo}}"
  47. data-op="{{$keyThird}}"
  48. {{in_array($keyThird, $rolePermission) ? 'disabled' : ''}}
  49. {{in_array($keyThird, $userPermissions) ? 'checked' : ''}}/>
  50. {{$valueThird['name'] ?? ''}}
  51. </label>
  52. @endif
  53. @endforeach
  54. @endif
  55. <!-- 第三级 end -->
  56. <br/>
  57. </span>
  58. @endif
  59. @endforeach
  60. </div>
  61. @endif
  62. <!-- 第二级end -->
  63. @endif
  64. @endforeach
  65. <!-- 第一级end -->
  66. </div>
  67. </div>
  68. </div>
  69. <script language="javascript">
  70. require(['bootstrap'], function ($) {
  71. $(function () {
  72. $('.perm-all').click(function () {
  73. var checked = $(this).get(0).checked;
  74. var group = $(this).data('group');
  75. $(".perm-item[data-group='" + group + "'],.perm-all-item[data-group='" + group + "']").each(function () {
  76. $(this).get(0).checked = checked;
  77. })
  78. });
  79. $('.perm-all-item').click(function () {
  80. var checked = $(this).get(0).checked;
  81. var group = $(this).data('group');
  82. var child = $(this).data('child');
  83. var allItem = $(".perm-item[data-group='" + group + "'][data-child='" + child + "']");
  84. allItem.each(function () {
  85. $(this).get(0).checked = checked;
  86. });
  87. var select_element = $(this).parents('.perm-group').find('.perm-all-item');
  88. select_element.each(function () {
  89. if ($(this).prop('checked')) {
  90. checked = true;
  91. }
  92. });
  93. var allChild = $(".perm-all[data-group=" + group + "]");
  94. allChild.get(0).checked = checked;
  95. });
  96. $('.perm-item').click(function () {
  97. var group = $(this).data('group');
  98. var child = $(this).data('child');
  99. var check = false;
  100. $(this).closest('span').find(".perm-item").each(function () {
  101. if ($(this).get(0).checked) {
  102. check = true;
  103. return false;
  104. }
  105. });
  106. var allitem = $(".perm-all-item[data-group=" + group + "][data-child=" + child + "]");
  107. if (allitem.length == 1) {
  108. allitem.get(0).checked = check;
  109. }
  110. var select_element = $(this).parents('.perm-group').find('.perm-all-item');
  111. select_element.each(function () {
  112. if ($(this).prop('checked')) {
  113. check = true;
  114. }
  115. });
  116. $(".perm-all[data-group=" + group + "]").get(0).checked = check;
  117. });
  118. });
  119. });
  120. </script>