From 42dffe807896fd8fca8c7ee2134a3f7701c9e0f8 Mon Sep 17 00:00:00 2001
From: John Bro <42930107+john1298308460@users.noreply.github.com>
Date: Wed, 24 Apr 2024 23:08:11 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BF=AB=E9=80=9F=E5=91=BD=E4=BB=A4?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E4=B8=AD=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E5=85=B3=E9=94=AE=E8=AF=8D=E7=AD=9B=E9=80=89=20(#4679)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Refs #3525
---
backend/app/dto/command.go | 1 +
backend/app/repo/command.go | 10 +++++++
backend/app/service/command.go | 2 +-
frontend/src/api/interface/index.ts | 1 +
.../src/views/host/terminal/command/index.vue | 26 ++++++++++++++-----
5 files changed, 32 insertions(+), 8 deletions(-)
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 @@
-
- {{ $t('terminal.group') }}
-
-
-
-
-
+
+
+
+ {{ $t('terminal.group') }}
+
+
+
+
+
+
+
+
+
+
({
command: '',
});
+const commandReq = reactive({
+ name: '',
+});
+
const cmdVisible = ref(false);
const loadGroups = async () => {
@@ -274,6 +285,7 @@ const search = async (column?: any) => {
info: info.value,
orderBy: paginationConfig.orderBy,
order: paginationConfig.order,
+ name: commandReq.name,
};
loading.value = true;
await getCommandPage(params)