diff --git a/src/plugin/admin/app/common/Layui.php b/src/plugin/admin/app/common/Layui.php index 363812c..eff814c 100644 --- a/src/plugin/admin/app/common/Layui.php +++ b/src/plugin/admin/app/common/Layui.php @@ -1,6 +1,7 @@ +EOF; + } + + /** + * 输入框模糊查询 + * @param $options + * @return void + */ + public function inputLike($options) + { + [$label, $field, $value, $props, $verify_string, $required_string, $class] = $this->options($options); + $type = $props['type'] ?? 'text'; + + $this->htmlContent .= << + $label +
+
+ + +
+
+ + EOF; } @@ -138,6 +164,17 @@ EOF; $this->inputRange($options); } + /** + * 数字输入框模糊查询 + * @param $options + * @return void + */ + public function inputNumberLike($options) + { + $options['props']['type'] = 'number'; + $this->inputLike($options); + } + /** * 密码输入框 * @param $options @@ -730,8 +767,12 @@ EOF; continue; } // 范围查询 - if ($type == 'search' && $info['search_type'] == 'between' && method_exists($form, "{$control}Range")) { - $control = "{$control}Range"; + if ($type == 'search') { + if ($info['search_type'] == 'between' && method_exists($form, "{$control}Range")) { + $control = "{$control}Range"; + } elseif ($info['search_type'] == 'like' && method_exists($form, "{$control}Like")) { + $control = "{$control}Like"; + } } $options = [ diff --git a/src/plugin/admin/app/common/Util.php b/src/plugin/admin/app/common/Util.php index 31f4cd6..10ded49 100644 --- a/src/plugin/admin/app/common/Util.php +++ b/src/plugin/admin/app/common/Util.php @@ -1,7 +1,8 @@ model; foreach ($where as $column => $value) { if (is_array($value)) { - if (in_array($value[0], ['>', '=', '<', '<>', 'like', 'not like'])) { + if ($value[0] === 'like') { + $model = $model->where($column, 'like', "%$value[1]%"); + } elseif (in_array($value[0], ['>', '=', '<', '<>', 'not like'])) { $model = $model->where($column, $value[0], $value[1]); } elseif ($value[0] == 'in') { $model = $model->whereIn($column, $value[1]); @@ -139,7 +144,7 @@ class Crud extends Base $model = $model->whereNull($column, $value[1]); } elseif ($value[0] == 'not null') { $model = $model->whereNotNull($column, $value[1]); - } else { + } elseif ($value[0] !== '' || $value[1] !== '') { $model = $model->whereBetween($column, $value); } } else { diff --git a/src/plugin/admin/app/controller/PluginController.php b/src/plugin/admin/app/controller/PluginController.php index 37f528f..7c807b9 100644 --- a/src/plugin/admin/app/controller/PluginController.php +++ b/src/plugin/admin/app/controller/PluginController.php @@ -1,10 +1,11 @@ createModel($model_class, $model_namespace, base_path($model_file), $table_name); + // 创建model + $this->createModel($model_class, $model_namespace, base_path($model_file), $table_name); - $controller_suffix = $plugin ? config("plugin.$plugin.app.controller_suffix") : config('app.controller_suffix'); - $controller_class = $controller_file_name; - $controller_namespace = str_replace('/' , '\\', trim($controller_path, '/')); - // 创建controller - $controller_url_name = $controller_suffix && substr($controller_class, -strlen($controller_suffix)) === $controller_suffix ? substr($controller_class, 0, -strlen($controller_suffix)) : $controller_class; - $controller_url_name = str_replace('_', '-', $inflector->tableize($controller_url_name)); + $controller_suffix = $plugin ? config("plugin.$plugin.app.controller_suffix") : config('app.controller_suffix'); + $controller_class = $controller_file_name; + $controller_namespace = str_replace('/', '\\', trim($controller_path, '/')); + // 创建controller + $controller_url_name = $controller_suffix && substr($controller_class, -strlen($controller_suffix)) === $controller_suffix ? substr($controller_class, 0, -strlen($controller_suffix)) : $controller_class; + $controller_url_name = str_replace('_', '-', $inflector->tableize($controller_url_name)); - if ($plugin) { - array_splice($explode, 0, 2); - } - array_shift($explode); - if ($app) { - array_shift($explode); - } - foreach ($explode as $index => $item) { - if (strtolower($item) === 'controller') { - unset($explode[$index]); + if ($plugin) { + array_splice($explode, 0, 2); } + array_shift($explode); + if ($app) { + array_shift($explode); + } + foreach ($explode as $index => $item) { + if (strtolower($item) === 'controller') { + unset($explode[$index]); + } + } + + $controller_base = implode('/', $explode); + $controller_class_with_namespace = "$controller_namespace\\$controller_class"; + $template_path = $controller_base ? "$controller_base/$controller_url_name" : $controller_url_name; + $this->createController($controller_class, $controller_namespace, base_path($controller_file), $model_class, $model_namespace, $title, $template_path); + + // 创建模版 + $template_file_path = ($plugin ? "/plugin/$plugin" : '') . '/app/' . ($app ? "$app/" : '') . 'view/' . $template_path; + + $model_class_with_namespace = "$model_namespace\\$model_class"; + $primary_key = (new $model_class_with_namespace)->getKeyName(); + $url_path_base = ($plugin ? "/app/$plugin/" : '/') . ($app ? "$app/" : '') . $template_path; + $this->createTemplate(base_path($template_file_path), $table_name, $url_path_base, $primary_key, "$controller_namespace\\$controller_class"); + } finally { + Util::resumeFileMonitor(); } - $controller_base = implode('/', $explode); - $controller_class_with_namespace = "$controller_namespace\\$controller_class"; - $template_path = $controller_base ? "$controller_base/$controller_url_name" : $controller_url_name; - $this->createController($controller_class, $controller_namespace, base_path($controller_file), $model_class, $model_namespace, $title, $template_path); - - // 创建模版 - $template_file_path = ($plugin ? "/plugin/$plugin" : '') . '/app/' . ($app ? "$app/" : '') . 'view/' . $template_path; - - $model_class_with_namespace = "$model_namespace\\$model_class"; - $primary_key = (new $model_class_with_namespace)->getKeyName(); - $url_path_base = ($plugin ? "/app/$plugin/" : '/') . ($app ? "$app/" : '') . $template_path; - $this->createTemplate(base_path($template_file_path), $table_name, $url_path_base, $primary_key, "$controller_namespace\\$controller_class"); - $menu = Rule::where('key', $controller_class_with_namespace)->first(); if (!$menu) { $menu = new Rule; @@ -570,7 +581,7 @@ class TableController extends Base $properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n"; $columns[$item->COLUMN_NAME] = $item->COLUMN_NAME; } - } catch (\Throwable $e) {echo $e;} + } catch (Throwable $e) {echo $e;} if (!isset($columns['created_at']) || !isset($columns['updated_at'])) { $timestamps = <<where($column, 'like', "%$value[1]%"); + } elseif (in_array($value[0], ['>', '=', '<', '<>', 'not like'])) { + $paginator = $paginator->where($column, $value[0], $value[1]); + } else { + if($value[0] !== '' || $value[1] !== '') { + $paginator = $paginator->whereBetween($column, $value); + } } - $paginator = $paginator->whereBetween($column, $value); } else { $paginator = $paginator->where($column, $value); } } } $paginator = $paginator->orderBy($field, $order)->paginate($limit, '*', 'page', $page); - $items = $paginator->items(); if ($format == 'tree') { $items_map = []; diff --git a/src/plugin/admin/app/view/table/create.html b/src/plugin/admin/app/view/table/create.html index ece3490..52e3833 100644 --- a/src/plugin/admin/app/view/table/create.html +++ b/src/plugin/admin/app/view/table/create.html @@ -160,7 +160,7 @@