hk 4 anos atrás
pai
commit
6dda20a7d9

+ 31 - 0
app/Admin/Actions/Post/BatchMsg.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Admin\Actions\Post;
+
+use Encore\Admin\Actions\BatchAction;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Http\Request;
+
+class BatchMsg extends BatchAction
+{
+    public $name = '批量回复';
+    protected $selector = '.report-posts';
+
+    public function handle(Collection $collection, Request $request){
+        foreach ($collection as $model) {
+            $model->msg = $request->get('msg');
+            $model->save();
+        }
+
+        return $this->response()->success('回复成功!')->refresh();
+    }
+
+    public function form(){
+        $this->textarea('msg', '回复内容');
+    }
+
+    // public function html()
+    // {
+    //     return "<a class='report-posts btn btn-sm btn-success'>批量回复</a>";
+    // }
+}

+ 8 - 22
app/Admin/Actions/Post/BatchStatus.php

@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
 class BatchStatus extends BatchAction
 {
     public $name = '批量修改状态';
+    protected $selector = '.report-posts';
 
-    public function handle(Collection $collection)
-    {
+    public function handle(Collection $collection){
         foreach ($collection as $model) {
             // 双向修改 未读、已读
             // $model->status = (int)!$model->status;
@@ -20,25 +20,11 @@ class BatchStatus extends BatchAction
             $model->save();
         }
 
-        return $this->response()->success('Success!')->refresh();
-    }
-
-}
-
-class BatchMsg extends BatchAction
-{
-    public $name = '批量回复';
-
-    public function handle(Collection $collection, Request $request){
-        foreach ($collection as $model) {
-            $msg = $request->get('msg');
-            $model->save('msg', $msg);
-        }
-
-        return $this->response()->success('Success!')->refresh();
-    }
-
-    public function form(){
-        $this->textarea('msg', '回复内容');
+        return $this->response()->success('修改成功!')->refresh();
     }
+    
+    // public function html()
+    // {        
+    //     return "<a class='status-posts btn btn-sm btn-success'><i>aaaaaaaaaaa</i>批量修改状态</a>";
+    // }
 }

+ 27 - 0
app/Admin/Actions/Post/Msg.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Admin\Actions\Post;
+
+use Encore\Admin\Actions\RowAction;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Http\Request;
+use App\Admin\Models\Feedback;
+
+/**
+ * 回复
+ */
+class Msg extends RowAction
+{
+    public $name = '回复';
+    public function handle(Model $model, Request $request){
+        $model->msg = $request->get('msg');
+        $model->save();
+
+        return $this->response()->success('回复成功!')->refresh();
+    }
+
+    public function form()
+    {
+        $this->textarea('msg','回复内容');
+    }
+}

+ 4 - 0
app/Admin/Actions/Post/StatusEdit.php

@@ -7,6 +7,10 @@ use Illuminate\Database\Eloquent\Model;
 use Illuminate\Http\Request;
 use App\Admin\Models\Feedback;
 
+/**
+ * 修改状态
+ * 已读、未读
+ */
 class StatusEdit extends RowAction
 {
     public $name = '修改状态';

+ 61 - 21
app/Admin/Controllers/FeedbackController.php

@@ -12,8 +12,11 @@ use App\Admin\Selectable\SelectFeedback;
 use App\Admin\Selectable\SeleteTag;
 use Illuminate\Support\Facades\Auth;
 use App\Admin\Actions\Post\StatusEdit;
+use App\Admin\Actions\Post\Msg;
 use App\Admin\Actions\Post\BatchStatus;
 use App\Admin\Actions\Post\BatchMsg;
+use Encore\Admin\Auth\Permission;
+// use Encore\Admin\Auth\Admin;
 
 class FeedbackController extends AdminController
 {
@@ -43,26 +46,63 @@ class FeedbackController extends AdminController
             }, $tags);
             return join(' ', $res);
         });
-        // $grid->column('status')->label(['0' => 'warning', '1' => 'success']);
-        $grid->status(trans('状态'))->display(function ($status) {
-            if ($status == 0) {
-                return "<span class='label bg-red'>未读</span>";
-            } else if ($status == 1) {
-                return "<span class='label bg-green'>已读</span>";
-            }
-        });
-        // 添加操作  修改状态
         $grid->actions(function ($actions) {
-            $actions->add(new StatusEdit);
+            // 去掉删除操作
+            $actions->disableDelete();
         });
-        // 添加批量操作  修改状态
-        $grid->batchActions(function ($batch) {
-            $batch->add(new BatchStatus);
-        });
-        // 添加批量操作  回复
+        
+        // 去掉批量删除
         $grid->batchActions(function ($batch) {
-            $batch->add(new BatchMsg);
-        });
+            $batch->disableDelete();
+        }); 
+        if (!Auth::guard('admin')->user()->can('status-edit')) {
+            // 去除所有操作
+            $grid->disableActions();
+            // 标签式状态
+            // $grid->column('status')->label(['0' => 'warning', '1' => 'success']);
+            $grid->status(trans('状态'))->display(function ($status) {
+                if ($status == 0) {
+                    return "<span class='label bg-red'>未读</span>";
+                } else if ($status == 1) {
+                    return "<span class='label bg-green'>已读</span>";
+                }
+            });
+            $grid->column('msg', __('回复内容'));
+        }else{
+            // 开关式状态
+            $states = [
+                'off' => ['value' => 0, 'text' => '未读', 'color' => 'primary'],
+                'on' => ['value' => 1, 'text' => '已读', 'color' => 'success'],
+            ];
+            $grid->column('status', __('状态'))->switch($states);
+            // 可行内编辑回复内容
+            $grid->column('msg', __('回复内容'))->editable('textarea');
+    
+            // 自定义操作  修改状态
+            $grid->actions(function ($actions) {
+                // 添加修改状态操作
+                $actions->add(new StatusEdit);
+                // 添加回复操作
+                $actions->add(new Msg);
+            });
+            // 添加批量操作  修改状态
+            $grid->batchActions(function ($batch) {
+                $batch->add(new BatchStatus);
+            });
+            // $grid->tools(function (Grid\Tools $tools) {
+            //     $tools->append(new BatchStatus);
+            // });
+            // 添加批量操作  回复
+            $grid->batchActions(function ($batch) {
+                $batch->add(new BatchMsg);
+            });
+            // $grid->tools(function (Grid\Tools $tools) {
+            //     $tools->append(new BatchMsg);
+            // });
+        }
+
+
+        
         return $grid;
     }
 
@@ -125,7 +165,7 @@ class FeedbackController extends AdminController
             $form->tags('tags', __('问题标签'))->pluck('name', 'id')->options(Tag::all())->saving(function ($value) {
                 foreach ($value as $key => $v) {
                     // 判断是否为字符串型整数 否新增  数字但tag表无相关数据 新增
-                    if(!ctype_digit($v) || (ctype_digit($v) && !Tag::find($v))) {
+                    if (!ctype_digit($v) || (ctype_digit($v) && !Tag::find($v))) {
                         $value[$key] = Tag::insertGetId(['name' => $v]);
                     }
                 }
@@ -143,7 +183,7 @@ class FeedbackController extends AdminController
             $form->tags('tags', __('问题标签'))->pluck('name', 'id')->options(Tag::all())->saving(function ($value) {
                 foreach ($value as $key => $v) {
                     // 判断是否为字符串型整数 否新增  数字但tag表无相关数据 新增
-                    if(!ctype_digit($v) || (ctype_digit($v) && !Tag::find($v))) {
+                    if (!ctype_digit($v) || (ctype_digit($v) && !Tag::find($v))) {
                         $value[$key] = Tag::insertGetId(['name' => $v]);
                     }
                 }
@@ -154,9 +194,9 @@ class FeedbackController extends AdminController
                 'off' => ['value' => 0, 'text' => '未读', 'color' => 'danger'],
             ];
             $form->switch('status', __('状态'))->states($states);
-            $form->textarea('msg', __('回复内容'))->value(function ($value){
+            $form->textarea('msg', __('回复内容'))->value(function ($value) {
                 dd($value);
-                if ($value){
+                if ($value) {
                     $form->hidden('status', __('状态'))->value(1);
                 }
             });