refactor: 规范化代码.
This commit is contained in:
@@ -10,6 +10,7 @@ export interface HostCreateRequest {
|
||||
code?: string;
|
||||
address?: string;
|
||||
tags?: Array<number>;
|
||||
groupIdList?: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,8 +31,7 @@ export interface HostQueryRequest extends Pagination {
|
||||
address?: string;
|
||||
favorite?: boolean;
|
||||
tags?: Array<number>;
|
||||
extra?: boolean;
|
||||
config?: boolean;
|
||||
queryTag?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,9 +46,10 @@ export interface HostQueryResponse extends TableData {
|
||||
updateTime: number;
|
||||
creator: string;
|
||||
updater: string;
|
||||
// FIXME 删除
|
||||
favorite: boolean;
|
||||
tags: Record<number, string>;
|
||||
configs: Record<string, HostConfigQueryResponse>;
|
||||
tags: Array<{ id: number, name: string }>;
|
||||
groupIdList: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +91,8 @@ export function updateHost(request: HostUpdateRequest) {
|
||||
/**
|
||||
* 通过 id 查询主机
|
||||
*/
|
||||
export function getHost(params: HostQueryRequest) {
|
||||
return axios.get<HostQueryResponse>('/asset/host/get', { params });
|
||||
export function getHost(id: number) {
|
||||
return axios.get<HostQueryResponse>('/asset/host/get', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</template>
|
||||
</a-alert>
|
||||
<!-- 保存按钮 -->
|
||||
<a-button v-permission="['asset:host-group:update-rel']"
|
||||
<a-button v-permission="['asset:host:update']"
|
||||
class="save-button"
|
||||
type="primary"
|
||||
:disabled="!group.key"
|
||||
|
||||
@@ -59,9 +59,10 @@
|
||||
import useLoading from '@/hooks/loading';
|
||||
import useVisible from '@/hooks/visible';
|
||||
import formRules from '../types/host.form.rules';
|
||||
import { createHost, updateHost } from '@/api/asset/host';
|
||||
import { createHost, getHost, updateHost } from '@/api/asset/host';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import TagMultiSelector from '@/components/meta/tag/tag-multi-selector.vue';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
const { visible, setVisible } = useVisible();
|
||||
const { loading, setLoading } = useLoading();
|
||||
@@ -76,6 +77,7 @@
|
||||
code: undefined,
|
||||
address: undefined,
|
||||
tags: undefined,
|
||||
groupIdList: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -93,12 +95,29 @@
|
||||
};
|
||||
|
||||
// 打开修改
|
||||
const openUpdate = (record: any) => {
|
||||
const openUpdate = async (id: number) => {
|
||||
title.value = '修改主机';
|
||||
isAddHandle.value = false;
|
||||
const tags = record?.hostTags?.map((s: { id: any; }) => s.id);
|
||||
renderForm({ ...defaultForm(), ...record, tags });
|
||||
renderForm({ ...defaultForm() });
|
||||
setVisible(true);
|
||||
await fetchHostRender(id);
|
||||
};
|
||||
|
||||
// 渲染主机
|
||||
const fetchHostRender = async (id: number) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data } = await getHost(id);
|
||||
const detail = Object.assign({} as Record<string, any>,
|
||||
pick(data, 'id', 'name', 'code', 'address', 'groupIdList'));
|
||||
// tag
|
||||
const tags = (data.tags || []).map(s => s.id);
|
||||
// 渲染
|
||||
renderForm({ ...detail, tags });
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染表单
|
||||
|
||||
Reference in New Issue
Block a user