fastadmin 表单操作修改

1. 隐藏fastadmin表单操作按钮

 

HTML代码:

<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                           data-operate-edit="{:$auth->check('pim/schedule/edit')}"
                           data-operate-del="{:$auth->check('pim/schedule/del')}"
                           data-operate-start="{:$auth->check('pim/schedule/start')}"
                           data-operate-finish="{:$auth->check('pim/schedule/finish')}"
                           width="100%">
                    </table>

js代码:

 1 {field: 'operate',
 2          title: __('Operate'),
 3          table: table,
 4          events: Table.api.events.operate,
 5          // formatter: Table.api.formatter.operate,
 6 
 7          formatter:function(value,row,index){
 8            var that = $.extend({},this);
 9            var table = $(that.table).clone(true);
10 
11            $(table).data("operate-edit",null);
12            $(table).data("operate-del",null);
13 
14            that.table = table;
15            return Table.api.formatter.operate.call(that,value,row,index);
16          }
17 },

 

2. 添加表单操作按钮

 1 {field: 'operate',
 2        title: __('Operate'),
 3        table: table,
 4 
 5        buttons:[
 6           {
 7              name:'start',
 8              text:'',
 9              classname:'btn btn-xs btn-info btn-ajax btn-restoreit',
10              icon:'fa fa-play',      //图标
11              url:'pim/schedule/start',   //控制器/方法
12              confirm:'是否开始?',    //弹窗确认
13              refresh:true,   //刷新
14           },
15           {
16              name:'finish',
17              text:'',
18              classname:'btn btn-xs btn-danger btn-ajax btn-restoreit',
19              icon:'fa fa-stop',      //图标
20              url:'pim/schedule/finish',  //控制器/方法
21              confirm:'是否结束?',    //弹窗确认
22              refresh:true,   //刷新
23            }
24          ],
25 
26          events: Table.api.events.operate,
27          // formatter: Table.api.formatter.operate,
28 
29          formatter:function(value,row,index){
30              var that = $.extend({},this);
31              var table = $(that.table).clone(true);
32 
33              $(table).data("operate-edit",null);
34              $(table).data("operate-del",null);
35 
36              that.table = table;
37              return Table.api.formatter.operate.call(that,value,row,index);
38           }
39  },

 

效果如下:

 

控制器代码:

    /**
     * 开始事务
     */
    public function start($ids = null)
    {
        /* step.1 从数据库中取出该数据*/
        $row = $this->model->get($ids);
        if (!$row){
            $this->error(__('No results were found'));
        }

        /* step.2 检查数据操作权限*/
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds)){
            if (!in_array($row[$this->dataLimitField] , $adminIds)){
                $this->error(__('You have no permission'));
            }
        }

        /* step.3 更新数据*/
        if($this->request->isPost()){
            $row->status = 1;
            $row->stime  = date('Y-m-d H:i:00');
            $row->save();
        }

        /* step.4 返回处理结果*/
        $rst = [
            'code' => 1,         //1表示成功
            'msg'  => '开启事务成功',   //提示信息
            'data' => $row,
            'url'  => '.',        //刷新地址
            'wait' => 3          //等待3秒
        ];
        return json($rst);
    }

 

posted @ 2022-06-01 15:49  cmooc  阅读(913)  评论(0编辑  收藏  举报