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

fix: 快速命令管理页面中增加关键词筛选 (#4679)

Refs #3525
This commit is contained in:
John Bro 2024-04-24 23:08:11 +08:00 committed by GitHub
parent 92f019cf7c
commit 42dffe8078
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 8 deletions

View File

@ -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 {

View File

@ -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+"%")
}
}

View File

@ -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
}

View File

@ -24,6 +24,7 @@ export interface SearchWithPage {
pageSize: number;
orderBy?: string;
order?: string;
name?: string;
}
export interface CommonModel {
id: number;

View File

@ -16,13 +16,20 @@
</el-button>
</template>
<template #search>
<el-select v-model="group" @change="search()" clearable class="p-w-200">
<template #prefix>{{ $t('terminal.group') }}</template>
<el-option :label="$t('commons.table.all')" value=""></el-option>
<div v-for="item in groupList" :key="item.name">
<el-option :value="item.id" :label="item.name" />
</div>
</el-select>
<el-row :gutter="5">
<el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
<el-select v-model="group" @change="search()" clearable class="p-w-200">
<template #prefix>{{ $t('terminal.group') }}</template>
<el-option :label="$t('commons.table.all')" value=""></el-option>
<div v-for="item in groupList" :key="item.name">
<el-option :value="item.id" :label="item.name" />
</div>
</el-select>
</el-col>
<el-col :xs="24" :sm="4" :md="4" :lg="4" :xl="4">
<TableSearch @search="search()" v-model:searchName="commandReq.name" />
</el-col>
</el-row>
</template>
<template #main>
<ComplexTable
@ -160,6 +167,10 @@ let commandInfo = reactive<Command.CommandOperate>({
command: '',
});
const commandReq = reactive({
name: '',
});
const cmdVisible = ref<boolean>(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)