mirror of https://gitee.com/anolis/sysom.git
add: sysom_web support del cluster
添加: sysom_web 支持删除单个集群(包含主机的集群不允许删除)
This commit is contained in:
parent
2bd3581fd0
commit
fdb7abd8cc
|
@ -18,3 +18,4 @@ sysom_api/uploads/*
|
|||
sysom_api/doc/*
|
||||
sysom_api/conf/develop.py
|
||||
sysom_api/sysom/settings.py
|
||||
venv/
|
|
@ -62,6 +62,7 @@ export default {
|
|||
'pages.clusterTable.clusterOption': '操作',
|
||||
'pages.clusterTable.delete': '删除',
|
||||
'pages.clusterTable.hostCount': '主机数量',
|
||||
'pages.clusterTable.notAllowToBeDelete': '不允许删除包含集群的主机',
|
||||
'pages.IssueTable.createIssue': '新增方案',
|
||||
'pages.journal.audit.title': '日志列表',
|
||||
'pages.journal.audit.created_at': '时间',
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Popconfirm, Table, Space } from 'antd';
|
||||
import { Popconfirm, message } from 'antd';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { useIntl, FormattedMessage } from 'umi';
|
||||
import ProTable from '@ant-design/pro-table';
|
||||
import { getClusterList } from '../service';
|
||||
import { getClusterList, delCluster } from '../service';
|
||||
import Cluster from '../components/ClusterForm';
|
||||
|
||||
const handleDelCluster = async (record) => {
|
||||
const hide = message.loading('正在删除');
|
||||
const token = localStorage.getItem('token');
|
||||
try {
|
||||
let res = await delCluster(record.id, token);
|
||||
hide();
|
||||
if (res.code == 200) {
|
||||
message.success('删除成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(`删除失败: ${res.message}`);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 集群列表页面
|
||||
*/
|
||||
|
@ -51,6 +69,29 @@ const ClusterList = () => {
|
|||
valueType: 'dateTime',
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: <FormattedMessage id="pages.clusterTable.clusterOption" defaultMessage="Operating" />,
|
||||
key: 'option',
|
||||
dataIndex: 'option',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<span key='delete'>
|
||||
<Popconfirm title="是否要删除该集群?" onConfirm={async () => {
|
||||
if (record.hosts.length > 0) {
|
||||
message.error(intl.formatMessage({
|
||||
id: 'pages.clusterTable.notAllowToBeDelete',
|
||||
defaultMessage: "Not allow to delete this cluster"
|
||||
}))
|
||||
} else {
|
||||
await handleDelCluster(record);
|
||||
clusterListTableActionRef.current?.reload();
|
||||
}
|
||||
}}>
|
||||
<a><FormattedMessage id="pages.clusterTable.delete" defaultMessage="host delete" /></a>
|
||||
</Popconfirm>
|
||||
</span>,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
|
|
|
@ -48,6 +48,24 @@ export async function addCluster(body, token, options) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单个集群
|
||||
* @param {number} id
|
||||
* @param {string} token
|
||||
* @param {object} options
|
||||
* @returns
|
||||
*/
|
||||
export async function delCluster(id, token, options) {
|
||||
return request(`${CLUSTER_URL}${id}/`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': token,
|
||||
},
|
||||
...(options || {}),
|
||||
})
|
||||
}
|
||||
|
||||
export async function getHost(params, options) {
|
||||
return request(HOST_URL, {
|
||||
method: 'GET',
|
||||
|
|
Loading…
Reference in New Issue