From 36a253ce0322ee512bbf2f95787480ccd69a38a7 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:45:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BB=E6=9C=BA=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=A2=9E=E5=8A=A0=E6=8E=92=E5=BA=8F=20(#3707?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/command.go | 2 ++ backend/app/service/command.go | 8 ++++---- frontend/src/api/interface/command.ts | 5 ----- frontend/src/api/modules/host.ts | 4 ++-- frontend/src/views/host/terminal/command/index.vue | 11 ++++++++++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/backend/app/dto/command.go b/backend/app/dto/command.go index 04f5721df..f2dc2a1fc 100644 --- a/backend/app/dto/command.go +++ b/backend/app/dto/command.go @@ -2,6 +2,8 @@ package dto type SearchCommandWithPage struct { SearchWithPage + OrderBy string `json:"orderBy"` + Order string `json:"order"` GroupID uint `json:"groupID"` Info string `json:"info"` } diff --git a/backend/app/service/command.go b/backend/app/service/command.go index a2ceb2210..2b16a554a 100644 --- a/backend/app/service/command.go +++ b/backend/app/service/command.go @@ -23,7 +23,7 @@ func NewICommandService() ICommandService { } func (u *CommandService) List() ([]dto.CommandInfo, error) { - commands, err := commandRepo.GetList() + commands, err := commandRepo.GetList(commonRepo.WithOrderBy("name")) if err != nil { return nil, constant.ErrRecordNotFound } @@ -39,7 +39,7 @@ func (u *CommandService) List() ([]dto.CommandInfo, error) { } func (u *CommandService) SearchForTree() ([]dto.CommandTree, error) { - cmdList, err := commandRepo.GetList() + cmdList, err := commandRepo.GetList(commonRepo.WithOrderBy("name")) if err != nil { return nil, err } @@ -65,11 +65,11 @@ 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)) + total, commands, err := commandRepo.Page(search.Page, search.PageSize, commonRepo.WithLikeName(search.Info), commonRepo.WithByGroupID(search.GroupID), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) if err != nil { return 0, nil, err } - groups, _ := groupRepo.GetList(commonRepo.WithByType("command")) + groups, _ := groupRepo.GetList(commonRepo.WithByType("command"), commonRepo.WithOrderBy("name")) var dtoCommands []dto.CommandInfo for _, command := range commands { var item dto.CommandInfo diff --git a/frontend/src/api/interface/command.ts b/frontend/src/api/interface/command.ts index b399c43e0..b59757320 100644 --- a/frontend/src/api/interface/command.ts +++ b/frontend/src/api/interface/command.ts @@ -1,5 +1,3 @@ -import { ReqPage } from '.'; - export namespace Command { export interface CommandInfo { id: number; @@ -13,7 +11,4 @@ export namespace Command { groupID: number; command: string; } - export interface CommandSearch extends ReqPage { - info: string; - } } diff --git a/frontend/src/api/modules/host.ts b/frontend/src/api/modules/host.ts index 165fa44b9..50488de9e 100644 --- a/frontend/src/api/modules/host.ts +++ b/frontend/src/api/modules/host.ts @@ -1,5 +1,5 @@ import http from '@/api'; -import { ResPage } from '../interface'; +import { ResPage, SearchWithPage } from '../interface'; import { Command } from '../interface/command'; import { Host } from '../interface/host'; import { Base64 } from 'js-base64'; @@ -56,7 +56,7 @@ export const deleteHost = (params: { ids: number[] }) => { export const getCommandList = () => { return http.get>(`/hosts/command`, {}); }; -export const getCommandPage = (params: Command.CommandSearch) => { +export const getCommandPage = (params: SearchWithPage) => { return http.post>(`/hosts/command/search`, params); }; export const getCommandTree = () => { diff --git a/frontend/src/views/host/terminal/command/index.vue b/frontend/src/views/host/terminal/command/index.vue index c07c3f192..3d8d11fb6 100644 --- a/frontend/src/views/host/terminal/command/index.vue +++ b/frontend/src/views/host/terminal/command/index.vue @@ -29,6 +29,7 @@ :pagination-config="paginationConfig" v-model:selects="selects" :data="data" + @sort-change="search" @search="search" > @@ -38,12 +39,14 @@ min-width="100" prop="name" fix + sortable /> (''); @@ -260,12 +265,16 @@ const buttons = [ }, ]; -const search = async () => { +const search = async (column?: any) => { + paginationConfig.orderBy = column?.order ? column.prop : paginationConfig.orderBy; + paginationConfig.order = column?.order ? column.order : paginationConfig.order; let params = { page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, groupID: Number(group.value), info: info.value, + orderBy: paginationConfig.orderBy, + order: paginationConfig.order, }; loading.value = true; await getCommandPage(params)