优化FastAdmin通用搜索——

1、支持指定class样式
2、延时隐藏避免select控件不会自适应宽度
3、默认显示搜索表单时,隐藏切换按钮
pull/101/head
PPPSCN 2019-03-01 23:05:26 +08:00
parent 73770e1b4a
commit 8cfead83bf
4 changed files with 55 additions and 15 deletions

View File

@ -25,7 +25,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{%javascriptList%}
]
]
],
//禁用默认搜索
search: false,
//启用普通表单搜索
commonSearch: true,
//可以控制是否默认显示搜索表单,false则隐藏,默认为false
searchFormVisible: false,
showColumns: false,
showToggle: false,
});
// 为表格绑定事件

View File

@ -6,6 +6,9 @@
*
* @author: Karson <karsonzhang@163.com>
* @update 2018-04-05 <https://gitee.com/karson/fastadmin>
*
* @author: pppscn <35696959@qq.com>
* @update 2019-02-16 <https://gitee.com/pp/fastadmin>
*/
!function ($) {
@ -18,12 +21,17 @@
var initCommonSearch = function (pColumns, that) {
var vFormCommon = createFormCommon(pColumns, that);
var vModal = sprintf("<div class=\"commonsearch-table %s\">", that.options.searchFormVisible ? "" : "hidden");
var vModal = "<div class=\"commonsearch-table\">";
vModal += vFormCommon;
vModal += "</div>";
that.$container.prepend($(vModal));
that.$commonsearch = $(".commonsearch-table", that.$container);
var form = $("form.form-commonsearch", that.$commonsearch);
if(!that.options.searchFormVisible){
setTimeout(function () {
that.$commonsearch.addClass('hidden');
},100);
}
require(['form'], function (Form) {
Form.api.bindevent(form);
@ -51,7 +59,7 @@
return Template(that.options.searchFormTemplate, {columns: pColumns, table: that});
}
var htmlForm = [];
htmlForm.push(sprintf('<form class="form-horizontal form-commonsearch" novalidate method="post" action="%s" >', that.options.actionForm));
htmlForm.push(sprintf('<form class="%s" novalidate method="post" action="%s">', that.options.searchFormCss.form, that.options.actionForm));
htmlForm.push('<fieldset>');
if (that.options.titleForm.length > 0)
htmlForm.push(sprintf("<legend>%s</legend>", that.options.titleForm));
@ -66,9 +74,9 @@
vObjCol.operate = that.options.renderDefault && operate ? operate : (typeof vObjCol.operate === 'undefined' ? '=' : vObjCol.operate);
ColumnsForSearch.push(vObjCol);
htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">');
htmlForm.push(sprintf('<label for="%s" class="control-label col-xs-4">%s</label>', vObjCol.field, vObjCol.title));
htmlForm.push('<div class="col-xs-8">');
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.form_group));
htmlForm.push(sprintf('<label for="%s" class="%s">%s</label>', vObjCol.field, that.options.searchFormCss.label, vObjCol.title));
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.container));
vObjCol.operate = vObjCol.operate ? vObjCol.operate.toUpperCase() : '=';
htmlForm.push(sprintf('<input type="hidden" class="form-control operate" name="%s-operate" data-name="%s" value="%s" readonly>', vObjCol.field, vObjCol.field, vObjCol.operate));
@ -120,7 +128,8 @@
htmlForm.push('</div>');
}
}
htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">');
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.form_group));
htmlForm.push(sprintf('<label class="%s">&nbsp;</label>', that.options.searchFormCss.label_btn));
htmlForm.push(createFormBtn(that).join(''));
htmlForm.push('</div>');
htmlForm.push('</div>');
@ -134,7 +143,7 @@
var htmlBtn = [];
var searchSubmit = that.options.formatCommonSubmitButton();
var searchReset = that.options.formatCommonResetButton();
htmlBtn.push('<div class="col-sm-8 col-xs-offset-4">');
htmlBtn.push(sprintf('<div class="%s">', that.options.searchFormCss.container));
htmlBtn.push(sprintf('<button type="submit" class="btn btn-success" formnovalidate>%s</button> ', searchSubmit));
htmlBtn.push(sprintf('<button type="reset" class="btn btn-default" >%s</button> ', searchReset));
htmlBtn.push('</div>');

View File

@ -9777,6 +9777,9 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
*
* @author: Karson <karsonzhang@163.com>
* @update 2018-04-05 <https://gitee.com/karson/fastadmin>
*
* @author: pppscn <35696959@qq.com>
* @update 2019-02-16 <https://gitee.com/pp/fastadmin>
*/
!function ($) {
@ -9789,12 +9792,17 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
var initCommonSearch = function (pColumns, that) {
var vFormCommon = createFormCommon(pColumns, that);
var vModal = sprintf("<div class=\"commonsearch-table %s\">", that.options.searchFormVisible ? "" : "hidden");
var vModal = "<div class=\"commonsearch-table\">";
vModal += vFormCommon;
vModal += "</div>";
that.$container.prepend($(vModal));
that.$commonsearch = $(".commonsearch-table", that.$container);
var form = $("form.form-commonsearch", that.$commonsearch);
if(!that.options.searchFormVisible){
setTimeout(function () {
that.$commonsearch.addClass('hidden');
},100);
}
require(['form'], function (Form) {
Form.api.bindevent(form);
@ -9822,7 +9830,7 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
return Template(that.options.searchFormTemplate, {columns: pColumns, table: that});
}
var htmlForm = [];
htmlForm.push(sprintf('<form class="form-horizontal form-commonsearch" novalidate method="post" action="%s" >', that.options.actionForm));
htmlForm.push(sprintf('<form class="%s" novalidate method="post" action="%s">', that.options.searchFormCss.form, that.options.actionForm));
htmlForm.push('<fieldset>');
if (that.options.titleForm.length > 0)
htmlForm.push(sprintf("<legend>%s</legend>", that.options.titleForm));
@ -9837,9 +9845,9 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
vObjCol.operate = that.options.renderDefault && operate ? operate : (typeof vObjCol.operate === 'undefined' ? '=' : vObjCol.operate);
ColumnsForSearch.push(vObjCol);
htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">');
htmlForm.push(sprintf('<label for="%s" class="control-label col-xs-4">%s</label>', vObjCol.field, vObjCol.title));
htmlForm.push('<div class="col-xs-8">');
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.form_group));
htmlForm.push(sprintf('<label for="%s" class="%s">%s</label>', vObjCol.field, that.options.searchFormCss.label, vObjCol.title));
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.container));
vObjCol.operate = vObjCol.operate ? vObjCol.operate.toUpperCase() : '=';
htmlForm.push(sprintf('<input type="hidden" class="form-control operate" name="%s-operate" data-name="%s" value="%s" readonly>', vObjCol.field, vObjCol.field, vObjCol.operate));
@ -9891,7 +9899,8 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
htmlForm.push('</div>');
}
}
htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">');
htmlForm.push(sprintf('<div class="%s">', that.options.searchFormCss.form_group));
htmlForm.push(sprintf('<label class="%s">&nbsp;</label>', that.options.searchFormCss.label_btn));
htmlForm.push(createFormBtn(that).join(''));
htmlForm.push('</div>');
htmlForm.push('</div>');
@ -9905,7 +9914,7 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
var htmlBtn = [];
var searchSubmit = that.options.formatCommonSubmitButton();
var searchReset = that.options.formatCommonResetButton();
htmlBtn.push('<div class="col-sm-8 col-xs-offset-4">');
htmlBtn.push(sprintf('<div class="%s">', that.options.searchFormCss.container));
htmlBtn.push(sprintf('<button type="submit" class="btn btn-success" formnovalidate>%s</button> ', searchSubmit));
htmlBtn.push(sprintf('<button type="reset" class="btn btn-default" >%s</button> ', searchReset));
htmlBtn.push('</div>');
@ -10300,6 +10309,13 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
import_url: '',
multi_url: '',
dragsort_url: 'ajax/weigh',
},
searchFormCss: {
form: 'form-commonsearch',
form_group: 'form-group col-xs-12 col-sm-6 col-md-4 col-lg-3',
label: 'control-label',
label_btn: 'control-label hidden-xs',
container: 'pp_container',
}
},
// Bootstrap-table 列配置

View File

@ -48,6 +48,13 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
import_url: '',
multi_url: '',
dragsort_url: 'ajax/weigh',
},
searchFormCss: {
form: 'form-commonsearch',
form_group: 'form-group col-xs-12 col-sm-6 col-md-4 col-lg-3',
label: 'control-label',
label_btn: 'control-label hidden-xs',
container: 'pp_container',
}
},
// Bootstrap-table 列配置