FastAdmin自定义通用搜索表单配置
searchFormVisible:false, //通用搜索表单是否初始显示
searchFormTemplate:'countrySearch', //通用搜索模板
commonSearch:true, //是否启用通用搜索
search:false,//关闭搜索框
//模板中的配置
<script id="countrySearch" type="text/html">
<!--form表单必须添加form-commsearch这个类-->
<form action="" class="form-commonsearch form-horizontal">
<!-- 自定义搜索表单 -->
</form>
</script>
FastAdmin 表单中 使用函数生成radio
{:build_radios('row[gender]', ['1'=>__('Gentleman'), '2'=>__('Lady')], 1);}
{:build_select('row[room_type]', $roomType, null, ['class'=>'form-control selectpicker', 'required'=>'', 'data-live-search'=>"true"])}
//还有一种用法
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="detainStatusList" item="vo"}
<label for="row[detain_status]-{$key}"><input id="row[detain_status]-{$key}" name="row[detain_status]" type="radio" value="{$key}" {in name="key" value="$row['detain_status']"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
FastAdmin selectpage添加默认选项
//如果发送的来源是 Selectpage,则转发到 Selectpage
if ($this->request->request('keyField')) {
$result=$this->selectpage();
//获取JSON数据
$content=json_decode($result->getContent(),true);
//解构
["list"=>$list,"total"=>$total]=$content;
//添加初始默认值
array_unshift($list, ['id'=>0,"classify_name"=>'无']);
//total +1
return json(['list'=>$list,'total'=>$total+1]);
}
FastAdmin自定义按钮
{field: 'operate', title: __('Operate'), table: table,buttons: [{
name: "classify",
text: "会场管理",//按钮名称
//classname 按钮类型有 btn-dialog、btn-ajax、btn-addtabs、btn-click
classname: 'btn btn-xs btn-success btn-addtabs',
icon: 'fa fa-sitemap',
// url: 'hotel/classify?city_id={id}',
url:function(row){
return 'hotel/classify?city_code='+row['city_code']+'&city_customized=1';
},
visible:function(row){
console.log(row);
return (row.status && row.hot) ? true : false;
}
}],events: Table.api.events.operate, formatter: Table.api.formatter.operate}
使用fast.api.open打开弹框,使用backend.api.addtabs打开tab标签页
//打开标签页
Backend.api.addtabs('salary/batchAdd',"每日薪资批量添加");
//打开弹框
Fast.api.open('salary/batchAdd',"每日薪资批量添加");
FastAdmin设置dailog弹框大小
表格外dialog弹框大小,设置在Table.api.init上面
$(".btn-add").data("area",["90%","90%"]);
// 初始化表格参数配置
Table.api.init({
表格内dialog btn弹框大小,设置在表格绑定事件上面
table.on("post-body.bs.table",function(){
$(".btn-editone").data("area",["90%","90%"])
});
Fastadmin 隐藏表格列中的删除按钮
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value,row,index){
var that = $.extend({}, this);
var table = $(that.table).clone(true);
if (row.id <4){
$(table).data("operate-del", null);
}
that.table = table;
return Table.api.formatter.operate.call(that, value, row, index);
}}
Fastadmin 通用搜索 查询关联表中字段
public function hotel(){
return $this->belongsTo('Hotel','hotel_id','id')->setEagerlyType(0);
}
FastAdmin 根据权限 列formatter显示不同api
使用场景举例说明 超级管理员权限拥有审核权限 而普通管理只需知道审核状态,这里主要使用的是Tabel.api.formatter.status和Table.api.formatter.toggle,简单的使用不同的形态,大家都知道,问题是需要根据条件不同动态显示,废话不多说,看源码
{field: 'status', title: '审核', searchList: {"0":'已审核',"1":"未审核"}, formatter: function(value,row,index){
if(row.status==1){
return Table.api.formatter.toggle.call(this,value,row,index);
}else{
return Table.api.formatter.status.call(this,value,row,index);
}
}}
FastAdmin 侧边栏 增加数字提醒
使用场景,新订单总量显示在侧边栏menu上提示
//左侧菜单
//修改admin/controller/Index.php index
list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
'dashboard' => 'hot',
'addon' => ['new', 'red', 'badge'],
'auth/rule' => __('Menu'),
'reservation?status=99'=>(new \app\common\model\Reservation)->where("status",99)->count(),
'quotation'=>(new \app\common\model\Quotation)->where("status",7)->count(),
'apply'=>(new \app\common\model\Apply)->where("status",1)->count(),
], $this->view->site['fixedpage']);
Fastadmin中使用Fast.api.ajax发起网络请求,阻止系统消息
Fast.api.ajax({
url:"worker/index",
data:{
filter:JSON.stringify({"worker.id":worker_id}),
op:JSON.stringify({'worker.id':'='})
},
method:"get"
},function(data,ret){
//成功的回调
console.log("成功",data,ret);
//这里可以自定义消息提醒
return false;//阻止系统自带的消息
},function(data,ret){
console.log("失败",data,ret);
return false;
});
有一点需要注意的是,控制器返回数据中,需要包含code=1,不然无法进入成功回调
Fastadmin 在commonSearch使用selectpage,数据来源网络
{field: 'worker_id', title: __('Worker_id'),formatter:(row,value,index)=>value.worker.name,addClass:"selectpage",
extend:'data-source="worker/index" data-field="name" data-primary-key="id" data-search-field="name,id_card"'},
Fastadmin 隐藏右边导出 搜索框等按钮
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-search="false"
data-show-toggle="false"
data-show-columns="false"
data-show-export="false"
data-common-search="false"
data-operate-edit="{:$auth->check('project/worker/edit')}"
data-operate-del="{:$auth->check('project/worker/del')}"
width="100%">
</table>