1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

feat: 主机快速命令增加排序 (#3707)

This commit is contained in:
ssongliu 2024-01-26 13:45:41 +08:00 committed by GitHub
parent bbe1161dc2
commit 36a253ce03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 12 deletions

View File

@ -2,6 +2,8 @@ package dto
type SearchCommandWithPage struct { type SearchCommandWithPage struct {
SearchWithPage SearchWithPage
OrderBy string `json:"orderBy"`
Order string `json:"order"`
GroupID uint `json:"groupID"` GroupID uint `json:"groupID"`
Info string `json:"info"` Info string `json:"info"`
} }

View File

@ -23,7 +23,7 @@ func NewICommandService() ICommandService {
} }
func (u *CommandService) List() ([]dto.CommandInfo, error) { func (u *CommandService) List() ([]dto.CommandInfo, error) {
commands, err := commandRepo.GetList() commands, err := commandRepo.GetList(commonRepo.WithOrderBy("name"))
if err != nil { if err != nil {
return nil, constant.ErrRecordNotFound return nil, constant.ErrRecordNotFound
} }
@ -39,7 +39,7 @@ func (u *CommandService) List() ([]dto.CommandInfo, error) {
} }
func (u *CommandService) SearchForTree() ([]dto.CommandTree, error) { func (u *CommandService) SearchForTree() ([]dto.CommandTree, error) {
cmdList, err := commandRepo.GetList() cmdList, err := commandRepo.GetList(commonRepo.WithOrderBy("name"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -65,11 +65,11 @@ func (u *CommandService) SearchForTree() ([]dto.CommandTree, error) {
} }
func (u *CommandService) SearchWithPage(search dto.SearchCommandWithPage) (int64, interface{}, 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 { if err != nil {
return 0, nil, err return 0, nil, err
} }
groups, _ := groupRepo.GetList(commonRepo.WithByType("command")) groups, _ := groupRepo.GetList(commonRepo.WithByType("command"), commonRepo.WithOrderBy("name"))
var dtoCommands []dto.CommandInfo var dtoCommands []dto.CommandInfo
for _, command := range commands { for _, command := range commands {
var item dto.CommandInfo var item dto.CommandInfo

View File

@ -1,5 +1,3 @@
import { ReqPage } from '.';
export namespace Command { export namespace Command {
export interface CommandInfo { export interface CommandInfo {
id: number; id: number;
@ -13,7 +11,4 @@ export namespace Command {
groupID: number; groupID: number;
command: string; command: string;
} }
export interface CommandSearch extends ReqPage {
info: string;
}
} }

View File

@ -1,5 +1,5 @@
import http from '@/api'; import http from '@/api';
import { ResPage } from '../interface'; import { ResPage, SearchWithPage } from '../interface';
import { Command } from '../interface/command'; import { Command } from '../interface/command';
import { Host } from '../interface/host'; import { Host } from '../interface/host';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
@ -56,7 +56,7 @@ export const deleteHost = (params: { ids: number[] }) => {
export const getCommandList = () => { export const getCommandList = () => {
return http.get<Array<Command.CommandInfo>>(`/hosts/command`, {}); return http.get<Array<Command.CommandInfo>>(`/hosts/command`, {});
}; };
export const getCommandPage = (params: Command.CommandSearch) => { export const getCommandPage = (params: SearchWithPage) => {
return http.post<ResPage<Command.CommandInfo>>(`/hosts/command/search`, params); return http.post<ResPage<Command.CommandInfo>>(`/hosts/command/search`, params);
}; };
export const getCommandTree = () => { export const getCommandTree = () => {

View File

@ -29,6 +29,7 @@
:pagination-config="paginationConfig" :pagination-config="paginationConfig"
v-model:selects="selects" v-model:selects="selects"
:data="data" :data="data"
@sort-change="search"
@search="search" @search="search"
> >
<el-table-column type="selection" fix /> <el-table-column type="selection" fix />
@ -38,12 +39,14 @@
min-width="100" min-width="100"
prop="name" prop="name"
fix fix
sortable
/> />
<el-table-column <el-table-column
:label="$t('terminal.command')" :label="$t('terminal.command')"
min-width="300" min-width="300"
show-overflow-tooltip show-overflow-tooltip
prop="command" prop="command"
sortable
/> />
<el-table-column <el-table-column
:label="$t('commons.table.group')" :label="$t('commons.table.group')"
@ -128,6 +131,8 @@ const paginationConfig = reactive({
currentPage: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
orderBy: 'name',
order: 'ascending',
}); });
const info = ref(); const info = ref();
const group = ref<string>(''); const group = ref<string>('');
@ -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 = { let params = {
page: paginationConfig.currentPage, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
groupID: Number(group.value), groupID: Number(group.value),
info: info.value, info: info.value,
orderBy: paginationConfig.orderBy,
order: paginationConfig.order,
}; };
loading.value = true; loading.value = true;
await getCommandPage(params) await getCommandPage(params)