zoukankan      html  css  js  c++  java
  • fastadmin后台表格列表增加自定义操作的按钮-编辑的前面加个审核

    整个流程梳理

    1 先去语言包增加  审核

    application/admin/lang/zh-cn/video.php

    2 控制中 增加审核函数  发现审核就是在编辑的基础上 少了一些 字段 我直接复制编辑函数改下名字 就拿来用了

    application/admin/controller/video.php

     public function auth($ids = null)
        {
            $row = $this->model->get($ids);
            if (!$row) {
                $this->error(__('No Results were found'));
            }
            $adminIds = $this->getDataLimitAdminIds();
            if (is_array($adminIds)) {
                if (!in_array($row[$this->dataLimitField], $adminIds)) {
                    $this->error(__('You have no permission'));
                }
            }
            if ($this->request->isPost()) {
                $params = $this->request->post("row/a");
                if ($params) {
                    $params = $this->preExcludeFields($params);
                    $result = false;
                    Db::startTrans();
                    try {
                        //是否采用模型验证
                        if ($this->modelValidate) {
                            $name = str_replace("\model\", "\validate\", get_class($this->model));
                            $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                            $row->validateFailException(true)->validate($validate);
                        }
                        $result = $row->allowField(true)->save($params);
                        Db::commit();
                    } catch (ValidateException $e) {
                        Db::rollback();
                        $this->error($e->getMessage());
                    } catch (PDOException $e) {
                        Db::rollback();
                        $this->error($e->getMessage());
                    } catch (Exception $e) {
                        Db::rollback();
                        $this->error($e->getMessage());
                    }
                    if ($result !== false) {
                        $this->success();
                 
                    } else {
                        $this->error(__('No rows were updated'));
                    }
                }
                $this->error(__('Parameter %s can not be empty', ''));
            }
            $this->view->assign("row", $row);
            return $this->view->fetch();
        }

    3   模板文件

    application/admin/view/video/auth.html

    代码如下

    <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
            <div class="col-xs-12 col-sm-8">
                 {$row.title|htmlentities} 
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Reason')}:</label>
            <div class="col-xs-12 col-sm-8">
               <input id="c-act_status" class="form-control" name="row[reason]" type="text" value="{$row.reason|htmlentities}">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-act_status" class="form-control" name="row[status]" type="number" value="{$row.status|htmlentities}">
            </div>
        </div>
        
            <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 col-sm-8">
                <button type="submit" class="btn btn-success btn-embossed ">{:__('OK')}</button>
                <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
            </div>
        </div>
    </form>

    4  最重要的 管理列表 增加一个审核按钮

     public/assets/js/backend/video.js

    添加如下代码

    define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    
        var Controller = {
            index: function () {
                // 初始化表格参数配置
                Table.api.init({
                    extend: {
                        index_url: 'video/index' + location.search,
                        add_url: 'video/add',
                        edit_url: 'video/edit',
                        auth_url: 'video/auth',
                        del_url: 'video/del',
                        multi_url: 'video/multi',
                        table: 'video',
                    }
                });
    
                var table = $("#table");
    
                // 初始化表格
                table.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    pk: 'id',
                    sortName: 'id',
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'title', title: __('Title')},
                            {field: 'url', title: __('Url')},
                            {field: 'type', title: __('Type')},
                            {field: 'create_time', title: __('Create_time')},
                            {field: 'user_id', title: __('User_id')},
                            {field: 'status', title: __('Status')},
                            {field: 'praise_num', title: __('Praise_num')},
                            {field: 'reply_num', title: __('Reply_num')},
                            {field: 'view_num', title: __('View_num')},
                            {field: 'video_time', title: __('Video_time')},
      
                            {field: 'operate', title: __('Operate'), table: table, 
                                 buttons: [
                                           {name: 'detail', text: __('Auth'),   icon: '', classname: 'btn btn-xs btn-primary btn-dialog', url: 'video/auth'}
                                         ], 
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
    
                // 为表格绑定事件
                Table.api.bindevent(table);
            },
            add: function () {
                Controller.api.bindevent();
            },
            edit: function () {
                Controller.api.bindevent();
            },
            auth: function () {
                Controller.api.bindevent();//这个地方如果不加,会造成你有跳转页面  不会出现延迟的那种消息通知
            },
            api: {
                bindevent: function () {
                    Form.api.bindevent($("form[role=form]"));
                }
            }
        };
        return Controller;
    });

    5 最终的结果如图

  • 相关阅读:
    重新想象 Windows 8 Store Apps (15) 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState, VisualStateManager
    重新想象 Windows 8 Store Apps (12) 控件之 GridView 特性: 拖动项, 项尺寸可变, 分组显示
    返璞归真 asp.net mvc (10) asp.net mvc 4.0 新特性之 Web API
    与众不同 windows phone (29) Communication(通信)之与 OData 服务通信
    与众不同 windows phone (33) Communication(通信)之源特定组播 SSM(Source Specific Multicast)
    与众不同 windows phone (27) Feature(特性)之搜索的可扩展性, 程序的生命周期和页面的生命周期, 页面导航, 系统状态栏
    与众不同 windows phone (30) Communication(通信)之基于 Socket TCP 开发一个多人聊天室
    返璞归真 asp.net mvc (12) asp.net mvc 4.0 新特性之移动特性
    重新想象 Windows 8 Store Apps (2) 控件之按钮控件: Button, HyperlinkButton, RepeatButton, ToggleButton, RadioButton, CheckBox, ToggleSwitch
    重新想象 Windows 8 Store Apps (10) 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom
  • 原文地址:https://www.cnblogs.com/baker95935/p/12842606.html
Copyright © 2011-2022 走看看