记录:fastadmin 列表页,自定义tab按钮,自定义传参 html代码示例:
<div class="panel-heading nav-custom-condition">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs">
<li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-status="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="statusList" item="vo"}
<li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-status="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
<li class=""><a href="#t" data-status="10" data-isyuqi="1" data-toggle="tab">已逾期</a></li>
</ul>
</div>
JS代码示例:
$('.panel-heading .nav-custom-condition a[data-toggle="tab"]', table.closest(".panel-intro")).on('shown.bs.tab', function (e) {
var that = $(this);
var options = table.bootstrapTable('getOptions');
var queryParams = options.queryParams;
options.pageNumber = 1;
options.queryParams = function (params) {
params = queryParams(params);
var filter = params.filter ? JSON.parse(params.filter) : {};
var op = params.op ? JSON.parse(params.op) : {};
if(that.data("status")){
filter['status'] = that.data("status");
op['status'] = '=';
}
if(that.data("isyuqi") == 1){
filter['status'] = 10;
var mydate = new Date();
var date = "" + mydate.getFullYear() + "-";
date += (mydate.getMonth()+1) + "-";
date += mydate.getDate();
filter['repayment_date'] = date;
op['repayment_date'] = '<';
}
params.filter = JSON.stringify(filter);
params.op = JSON.stringify(op);
return params;
};
table.trigger("uncheckbox");
table.bootstrapTable('refresh', {pageNumber: 1});
return false;
});
页面效果示例:
特别注意:
若op里面传入“>”、“>=”、“<”、“<=”,fastadmin统一接收参数的方法buildparams里面会进行intval($v)处理,若你传入的是非数字类型,则此处需要进行特殊处理。 比如,此处我传入的是日期格式:
校验日期格式:
function is_date($date)
{
if (!preg_match("/^(([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}))|(([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}))$/", $date)) {
return false;
}
return true;
}
|