dolphinphp海豚后台管理系统搜索功能加=或者like
每个业务功能不同,对搜索要求也不同,有些场景需要like,有些场景需要=。于是就有了此文。
下面介绍如何添加设置搜索功能:
1、创建table时加上参数:
ZBuilder::make('table')->setSearch($srhuser, '', '', '', '=')
2、修改common/builder/table/Builder.php,找到如下代码:
$this->_vars['search'] = [
'fields' => $_temp_fields,
'field_all' => implode('|', array_keys($_temp_fields)),
'placeholder' => $this->_search['placeholder'] != '' ? $this->_search['placeholder'] : '请输入'. implode('/', $_temp_fields),
'url' => $this->_search['url'] == '' ? $this->request->baseUrl(true) : $this->_search['url'],
'searchtype' => $this->_search['searchtype'],//新增此行代码
];
3、找到common/builder/table/layout.html如下代码:
{notempty name="search"}
<div class="pull-right search-bar">
<input type="hidden" name="search_field" id="search-field" value="{php}echo input('param.search_field', '') == '' ? $search['field_all'] : input('param.search_field');{/php}">
<input type="hidden" name="search-type" id="search-type" value="{$search['searchtype']}">//新增此行
4、找到public/static/admin/js/builder/table.js
$('#search-input').on('keyup', function (e) {
if (e.keyCode === 13) {
var $url = $(this).data('url');
var $filed = $('#search-field').val();
var $keyword = $(this).val();
var $searchType = $('#search-type').val();//新增此行
var _curr_params = {
'search_field': $filed || '',
'keyword': $keyword || '', //注意最后一个,
'searchtype': $searchType || '',//新增此行
};
goto($url, _curr_params, true);
}
});
$('#search-submit-btn').click(function () {
var $url = $('#search-input').data('url');
var $filed = $('#search-field').val();
var $keyword = $('#search-input').val();
var $searchType = $('#search-type').val();//新增此行
var _curr_params = {
'search_field': $filed || '',
'keyword': $keyword || '', //注意最后一个,
'searchtype': $searchType || '',//新增此行
};
goto($url, _curr_params, true);
});
5、找到application/common/controller/Common.php中的方法 getMap()方法:
$search_type = input('searchtype', '');//新增此行
$map = [];
// 搜索框搜索
if ($search_field != '' && $keyword !== '') {
//下面此行修改为以下代码:
$map[$search_field] = (empty($search_type) || $search_type == 'like ') ? ['like', "%$keyword%"] : ['=', $keyword];
}
6、刷新一下页面,试下效果呗
|