CommentBatchAction.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Admin\Actions\Feeds;
  3. use App\Models\FeedComment;
  4. use App\Models\FeedLike;
  5. use Dcat\Admin\Grid\BatchAction;
  6. use Dingo\Blueprint\Annotation\Method\Post;
  7. use Illuminate\Http\Request;
  8. class CommentBatchAction extends BatchAction
  9. {
  10. protected $action;
  11. // 注意action的构造方法参数一定要给默认值
  12. public function __construct($title = null, $action = 1)
  13. {
  14. $this->title = $title;
  15. $this->action = $action;
  16. }
  17. // 确认弹窗信息
  18. public function confirm()
  19. {
  20. return trans('feeds.action.sure_delete_content').'?';
  21. }
  22. // 处理请求
  23. public function handle(Request $request)
  24. {
  25. // 获取选中的文章ID数组
  26. $keys = $this->getKey();
  27. //dd($keys);
  28. // 获取请求参数
  29. $action = $request->get('action');
  30. if($action==1){
  31. //评论
  32. FeedComment::query()->whereIn('id',$keys)->delete();
  33. }elseif($action==2){
  34. //点赞
  35. FeedLike::query()->whereIn('id',$keys)->delete();
  36. }
  37. return $this->response()->success('success')->refresh();
  38. }
  39. public function script(){
  40. if($this->action==1){
  41. return <<<JS
  42. $('.app-admin-actions-feeds-commentlist_grid-select-all-btn').bind('click',function (){
  43. if($(this).parent().children().find('.dropdown-menu').hasClass('show')){
  44. $(this).parent().children().find('.dropdown-menu').removeClass('show');
  45. }else{
  46. $(this).parent().children().find('.dropdown-menu').addClass('show');
  47. }
  48. })
  49. JS;
  50. }else{
  51. return <<<JS
  52. $('.app-admin-actions-feeds-likelist_grid-select-all-btn').bind('click',function (){
  53. if($(this).parent().children().find('.dropdown-menu').hasClass('show')){
  54. $(this).parent().children().find('.dropdown-menu').removeClass('show');
  55. }else{
  56. $(this).parent().children().find('.dropdown-menu').addClass('show');
  57. }
  58. })
  59. JS;
  60. }
  61. }
  62. // 设置请求参数
  63. public function parameters()
  64. {
  65. return [
  66. 'action' => $this->action,
  67. ];
  68. }
  69. }