• dcatadmin批量操作时异步请求获取当前选中的id


    需求

    批量发货时,需要可以修改每个发货单中的收货地址,所以需要点击批量生成后生成一个表单,并获取到选取的ids

    遇到的问题

    加载form时无法获取ids

    解决方法

    1. 重写Modal类
      GridBatchModal.php
    namespace App\Admin\Actions;
    
    use Dcat\Admin\Widgets\Modal;
    
    class GridBatchModal extends Modal
    {
        protected function getRenderableScript() {
            if (!$this->getRenderable()) {
                return;
            }
    
            $url = $this->renderable->getUrl();
    
            return <<<JS
    
    
    target.on('{$this->target}:load', function () {
    
        var key = Dcat.grid.selected('')
    
        Dcat.helpers.asyncRender('{$url}&ids='+key, function (html) {
            body.html(html);
    
            {$this->loadScript}
    
            target.trigger('{$this->target}:loaded');
        });
    });
    JS;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    1. 使用modal
      CommonGridBatchAction.php
    
    
    namespace App\Admin\Actions\Grid;
    
    use App\Admin\Actions\GridBatchModal;
    use App\Admin\Forms\BatchSureSendForm;
    use Dcat\Admin\Grid\BatchAction;
    
    
    class CommonGridBatchAction extends BatchAction
    {
    
        /**
         * @return string
         */
    	protected $title = 'Title';
        protected $function;
        public function __construct($title = null,$function = null)
        {
            $this->title = $title;
            $this->function = $function;
    
        }
    
        public function render()
        {
    
            $function = $this->function;
            return $this->$function();
        }
    
        public function batch_erp_out_order_send(){
    
            $keys = $this->getKey();
            $form = BatchSureSendForm::make()->payload([ ]);
            $modal = GridBatchModal::make()
                ->xl()
                ->title($this->title)
                ->body($form)
                ->button($this->title);
    
            return $modal;
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    1. 使用Form
      BatchSureSendForm.php
    
    
    namespace App\Admin\Forms;
    
    use App\Models\ExpressOrder;
    use Dcat\Admin\Contracts\LazyRenderable;
    use Dcat\Admin\Traits\LazyWidget;
    use Dcat\Admin\Widgets\Form;
    use Illuminate\Support\Facades\DB;
    
    class BatchSureSendForm extends Form implements LazyRenderable
    {
        use LazyWidget;
        /**
         * Handle the form request.
         *
         * @param array $input
         *
         * @return mixed
         */
        public function handle(array $input)
        {
      
            DB::beginTransaction();
         	//发货流程
            if($res == true){
                DB::commit();
                return $this
                    ->response()
                    ->success('发货成功')
                    ->refresh();
            }else{
                DB::rollBack();
                return $this
                    ->response()
                    ->error($msg);
            }
    
        }
    
        /**
         * Build a form here.
         */
        public function form()
        {
        	//或者$this->payload['ids']
            dump(request('ids'));
        }
    
     
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50

    参考原文:
    https://www.zongscan.com/demo333/96494.html

  • 相关阅读:
    python实现层次分析法(AHP)
    指针(5)
    计算机毕设源码网站springboot毕业设计管理系统
    14-bean创建流程5-初始化和循环依赖
    颜色模型(color model)
    深入探究Spring自动配置原理及SPI机制:实现灵活的插件化开发
    基于springboot,vue疫情防疫管理系统
    详解Spring Boot中@PostConstruct的使用
    Connor学Android - JNI和NDK编程
    数据结构——二叉树层序遍历
  • 原文地址:https://blog.csdn.net/weixin_53289224/article/details/134456883