diff --git a/catch/system/controller/DataDictionary.php b/catch/system/controller/DataDictionary.php index 41190ea..0006229 100644 --- a/catch/system/controller/DataDictionary.php +++ b/catch/system/controller/DataDictionary.php @@ -6,6 +6,7 @@ use catcher\base\CatchController; use catcher\CatchResponse; use catcher\exceptions\FailedException; use catcher\library\BackUpDatabase; +use think\Collection; use think\facade\Console; use think\facade\Db; use think\Paginator; @@ -22,36 +23,26 @@ class DataDictionary extends CatchController { $tables = Db::query('show table status'); - $tablename = $request->get('tablename'); - $engine = $request->get('engine'); - - $searchTables = []; - $searchMode = false; - if ($tablename || $engine) { - $searchMode = true; - } - + // 重组数据 foreach ($tables as $key => &$table) { - $table = array_change_key_case($table); - $table['index_length'] = $table['index_length'] > 1024 ? intval($table['index_length']/1024) .'MB' : $table['index_length'].'KB'; - $table['data_length'] = $table['data_length'] > 1024 ? intval($table['data_length']/1024) .'MB' : $table['data_length'].'KB'; - $table['create_time'] = date('Y-m-d', strtotime($table['create_time'])); - // 搜索 - if ($tablename && !$engine && stripos($table['name'], $tablename) !== false) { - $searchTables[] = $table; - } - // 搜索 - if (!$tablename && $engine && stripos($table['engine'], $engine) !== false) { - $searchTables[] = $table; - } - - if ($tablename && $engine && stripos($table['engine'], $engine) !== false && stripos($table['name'], $tablename) !== false) { - $searchTables[] = $table; - } + $table = array_change_key_case($table); + $table['index_length'] = $table['index_length'] > 1024 ? intval($table['index_length']/1024) .'MB' : $table['index_length'].'KB'; + $table['data_length'] = $table['data_length'] > 1024 ? intval($table['data_length']/1024) .'MB' : $table['data_length'].'KB'; + $table['create_time'] = date('Y-m-d', strtotime($table['create_time'])); } + // 搜素 + $tables = new Collection($tables); + // 名称搜索 + if ($name = $request->get('tablename', null)) { + $tables = $tables->where('name', 'like', $name)->values(); + } + // 引擎搜索 + if ($engine = $request->get('engine', null)) { + $tables = $tables->where('engine', $engine)->values(); + } - return CatchResponse::paginate(Paginator::make(!$searchMode ? $tables : $searchTables, $request->get('limit') ?? 10, $request->get('page') ?? 1, $searchMode ? count($searchTables) : count($tables), false, [])); + return CatchResponse::paginate(Paginator::make($tables->toArray(), $request->get('limit') ?? 10, $request->get('page') ?? 1, $tables->count(), false, [])); } /**