海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.6 KiB

  1. <?php
  2. namespace App\AdminAgent\Actions\Grid;
  3. use Dcat\Admin\Actions\Response;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Dcat\Admin\Grid\Tools\AbstractTool;
  6. use Dcat\Admin\Traits\HasPermissions;
  7. use Illuminate\Contracts\Auth\Authenticatable;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Http\Request;
  10. class DemandConfirm extends RowAction
  11. {
  12. protected $model;
  13. public function __construct(string $model = null)
  14. {
  15. $this->model = $model;
  16. }
  17. /**
  18. * 标题
  19. *
  20. * @return string
  21. */
  22. public function title()
  23. {
  24. return 'Copy';
  25. }
  26. /**
  27. * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗
  28. *
  29. * 允许返回字符串或数组类型
  30. *
  31. * @return array|string|void
  32. */
  33. public function confirm()
  34. {
  35. return [
  36. // 确认弹窗 title
  37. "您确定要复制这行数据吗?",
  38. // 确认弹窗 content
  39. $this->row->username,
  40. ];
  41. }
  42. /**
  43. * 处理请求
  44. *
  45. * @param Request $request
  46. *
  47. * @return \Dcat\Admin\Actions\Response
  48. */
  49. public function handle(Request $request)
  50. {
  51. // 获取当前行ID
  52. $id = $this->getKey();
  53. // 获取 parameters 方法传递的参数
  54. $username = $request->get('username');
  55. $model = $request->get('model');
  56. // 复制数据
  57. $model::find($id)->replicate()->save();
  58. // 返回响应结果并刷新页面
  59. return $this->response()->success("复制成功: [{$username}]")->refresh();
  60. }
  61. /**
  62. * 设置要POST到接口的数据
  63. *
  64. * @return array
  65. */
  66. public function parameters()
  67. {
  68. return [
  69. // 发送当前行 username 字段数据到接口
  70. 'username' => $this->row->username,
  71. // 把模型类名传递到接口
  72. 'model' => $this->model,
  73. ];
  74. }
  75. }