1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +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"` Order string `json:"order"`
GroupID uint `json:"groupID"` GroupID uint `json:"groupID"`
Info string `json:"info"` Info string `json:"info"`
Name string `json:"name"`
} }
type CommandOperate struct { type CommandOperate struct {

View File

@ -16,6 +16,7 @@ type ICommandRepo interface {
Update(id uint, vars map[string]interface{}) error Update(id uint, vars map[string]interface{}) error
Delete(opts ...DBOption) error Delete(opts ...DBOption) error
Get(opts ...DBOption) (model.Command, error) Get(opts ...DBOption) (model.Command, error)
WithLikeName(name string) DBOption
} }
func NewICommandRepo() ICommandRepo { func NewICommandRepo() ICommandRepo {
@ -79,3 +80,12 @@ func (u *CommandRepo) Delete(opts ...DBOption) error {
} }
return db.Delete(&model.Command{}).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) { 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 { if err != nil {
return 0, nil, err return 0, nil, err
} }

View File

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

View File

@ -16,6 +16,8 @@
</el-button> </el-button>
</template> </template>
<template #search> <template #search>
<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"> <el-select v-model="group" @change="search()" clearable class="p-w-200">
<template #prefix>{{ $t('terminal.group') }}</template> <template #prefix>{{ $t('terminal.group') }}</template>
<el-option :label="$t('commons.table.all')" value=""></el-option> <el-option :label="$t('commons.table.all')" value=""></el-option>
@ -23,6 +25,11 @@
<el-option :value="item.id" :label="item.name" /> <el-option :value="item.id" :label="item.name" />
</div> </div>
</el-select> </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>
<template #main> <template #main>
<ComplexTable <ComplexTable
@ -160,6 +167,10 @@ let commandInfo = reactive<Command.CommandOperate>({
command: '', command: '',
}); });
const commandReq = reactive({
name: '',
});
const cmdVisible = ref<boolean>(false); const cmdVisible = ref<boolean>(false);
const loadGroups = async () => { const loadGroups = async () => {
@ -274,6 +285,7 @@ const search = async (column?: any) => {
info: info.value, info: info.value,
orderBy: paginationConfig.orderBy, orderBy: paginationConfig.orderBy,
order: paginationConfig.order, order: paginationConfig.order,
name: commandReq.name,
}; };
loading.value = true; loading.value = true;
await getCommandPage(params) await getCommandPage(params)