支持模糊搜索
This commit is contained in:
parent
4cba3c47d9
commit
ea86e944cf
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace plugin\admin\app\common;
|
||||
namespace Webman\Admin\plugin\admin\app\common;
|
||||
|
||||
use plugin\admin\app\common\Util;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class Layui
|
||||
@ -124,6 +125,31 @@ EOF;
|
||||
</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;
|
||||
}
|
||||
|
||||
@ -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")) {
|
||||
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 = [
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\common;
|
||||
namespace Webman\Admin\plugin\admin\app\common;
|
||||
|
||||
use process\Monitor;
|
||||
use Throwable;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
@ -10,6 +11,8 @@ use support\exception\BusinessException;
|
||||
use support\Db;
|
||||
use Workerman\Timer;
|
||||
use Workerman\Worker;
|
||||
use function plugin\admin\app\common\base_path;
|
||||
use function plugin\admin\app\common\config;
|
||||
|
||||
class Util
|
||||
{
|
||||
@ -521,7 +524,7 @@ class Util
|
||||
|
||||
|
||||
/**
|
||||
* reload webman
|
||||
* Reload webman
|
||||
* @return bool
|
||||
*/
|
||||
public static function reloadWebman()
|
||||
@ -539,4 +542,26 @@ class Util
|
||||
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
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
namespace Webman\Admin\plugin\admin\app\controller;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use plugin\admin\app\common\Auth;
|
||||
use plugin\admin\app\common\Tree;
|
||||
use plugin\admin\app\common\Util;
|
||||
use plugin\admin\app\controller\Base;
|
||||
use support\exception\BusinessException;
|
||||
use support\Model;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use function plugin\admin\app\controller\config;
|
||||
use function plugin\admin\app\controller\json;
|
||||
|
||||
class Crud extends Base
|
||||
{
|
||||
@ -129,7 +132,9 @@ class Crud extends Base
|
||||
$model = $this->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 {
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
namespace Webman\Admin\plugin\admin\app\controller;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use plugin\admin\app\common\Util;
|
||||
use plugin\admin\app\controller\Base;
|
||||
use process\Monitor;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
@ -13,6 +14,13 @@ use support\Response;
|
||||
use ZIPARCHIVE;
|
||||
use function array_diff;
|
||||
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 const DIRECTORY_SEPARATOR;
|
||||
use const PATH_SEPARATOR;
|
||||
@ -113,10 +121,7 @@ class PluginController extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$monitor_support_pause = method_exists(Monitor::class, 'pause');
|
||||
if ($monitor_support_pause) {
|
||||
Monitor::pause();
|
||||
}
|
||||
Util::pauseFileMonitor();
|
||||
try {
|
||||
// 解压zip到plugin目录
|
||||
if ($has_zip_archive) {
|
||||
@ -154,9 +159,7 @@ class PluginController extends Base
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if ($monitor_support_pause) {
|
||||
Monitor::resume();
|
||||
}
|
||||
Util::resumeFileMonitor();
|
||||
}
|
||||
|
||||
Util::reloadWebman();
|
||||
|
@ -1,17 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
namespace Webman\Admin\plugin\admin\app\controller;
|
||||
|
||||
use Doctrine\Inflector\InflectorFactory;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use plugin\admin\app\common\Layui;
|
||||
use plugin\admin\app\common\Util;
|
||||
use plugin\admin\app\controller\Base;
|
||||
use plugin\admin\app\model\Role;
|
||||
use plugin\admin\app\model\Rule;
|
||||
use plugin\admin\app\model\Option;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
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
|
||||
{
|
||||
@ -470,15 +476,17 @@ class TableController extends Base
|
||||
$app = strtolower($explode[1]) !== 'controller' ? $explode[1] : '';
|
||||
}
|
||||
|
||||
Util::pauseFileMonitor();
|
||||
try {
|
||||
$model_class = $model_file_name;
|
||||
$model_namespace = str_replace('/' , '\\', trim($model_path, '/'));
|
||||
$model_namespace = str_replace('/', '\\', trim($model_path, '/'));
|
||||
|
||||
// 创建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_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));
|
||||
@ -508,6 +516,9 @@ class TableController extends Base
|
||||
$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();
|
||||
}
|
||||
|
||||
$menu = Rule::where('key', $controller_class_with_namespace)->first();
|
||||
if (!$menu) {
|
||||
@ -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 = <<<EOF
|
||||
/**
|
||||
@ -1179,17 +1190,21 @@ EOF;
|
||||
}
|
||||
if (isset($allow_column[$column])) {
|
||||
if (is_array($value)) {
|
||||
if (in_array($value[0], ['', 'undefined']) || in_array($value[1], ['', 'undefined'])) {
|
||||
continue;
|
||||
}
|
||||
if ($value[0] === 'like') {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$paginator = $paginator->where($column, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$paginator = $paginator->orderBy($field, $order)->paginate($limit, '*', 'page', $page);
|
||||
|
||||
$items = $paginator->items();
|
||||
if ($format == 'tree') {
|
||||
$items_map = [];
|
||||
|
@ -160,7 +160,7 @@
|
||||
|
||||
<script type="text/html" id="form-search_type">
|
||||
<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>
|
||||
{{# }); }}
|
||||
</select>
|
||||
|
@ -164,7 +164,7 @@
|
||||
|
||||
<script type="text/html" id="form-search_type">
|
||||
<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>
|
||||
{{# }); }}
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user