Form.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace UCore\DcatAdmin\Widgets;
  3. use UCore\DcatAdmin\ActionLog\ActionForm;
  4. use UCore\DcatAdmin\Traits\Controller;
  5. use Dcat\Admin\Widgets\Form as BaseForm;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Http\JsonResponse;
  8. class Form extends BaseForm
  9. {
  10. protected int $status = 0;
  11. use Controller;
  12. protected function status($status)
  13. {
  14. $this->status = $status;
  15. return $this;
  16. }
  17. public function getActionName()
  18. {
  19. return static::class;
  20. }
  21. final public function handle($input)
  22. {
  23. $log = new ActionForm();
  24. $log->objectClass = $this->getActionName();
  25. $log->admin_id = Admin::user()->id;
  26. $log->url = \request()->getRequestUri();
  27. $log->before = $input;
  28. $log->after =[];
  29. /**
  30. *
  31. * @var JsonResponse $resp
  32. */
  33. $resp = $this->run($input);
  34. $log->status = $this->status;
  35. $log->after = $resp;
  36. return $resp;
  37. }
  38. public function resReturn($res)
  39. {
  40. if(is_string($res)){
  41. return $this->error($res);
  42. }
  43. return $this->success("处理成功")->refresh();
  44. }
  45. /**
  46. * 返回错误信息
  47. *
  48. * @param $message
  49. * @return \Dcat\Admin\Http\JsonResponse
  50. */
  51. public function error($message)
  52. {
  53. $this->status(-1);
  54. return $this->response()->error(__($message));
  55. }
  56. /**
  57. * 带有翻译的返回
  58. * @param $message
  59. * @return JsonResponse
  60. */
  61. public function _error($message)
  62. {
  63. return $this->response()->error($message);
  64. }
  65. /**
  66. * 带有翻译的返回
  67. * @param $message
  68. * @return JsonResponse
  69. */
  70. public function _success($message)
  71. {
  72. return $this->response()->success($message);
  73. }
  74. /**
  75. * 返回成功的消息
  76. *
  77. * @param $message
  78. * @return \Dcat\Admin\Http\JsonResponse
  79. */
  80. public function success($message)
  81. {
  82. $this->status(1);
  83. return $this->response()->success($message);
  84. }
  85. protected function getAdminId()
  86. {
  87. return Admin::user()->id;
  88. }
  89. }