InquiryHandle.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Admin\Actions\Tools;
  3. use App\Admin\Repositories\DistInquiry;
  4. use Dcat\Admin\Grid\Tools\AbstractTool;
  5. use Dcat\Admin\Widgets\Modal;
  6. use Illuminate\Http\Request;
  7. class InquiryHandle extends AbstractTool
  8. {
  9. protected $style = 'btn btn-success';
  10. /**
  11. * 按钮文本
  12. *
  13. * @return string|void
  14. */
  15. public function title()
  16. {
  17. return admin_trans_label('process');
  18. }
  19. /**
  20. * 确认弹窗,如果不需要则返回空即可
  21. *
  22. * @return array|string|void
  23. */
  24. public function confirm()
  25. {
  26. // 只显示标题
  27. // return '您确定要发送新的提醒消息吗?';
  28. // 显示标题和内容
  29. return ['Are you sure you want to process this document?', ''];
  30. }
  31. /**
  32. * 处理请求
  33. * 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
  34. *
  35. * @param Request $request
  36. */
  37. public function handle(Request $request)
  38. {
  39. $keys = $request->input('_key');
  40. if (is_array($keys) && count($keys) > 0) {
  41. $result = DistInquiry::distSetStatusProcessed($keys);
  42. if ($result === false) {
  43. return $this->response()->error('Failed to process!')->refresh();
  44. }
  45. return $this->response()->success('Success')->refresh();
  46. } else {
  47. return $this->response()->error('No data selected!')->refresh();
  48. }
  49. // 你的代码逻辑
  50. }
  51. public function actionScript(){
  52. $warning = __('No data selected!');
  53. return <<<JS
  54. function (data, target, action) {
  55. var key = {$this->getSelectedKeysScript()}
  56. if (key.length === 0) {
  57. Dcat.warning('{$warning}');
  58. return false;
  59. }
  60. // 设置主键为复选框选中的行ID数组
  61. action.options.key = key;
  62. }
  63. JS;
  64. }
  65. public function getSelectedKeysScript()
  66. {
  67. return "Dcat.grid.selected('{$this->parent->getName()}')";
  68. }
  69. }