支持模糊搜索
This commit is contained in:
parent
4cba3c47d9
commit
ea86e944cf
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace plugin\admin\app\common;
|
namespace Webman\Admin\plugin\admin\app\common;
|
||||||
|
|
||||||
|
use plugin\admin\app\common\Util;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
class Layui
|
class Layui
|
||||||
@ -124,6 +125,31 @@ EOF;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
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 .= <<<EOF
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
$label
|
||||||
|
<div class="$class">
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="hidden" autocomplete="off" name="{$field}[]" value="like" class="layui-input inline-block">
|
||||||
|
<input type="$type" autocomplete="off" name="{$field}[]" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +164,17 @@ EOF;
|
|||||||
$this->inputRange($options);
|
$this->inputRange($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字输入框模糊查询
|
||||||
|
* @param $options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function inputNumberLike($options)
|
||||||
|
{
|
||||||
|
$options['props']['type'] = 'number';
|
||||||
|
$this->inputLike($options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码输入框
|
* 密码输入框
|
||||||
* @param $options
|
* @param $options
|
||||||
@ -730,8 +767,12 @@ EOF;
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 范围查询
|
// 范围查询
|
||||||
if ($type == 'search' && $info['search_type'] == 'between' && method_exists($form, "{$control}Range")) {
|
if ($type == 'search') {
|
||||||
$control = "{$control}Range";
|
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 = [
|
$options = [
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace plugin\admin\app\common;
|
namespace Webman\Admin\plugin\admin\app\common;
|
||||||
|
|
||||||
|
use process\Monitor;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Illuminate\Database\Connection;
|
use Illuminate\Database\Connection;
|
||||||
use Illuminate\Database\Schema\Builder;
|
use Illuminate\Database\Schema\Builder;
|
||||||
@ -10,6 +11,8 @@ use support\exception\BusinessException;
|
|||||||
use support\Db;
|
use support\Db;
|
||||||
use Workerman\Timer;
|
use Workerman\Timer;
|
||||||
use Workerman\Worker;
|
use Workerman\Worker;
|
||||||
|
use function plugin\admin\app\common\base_path;
|
||||||
|
use function plugin\admin\app\common\config;
|
||||||
|
|
||||||
class Util
|
class Util
|
||||||
{
|
{
|
||||||
@ -521,7 +524,7 @@ class Util
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reload webman
|
* Reload webman
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function reloadWebman()
|
public static function reloadWebman()
|
||||||
@ -539,4 +542,26 @@ class Util
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause file monitor
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function pauseFileMonitor()
|
||||||
|
{
|
||||||
|
if (method_exists(Monitor::class, 'pause')) {
|
||||||
|
Monitor::pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resume file monitor
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function resumeFileMonitor()
|
||||||
|
{
|
||||||
|
if (method_exists(Monitor::class, 'resume')) {
|
||||||
|
Monitor::resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace plugin\admin\app\controller;
|
namespace Webman\Admin\plugin\admin\app\controller;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use plugin\admin\app\common\Auth;
|
use plugin\admin\app\common\Auth;
|
||||||
use plugin\admin\app\common\Tree;
|
use plugin\admin\app\common\Tree;
|
||||||
use plugin\admin\app\common\Util;
|
use plugin\admin\app\common\Util;
|
||||||
|
use plugin\admin\app\controller\Base;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Model;
|
use support\Model;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use function plugin\admin\app\controller\config;
|
||||||
|
use function plugin\admin\app\controller\json;
|
||||||
|
|
||||||
class Crud extends Base
|
class Crud extends Base
|
||||||
{
|
{
|
||||||
@ -129,7 +132,9 @@ class Crud extends Base
|
|||||||
$model = $this->model;
|
$model = $this->model;
|
||||||
foreach ($where as $column => $value) {
|
foreach ($where as $column => $value) {
|
||||||
if (is_array($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]);
|
$model = $model->where($column, $value[0], $value[1]);
|
||||||
} elseif ($value[0] == 'in') {
|
} elseif ($value[0] == 'in') {
|
||||||
$model = $model->whereIn($column, $value[1]);
|
$model = $model->whereIn($column, $value[1]);
|
||||||
@ -139,7 +144,7 @@ class Crud extends Base
|
|||||||
$model = $model->whereNull($column, $value[1]);
|
$model = $model->whereNull($column, $value[1]);
|
||||||
} elseif ($value[0] == 'not null') {
|
} elseif ($value[0] == 'not null') {
|
||||||
$model = $model->whereNotNull($column, $value[1]);
|
$model = $model->whereNotNull($column, $value[1]);
|
||||||
} else {
|
} elseif ($value[0] !== '' || $value[1] !== '') {
|
||||||
$model = $model->whereBetween($column, $value);
|
$model = $model->whereBetween($column, $value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace plugin\admin\app\controller;
|
namespace Webman\Admin\plugin\admin\app\controller;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use plugin\admin\app\common\Util;
|
use plugin\admin\app\common\Util;
|
||||||
|
use plugin\admin\app\controller\Base;
|
||||||
use process\Monitor;
|
use process\Monitor;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
@ -13,6 +14,13 @@ use support\Response;
|
|||||||
use ZIPARCHIVE;
|
use ZIPARCHIVE;
|
||||||
use function array_diff;
|
use function array_diff;
|
||||||
use function ini_get;
|
use function ini_get;
|
||||||
|
use function plugin\admin\app\controller\base_path;
|
||||||
|
use function plugin\admin\app\controller\config;
|
||||||
|
use function plugin\admin\app\controller\get_realpath;
|
||||||
|
use function plugin\admin\app\controller\is_phar;
|
||||||
|
use function plugin\admin\app\controller\json;
|
||||||
|
use function plugin\admin\app\controller\response;
|
||||||
|
use function plugin\admin\app\controller\session;
|
||||||
use function scandir;
|
use function scandir;
|
||||||
use const DIRECTORY_SEPARATOR;
|
use const DIRECTORY_SEPARATOR;
|
||||||
use const PATH_SEPARATOR;
|
use const PATH_SEPARATOR;
|
||||||
@ -113,10 +121,7 @@ class PluginController extends Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$monitor_support_pause = method_exists(Monitor::class, 'pause');
|
Util::pauseFileMonitor();
|
||||||
if ($monitor_support_pause) {
|
|
||||||
Monitor::pause();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// 解压zip到plugin目录
|
// 解压zip到plugin目录
|
||||||
if ($has_zip_archive) {
|
if ($has_zip_archive) {
|
||||||
@ -154,9 +159,7 @@ class PluginController extends Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if ($monitor_support_pause) {
|
Util::resumeFileMonitor();
|
||||||
Monitor::resume();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Util::reloadWebman();
|
Util::reloadWebman();
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace plugin\admin\app\controller;
|
namespace Webman\Admin\plugin\admin\app\controller;
|
||||||
|
|
||||||
use Doctrine\Inflector\InflectorFactory;
|
use Doctrine\Inflector\InflectorFactory;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use plugin\admin\app\common\Layui;
|
use plugin\admin\app\common\Layui;
|
||||||
use plugin\admin\app\common\Util;
|
use plugin\admin\app\common\Util;
|
||||||
|
use plugin\admin\app\controller\Base;
|
||||||
use plugin\admin\app\model\Role;
|
use plugin\admin\app\model\Role;
|
||||||
use plugin\admin\app\model\Rule;
|
use plugin\admin\app\model\Rule;
|
||||||
use plugin\admin\app\model\Option;
|
use plugin\admin\app\model\Option;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use Throwable;
|
||||||
|
use function plugin\admin\app\controller\base_path;
|
||||||
|
use function plugin\admin\app\controller\config;
|
||||||
|
use function plugin\admin\app\controller\json;
|
||||||
|
use function plugin\admin\app\controller\view;
|
||||||
|
|
||||||
class TableController extends Base
|
class TableController extends Base
|
||||||
{
|
{
|
||||||
@ -470,45 +476,50 @@ class TableController extends Base
|
|||||||
$app = strtolower($explode[1]) !== 'controller' ? $explode[1] : '';
|
$app = strtolower($explode[1]) !== 'controller' ? $explode[1] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$model_class = $model_file_name;
|
Util::pauseFileMonitor();
|
||||||
$model_namespace = str_replace('/' , '\\', trim($model_path, '/'));
|
try {
|
||||||
|
$model_class = $model_file_name;
|
||||||
|
$model_namespace = str_replace('/', '\\', trim($model_path, '/'));
|
||||||
|
|
||||||
// 创建model
|
// 创建model
|
||||||
$this->createModel($model_class, $model_namespace, base_path($model_file), $table_name);
|
$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_suffix = $plugin ? config("plugin.$plugin.app.controller_suffix") : config('app.controller_suffix');
|
||||||
$controller_class = $controller_file_name;
|
$controller_class = $controller_file_name;
|
||||||
$controller_namespace = str_replace('/' , '\\', trim($controller_path, '/'));
|
$controller_namespace = str_replace('/', '\\', trim($controller_path, '/'));
|
||||||
// 创建controller
|
// 创建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 = $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_url_name = str_replace('_', '-', $inflector->tableize($controller_url_name));
|
||||||
|
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
array_splice($explode, 0, 2);
|
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]);
|
|
||||||
}
|
}
|
||||||
|
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();
|
$menu = Rule::where('key', $controller_class_with_namespace)->first();
|
||||||
if (!$menu) {
|
if (!$menu) {
|
||||||
$menu = new Rule;
|
$menu = new Rule;
|
||||||
@ -570,7 +581,7 @@ class TableController extends Base
|
|||||||
$properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n";
|
$properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n";
|
||||||
$columns[$item->COLUMN_NAME] = $item->COLUMN_NAME;
|
$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'])) {
|
if (!isset($columns['created_at']) || !isset($columns['updated_at'])) {
|
||||||
$timestamps = <<<EOF
|
$timestamps = <<<EOF
|
||||||
/**
|
/**
|
||||||
@ -1179,17 +1190,21 @@ EOF;
|
|||||||
}
|
}
|
||||||
if (isset($allow_column[$column])) {
|
if (isset($allow_column[$column])) {
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
if (in_array($value[0], ['', 'undefined']) || in_array($value[1], ['', 'undefined'])) {
|
if ($value[0] === 'like') {
|
||||||
continue;
|
$paginator = $paginator->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 {
|
} else {
|
||||||
$paginator = $paginator->where($column, $value);
|
$paginator = $paginator->where($column, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$paginator = $paginator->orderBy($field, $order)->paginate($limit, '*', 'page', $page);
|
$paginator = $paginator->orderBy($field, $order)->paginate($limit, '*', 'page', $page);
|
||||||
|
|
||||||
$items = $paginator->items();
|
$items = $paginator->items();
|
||||||
if ($format == 'tree') {
|
if ($format == 'tree') {
|
||||||
$items_map = [];
|
$items_map = [];
|
||||||
|
@ -160,7 +160,7 @@
|
|||||||
|
|
||||||
<script type="text/html" id="form-search_type">
|
<script type="text/html" id="form-search_type">
|
||||||
<select name="forms[{{ d.LAY_INDEX-1 }}][search_type]" lay-verify="">
|
<select name="forms[{{ d.LAY_INDEX-1 }}][search_type]" lay-verify="">
|
||||||
{{# layui.each([["normal", "普通查询"], ["between", "范围查询"]], function (index, item) { }}
|
{{# layui.each([["normal", "普通查询"], ["between", "范围查询"], ["like", "模糊查询"]], function (index, item) { }}
|
||||||
<option value="{{ item[0] }}" {{ d.search_type==item[0]?'selected':''}}>{{ item[1] }}</option>
|
<option value="{{ item[0] }}" {{ d.search_type==item[0]?'selected':''}}>{{ item[1] }}</option>
|
||||||
{{# }); }}
|
{{# }); }}
|
||||||
</select>
|
</select>
|
||||||
|
@ -164,7 +164,7 @@
|
|||||||
|
|
||||||
<script type="text/html" id="form-search_type">
|
<script type="text/html" id="form-search_type">
|
||||||
<select name="forms[{{ d.LAY_INDEX-1 }}][search_type]" lay-verify="">
|
<select name="forms[{{ d.LAY_INDEX-1 }}][search_type]" lay-verify="">
|
||||||
{{# layui.each([["normal", "普通查询"], ["between", "范围查询"]], function (index, item) { }}
|
{{# layui.each([["normal", "普通查询"], ["between", "范围查询"], ["like", "模糊查询"]], function (index, item) { }}
|
||||||
<option value="{{ item[0] }}" {{ d.search_type==item[0]?'selected':''}}>{{ item[1] }}</option>
|
<option value="{{ item[0] }}" {{ d.search_type==item[0]?'selected':''}}>{{ item[1] }}</option>
|
||||||
{{# }); }}
|
{{# }); }}
|
||||||
</select>
|
</select>
|
||||||
|
Loading…
Reference in New Issue
Block a user