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