mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 增加主机信息查询接口
This commit is contained in:
parent
907d8614a8
commit
c5b2eddd3f
@ -27,13 +27,13 @@ func (b *BaseApi) Create(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) PageHosts(c *gin.Context) {
|
func (b *BaseApi) PageHosts(c *gin.Context) {
|
||||||
var req dto.PageInfo
|
var req dto.SearchWithPage
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
total, list, err := hostService.Page(req)
|
total, list, err := hostService.Search(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
|
@ -14,6 +14,11 @@ type HostCreate struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SearchWithPage struct {
|
||||||
|
PageInfo
|
||||||
|
Info string `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
type HostInfo struct {
|
type HostInfo struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
@ -3,6 +3,7 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/app/model"
|
"github.com/1Panel-dev/1Panel/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/global"
|
"github.com/1Panel-dev/1Panel/global"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HostRepo struct{}
|
type HostRepo struct{}
|
||||||
@ -10,6 +11,7 @@ type HostRepo struct{}
|
|||||||
type IHostRepo interface {
|
type IHostRepo interface {
|
||||||
Get(opts ...DBOption) (model.Host, error)
|
Get(opts ...DBOption) (model.Host, error)
|
||||||
Page(limit, offset int, opts ...DBOption) (int64, []model.Host, error)
|
Page(limit, offset int, opts ...DBOption) (int64, []model.Host, error)
|
||||||
|
WithByInfo(info string) DBOption
|
||||||
Create(host *model.Host) error
|
Create(host *model.Host) error
|
||||||
Update(id uint, vars map[string]interface{}) error
|
Update(id uint, vars map[string]interface{}) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...DBOption) error
|
||||||
@ -41,6 +43,13 @@ func (u *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host,
|
|||||||
return count, hosts, err
|
return count, hosts, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *HostRepo) WithByInfo(info string) DBOption {
|
||||||
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
|
infoStr := "%" + info + "%"
|
||||||
|
return g.Where("name LIKE ? OR addr LIKE ?", infoStr, infoStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (u *HostRepo) Create(host *model.Host) error {
|
func (u *HostRepo) Create(host *model.Host) error {
|
||||||
return global.DB.Create(host).Error
|
return global.DB.Create(host).Error
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ type HostService struct{}
|
|||||||
|
|
||||||
type IHostService interface {
|
type IHostService interface {
|
||||||
GetConnInfo(id uint) (*model.Host, error)
|
GetConnInfo(id uint) (*model.Host, error)
|
||||||
Page(search dto.PageInfo) (int64, interface{}, error)
|
Search(search dto.SearchWithPage) (int64, interface{}, error)
|
||||||
Create(hostDto dto.HostCreate) (*dto.HostInfo, error)
|
Create(hostDto dto.HostCreate) (*dto.HostInfo, error)
|
||||||
Update(id uint, upMap map[string]interface{}) error
|
Update(id uint, upMap map[string]interface{}) error
|
||||||
BatchDelete(ids []uint) error
|
BatchDelete(ids []uint) error
|
||||||
@ -30,8 +30,8 @@ func (u *HostService) GetConnInfo(id uint) (*model.Host, error) {
|
|||||||
return &host, err
|
return &host, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HostService) Page(search dto.PageInfo) (int64, interface{}, error) {
|
func (u *HostService) Search(search dto.SearchWithPage) (int64, interface{}, error) {
|
||||||
total, hosts, err := hostRepo.Page(search.Page, search.PageSize)
|
total, hosts, err := hostRepo.Page(search.Page, search.PageSize, hostRepo.WithByInfo(search.Info))
|
||||||
var dtoHosts []dto.HostInfo
|
var dtoHosts []dto.HostInfo
|
||||||
for _, host := range hosts {
|
for _, host := range hosts {
|
||||||
var item dto.HostInfo
|
var item dto.HostInfo
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { CommonModel } from '.';
|
import { CommonModel, ReqPage } from '.';
|
||||||
|
|
||||||
export namespace Host {
|
export namespace Host {
|
||||||
export interface Host extends CommonModel {
|
export interface Host extends CommonModel {
|
||||||
@ -21,4 +21,7 @@ export namespace Host {
|
|||||||
|
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
export interface ReqSearchWithPage extends ReqPage {
|
||||||
|
info?: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import http from '@/api';
|
import http from '@/api';
|
||||||
import { ResPage, ReqPage } from '../interface';
|
import { ResPage } from '../interface';
|
||||||
import { Host } from '../interface/host';
|
import { Host } from '../interface/host';
|
||||||
|
|
||||||
export const getHostList = (params: ReqPage) => {
|
export const getHostList = (params: Host.ReqSearchWithPage) => {
|
||||||
return http.post<ResPage<Host.Host>>(`/hosts/search`, params);
|
return http.post<ResPage<Host.Host>>(`/hosts/search`, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ export default {
|
|||||||
commons: {
|
commons: {
|
||||||
button: {
|
button: {
|
||||||
create: 'Create',
|
create: 'Create',
|
||||||
|
add: 'Add',
|
||||||
delete: 'Delete',
|
delete: 'Delete',
|
||||||
edit: 'Edit',
|
edit: 'Edit',
|
||||||
confirm: 'Confirm',
|
confirm: 'Confirm',
|
||||||
|
@ -2,6 +2,7 @@ export default {
|
|||||||
commons: {
|
commons: {
|
||||||
button: {
|
button: {
|
||||||
create: '创建',
|
create: '创建',
|
||||||
|
add: '添加',
|
||||||
delete: '删除',
|
delete: '删除',
|
||||||
edit: '编辑',
|
edit: '编辑',
|
||||||
confirm: '确认',
|
confirm: '确认',
|
||||||
|
@ -37,7 +37,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-drawer :size="320" v-model="hostDrawer" :title="$t('terminal.hostHistory')" direction="rtl">
|
<el-drawer :size="320" v-model="hostDrawer" :title="$t('terminal.hostHistory')" direction="rtl">
|
||||||
<el-button @click="onAddHost">{{ $t('terminal.addHost') }}</el-button>
|
<el-input size="small" clearable style="margin-top: 5px" v-model="searcConfig.info">
|
||||||
|
<template #prepend>
|
||||||
|
<el-button icon="plus" @click="onAddHost">{{ $t('commons.button.add') }}</el-button>
|
||||||
|
</template>
|
||||||
|
<template #append><el-button icon="search" @click="loadHost" /></template>
|
||||||
|
</el-input>
|
||||||
<div v-infinite-scroll="nextPage" style="overflow: auto">
|
<div v-infinite-scroll="nextPage" style="overflow: auto">
|
||||||
<el-card
|
<el-card
|
||||||
@click="onConnLocal()"
|
@click="onConnLocal()"
|
||||||
@ -89,16 +94,16 @@
|
|||||||
<el-dialog v-model="connVisiable" :title="$t('terminal.addHost')" width="30%">
|
<el-dialog v-model="connVisiable" :title="$t('terminal.addHost')" width="30%">
|
||||||
<el-form ref="hostInfoRef" label-width="80px" :model="hostInfo" :rules="rules">
|
<el-form ref="hostInfoRef" label-width="80px" :model="hostInfo" :rules="rules">
|
||||||
<el-form-item :label="$t('commons.table.name')" prop="name">
|
<el-form-item :label="$t('commons.table.name')" prop="name">
|
||||||
<el-input v-model="hostInfo.name" style="width: 80%" />
|
<el-input clearable v-model="hostInfo.name" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="IP" prop="addr">
|
<el-form-item label="IP" prop="addr">
|
||||||
<el-input v-model="hostInfo.addr" style="width: 80%" />
|
<el-input clearable v-model="hostInfo.addr" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('terminal.port')" prop="port">
|
<el-form-item :label="$t('terminal.port')" prop="port">
|
||||||
<el-input v-model.number="hostInfo.port" style="width: 80%" />
|
<el-input clearable v-model.number="hostInfo.port" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('terminal.user')" prop="user">
|
<el-form-item :label="$t('terminal.user')" prop="user">
|
||||||
<el-input v-model="hostInfo.user" style="width: 80%" />
|
<el-input clearable v-model="hostInfo.user" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('terminal.authMode')" prop="authMode">
|
<el-form-item :label="$t('terminal.authMode')" prop="authMode">
|
||||||
<el-radio-group v-model="hostInfo.authMode">
|
<el-radio-group v-model="hostInfo.authMode">
|
||||||
@ -107,10 +112,10 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('terminal.password')" v-if="hostInfo.authMode === 'password'" prop="password">
|
<el-form-item :label="$t('terminal.password')" v-if="hostInfo.authMode === 'password'" prop="password">
|
||||||
<el-input show-password type="password" v-model="hostInfo.password" style="width: 80%" />
|
<el-input clearable show-password type="password" v-model="hostInfo.password" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('terminal.key')" v-if="hostInfo.authMode === 'key'" prop="privateKey">
|
<el-form-item :label="$t('terminal.key')" v-if="hostInfo.authMode === 'key'" prop="privateKey">
|
||||||
<el-input type="textarea" v-model="hostInfo.privateKey" style="width: 80%" />
|
<el-input clearable type="textarea" v-model="hostInfo.privateKey" style="width: 80%" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@ -148,6 +153,12 @@ let tabIndex = 0;
|
|||||||
const data = ref();
|
const data = ref();
|
||||||
const hostDrawer = ref(false);
|
const hostDrawer = ref(false);
|
||||||
|
|
||||||
|
let searcConfig = reactive<Host.ReqSearchWithPage>({
|
||||||
|
info: '',
|
||||||
|
page: 1,
|
||||||
|
pageSize: 8,
|
||||||
|
});
|
||||||
|
|
||||||
const paginationConfig = reactive({
|
const paginationConfig = reactive({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 8,
|
pageSize: 8,
|
||||||
@ -212,7 +223,9 @@ const handleTabsEdit = (targetName: string, action: 'remove' | 'add') => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadHost = async () => {
|
const loadHost = async () => {
|
||||||
const res = await getHostList({ page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize });
|
searcConfig.page = paginationConfig.currentPage;
|
||||||
|
searcConfig.pageSize = paginationConfig.pageSize;
|
||||||
|
const res = await getHostList(searcConfig);
|
||||||
data.value = res.data.items;
|
data.value = res.data.items;
|
||||||
paginationConfig.total = res.data.total;
|
paginationConfig.total = res.data.total;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user