From 425113a0d7fe664e5ac95122d745408c7f328f2a Mon Sep 17 00:00:00 2001 From: walkor Date: Tue, 16 May 2023 12:02:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/admin/app/common/Layui.php | 14 ++++++++++++-- .../admin/app/controller/TableController.php | 10 ++++++++++ src/plugin/admin/app/view/table/view.html | 10 ++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/plugin/admin/app/common/Layui.php b/src/plugin/admin/app/common/Layui.php index 1d93e7e..0cfc90e 100644 --- a/src/plugin/admin/app/common/Layui.php +++ b/src/plugin/admin/app/common/Layui.php @@ -816,10 +816,10 @@ EOF; $props['value'] = $default; } // 表单不显示主键 - if (($filter == 'form_show' && $primary_key && $field == $primary_key && $auto_increment)) { + if ($filter == 'form_show' && $primary_key && $field == $primary_key && $auto_increment) { continue; } - // 范围查询 + // 查询类型 if ($type == 'search') { if ($info['search_type'] == 'between' && method_exists($form, "{$control}Range")) { $control = "{$control}Range"; @@ -827,6 +827,16 @@ EOF; $control = "{$control}Like"; } } + // 查询移除required + if ($type == 'search' && !empty($props['lay-verify'])) { + $verify_items = explode('|', $props['lay-verify']); + foreach ($verify_items as $key => $value) { + if ($value === 'required') { + unset($verify_items[$key]); + } + } + $props['lay-verify'] = implode('|', $verify_items); + } $options = [ 'label' => $info['comment'] ?: $field, diff --git a/src/plugin/admin/app/controller/TableController.php b/src/plugin/admin/app/controller/TableController.php index 0acd067..84aa0d7 100644 --- a/src/plugin/admin/app/controller/TableController.php +++ b/src/plugin/admin/app/controller/TableController.php @@ -871,6 +871,16 @@ EOF where: [] }) }); + + // 字段允许为空 + form.verify({ + phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"], + email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"], + url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"], + number: [/(^$)|^\d+$/,'只能填写数字'], + date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"], + identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"] + }); // 表格排序事件 table.on("sort(data-table)", function(obj){ diff --git a/src/plugin/admin/app/view/table/view.html b/src/plugin/admin/app/view/table/view.html index 91bd15f..8ed3d24 100644 --- a/src/plugin/admin/app/view/table/view.html +++ b/src/plugin/admin/app/view/table/view.html @@ -237,6 +237,16 @@ } }); + // 字段允许为空 + form.verify({ + phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"], + email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"], + url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"], + number: [/(^$)|^\d+$/,'只能填写数字'], + date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"], + identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"] + }); + form.on("submit(table-query)", function(data) { table.reload("data-table", { where: data.field