From 3d9315b6a79760024e139c418704ff188bd7aefb Mon Sep 17 00:00:00 2001 From: tbphp Date: Wed, 16 Jul 2025 23:42:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=86=E7=BB=84=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/group_handler.go | 8 ++++---- web/src/components/keys/GroupFormModal.vue | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/handler/group_handler.go b/internal/handler/group_handler.go index cbbaea1..ce6c57a 100644 --- a/internal/handler/group_handler.go +++ b/internal/handler/group_handler.go @@ -83,8 +83,8 @@ func isValidGroupName(name string) bool { if name == "" { return false } - // 允许使用小写字母、数字和下划线,长度在 3 到 30 个字符之间 - match, _ := regexp.MatchString("^[a-z0-9_]{3,30}$", name) + // 允许使用小写字母、数字、下划线和中划线,长度在 3 到 30 个字符之间 + match, _ := regexp.MatchString("^[a-z0-9_-]{3,30}$", name) return match } @@ -151,7 +151,7 @@ func (s *Server) CreateGroup(c *gin.Context) { // Data Cleaning and Validation name := strings.TrimSpace(req.Name) if !isValidGroupName(name) { - response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "Invalid group name format. Use 3-30 lowercase letters, numbers, and underscores.")) + response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "无效的分组名称。只能包含小写字母、数字、中划线或下划线,长度3-30位")) return } @@ -265,7 +265,7 @@ func (s *Server) UpdateGroup(c *gin.Context) { if req.Name != nil { cleanedName := strings.TrimSpace(*req.Name) if !isValidGroupName(cleanedName) { - response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "Invalid group name format. Name is required and must be 3-30 lowercase letters, numbers, or underscores.")) + response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "无效的分组名称格式。只能包含小写字母、数字、中划线或下划线,长度3-30位")) return } group.Name = cleanedName diff --git a/web/src/components/keys/GroupFormModal.vue b/web/src/components/keys/GroupFormModal.vue index 285445c..53ff94a 100644 --- a/web/src/components/keys/GroupFormModal.vue +++ b/web/src/components/keys/GroupFormModal.vue @@ -92,8 +92,8 @@ const rules: FormRules = { trigger: ["blur", "input"], }, { - pattern: /^[a-z]+$/, - message: "只能输入小写字母", + pattern: /^[a-z0-9_-]{3,30}$/, + message: "只能包含小写字母、数字、中划线或下划线,长度3-30位", trigger: ["blur", "input"], }, ], @@ -330,7 +330,10 @@ async function handleSubmit() {

基础信息

- +