diff --git a/backend/app/dto/command.go b/backend/app/dto/command.go index f2dc2a1fc..caa9115c6 100644 --- a/backend/app/dto/command.go +++ b/backend/app/dto/command.go @@ -6,6 +6,7 @@ type SearchCommandWithPage struct { Order string `json:"order"` GroupID uint `json:"groupID"` Info string `json:"info"` + Name string `json:"name"` } type CommandOperate struct { diff --git a/backend/app/repo/command.go b/backend/app/repo/command.go index a61809617..4abe27335 100644 --- a/backend/app/repo/command.go +++ b/backend/app/repo/command.go @@ -16,6 +16,7 @@ type ICommandRepo interface { Update(id uint, vars map[string]interface{}) error Delete(opts ...DBOption) error Get(opts ...DBOption) (model.Command, error) + WithLikeName(name string) DBOption } func NewICommandRepo() ICommandRepo { @@ -79,3 +80,12 @@ func (u *CommandRepo) Delete(opts ...DBOption) error { } return db.Delete(&model.Command{}).Error } + +func (a CommandRepo) WithLikeName(name string) DBOption { + return func(g *gorm.DB) *gorm.DB { + if len(name) == 0 { + return g + } + return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%") + } +} diff --git a/backend/app/service/command.go b/backend/app/service/command.go index 2b16a554a..67f5c656b 100644 --- a/backend/app/service/command.go +++ b/backend/app/service/command.go @@ -65,7 +65,7 @@ func (u *CommandService) SearchForTree() ([]dto.CommandTree, error) { } func (u *CommandService) SearchWithPage(search dto.SearchCommandWithPage) (int64, interface{}, error) { - total, commands, err := commandRepo.Page(search.Page, search.PageSize, commonRepo.WithLikeName(search.Info), commonRepo.WithByGroupID(search.GroupID), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) + total, commands, err := commandRepo.Page(search.Page, search.PageSize, commandRepo.WithLikeName(search.Name), commonRepo.WithLikeName(search.Info), commonRepo.WithByGroupID(search.GroupID), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) if err != nil { return 0, nil, err } diff --git a/frontend/src/api/interface/index.ts b/frontend/src/api/interface/index.ts index 02e14acb1..411be2e67 100644 --- a/frontend/src/api/interface/index.ts +++ b/frontend/src/api/interface/index.ts @@ -24,6 +24,7 @@ export interface SearchWithPage { pageSize: number; orderBy?: string; order?: string; + name?: string; } export interface CommonModel { id: number; diff --git a/frontend/src/views/host/terminal/command/index.vue b/frontend/src/views/host/terminal/command/index.vue index 43b066017..1fdbb49aa 100644 --- a/frontend/src/views/host/terminal/command/index.vue +++ b/frontend/src/views/host/terminal/command/index.vue @@ -16,13 +16,20 @@