🔨 优化代码逻辑.
This commit is contained in:
@@ -47,4 +47,11 @@ public interface UpdatePasswordAction extends Serializable {
|
|||||||
*/
|
*/
|
||||||
String getPassword();
|
String getPassword();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置密码
|
||||||
|
*
|
||||||
|
* @param password password
|
||||||
|
*/
|
||||||
|
void setPassword(String password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,20 +17,23 @@ export interface HostUpdateConfigRequest {
|
|||||||
config: string;
|
config: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 主机 SSH 配置
|
export interface HostBaseConfig {
|
||||||
export interface HostSshConfig {
|
|
||||||
username?: string;
|
username?: string;
|
||||||
port?: number;
|
port?: number;
|
||||||
password?: string;
|
password?: string;
|
||||||
authType?: string;
|
authType?: string;
|
||||||
|
useNewPassword?: boolean;
|
||||||
|
hasPassword?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主机 SSH 配置
|
||||||
|
export interface HostSshConfig extends HostBaseConfig {
|
||||||
keyId?: number;
|
keyId?: number;
|
||||||
identityId?: number;
|
identityId?: number;
|
||||||
connectTimeout?: number;
|
connectTimeout?: number;
|
||||||
charset?: string;
|
charset?: string;
|
||||||
fileNameCharset?: string;
|
fileNameCharset?: string;
|
||||||
fileContentCharset?: string;
|
fileContentCharset?: string;
|
||||||
useNewPassword?: boolean;
|
|
||||||
hasPassword?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +46,6 @@ export function updateHostConfig(request: HostUpdateConfigRequest) {
|
|||||||
/**
|
/**
|
||||||
* 查询主机配置
|
* 查询主机配置
|
||||||
*/
|
*/
|
||||||
export function getHostSshConfig<T>(request: HostUpdateQueryRequest) {
|
export function getHostConfig<T>(request: HostUpdateQueryRequest) {
|
||||||
return axios.post<T>('/asset/host-config/get', request);
|
return axios.post<T>('/asset/host-config/get', request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
const props = withDefaults(defineProps<Partial<{
|
const props = withDefaults(defineProps<Partial<{
|
||||||
modelValue: number;
|
modelValue: number;
|
||||||
authorized: boolean;
|
authorized: boolean;
|
||||||
|
type: string;
|
||||||
}>>(), {
|
}>>(), {
|
||||||
authorized: false
|
authorized: false
|
||||||
});
|
});
|
||||||
@@ -66,7 +67,8 @@
|
|||||||
const hostIdentities = props.authorized
|
const hostIdentities = props.authorized
|
||||||
? await cacheStore.loadAuthorizedHostIdentities()
|
? await cacheStore.loadAuthorizedHostIdentities()
|
||||||
: await cacheStore.loadHostIdentities();
|
: await cacheStore.loadHostIdentities();
|
||||||
optionData.value = hostIdentities.map(s => {
|
optionData.value = hostIdentities.filter(s => !props.type || s.type === props.type)
|
||||||
|
.map(s => {
|
||||||
return {
|
return {
|
||||||
label: s.name,
|
label: s.name,
|
||||||
value: s.id,
|
value: s.id,
|
||||||
|
|||||||
@@ -54,18 +54,16 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { HostUpdateRequest } from '@/api/asset/host';
|
|
||||||
import { ref, nextTick } from 'vue';
|
import { ref, nextTick } from 'vue';
|
||||||
import useVisible from '@/hooks/visible';
|
import useVisible from '@/hooks/visible';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { useCacheStore, useDictStore } from '@/store';
|
import { useCacheStore } from '@/store';
|
||||||
import { HostType } from '../types/const';
|
import { HostType } from '../types/const';
|
||||||
import { useCounter } from '@vueuse/core';
|
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 HostFormSsh from './host-form-ssh.vue';
|
||||||
import HostFormSpec from './host-form-spec.vue';
|
import HostFormSpec from './host-form-spec.vue';
|
||||||
|
|
||||||
const { toOptions } = useDictStore();
|
|
||||||
const { count: updatedCount, inc: incrUpdatedCount, reset: resetCounter } = useCounter();
|
const { count: updatedCount, inc: incrUpdatedCount, reset: resetCounter } = useCounter();
|
||||||
const { visible, setVisible } = useVisible();
|
const { visible, setVisible } = useVisible();
|
||||||
|
|
||||||
@@ -74,8 +72,6 @@
|
|||||||
const hostId = ref<number>();
|
const hostId = ref<number>();
|
||||||
const types = ref<string[]>([]);
|
const types = ref<string[]>([]);
|
||||||
const infoRef = ref();
|
const infoRef = ref();
|
||||||
const formRef = ref();
|
|
||||||
const formModel = ref<HostUpdateRequest>({});
|
|
||||||
|
|
||||||
const emits = defineEmits(['reload']);
|
const emits = defineEmits(['reload']);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
:auto-label-width="true"
|
:auto-label-width="true"
|
||||||
:rules="sshFormRules">
|
:rules="sshFormRules">
|
||||||
<!-- 端口 -->
|
<!-- 端口 -->
|
||||||
<a-form-item field="port" label="端口">
|
<a-form-item field="port"
|
||||||
|
label="端口"
|
||||||
|
hide-asterisk>
|
||||||
<a-input-number v-model="formModel.port"
|
<a-input-number v-model="formModel.port"
|
||||||
placeholder="请输入 SSH 端口"
|
placeholder="请输入 SSH 端口"
|
||||||
hide-button />
|
hide-button />
|
||||||
@@ -16,23 +18,27 @@
|
|||||||
<a-form-item field="username"
|
<a-form-item field="username"
|
||||||
label="用户名"
|
label="用户名"
|
||||||
:rules="usernameRules"
|
:rules="usernameRules"
|
||||||
:help="SshAuthType.IDENTITY === formModel.authType ? '将使用主机身份的用户名' : undefined">
|
:help="HostAuthType.IDENTITY === formModel.authType ? '将使用主机身份的用户名' : undefined"
|
||||||
|
hide-asterisk>
|
||||||
<a-input v-model="formModel.username"
|
<a-input v-model="formModel.username"
|
||||||
:disabled="SshAuthType.IDENTITY === formModel.authType"
|
:disabled="HostAuthType.IDENTITY === formModel.authType"
|
||||||
placeholder="请输入用户名" />
|
placeholder="请输入用户名" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 认证方式 -->
|
<!-- 认证方式 -->
|
||||||
<a-form-item field="authType" label="认证方式">
|
<a-form-item field="authType"
|
||||||
|
label="认证方式"
|
||||||
|
hide-asterisk>
|
||||||
<a-radio-group type="button"
|
<a-radio-group type="button"
|
||||||
class="auth-type-group usn"
|
class="auth-type-group usn"
|
||||||
v-model="formModel.authType"
|
v-model="formModel.authType"
|
||||||
:options="toRadioOptions(sshAuthTypeKey)" />
|
:options="toRadioOptions(sshAuthTypeKey)" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 主机密码 -->
|
<!-- 主机密码 -->
|
||||||
<a-form-item v-if="SshAuthType.PASSWORD === formModel.authType"
|
<a-form-item v-if="HostAuthType.PASSWORD === formModel.authType"
|
||||||
field="password"
|
field="password"
|
||||||
label="主机密码"
|
label="主机密码"
|
||||||
:rules="passwordRules">
|
:rules="passwordRules"
|
||||||
|
hide-asterisk>
|
||||||
<a-input-password v-model="formModel.password"
|
<a-input-password v-model="formModel.password"
|
||||||
:disabled="!formModel.useNewPassword && formModel.hasPassword"
|
:disabled="!formModel.useNewPassword && formModel.hasPassword"
|
||||||
placeholder="主机密码" />
|
placeholder="主机密码" />
|
||||||
@@ -44,19 +50,23 @@
|
|||||||
unchecked-text="使用原密码" />
|
unchecked-text="使用原密码" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 主机密钥 -->
|
<!-- 主机密钥 -->
|
||||||
<a-form-item v-if="SshAuthType.KEY === formModel.authType"
|
<a-form-item v-if="HostAuthType.KEY === formModel.authType"
|
||||||
field="keyId"
|
field="keyId"
|
||||||
label="主机密钥">
|
label="主机密钥"
|
||||||
|
hide-asterisk>
|
||||||
<host-key-selector v-model="formModel.keyId" />
|
<host-key-selector v-model="formModel.keyId" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 主机身份 -->
|
<!-- 主机身份 -->
|
||||||
<a-form-item v-if="SshAuthType.IDENTITY === formModel.authType"
|
<a-form-item v-if="HostAuthType.IDENTITY === formModel.authType"
|
||||||
field="identityId"
|
field="identityId"
|
||||||
label="主机身份">
|
label="主机身份"
|
||||||
|
hide-asterisk>
|
||||||
<host-identity-selector v-model="formModel.identityId" />
|
<host-identity-selector v-model="formModel.identityId" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 连接超时时间 -->
|
<!-- 连接超时时间 -->
|
||||||
<a-form-item field="connectTimeout" label="连接超时时间">
|
<a-form-item field="connectTimeout"
|
||||||
|
label="连接超时时间"
|
||||||
|
hide-asterisk>
|
||||||
<a-input-number v-model="formModel.connectTimeout"
|
<a-input-number v-model="formModel.connectTimeout"
|
||||||
placeholder="请输入连接超时时间"
|
placeholder="请输入连接超时时间"
|
||||||
hide-button>
|
hide-button>
|
||||||
@@ -66,15 +76,21 @@
|
|||||||
</a-input-number>
|
</a-input-number>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- SSH 输出编码 -->
|
<!-- SSH 输出编码 -->
|
||||||
<a-form-item field="charset" label="SSH输出编码">
|
<a-form-item field="charset"
|
||||||
|
label="SSH输出编码"
|
||||||
|
hide-asterisk>
|
||||||
<a-input v-model="formModel.charset" placeholder="请输入 SSH 输出编码" />
|
<a-input v-model="formModel.charset" placeholder="请输入 SSH 输出编码" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 文件名称编码 -->
|
<!-- 文件名称编码 -->
|
||||||
<a-form-item field="fileNameCharset" label="文件名称编码">
|
<a-form-item field="fileNameCharset"
|
||||||
|
label="文件名称编码"
|
||||||
|
hide-asterisk>
|
||||||
<a-input v-model="formModel.fileNameCharset" placeholder="请输入 SFTP 文件名称编码" />
|
<a-input v-model="formModel.fileNameCharset" placeholder="请输入 SFTP 文件名称编码" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 文件内容编码 -->
|
<!-- 文件内容编码 -->
|
||||||
<a-form-item field="fileContentCharset" label="文件内容编码">
|
<a-form-item field="fileContentCharset"
|
||||||
|
label="文件内容编码"
|
||||||
|
hide-asterisk>
|
||||||
<a-input v-model="formModel.fileContentCharset" placeholder="请输入 SFTP 文件内容编码" />
|
<a-input v-model="formModel.fileContentCharset" placeholder="请输入 SFTP 文件内容编码" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 操作 -->
|
<!-- 操作 -->
|
||||||
@@ -114,12 +130,12 @@
|
|||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import useLoading from '@/hooks/loading';
|
import useLoading from '@/hooks/loading';
|
||||||
import { useDictStore } from '@/store';
|
import { useDictStore } from '@/store';
|
||||||
import { sshAuthTypeKey, SshAuthType, HostType } from '../types/const';
|
import { sshAuthTypeKey, HostAuthType, HostType } from '../types/const';
|
||||||
import { sshFormRules } from '../types/form.rules';
|
import { sshFormRules } from '../types/form.rules';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { encrypt } from '@/utils/rsa';
|
import { encrypt } from '@/utils/rsa';
|
||||||
import { testHostConnect } from '@/api/asset/host';
|
import { testHostConnect } from '@/api/asset/host';
|
||||||
import { getHostSshConfig, updateHostConfig } from '@/api/asset/host-config';
|
import { getHostConfig, updateHostConfig } from '@/api/asset/host-config';
|
||||||
import HostIdentitySelector from '@/components/asset/host-identity/selector/index.vue';
|
import HostIdentitySelector from '@/components/asset/host-identity/selector/index.vue';
|
||||||
import HostKeySelector from '@/components/asset/host-key/selector/index.vue';
|
import HostKeySelector from '@/components/asset/host-key/selector/index.vue';
|
||||||
|
|
||||||
@@ -129,7 +145,7 @@
|
|||||||
|
|
||||||
const { loading, setLoading } = useLoading();
|
const { loading, setLoading } = useLoading();
|
||||||
const { loading: connectLoading, setLoading: setConnectLoading } = useLoading();
|
const { loading: connectLoading, setLoading: setConnectLoading } = useLoading();
|
||||||
const { toOptions, toRadioOptions } = useDictStore();
|
const { toRadioOptions } = useDictStore();
|
||||||
|
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const formModel = ref<HostSshConfig>({} as HostSshConfig);
|
const formModel = ref<HostSshConfig>({} as HostSshConfig);
|
||||||
@@ -141,7 +157,7 @@
|
|||||||
cb('用户名长度不能大于128位');
|
cb('用户名长度不能大于128位');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (formModel.value.authType !== SshAuthType.IDENTITY && !value) {
|
if (formModel.value.authType !== HostAuthType.IDENTITY && !value) {
|
||||||
cb('请输入用户名');
|
cb('请输入用户名');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -167,7 +183,7 @@
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
// 加载配置
|
// 加载配置
|
||||||
const { data } = await getHostSshConfig<HostSshConfig>({
|
const { data } = await getHostConfig<HostSshConfig>({
|
||||||
hostId: props.hostId,
|
hostId: props.hostId,
|
||||||
type: HostType.SSH.value,
|
type: HostType.SSH.value,
|
||||||
});
|
});
|
||||||
@@ -212,7 +228,7 @@
|
|||||||
// 加密参数
|
// 加密参数
|
||||||
const requestData = { ...formModel.value };
|
const requestData = { ...formModel.value };
|
||||||
try {
|
try {
|
||||||
requestData.password = await encrypt(formRef.value.password);
|
requestData.password = await encrypt(formModel.value.password);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const HostOsType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 主机认证方式
|
// 主机认证方式
|
||||||
export const SshAuthType = {
|
export const HostAuthType = {
|
||||||
// 密码认证
|
// 密码认证
|
||||||
PASSWORD: 'PASSWORD',
|
PASSWORD: 'PASSWORD',
|
||||||
// 密钥认证
|
// 密钥认证
|
||||||
@@ -65,7 +65,7 @@ export const hostArchTypeKey = 'hostArchType';
|
|||||||
// 主机状态 字典项
|
// 主机状态 字典项
|
||||||
export const hostStatusKey = 'hostStatus';
|
export const hostStatusKey = 'hostStatus';
|
||||||
|
|
||||||
// 主机认证方式 字典项
|
// 主机 SSH 认证方式 字典项
|
||||||
export const sshAuthTypeKey = 'hostSshAuthType';
|
export const sshAuthTypeKey = 'hostSshAuthType';
|
||||||
|
|
||||||
// 加载的字典值
|
// 加载的字典值
|
||||||
|
|||||||
@@ -11,13 +11,13 @@
|
|||||||
:options="toRadioOptions(extraSshAuthTypeKey)" />
|
:options="toRadioOptions(extraSshAuthTypeKey)" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 用户名 -->
|
<!-- 用户名 -->
|
||||||
<a-form-item v-if="formModel.authType === ExtraSshAuthType.CUSTOM_KEY"
|
<a-form-item v-if="formModel.authType === ExtraHostAuthType.CUSTOM_KEY"
|
||||||
field="username"
|
field="username"
|
||||||
label="用户名">
|
label="用户名">
|
||||||
<a-input v-model="formModel.username" placeholder="请输入用户名" />
|
<a-input v-model="formModel.username" placeholder="请输入用户名" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 主机密钥 -->
|
<!-- 主机密钥 -->
|
||||||
<a-form-item v-if="formModel.authType === ExtraSshAuthType.CUSTOM_KEY"
|
<a-form-item v-if="formModel.authType === ExtraHostAuthType.CUSTOM_KEY"
|
||||||
field="keyId"
|
field="keyId"
|
||||||
label="主机密钥"
|
label="主机密钥"
|
||||||
:rules="{ required: true, message: '请选择主机密钥' }">
|
:rules="{ required: true, message: '请选择主机密钥' }">
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
:authorized="true" />
|
:authorized="true" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- 主机身份 -->
|
<!-- 主机身份 -->
|
||||||
<a-form-item v-if="formModel.authType === ExtraSshAuthType.CUSTOM_IDENTITY"
|
<a-form-item v-if="formModel.authType === ExtraHostAuthType.CUSTOM_IDENTITY"
|
||||||
field="identityId"
|
field="identityId"
|
||||||
label="主机身份"
|
label="主机身份"
|
||||||
:rules="{ required: true, message: '请选择主机身份' }">
|
:rules="{ required: true, message: '请选择主机身份' }">
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
import type { HostSshExtraSettingModel } from '@/api/asset/host-extra';
|
import type { HostSshExtraSettingModel } from '@/api/asset/host-extra';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { getHostExtraItem } from '@/api/asset/host-extra';
|
import { getHostExtraItem } from '@/api/asset/host-extra';
|
||||||
import { ExtraSshAuthType, extraSshAuthTypeKey } from '../../../types/const';
|
import { ExtraHostAuthType, extraSshAuthTypeKey } from '../../../types/const';
|
||||||
import { useDictStore } from '@/store';
|
import { useDictStore } from '@/store';
|
||||||
import HostKeySelector from '@/components/asset/host-key/selector/index.vue';
|
import HostKeySelector from '@/components/asset/host-key/selector/index.vue';
|
||||||
import HostIdentitySelector from '@/components/asset/host-identity/selector/index.vue';
|
import HostIdentitySelector from '@/components/asset/host-identity/selector/index.vue';
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const formModel = ref<Partial<HostSshExtraSettingModel>>({
|
const formModel = ref<Partial<HostSshExtraSettingModel>>({
|
||||||
authType: ExtraSshAuthType.DEFAULT,
|
authType: ExtraHostAuthType.DEFAULT,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 渲染表单
|
// 渲染表单
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ export const ExtraSettingItems = {
|
|||||||
LABEL: 'LABEL',
|
LABEL: 'LABEL',
|
||||||
};
|
};
|
||||||
|
|
||||||
// 主机额外配置 ssh 认证方式
|
// 主机额外配置认证方式
|
||||||
export const ExtraSshAuthType = {
|
export const ExtraHostAuthType = {
|
||||||
// 使用默认认证方式
|
// 使用默认认证方式
|
||||||
DEFAULT: 'DEFAULT',
|
DEFAULT: 'DEFAULT',
|
||||||
// 自定义密钥
|
// 自定义密钥
|
||||||
|
|||||||
Reference in New Issue
Block a user