Files
orion-visor/orion-visor-ui/src/api/asset/host.ts

181 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-10-25 10:26:14 +08:00
import type { DataGrid, Pagination } from '@/types/global';
import type { TableData } from '@arco-design/web-vue/es/table/interface';
2023-09-11 16:33:57 +08:00
import axios from 'axios';
2024-05-31 16:32:45 +08:00
import qs from 'query-string';
2023-09-11 16:33:57 +08:00
2024-07-22 19:36:02 +08:00
// 主机类型
export type HostType = 'SSH' | string | undefined;
2023-09-11 16:33:57 +08:00
/**
*
*/
export interface HostCreateRequest {
2024-07-22 19:36:02 +08:00
type?: string;
2023-09-11 16:33:57 +08:00
name?: string;
code?: string;
address?: string;
2024-07-22 19:36:02 +08:00
port?: number;
2023-09-14 16:18:41 +08:00
tags?: Array<number>;
2023-11-14 18:38:46 +08:00
groupIdList?: Array<number>;
2023-09-11 16:33:57 +08:00
}
/**
*
*/
export interface HostUpdateRequest extends HostCreateRequest {
2023-09-25 14:36:13 +08:00
id?: number;
2023-09-11 16:33:57 +08:00
}
2024-07-22 19:36:02 +08:00
/**
*
*/
export interface HostUpdateStatusRequest {
id: number;
status: string;
}
/**
*
*/
export interface HostUpdateConfigRequest {
id: number;
config: string;
}
2023-09-11 16:33:57 +08:00
/**
*
*/
export interface HostQueryRequest extends Pagination {
2023-10-07 18:08:31 +08:00
searchValue?: string;
2023-09-11 16:33:57 +08:00
id?: number;
2024-07-22 19:36:02 +08:00
type?: string;
2023-09-11 16:33:57 +08:00
name?: string;
code?: string;
address?: string;
2024-07-22 19:36:02 +08:00
status?: string;
2023-09-14 16:18:41 +08:00
tags?: Array<number>;
2023-11-14 18:38:46 +08:00
queryTag?: boolean;
2023-09-11 16:33:57 +08:00
}
/**
*
*/
2024-02-29 19:15:08 +08:00
export interface HostQueryResponse extends TableData, HostQueryResponseExtra {
2023-11-01 18:57:53 +08:00
id: number;
2024-07-22 19:36:02 +08:00
type: string;
2023-11-01 18:57:53 +08:00
name: string;
code: string;
address: string;
2024-07-22 19:36:02 +08:00
port: string;
status: string;
2023-09-11 16:33:57 +08:00
createTime: number;
updateTime: number;
creator: string;
updater: string;
2023-09-14 16:18:41 +08:00
favorite: boolean;
2023-12-19 01:06:09 +08:00
alias: string;
2024-02-29 19:15:08 +08:00
color: string;
2023-11-14 18:38:46 +08:00
tags: Array<{ id: number, name: string }>;
groupIdList: Array<number>;
2024-02-29 19:15:08 +08:00
}
2023-12-19 01:06:09 +08:00
2024-02-29 19:15:08 +08:00
/**
*
*/
export interface HostQueryResponseExtra {
2023-12-19 01:06:09 +08:00
editable: boolean;
loading: boolean;
modCount: number;
2023-09-14 16:18:41 +08:00
}
2024-07-22 19:36:02 +08:00
/**
*
*/
export interface HostConfigQueryResponse extends HostConfigQueryResponseExtra {
id: number;
type: string;
config: Record<string, any>;
}
/**
*
*/
export interface HostConfigQueryResponseExtra {
current: number;
}
2023-09-11 16:33:57 +08:00
/**
*
*/
export function createHost(request: HostCreateRequest) {
return axios.post('/asset/host/create', request);
}
/**
* id
*/
export function updateHost(request: HostUpdateRequest) {
return axios.put('/asset/host/update', request);
}
/**
2024-07-22 19:36:02 +08:00
* id
*/
export function updateHostStatus(request: HostUpdateStatusRequest) {
return axios.put('/asset/host/update-status', request);
}
/**
* id
*/
export function updateHostConfig(request: HostUpdateConfigRequest) {
return axios.put('/asset/host/update-config', request);
}
/**
*
2023-09-11 16:33:57 +08:00
*/
2023-11-14 18:38:46 +08:00
export function getHost(id: number) {
return axios.get<HostQueryResponse>('/asset/host/get', { params: { id } });
2023-09-11 16:33:57 +08:00
}
/**
2023-11-09 16:10:58 +08:00
*
2023-09-11 16:33:57 +08:00
*/
2024-07-22 19:36:02 +08:00
export function getHostList(type: HostType) {
return axios.get<Array<HostQueryResponse>>('/asset/host/list', { params: { type } });
}
/**
* id
*/
export function getHostConfig(id: number) {
return axios.get<HostConfigQueryResponse>('/asset/host/get-config', { params: { id } });
2023-09-11 16:33:57 +08:00
}
/**
*
*/
export function getHostPage(request: HostQueryRequest) {
return axios.post<DataGrid<HostQueryResponse>>('/asset/host/query', request);
}
/**
* id
*/
export function deleteHost(id: number) {
return axios.delete('/asset/host/delete', { params: { id } });
}
2024-05-31 16:32:45 +08:00
/**
*
*/
export function batchDeleteHost(idList: Array<number>) {
return axios.delete('/asset/host/batch-delete', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}