🐛 复制主机.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { HostSpecExtraModel, HostExtraUpdateRequest } from './host-extra';
|
import type { HostExtraUpdateRequest, HostSpecExtraModel } from './host-extra';
|
||||||
import type { TableData } from '@arco-design/web-vue';
|
import type { TableData } from '@arco-design/web-vue';
|
||||||
import type { DataGrid, OrderDirection, Pagination } from '@/types/global';
|
import type { DataGrid, OrderDirection, Pagination } from '@/types/global';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
@@ -114,6 +114,13 @@ export function updateHost(request: HostUpdateRequest) {
|
|||||||
return axios.put('/asset/host/update', request);
|
return axios.put('/asset/host/update', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制主机
|
||||||
|
*/
|
||||||
|
export function copyHost(request: HostUpdateRequest) {
|
||||||
|
return axios.post('/asset/host/copy', request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 id 更新主机状态
|
* 通过 id 更新主机状态
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<host-form-info ref="infoRef"
|
<host-form-info ref="infoRef"
|
||||||
class="form-panel"
|
class="form-panel"
|
||||||
@change-type="(ts: string[]) => types = ts"
|
@change-type="(ts: string[]) => types = ts"
|
||||||
@updated="updateHostInfo" />
|
@updated="onUpdateHostInfo" />
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<!-- 规格配置 -->
|
<!-- 规格配置 -->
|
||||||
<a-tab-pane v-permission="['asset:host:update']"
|
<a-tab-pane v-permission="['asset:host:update']"
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<host-form-spec v-if="hostId"
|
<host-form-spec v-if="hostId"
|
||||||
class="form-panel"
|
class="form-panel"
|
||||||
:hostId="hostId"
|
:hostId="hostId"
|
||||||
@updated="incrUpdatedCount" />
|
@updated="onUpdateHostSpec" />
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<!-- SSH 配置 -->
|
<!-- SSH 配置 -->
|
||||||
<a-tab-pane v-permission="['asset:host:update-config']"
|
<a-tab-pane v-permission="['asset:host:update-config']"
|
||||||
@@ -59,12 +59,10 @@
|
|||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { useCacheStore } from '@/store';
|
import { useCacheStore } from '@/store';
|
||||||
import { HostType } from '../types/const';
|
import { HostType } from '../types/const';
|
||||||
import { useCounter } from '@vueuse/core';
|
|
||||||
import HostFormInfo from './host-form-info.vue';
|
import HostFormInfo from './host-form-info.vue';
|
||||||
import HostFormSsh from './host-form-ssh.vue';
|
|
||||||
import HostFormSpec from './host-form-spec.vue';
|
import HostFormSpec from './host-form-spec.vue';
|
||||||
|
import HostFormSsh from './host-form-ssh.vue';
|
||||||
|
|
||||||
const { count: updatedCount, inc: incrUpdatedCount, reset: resetCounter } = useCounter();
|
|
||||||
const { visible, setVisible } = useVisible();
|
const { visible, setVisible } = useVisible();
|
||||||
|
|
||||||
const activeTab = ref<string>('info');
|
const activeTab = ref<string>('info');
|
||||||
@@ -72,6 +70,7 @@
|
|||||||
const hostId = ref<number>();
|
const hostId = ref<number>();
|
||||||
const types = ref<string[]>([]);
|
const types = ref<string[]>([]);
|
||||||
const infoRef = ref();
|
const infoRef = ref();
|
||||||
|
const hostViewUpdated = ref(false);
|
||||||
|
|
||||||
const emits = defineEmits(['reload']);
|
const emits = defineEmits(['reload']);
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@
|
|||||||
|
|
||||||
// 打开复制
|
// 打开复制
|
||||||
const openCopy = (id: number) => {
|
const openCopy = (id: number) => {
|
||||||
init('复制主机', id);
|
init('复制主机', undefined);
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
infoRef.value.openCopy(id);
|
infoRef.value.openCopy(id);
|
||||||
});
|
});
|
||||||
@@ -104,9 +103,9 @@
|
|||||||
title.value = _title;
|
title.value = _title;
|
||||||
activeTab.value = 'info';
|
activeTab.value = 'info';
|
||||||
hostId.value = id;
|
hostId.value = id;
|
||||||
|
hostViewUpdated.value = false;
|
||||||
types.value = [];
|
types.value = [];
|
||||||
checkHostGroup();
|
checkHostGroup();
|
||||||
resetCounter();
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,14 +122,20 @@
|
|||||||
defineExpose({ openAdd, openUpdate, openCopy });
|
defineExpose({ openAdd, openUpdate, openCopy });
|
||||||
|
|
||||||
// 更新主机信息
|
// 更新主机信息
|
||||||
const updateHostInfo = (id: number) => {
|
const onUpdateHostInfo = (id: number) => {
|
||||||
hostId.value = id;
|
hostId.value = id;
|
||||||
incrUpdatedCount();
|
hostViewUpdated.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新主机信息
|
||||||
|
const onUpdateHostSpec = () => {
|
||||||
|
hostViewUpdated.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理关闭
|
// 处理关闭
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
if (updatedCount.value) {
|
// 修改主机视图信息后刷新列表
|
||||||
|
if (hostViewUpdated.value) {
|
||||||
emits('reload');
|
emits('reload');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,28 +5,6 @@
|
|||||||
label-align="right"
|
label-align="right"
|
||||||
:auto-label-width="true"
|
:auto-label-width="true"
|
||||||
:rules="hostFormRules">
|
:rules="hostFormRules">
|
||||||
<!-- 主机协议 -->
|
|
||||||
<a-form-item field="types" label="主机协议">
|
|
||||||
<a-select v-model="formModel.types"
|
|
||||||
placeholder="请选择支持的主机协议"
|
|
||||||
:options="toOptions(hostTypeKey)"
|
|
||||||
multiple
|
|
||||||
allow-clear />
|
|
||||||
</a-form-item>
|
|
||||||
<!-- 系统类型 -->
|
|
||||||
<a-form-item field="osType" label="系统类型">
|
|
||||||
<a-select v-model="formModel.osType"
|
|
||||||
placeholder="请选择系统类型"
|
|
||||||
:options="toOptions(hostOsTypeKey)"
|
|
||||||
allow-clear />
|
|
||||||
</a-form-item>
|
|
||||||
<!-- 系统架构 -->
|
|
||||||
<a-form-item field="archType" label="系统架构">
|
|
||||||
<a-select v-model="formModel.archType"
|
|
||||||
placeholder="请选择系统架构"
|
|
||||||
:options="toOptions(hostArchTypeKey)"
|
|
||||||
allow-clear />
|
|
||||||
</a-form-item>
|
|
||||||
<!-- 主机名称 -->
|
<!-- 主机名称 -->
|
||||||
<a-form-item field="name" label="主机名称">
|
<a-form-item field="name" label="主机名称">
|
||||||
<a-input v-model="formModel.name"
|
<a-input v-model="formModel.name"
|
||||||
@@ -45,6 +23,28 @@
|
|||||||
placeholder="请输入主机地址"
|
placeholder="请输入主机地址"
|
||||||
allow-clear />
|
allow-clear />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<!-- 系统类型 -->
|
||||||
|
<a-form-item field="osType" label="系统类型">
|
||||||
|
<a-select v-model="formModel.osType"
|
||||||
|
placeholder="请选择系统类型"
|
||||||
|
:options="toOptions(hostOsTypeKey)"
|
||||||
|
allow-clear />
|
||||||
|
</a-form-item>
|
||||||
|
<!-- 系统架构 -->
|
||||||
|
<a-form-item field="archType" label="系统架构">
|
||||||
|
<a-select v-model="formModel.archType"
|
||||||
|
placeholder="请选择系统架构"
|
||||||
|
:options="toOptions(hostArchTypeKey)"
|
||||||
|
allow-clear />
|
||||||
|
</a-form-item>
|
||||||
|
<!-- 主机协议 -->
|
||||||
|
<a-form-item field="types" label="主机协议">
|
||||||
|
<a-select v-model="formModel.types"
|
||||||
|
placeholder="请选择支持的主机协议"
|
||||||
|
:options="toOptions(hostTypeKey)"
|
||||||
|
multiple
|
||||||
|
allow-clear />
|
||||||
|
</a-form-item>
|
||||||
<!-- 主机分组 -->
|
<!-- 主机分组 -->
|
||||||
<a-form-item field="groupIdList" label="主机分组">
|
<a-form-item field="groupIdList" label="主机分组">
|
||||||
<host-group-tree-selector v-model="formModel.groupIdList"
|
<host-group-tree-selector v-model="formModel.groupIdList"
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import useLoading from '@/hooks/loading';
|
import useLoading from '@/hooks/loading';
|
||||||
import { hostFormRules } from '../types/form.rules';
|
import { hostFormRules } from '../types/form.rules';
|
||||||
import { createHost, getHost, updateHost } from '@/api/asset/host';
|
import { createHost, getHost, updateHost, copyHost } from '@/api/asset/host';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import { tagColor, hostTypeKey, hostOsTypeKey, HostOsType, hostArchTypeKey } from '../types/const';
|
import { tagColor, hostTypeKey, hostOsTypeKey, HostOsType, hostArchTypeKey } from '../types/const';
|
||||||
@@ -118,6 +118,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isCopy = ref(false);
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const formModel = ref<HostUpdateRequest>({});
|
const formModel = ref<HostUpdateRequest>({});
|
||||||
|
|
||||||
@@ -135,6 +136,7 @@
|
|||||||
// 打开复制
|
// 打开复制
|
||||||
const openCopy = async (id: number) => {
|
const openCopy = async (id: number) => {
|
||||||
renderForm({ ...defaultForm() });
|
renderForm({ ...defaultForm() });
|
||||||
|
isCopy.value = true;
|
||||||
await fetchHostRender(id);
|
await fetchHostRender(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,7 +190,12 @@
|
|||||||
if (error) {
|
if (error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!formModel.value.id) {
|
if (isCopy.value) {
|
||||||
|
// 复制
|
||||||
|
const { data } = await copyHost(formModel.value);
|
||||||
|
Message.success('复制成功');
|
||||||
|
emits('updated', data);
|
||||||
|
} else if (!formModel.value.id) {
|
||||||
// 新增
|
// 新增
|
||||||
const { data } = await createHost(formModel.value);
|
const { data } = await createHost(formModel.value);
|
||||||
Message.success('创建成功');
|
Message.success('创建成功');
|
||||||
|
|||||||
Reference in New Issue
Block a user