fastadmin常见操作

1.动态下拉组件

排序参数: data-order-by='id desc'
必填: data-rule="required"
<input id="c-classify_id" data-rule="required" data-order-by='id desc' data-source="navigation/classify/selectpage" class="form-control selectpage" name="row[classify_id]" type="text" value="{$row.classify_id|htmlentities}">

2.点击修改内容

添加:,editable:true,
{field: 'title', title: __('Title'),editable:true, operate: 'like'},

3.表格点击下拉修改

{
	field: 'service_id',
	title: '业务类型',
	editable: {
	    type: 'select',
	    pk: 1,
	    source: Config.services,
	},
	operate:'=', addclass: 'selectpage',
	extend:"data-source='base/type/selectpage' data-params='{\"custom[status]\":1}' data-order-by='weigh desc' data-pagination='false' "
},

在控制器初始化的时候需要添加:

$services=$this->getService();
$this->assignconfig('services', $services);
public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\config\Group;
        $this->modelValidate=false;
        $services=$this->getService();
        $this->assignconfig('services', $services);

    }

4.点击箭头排序

{field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},

5.图片显示
{field: ‘fileimage’, title: __(‘Fileimage’), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

6.拖动排序
添加(这里的参数是表名):table: ‘navigation_list’,
Table.api.init({
extend: {
index_url: ‘navigation/listing/index’,
add_url: ‘navigation/listing/add’,
edit_url: ‘navigation/listing/edit’,
del_url: ‘navigation/listing/del’,
multi_url: ‘navigation/listing/multi’,
table: ‘navigation_list’,
}
});
7.树形显示

<input id="c-information_sources" data-rule="required" data-source="base/Source/selectpage3" data-params='{"custom[status]":1,"isTree":1}' data-order-by="weigh desc"
                   class="form-control selectpage" name="row[information_sources]" type="text" placeholder="单选,如果没有符合的来源,请联系管理员新增。">
{field: 'type', title: '业务类型',searchable:true,visible:false,
                            operate:'=', addclass: 'selectpage', placeholder: '单选搜索',
                            extend:"data-source='base/type/selectpage' data-params='{\"custom[status]\":1}' data-order-by='weigh desc'"},

8.拖动排序
第一步:数据库中添加
数据库 weigh 权重 int 后台的排序字段,如果存在该字段将出现排序按钮,可上下拖动进行排序

第二步:模型中添加

protected static function init()
    {
        self::afterInsert(function ($row) {
            $row->save(['weigh' => $row['id']]);
        });
    }

第三步:js的初始化表格中添加
table: ‘navigation_list’,//参数为数据库名称
// 初始化表格参数配置

Table.api.init({
            extend: {
                index_url: 'navigation/listing/index',
                add_url: 'navigation/listing/add',
                edit_url: 'navigation/listing/edit',
                del_url: 'navigation/listing/del',
                multi_url: 'navigation/listing/multi',
                table: 'navigation_list',
            }
        });

第四步:按钮显示

{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

9.联动查询

<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2 ">业务类型:</label>
        <div class="col-xs-12 col-sm-8">
            <!--{:build_select('row[type]', $typedata,$typeid, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}-->
            <input id="c-type" data-rule="required" data-source="base/type/selectpage" data-field="name" data-page-size="5"
                   class="form-control selectpage" name="row[type]" value="{$row.type}" type="text" placeholder="点击下拉可选择业务类型">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2 ">数据来源:</label>
        <div class="col-xs-12 col-sm-8">
            <!--{:build_select('row[type]', $typedata,$typeid, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}-->
            <input id="c-source_three" data-rule="required" data-source="base/Source_Three/selectpage" data-field="name" data-page-size="10"
                   class="form-control selectpage" name="row[source_three]" value="{$row.source_three}" type="text" placeholder="点击下拉可选择数据来源">
        </div>
    </div>
add: function () {
            Form.api.bindevent($("form[role=form]"));
            $('#c-source_three').data("params", function (obj) {
                if($('#c-type').val() == ""){
                    return {
                        isTree:1,
                    };
                }else{
                    return {
                        custom: {
                            service_id: $('#c-type').val()
                        },
                        isTree:1,
                    };
                }
            });
            $('#c-type').change(function () {
                //根据服务类型显示是否显示数据
                $('#c-source_three').selectPageClear();

            });
        },

        edit: function () {
            Form.api.bindevent($("form[role=form]"));
            $('#c-source_three').data("params", function (obj) {
                if($('#c-type').val() == ""){
                    return {
                        isTree:1,
                    };
                }else{
                    return {
                        custom: {
                            service_id: $('#c-type').val()
                        },
                        isTree:1,
                    };
                }
            });
            $('#c-type').change(function () {
                //根据服务类型显示是否显示数据
                $('#c-source_three').selectPageClear();

            });
        },

10.定义方法

columns: [
   [
        {field: 'color', title: __('颜色'), operate: false, formatter: Controller.api.formatter.base, cellStyle:function(value,row,index){
                return {css:{"color":value}};
            }},
        // {field: 'color', title: __('颜色'),operate:false, formatter: Controller.api.formatter.base},
        {field: 'belonging', title: __('数据所属'),formatter:Table.api.formatter.status,extend:'autocomplete="off"',searchList: {"0":__('公司'),"1":__('个人'),"2":__('部门')}},
        {field: 'api', title: __('接口'),extend:'autocomplete="off"'},
        {field: 'createtime', title: __('创建时间'),sortable:true,formatter: Table.api.formatter.datetime,operate:false, addclass: 'createtime',extend:'autocomplete="off" '},
    ]
]
api: {
    bindevent: function () {
        Form.api.bindevent($("form[role=form]"));
    },
    formatter:{
        base: function (value, row, index) {
            return '<span style=background:'+value+'> ' + value + '</span>'
        },
    }

}

11.定义属性

columns: [
[
   {field: 'state', checkbox: true,},
   {field: 'id', title: __('Id'),operate:false,visible:false},
   {field: 'call', title: __('基础信息'), width:'120px',operate: false,visible: true, formatter: Controller.api.formatter.base},

   {field: 'call',title: __('称呼'),visible:false,editable:true,operate: 'LIKE %...%', placeholder: '模糊搜索',extend:'autocomplete="off"'},
   {field: 'phone_number', title: __('手机号'),visible:false,operate: 'LIKE %...%', placeholder: '模糊搜索',extend:'autocomplete="off"'},
   {field: 'phone_str', title: __('手机号'),visible:true,width:'100px',operate: false},
   {field: 'customerstatus.status_name', title: __('客户状态'), operate: false,visible: true,width:'100px', cellStyle:Controller.api.formatter.css_span,formatter: Controller.api.formatter.customer},

   ]
]
api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                css_span:function () {
                    return {
                        css:{
                            "white-space ":"normal",
                            "text-align ":"left",
                        }
                    };
                },
                css_span2:function () {
                    return {
                        css:{
                            "white-space ":"normal",
                            "text-align ":"left",
                            "line-height ":"30px",
                            "letter-spacing ":"1px",

                        }
                    };
                },
                base: function (value, row, index) {
                    var sex='';
                    if(row.sex =='2'){
                        sex='女';
                    }else if(row.sex =='1'){
                        sex='男';
                    }else{
                        sex='未知';
                    }
                    return '<span> ' + value + '</span><br/>' +
                        '<span>' + sex + '</span><br/>'
                },
                add: function (value, row, index) {
                    return '<span> ' + value + '</span><br/>' +
                        '<span>' + row.create_time + '</span>';
                },
                customer: function (value, row, index) {
                    return '<span> ' + value + '</span><br/><br/>' +
                        '<span>' + row.stat_str + '</span><br/>'
                },
                interview: function (value, row, index) {
                    return '<span> ' + value + '</span><br/><br/>' +
                        '<span>' + row.estimate_visiting_time + '</span><br/>'
                },
            }
        }

12.表单点击下拉修改
在这里插入图片描述
控制器代码:

public function _initialize()
{
    parent::_initialize();
    $this->model = new \app\admin\model\config\Group;
    $this->modelValidate=false;
    //getIcon   getChart
    $getIcon=$this->getIcon();
    $getChart=$this->getChart();
    $services=$this->getService();
    $this->assignconfig('geticon', $getIcon);
    $this->assignconfig('getchart', $getChart);

    $this->assignconfig('services', $services);

}
public function getService(){
        $map['status']=1;
        if($this->auth->type >0){
            $map['id']=$this->auth->type;
        }
        $list = Type::where($map)->order('weigh desc')->select();
        $data[]=[
            'value'=>0,
            'text'=>'默认',
        ];
        foreach ($list as $li){
            $data[]=[
                'value'=>$li->id,
                'text'=>$li->name,
            ];
        }

        return $data;
    }
    public function getIcon(){
        $list = Icon::order('id desc')->select();
        foreach ($list as $li){
            $data[]=[
                'value'=>$li->id,
                'text'=>$li->title,
            ];
        }

        return $data;
    }
    public function getChart(){

        $list = Chart::order('id desc')->select();
        foreach ($list as $li){
            $data[]=[
                'value'=>$li->id,
                'text'=>$li->title,
            ];
        }

        return $data;
    }

js代码

{
    field: 'service_id',
    title: '业务类型',
    editable: {
        type: 'select',
        pk: 1,
        source: Config.services,
    },
    operate:'=', addclass: 'selectpage',
    extend:"data-source='base/type/selectpage' data-params='{\"custom[status]\":1}' data-order-by='weigh desc' data-pagination='false' "
},
{
    field: 'icon',
    title: '首页头部图标',
    editable: {
        type: 'select',
        pk: 1,
        source: Config.geticon,
    },
    operate:'=', addclass: 'selectpage',
    extend:"data-source='totals/icon/selectpage' data-params='{\"custom[status]\":1}' data-order-by='weigh desc' data-pagination='false' "
},
{
    field: 'chart',
    title: '首页统计图',
    editable: {
        type: 'select',
        pk: 1,
        source: Config.getchart,
    },
    operate:'=', addclass: 'selectpage',
    extend:"data-source='totals/chart/selectpage' data-params='{\"custom[status]\":1}' data-order-by='weigh desc' data-pagination='false' "
},
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

原克技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值