refactor: 修改主机配置.

This commit is contained in:
lijiahang
2023-12-25 12:12:05 +08:00
parent 5cf70595c0
commit b2a697f6ba
7 changed files with 75 additions and 43 deletions

View File

@@ -4,8 +4,8 @@ import axios from 'axios';
* 主机配置请求
*/
export interface HostConfigRequest {
id?: number;
hostId?: number;
type?: string;
version?: number;
status?: number;
config?: string;

View File

@@ -16,7 +16,9 @@
</template>
<a-spin :loading="loading" class="host-config-container">
<!-- SSH 配置 -->
<ssh-config-form :content="config.SSH" @submitted="(e) => config.SSH.config = e" />
<ssh-config-form :host-id="record.id"
:content="config.ssh"
@submitted="(e) => config.ssh.config = e" />
</a-spin>
</a-drawer>
</template>
@@ -42,9 +44,9 @@
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore();
const record = ref();
const record = ref({} as any);
const config = ref<HostConfigWrapper>({
SSH: undefined
ssh: undefined
});
// 打开
@@ -61,6 +63,7 @@
data.forEach(s => {
config.value[s.type] = s;
});
console.log(config.value);
} catch ({ message }) {
Message.error(`配置加载失败 ${message}`);
setVisible(false);

View File

@@ -107,7 +107,6 @@
<a-form-item field="fileNameCharset"
label="文件名称编码"
:hide-asterisk="true"
label-col-flex="86px">
<a-input v-model="formModel.fileNameCharset" placeholder="请输入 SFTP 文件名称编码" />
</a-form-item>
@@ -115,7 +114,6 @@
<a-form-item field="fileContentCharset"
label="文件内容编码"
:hide-asterisk="true"
label-col-flex="86px">
<a-input v-model="formModel.fileContentCharset" placeholder="请输入 SFTP 文件内容编码" />
</a-form-item>
@@ -150,12 +148,14 @@
import HostKeySelector from '@/components/asset/host-key/host-key-selector.vue';
import HostIdentitySelector from '@/components/asset/host-identity/host-identity-selector.vue';
import { EnabledStatus } from '@/types/const';
import { HostConfigType } from '../../../types/const';
const { loading, setLoading } = useLoading();
const { toOptions } = useDictStore();
const props = defineProps({
content: Object
content: Object,
hostId: Number,
});
const emits = defineEmits(['submitted']);
@@ -220,7 +220,8 @@
const updateStatus = (e: number) => {
setLoading(true);
return updateHostConfigStatus({
id: props?.content?.id,
hostId: props?.hostId,
type: HostConfigType.SSH,
status: e,
version: config.version
}).then(({ data }) => {
@@ -249,8 +250,10 @@
return false;
}
setLoading(true);
// 更新
const { data } = await updateHostConfig({
id: props?.content?.id,
hostId: props?.hostId,
type: HostConfigType.SSH,
version: config.version,
config: JSON.stringify(formModel.value)
});
@@ -258,7 +261,7 @@
setLoading(false);
Message.success('修改成功');
// 回调 props
emits('submitted', { ...formModel });
emits('submitted', { ...formModel.value });
} catch (e) {
} finally {
setLoading(false);

View File

@@ -2,11 +2,16 @@ import type { HostSshConfig } from '../components/config/ssh/types/const';
// 主机所有配置
export interface HostConfigWrapper {
SSH: HostSshConfig | unknown;
ssh: HostSshConfig | unknown;
[key: string]: unknown;
}
// 主机配置类型
export const HostConfigType = {
SSH: 'ssh'
};
// tag 颜色
export const tagColor = [
'arcoblue',