index.blade.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. @extends('admin.table_layouts')
  2. @section('content')
  3. <div class="page-content container-fluid">
  4. <div class="panel">
  5. <div class="panel-heading">
  6. <h2 class="panel-title">{{ trans('admin.menu.rule.list') }}</h2>
  7. @can('admin.rule.store')
  8. <div class="panel-actions">
  9. <button class="btn btn-outline-primary" data-toggle="modal" data-target="#add">
  10. <i class="icon wb-plus" aria-hidden="true"></i> {{ trans('common.add') }}
  11. </button>
  12. </div>
  13. @endcan
  14. </div>
  15. <div class="panel-body">
  16. <form class="form-row">
  17. <div class="form-group col-xxl-1 col-lg-3 col-md-3 col-4">
  18. <select class="form-control" name="type" data-plugin="selectpicker" data-style="btn-outline btn-primary"
  19. title="{{ trans('model.rule.attribute') }}">
  20. <option value="1">{{ trans('admin.rule.type.reg') }}</option>
  21. <option value="2">{{ trans('admin.rule.type.domain') }}</option>
  22. <option value="3">{{ trans('admin.rule.type.ip') }}</option>
  23. <option value="4">{{ trans('admin.rule.type.protocol') }}</option>
  24. </select>
  25. </div>
  26. <div class="form-group col-xxl-1 col-lg-3 col-md-3 col-4">
  27. <button class="btn btn-danger" type="button" onclick="resetSearchForm()">{{ trans('common.reset') }}</button>
  28. </div>
  29. </form>
  30. <table class="text-md-center" data-toggle="table" data-mobile-responsive="true">
  31. <thead class="thead-default">
  32. <tr>
  33. <th> #</th>
  34. <th> {{ trans('model.rule.attribute') }}</th>
  35. <th> {{ trans('model.rule.name') }}</th>
  36. <th> {{ trans('model.rule.pattern') }}</th>
  37. <th> {{ trans('common.action') }}</th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. @foreach ($rules as $rule)
  42. <tr>
  43. <td> {{ $rule->id }} </td>
  44. <td> {!! $rule->type_label !!} </td>
  45. <td>
  46. <input class="form-control" id="name_{{ $rule->id }}" name="name" type="text" value="{{ $rule->name }}" />
  47. </td>
  48. <td>
  49. <input class="form-control" id="pattern_{{ $rule->id }}" name="pattern" type="text" value="{{ $rule->pattern }}" />
  50. </td>
  51. <td>
  52. @canany(['admin.rule.update', 'admin.rule.destroy'])
  53. <div class="btn-group">
  54. @can('admin.rule.update')
  55. <button class="btn btn-sm btn-outline-primary" onclick="editRule('{{ $rule->id }}')">
  56. <i class="icon wb-edit"></i></button>
  57. @endcan
  58. @can('admin.rule.destroy')
  59. <button class="btn btn-sm btn-outline-danger"
  60. onclick="delRule('{{ route('admin.rule.destroy', $rule) }}','{{ $rule->name }}')">
  61. <i class="icon wb-trash"></i></button>
  62. @endcan
  63. </div>
  64. @endcanany
  65. </td>
  66. </tr>
  67. @endforeach
  68. </tbody>
  69. </table>
  70. </div>
  71. <div class="panel-footer">
  72. <div class="row">
  73. <div class="col-sm-4">
  74. {!! trans('admin.rule.counts', ['num' => $rules->total()]) !!}
  75. </div>
  76. <div class="col-sm-8">
  77. <nav class="Page navigation float-right">
  78. {{ $rules->links() }}
  79. </nav>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. @can('admin.rule.store')
  86. <div class="modal fade" id="add" role="dialog" aria-hidden="true" tabindex="-1">
  87. <div class="modal-dialog modal-simple modal-center">
  88. <div class="modal-content">
  89. <div class="modal-header">
  90. <button class="close" data-dismiss="modal" type="button" aria-label="{{ trans('common.close') }}">
  91. <span aria-hidden="true">×</span>
  92. </button>
  93. <h4 class="modal-title">{{ trans('admin.action.add_item', ['attribute' => trans('model.rule.attribute')]) }}</h4>
  94. </div>
  95. <form class="modal-body" action="#" method="post">
  96. <div class="alert alert-danger" id="msg" style="display: none;"></div>
  97. <div class="form-row">
  98. <div class="col-12">
  99. <div class="form-group row">
  100. <label class="col-md-2 col-sm-3 col-form-label" for="add_type">{{ trans('model.rule.attribute') }}</label>
  101. <div class="col-xl-4 col-sm-8">
  102. <select class="form-control" id="add_type" name="add_type" data-plugin="selectpicker" data-style="btn-outline btn-primary">
  103. <option value="1">{{ trans('admin.rule.type.reg') }}</option>
  104. <option value="2">{{ trans('admin.rule.type.domain') }}</option>
  105. <option value="3">{{ trans('admin.rule.type.ip') }}</option>
  106. <option value="4">{{ trans('admin.rule.type.protocol') }}</option>
  107. </select>
  108. </div>
  109. </div>
  110. <div class="form-group row">
  111. <label class="col-md-2 col-sm-3 col-form-label" for="name">{{ trans('model.rule.name') }}</label>
  112. <div class="col-xl-6 col-sm-8">
  113. <input class="form-control" id="name" name="name" type="text" required />
  114. </div>
  115. </div>
  116. </div>
  117. <div class="col-12">
  118. <div class="form-group row">
  119. <label class="col-md-2 col-sm-3 col-form-label" for="pattern">{{ trans('model.rule.pattern') }}</label>
  120. <div class="col-xl-6 col-sm-8">
  121. <input class="form-control" id="pattern" name="pattern" type="text" required />
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </form>
  127. <div class="modal-footer">
  128. <button class="btn btn-danger mr-auto" data-dismiss="modal">{{ trans('common.close') }}</button>
  129. <button class="btn btn-primary" type="button" onclick="addRule()">{{ trans('common.add') }}</button>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. @endcan
  135. @endsection
  136. @push('javascript')
  137. <script>
  138. $(document).ready(function() {
  139. $("select").selectpicker("val", {{ Request::query('type') }});
  140. });
  141. @can('admin.rule.store')
  142. // 添加规则
  143. function addRule() {
  144. $.ajax({
  145. method: "POST",
  146. url: "{{ route('admin.rule.store') }}",
  147. data: {
  148. _token: '{{ csrf_token() }}',
  149. type: $("#add_type").val(),
  150. name: $("#name").val(),
  151. pattern: $("#pattern").val()
  152. },
  153. dataType: "json",
  154. success: function(ret) {
  155. $("#add").modal("hide");
  156. if (ret.status === "success") {
  157. swal.fire({
  158. title: ret.message,
  159. icon: "success",
  160. timer: 1000,
  161. showConfirmButton: false
  162. }).then(() => window.location.reload());
  163. } else {
  164. swal.fire({
  165. title: ret.message,
  166. icon: "error"
  167. }).then(() => window.location.reload());
  168. }
  169. },
  170. error: function(data) {
  171. $("#add").modal("hide");
  172. let str = "";
  173. const errors = data.responseJSON;
  174. if ($.isEmptyObject(errors) === false) {
  175. $.each(errors.errors, function(index, value) {
  176. str += "<li>" + value + "</li>";
  177. });
  178. swal.fire({
  179. title: '{{ trans('admin.hint') }}',
  180. html: str,
  181. icon: "error",
  182. confirmButtonText: '{{ trans('common.confirm') }}'
  183. });
  184. }
  185. }
  186. });
  187. }
  188. @endcan
  189. @can('admin.rule.update')
  190. // 编辑规则
  191. function editRule(id) {
  192. $.ajax({
  193. method: "PUT",
  194. url: '{{ route('admin.rule.update', '') }}/' + id,
  195. data: {
  196. _token: '{{ csrf_token() }}',
  197. name: $("#name_" + id).val(),
  198. pattern: $("#pattern_" + id).val()
  199. },
  200. dataType: "json",
  201. success: function(ret) {
  202. if (ret.status === "success") {
  203. swal.fire({
  204. title: ret.message,
  205. icon: "success",
  206. timer: 1000,
  207. showConfirmButton: false
  208. }).then(() => window.location.reload());
  209. } else {
  210. swal.fire({
  211. title: ret.message,
  212. icon: "error"
  213. }).then(() => window.location.reload());
  214. }
  215. },
  216. error: function(data) {
  217. let str = "";
  218. const errors = data.responseJSON;
  219. if ($.isEmptyObject(errors) === false) {
  220. $.each(errors.errors, function(index, value) {
  221. str += "<li>" + value + "</li>";
  222. });
  223. swal.fire({
  224. title: '{{ trans('admin.hint') }}',
  225. html: str,
  226. icon: "error",
  227. confirmButtonText: '{{ trans('common.confirm') }}'
  228. });
  229. }
  230. }
  231. });
  232. }
  233. @endcan
  234. @can('admin.rule.destroy')
  235. // 删除规则
  236. function delRule(url, name) {
  237. swal.fire({
  238. title: '{{ trans('common.warning') }}',
  239. text: '{{ trans('admin.confirm.delete.0', ['attribute' => trans('model.rule.attribute')]) }}' + name +
  240. '{{ trans('admin.confirm.delete.1') }}',
  241. icon: "warning",
  242. showCancelButton: true,
  243. cancelButtonText: '{{ trans('common.close') }}',
  244. confirmButtonText: '{{ trans('common.confirm') }}'
  245. }).then((result) => {
  246. if (result.value) {
  247. $.ajax({
  248. method: "DELETE",
  249. url: url,
  250. data: {
  251. _token: '{{ csrf_token() }}'
  252. },
  253. dataType: "json",
  254. success: function(ret) {
  255. if (ret.status === "success") {
  256. swal.fire({
  257. title: ret.message,
  258. icon: "success",
  259. timer: 1000,
  260. showConfirmButton: false
  261. }).then(() => window.location.reload());
  262. } else {
  263. swal.fire({
  264. title: ret.message,
  265. icon: "error"
  266. }).then(() => window.location.reload());
  267. }
  268. }
  269. });
  270. }
  271. });
  272. }
  273. @endcan
  274. </script>
  275. @endpush