• 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

  • 相关阅读:
    【AI学习】RAG与推荐系统
    基于springboot 停车场管理系统-计算机毕设 附源码 39315
    [附源码]Python计算机毕业设计GuiTar网站设计
    Qt操作Sqlite类封装,及命令行导入csv文件到Sqlite数据库
    Apollo 应用与源码分析:Monitor监控-软件监控-时间延迟监控
    Windows OpenGL ES 图像对比度调节
    Scott-Knott ESD test
    常见场景面试题:BitMap、布隆过滤器
    【初阶算法4】——归并排序的详解,及其归并排序的扩展
    C/C++ 遍历文件夹(最全方法)
  • 原文地址:https://blog.csdn.net/weixin_53289224/article/details/134456883