From 945903a8bb25f1fe024b51c4c458d8af96cc6d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=97=E9=87=8C?= Date: Mon, 24 May 2021 20:31:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?validator.go=20:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=AD=A3=E5=88=99=E6=A0=A1=E9=AA=8C=E3=80=82?= =?UTF-8?q?=20verify.go=20:=20UUID=E7=9A=84=E6=AD=A3=E5=88=99=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E4=BD=BF=E7=94=A8=E7=A4=BA=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/utils/validator.go | 18 ++++++++++++++++++ server/utils/verify.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/utils/validator.go b/server/utils/validator.go index 43cc6c69..eb1cc25d 100644 --- a/server/utils/validator.go +++ b/server/utils/validator.go @@ -3,6 +3,7 @@ package utils import ( "errors" "reflect" + "regexp" "strconv" "strings" ) @@ -38,6 +39,15 @@ func NotEmpty() string { return "notEmpty" } +//@author: [zooqkl](https://github.com/zooqkl) +//@function: RegexpMatch +//@description: 正则校验 校验输入项是否满足正则表达式 +//@param: rule string +//@return: string +func RegexpMatch(rule string) string { + return "regexp=" + rule +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: Lt //@description: 小于入参(<) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较 @@ -134,6 +144,10 @@ func Verify(st interface{}, roleMap Rules) (err error) { if isBlank(val) { return errors.New(tagVal.Name + "值不能为空") } + case strings.Split(v, "=")[0] == "regexp": + if !regexpMatch(strings.Split(v, "=")[1], val.String()) { + return errors.New(tagVal.Name + "格式校验不通过") + } case compareMap[strings.Split(v, "=")[0]]: if !compareVerify(val, v) { return errors.New(tagVal.Name + "长度或值不在合法范围," + v) @@ -267,3 +281,7 @@ func compare(value interface{}, VerifyStr string) bool { return false } } + +func regexpMatch(rule, matchStr string) bool { + return regexp.MustCompile(rule).MatchString(matchStr) +} diff --git a/server/utils/verify.go b/server/utils/verify.go index 9e5796f7..aa64c62d 100644 --- a/server/utils/verify.go +++ b/server/utils/verify.go @@ -14,5 +14,5 @@ var ( AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}} OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}} ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}} - SetUserAuthorityVerify = Rules{"UUID": {NotEmpty()}, "AuthorityId": {NotEmpty()}} + SetUserAuthorityVerify = Rules{"UUID": {NotEmpty(), RegexpMatch("[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}")}, "AuthorityId": {NotEmpty()}} ) From 9eb9c02dccc15577f14b94ac021f2f66343d7347 Mon Sep 17 00:00:00 2001 From: fengchao Date: Fri, 13 Aug 2021 17:54:21 +0800 Subject: [PATCH 2/3] Fix jslint error/warning in auto generated code. Below errors are fixed in this commit: * No new line at end of file * Extra empty line * Extra white space * Wrong tab indent * Use "" to quote string --- server/resource/template/web/api.js.tpl | 2 +- server/resource/template/web/form.vue.tpl | 94 ++++++------- server/resource/template/web/table.vue.tpl | 147 +++++++++++---------- 3 files changed, 122 insertions(+), 121 deletions(-) diff --git a/server/resource/template/web/api.js.tpl b/server/resource/template/web/api.js.tpl index 9b771ba9..a8b77cf4 100644 --- a/server/resource/template/web/api.js.tpl +++ b/server/resource/template/web/api.js.tpl @@ -94,4 +94,4 @@ export const get{{.StructName}}List = (params) => { method: 'get', params }) -} \ No newline at end of file +} diff --git a/server/resource/template/web/form.vue.tpl b/server/resource/template/web/form.vue.tpl index 5a83bdd8..5fb3508b 100644 --- a/server/resource/template/web/form.vue.tpl +++ b/server/resource/template/web/form.vue.tpl @@ -3,35 +3,35 @@ {{- range .Fields}} - {{ if eq .FieldType "bool" -}} - - {{ end -}} - {{ if eq .FieldType "string" -}} - - {{ end -}} - {{ if eq .FieldType "int" -}} - {{ if .DictType -}} - - - - {{ else -}} - - {{ end -}} - {{ end -}} - {{ if eq .FieldType "time.Time" }} - - {{ end -}} - {{ if eq .FieldType "float64" }} - - {{ end -}} + {{- if eq .FieldType "bool" }} + + {{- end }} + {{- if eq .FieldType "string" }} + + {{- end }} + {{- if eq .FieldType "int" }} + {{- if .DictType }} + + + + {{- else }} + + {{- end }} + {{- end }} + {{- if eq .FieldType "time.Time" }} + + {{- end }} + {{- if eq .FieldType "float64" }} + + {{- end }} - {{ end -}} + {{- end }} 保存 返回 - + \ No newline at end of file + diff --git a/server/resource/template/web/table.vue.tpl b/server/resource/template/web/table.vue.tpl index 52d68967..a8c6f8e4 100644 --- a/server/resource/template/web/table.vue.tpl +++ b/server/resource/template/web/table.vue.tpl @@ -19,8 +19,8 @@ {{- else }} - - {{ end }} {{ end }} {{ end }} + + {{ end }}{{ end }}{{ end }} 查询 新增 @@ -52,15 +52,16 @@ {{- if .DictType}} {{- else if eq .FieldType "bool" }} {{- else }} - {{ end -}} - {{ end -}} + + {{- end }} + {{- end }}