作者 Karson

新增列表搜索autocomplete配置

优化关联搜索
优化附件列表缩略图显示
... ... @@ -273,39 +273,41 @@ class Backend extends Controller
$op = (array)json_decode($op, true);
$filter = $filter ? $filter : [];
$where = [];
$alias = [];
$bind = [];
$name = '';
$tableName = '';
if ($relationSearch) {
if (!empty($this->model)) {
$name = $this->model->getTable();
$tableName = $name . '.';
}
$sortArr = explode(',', $sort);
foreach ($sortArr as $index => & $item) {
$item = stripos($item, ".") === false ? $tableName . trim($item) : $item;
}
unset($item);
$sort = implode(',', $sortArr);
$aliasName = '';
if (!empty($this->model)) {
$name = $this->model->getTable();
$alias[$name] = Loader::parseName(basename(str_replace('\\', '/', get_class($this->model))));
$aliasName = $alias[$name] . '.';
}
$sortArr = explode(',', $sort);
foreach ($sortArr as $index => & $item) {
$item = stripos($item, ".") === false ? $aliasName . trim($item) : $item;
}
unset($item);
$sort = implode(',', $sortArr);
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$where[] = [$tableName . $this->dataLimitField, 'in', $adminIds];
$where[] = [$aliasName . $this->dataLimitField, 'in', $adminIds];
}
if ($search) {
$searcharr = is_array($searchfields) ? $searchfields : explode(',', $searchfields);
foreach ($searcharr as $k => &$v) {
$v = stripos($v, ".") === false ? $tableName . $v : $v;
$v = stripos($v, ".") === false ? $aliasName . $v : $v;
}
unset($v);
$where[] = [implode("|", $searcharr), "LIKE", "%{$search}%"];
}
$index = 0;
foreach ($filter as $k => $v) {
if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) {
continue;
}
$sym = isset($op[$k]) ? $op[$k] : '=';
if (stripos($k, ".") === false) {
$k = $tableName . $k;
$k = $aliasName . $k;
}
$v = !is_array($v) ? trim($v) : $v;
$sym = strtoupper(isset($op[$k]) ? $op[$k] : $sym);
... ... @@ -341,10 +343,11 @@ class Backend extends Controller
case 'FINDINSET':
case 'FIND_IN_SET':
$v = is_array($v) ? $v : explode(',', str_replace(' ', ',', $v));
foreach ($v as $index => $item) {
$item = str_replace([' ', ',', "'"], '', $item);
$item = addslashes(htmlentities(strip_tags($item)));
$where[] = "FIND_IN_SET('{$item}', `" . ($relationSearch ? str_replace('.', '`.`', $k) : $k) . "`)";
$findArr = array_values($v);
foreach ($findArr as $idx => $item) {
$bindName = "item_" . $index . "_" . $idx;
$bind[$bindName] = $item;
$where[] = "FIND_IN_SET(:{$bindName}, `" . str_replace('.', '`.`', $k) . "`)";
}
break;
case 'IN':
... ... @@ -385,10 +388,10 @@ class Backend extends Controller
$arr = $arr[0];
}
$tableArr = explode('.', $k);
if (count($tableArr) > 1 && $tableArr[0] != $name) {
if (count($tableArr) > 1 && $tableArr[0] != $name && !in_array($tableArr[0], $alias)) {
//修复关联模型下时间无法搜索的BUG
$relation = Loader::parseName($tableArr[0], 1, false);
$this->model->alias([$this->model->$relation()->getTable() => $tableArr[0]]);
$alias[$this->model->$relation()->getTable()] = $tableArr[0];
}
$where[] = [$k, str_replace('RANGE', 'BETWEEN', $sym) . ' TIME', $arr];
break;
... ... @@ -401,8 +404,14 @@ class Backend extends Controller
default:
break;
}
$index++;
}
$where = function ($query) use ($where) {
$this->model->alias($alias);
$model = $this->model;
$where = function ($query) use ($where, $alias, $bind, &$model) {
$model->alias($alias);
$model->bind($bind);
foreach ($where as $k => $v) {
if (is_array($v)) {
call_user_func_array([$query, 'where'], $v);
... ... @@ -411,7 +420,7 @@ class Backend extends Controller
}
}
};
return [$where, $sort, $order, $offset, $limit, $page];
return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind];
}
/**
... ...
... ... @@ -15,12 +15,31 @@ class Attachment extends Model
// 定义字段类型
protected $type = [
];
protected $append = [
'thumb_style'
];
public function setUploadtimeAttr($value)
{
return is_numeric($value) ? $value : strtotime($value);
}
/**
* 获取云储存的缩略图样式字符
*/
public function getThumbStyleAttr($value, $data)
{
if (!isset($data['storage']) || $data['storage'] == 'local') {
return '';
} else {
$config = get_addon_config($data['storage']);
if ($config && isset($config['thumbstyle'])) {
return $config['thumbstyle'];
}
}
return '';
}
public static function getMimetypeList()
{
$data = [
... ...
... ... @@ -162,8 +162,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
formatter: {
thumb: function (value, row, index) {
if (row.mimetype.indexOf("image") > -1) {
var style = row.storage === 'upyun' ? '!/fwfh/120x90' : '';
return '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + style + '" alt="" style="max-height:90px;max-width:120px"></a>';
return '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + row.thumb_style + '" alt="" style="max-height:90px;max-width:120px"></a>';
} else {
return '<a href="' + row.fullurl + '" target="_blank"><img src="' + Fast.api.fixurl("ajax/icon") + "?suffix=" + row.imagetype + '" alt="" style="max-height:90px;max-width:120px"></a>';
}
... ...
... ... @@ -80,6 +80,7 @@
var extend = typeof vObjCol.extend === 'undefined' ? '' : vObjCol.extend;
var style = typeof vObjCol.style === 'undefined' ? '' : sprintf('style="%s"', vObjCol.style);
extend = typeof vObjCol.data !== 'undefined' && extend == '' ? vObjCol.data : extend;
extend = typeof vObjCol.autocomplete !== 'undefined' ? extend + ' autocomplete="' + (vObjCol.autocomplete === false || vObjCol.autocomplete === 'off' ? 'off' : 'on') + '"' : extend;
if (vObjCol.searchList) {
if (typeof vObjCol.searchList === 'function') {
htmlForm.push(vObjCol.searchList.call(this, vObjCol));
... ...