index.blade.bak.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. @extends('layouts.app')
  2. @section('title')查询-角色@endsection
  3. @section('content')
  4. <span id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. @component('maintenance.role.menu')@endcomponent
  7. </span>
  8. <div class="container-fluid">
  9. <div class="card">
  10. <div id="form_div"></div>
  11. <div class="card-body" id="list">
  12. @if(Session::has('successTip'))
  13. <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
  14. @endif
  15. <table class="table table-striped table-sm td-min-width-80" id="table">
  16. <tr v-for="(role,i) in roles" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
  17. <td class="text-muted">@{{role.id}}</td>
  18. <td>@{{role.name}}</td>
  19. <td>
  20. <div style="max-height: 130px;overflow-y: scroll;border: solid 1px #ddd;" v-if="role.authorities.length>0">
  21. <ul class="list-group">
  22. <li v-for="authority in role.authorities" v-if="authority.permission=='允许'" style="list-style: none">@{{ authority.alias_name }}</li>
  23. </ul>
  24. </div>
  25. </td>
  26. <td>
  27. <div style="max-height: 130px;overflow-y: scroll;border: solid 1px #ddd;" v-if="role.authorities.length>0">
  28. <ul class="list-group">
  29. <li v-for="authority in role.authorities" v-if="authority.permission=='禁止'" style="list-style: none">@{{ authority.alias_name }}</li>
  30. </ul>
  31. </div>
  32. </td>
  33. <td class="text-muted">@{{role.created_at}}</td>
  34. <td>
  35. @can('角色-编辑')
  36. <button class="btn btn-sm btn-outline-primary" @click="edit(role.id)">改</button> @endcan
  37. @can('角色-删除')
  38. <button class="btn btn-sm btn-outline-dark" @click="destroy(role)">删</button> @endcan
  39. </td>
  40. </tr>
  41. </table>
  42. {{$roles->links()}}
  43. </div>
  44. </div>
  45. </div>
  46. @endsection
  47. @section('lastScript')
  48. <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
  49. <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版--}}
  50. <script>
  51. new Vue({
  52. el:"#list",
  53. data:{
  54. roles:[
  55. @foreach( $roles as $role )
  56. {id:'{{$role->id}}',name:'{{$role->name}}',
  57. authorities:{!! $role->authorities !!},created_at:'{{$role->created_at}}',
  58. },
  59. @endforeach
  60. ],
  61. form:'',
  62. selectTr:0
  63. },
  64. mounted:function(){
  65. let data = [[
  66. {name:'role',type:'input',tip:'角色名:可在两侧添加百分号(%)进行模糊搜索',placeholder:'角色名'}]];
  67. this.form = new query({
  68. el: '#form_div',
  69. condition: data,
  70. });
  71. this.form.init();
  72. let column = [
  73. {name:'id',value: 'ID'},
  74. {name:'name',value: '角色'},
  75. {name:'alias_name',value: '允许权限', neglect: true},
  76. {name:'alias_name_false',value: '禁止权限', neglect: true},
  77. {name:'created_at',value: '创建时间'},
  78. {name:'operation',value: '操作', neglect: true},
  79. ];
  80. new Header({
  81. el:"table",
  82. name:"role",
  83. column: column,
  84. data: this.roles,
  85. fixedTop: ($('#form_div').height())+2,
  86. }).init();
  87. },
  88. methods:{
  89. edit:function(id){
  90. location.href = "{{url('maintenance/role')}}/"+id+"/edit";
  91. },
  92. destroy:function(role){
  93. if(!confirm('确定要删除角色“' + role.name + '”吗?')){return};
  94. let data=this;
  95. let url = "{{url('maintenance/role')}}/"+role.id;
  96. axios.delete(url,{id:role.id})
  97. .then(function (response) {
  98. if(response.data.success){
  99. for (let i = 0; i < data.roles.length; i++) {
  100. if (data.roles[i].id===role.id){
  101. data.roles.splice(i,1);
  102. break;
  103. }
  104. }
  105. tempTip.setDuration(1000);
  106. tempTip.showSuccess('删除角色"'+role.name+'"成功!')
  107. }else{
  108. tempTip.setDuration(1000);
  109. tempTip.show('删除角色"'+role.name+'"失败!')
  110. }
  111. })
  112. .catch(function (err) {
  113. tempTip.setDuration(3000);
  114. tempTip.show('删除角色失败!'+'网络错误:' + err)
  115. });
  116. },
  117. }
  118. });
  119. </script>
  120. @endsection