DialogTool.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Admin\Extensions\Tools;
  3. use Encore\Admin\Grid\Tools\AbstractTool;
  4. use Encore\Admin\Widgets\Form;
  5. /**
  6. * Created by PhpStorm.
  7. * User: zhongjianquan
  8. * Date: 2018/9/29
  9. * Time: 上午11:45
  10. */
  11. class DialogTool extends AbstractTool
  12. {
  13. /**
  14. * @var 弹窗表单数据
  15. */
  16. protected $config;
  17. public function __construct($widget, $config = array(), $buttonName = '按钮')
  18. {
  19. if (empty($config)) {
  20. $config = array(
  21. 'button' => $buttonName,
  22. 'title' => "提示",
  23. 'dialog_cancel' => "取消",
  24. 'dialog_ok' => "确认",
  25. 'is_batch' => true
  26. );
  27. }
  28. $this->config=$config;
  29. $this->config['uniqid']=uniqid();
  30. if ($widget instanceof Form) {
  31. $widget->attribute('id', 'dialog-form-'.$this->config['uniqid']);
  32. $widget->disableReset();
  33. $widget->disableSubmit();
  34. $this->config['is_form']=true;
  35. } else {
  36. $this->config['is_form']=false;
  37. }
  38. $this->config['form']=$widget->render();
  39. }
  40. public function render()
  41. {
  42. return view('admin.tools.dialog', $this->config);
  43. }
  44. }