fix 修复代码生成日期范围查询
This commit is contained in:
parent
c235475dca
commit
f992d7dacc
108
internal/app/boot/custom_validations_boot.go
Normal file
108
internal/app/boot/custom_validations_boot.go
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package boot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/text/gregex"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
"github.com/gogf/gf/v2/util/gvalid"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gvalid.RegisterRule("integer-array", IntegerArray)
|
||||||
|
gvalid.RegisterRule("float-array", FloatArray)
|
||||||
|
gvalid.RegisterRule("date-array", DateArray)
|
||||||
|
gvalid.RegisterRule("datetime-array", DatetimeArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IntegerArray(ctx context.Context, RI gvalid.RuleFuncInput) error {
|
||||||
|
if RI.Value.IsNil() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if RI.Value.IsSlice() {
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
for _, v := range RI.Value.Array() {
|
||||||
|
valueStr := strings.TrimSpace(gconv.String(v))
|
||||||
|
if valueStr == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := strconv.Atoi(valueStr); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func FloatArray(ctx context.Context, RI gvalid.RuleFuncInput) error {
|
||||||
|
if RI.Value.IsNil() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !RI.Value.IsSlice() {
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
for _, v := range RI.Value.Array() {
|
||||||
|
valueStr := strings.TrimSpace(gconv.String(v))
|
||||||
|
if valueStr == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := strconv.ParseFloat(valueStr, 10); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DateArray(ctx context.Context, RI gvalid.RuleFuncInput) error {
|
||||||
|
if RI.Value.IsNil() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !RI.Value.IsSlice() {
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
for _, v := range RI.Value.Array() {
|
||||||
|
// support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time.
|
||||||
|
if _, ok := v.(gtime.Time); ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valueStr := strings.TrimSpace(gconv.String(v))
|
||||||
|
if valueStr == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DatetimeArray(ctx context.Context, RI gvalid.RuleFuncInput) error {
|
||||||
|
if RI.Value.IsNil() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !RI.Value.IsSlice() {
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
for _, v := range RI.Value.Array() {
|
||||||
|
// support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time.
|
||||||
|
if _, ok := v.(gtime.Time); ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valueStr := strings.TrimSpace(gconv.String(v))
|
||||||
|
if valueStr == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := gtime.StrToTimeFormat(valueStr, "Y-m-d H:i:s"); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return gerror.New(RI.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -12,7 +12,7 @@
|
|||||||
<el-row>
|
<el-row>
|
||||||
{{$colIndex := 0}}
|
{{$colIndex := 0}}
|
||||||
{{range $index, $column := .table.QueryColumns}}
|
{{range $index, $column := .table.QueryColumns}}
|
||||||
{{if and $column.IsQuery (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") (ne $column.ColumnName "created_at") (ne $column.ColumnName "updated_at") (ne $column.ColumnName "deleted_at")}}
|
{{if and $column.IsQuery (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") }}
|
||||||
{{if eq $colIndex 2}}
|
{{if eq $colIndex 2}}
|
||||||
<el-col :span="8" :class="!showAll ? 'colBlock' : 'colNone'">
|
<el-col :span="8" :class="!showAll ? 'colBlock' : 'colNone'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
@ -68,6 +68,7 @@
|
|||||||
<el-date-picker
|
<el-date-picker
|
||||||
clearable style="width: 200px"
|
clearable style="width: 200px"
|
||||||
v-model="tableData.param.{{$column.HtmlField}}"
|
v-model="tableData.param.{{$column.HtmlField}}"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
{{if eq $column.QueryType "BETWEEN"}}
|
{{if eq $column.QueryType "BETWEEN"}}
|
||||||
type="daterange"
|
type="daterange"
|
||||||
range-separator="至"
|
range-separator="至"
|
||||||
@ -87,6 +88,8 @@
|
|||||||
<el-date-picker
|
<el-date-picker
|
||||||
clearable style="width: 200px"
|
clearable style="width: 200px"
|
||||||
v-model="tableData.param.{{$column.HtmlField}}"
|
v-model="tableData.param.{{$column.HtmlField}}"
|
||||||
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
{{if eq $column.QueryType "BETWEEN"}}
|
{{if eq $column.QueryType "BETWEEN"}}
|
||||||
type="datetimerange"
|
type="datetimerange"
|
||||||
range-separator="至"
|
range-separator="至"
|
||||||
@ -129,21 +132,6 @@
|
|||||||
{{$colIndex = ($colIndex | plus 1)}}
|
{{$colIndex = ($colIndex | plus 1)}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if eq $column.ColumnName "created_at"}}
|
|
||||||
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
|
|
||||||
<el-form-item label="创建日期" prop="dateRange">
|
|
||||||
<el-date-picker
|
|
||||||
clearable style="width: 200px"
|
|
||||||
v-model="tableData.param.dateRange"
|
|
||||||
type="daterange"
|
|
||||||
range-separator="-"
|
|
||||||
value-format="YYYY-MM-DD"
|
|
||||||
start-placeholder="开始日期"
|
|
||||||
end-placeholder="结束日期"
|
|
||||||
></el-date-picker>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if gt $colIndex 2}}
|
{{if gt $colIndex 2}}
|
||||||
<el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
|
<el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<el-row>
|
<el-row>
|
||||||
{{$colIndex := 0}}
|
{{$colIndex := 0}}
|
||||||
{{range $index, $column := .table.QueryColumns}}
|
{{range $index, $column := .table.QueryColumns}}
|
||||||
{{if and $column.IsQuery (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") (ne $column.ColumnName "created_at") (ne $column.ColumnName "updated_at") (ne $column.ColumnName "deleted_at")}}
|
{{if and $column.IsQuery (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by")}}
|
||||||
{{if eq $colIndex 2}}
|
{{if eq $colIndex 2}}
|
||||||
<el-col :span="8" :class="!showAll ? 'colBlock' : 'colNone'">
|
<el-col :span="8" :class="!showAll ? 'colBlock' : 'colNone'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
@ -71,6 +71,7 @@
|
|||||||
<el-date-picker
|
<el-date-picker
|
||||||
clearable style="width: 200px"
|
clearable style="width: 200px"
|
||||||
v-model="tableData.param.{{$column.HtmlField}}"
|
v-model="tableData.param.{{$column.HtmlField}}"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
{{if eq $column.QueryType "BETWEEN"}}
|
{{if eq $column.QueryType "BETWEEN"}}
|
||||||
type="daterange"
|
type="daterange"
|
||||||
range-separator="至"
|
range-separator="至"
|
||||||
@ -90,6 +91,8 @@
|
|||||||
<el-date-picker
|
<el-date-picker
|
||||||
clearable style="width: 200px"
|
clearable style="width: 200px"
|
||||||
v-model="tableData.param.{{$column.HtmlField}}"
|
v-model="tableData.param.{{$column.HtmlField}}"
|
||||||
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
{{if eq $column.QueryType "BETWEEN"}}
|
{{if eq $column.QueryType "BETWEEN"}}
|
||||||
type="datetimerange"
|
type="datetimerange"
|
||||||
range-separator="至"
|
range-separator="至"
|
||||||
@ -132,21 +135,6 @@
|
|||||||
{{$colIndex = ($colIndex | plus 1)}}
|
{{$colIndex = ($colIndex | plus 1)}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if eq $column.ColumnName "created_at"}}
|
|
||||||
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
|
|
||||||
<el-form-item label="创建日期" prop="dateRange">
|
|
||||||
<el-date-picker
|
|
||||||
clearable style="width: 200px"
|
|
||||||
v-model="tableData.param.dateRange"
|
|
||||||
type="daterange"
|
|
||||||
range-separator="-"
|
|
||||||
value-format="YYYY-MM-DD"
|
|
||||||
start-placeholder="开始日期"
|
|
||||||
end-placeholder="结束日期"
|
|
||||||
></el-date-picker>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if gt $colIndex 2}}
|
{{if gt $colIndex 2}}
|
||||||
<el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
|
<el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user