2021-07-28 18:03:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="cancel" width="650px">
|
2023-07-03 21:42:04 +08:00
|
|
|
|
<el-form :model="form" ref="machineForm" :rules="rules" label-width="auto">
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-tabs v-model="tabActiveName">
|
|
|
|
|
|
<el-tab-pane label="基础信息" name="basic">
|
2023-12-05 23:03:51 +08:00
|
|
|
|
<el-form-item ref="tagSelectRef" prop="tagId" label="标签">
|
|
|
|
|
|
<tag-tree-select
|
|
|
|
|
|
multiple
|
|
|
|
|
|
@change-tag="
|
|
|
|
|
|
(tagIds) => {
|
|
|
|
|
|
form.tagId = tagIds;
|
|
|
|
|
|
tagSelectRef.validate();
|
|
|
|
|
|
}
|
|
|
|
|
|
"
|
2024-02-07 06:37:59 +00:00
|
|
|
|
:tag-path="form.tagPath"
|
2024-02-29 22:12:50 +08:00
|
|
|
|
:select-tags="form.tagId"
|
2023-12-05 23:03:51 +08:00
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
/>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-form-item>
|
2024-04-06 04:03:38 +00:00
|
|
|
|
<el-form-item prop="protocol" label="机器类型" required>
|
|
|
|
|
|
<el-radio-group v-model="form.protocol" @change="handleChangeProtocol">
|
|
|
|
|
|
<el-radio :value="1">SSH</el-radio>
|
|
|
|
|
|
<el-radio :value="2">RDP</el-radio>
|
|
|
|
|
|
<!-- <el-radio :value="3">VNC</el-radio> -->
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item prop="name" label="名称" required>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
|
|
|
|
|
|
</el-form-item>
|
2024-04-06 04:03:38 +00:00
|
|
|
|
<el-form-item prop="ip" label="ip" req uired>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-col :span="18">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-input :disabled="form.id" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"> </el-input>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col style="text-align: center" :span="1">:</el-col>
|
|
|
|
|
|
<el-col :span="5">
|
|
|
|
|
|
<el-input type="number" v-model.number="form.port" placeholder="端口"></el-input>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item prop="username" label="用户名">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-input v-model.trim="form.username" placeholder="请输授权用户名" autocomplete="new-password"> </el-input>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-26 17:15:49 +08:00
|
|
|
|
<el-form-item label="认证方式" required>
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-select @change="changeAuthMethod" style="width: 100%" v-model="state.authType" placeholder="请选认证方式">
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-option key="1" label="密码" :value="1"> </el-option>
|
|
|
|
|
|
<el-option key="2" label="授权凭证" :value="2"> </el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item v-if="state.authType == 1" prop="password" label="密码">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-input type="password" show-password v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password">
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item v-if="state.authType == 2" prop="authCertId" label="授权凭证" required>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<auth-cert-select ref="authCertSelectRef" v-model="form.authCertId" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item prop="remark" label="备注">
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-input type="textarea" v-model="form.remark"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
|
|
|
|
|
|
<el-tab-pane label="其他配置" name="other">
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item prop="enableRecorder" label="终端回放">
|
2024-03-02 19:08:19 +08:00
|
|
|
|
<el-checkbox v-model="form.enableRecorder" :true-value="1" :false-value="-1"></el-checkbox>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-09 17:29:52 +08:00
|
|
|
|
<el-form-item prop="sshTunnelMachineId" label="SSH隧道">
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<ssh-tunnel-select v-model="form.sshTunnelMachineId" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
</el-tabs>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
2022-05-12 10:34:16 +08:00
|
|
|
|
<div>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<el-button @click="testConn" :loading="testConnBtnLoading" type="success">测试连接</el-button>
|
2022-01-16 21:45:00 +08:00
|
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
2023-12-11 01:00:09 +08:00
|
|
|
|
<el-button type="primary" :loading="saveBtnLoading" @click="btnOk">确 定</el-button>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
<script lang="ts" setup>
|
2024-04-06 04:03:38 +00:00
|
|
|
|
import { reactive, ref, toRefs, watch } from 'vue';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
import { machineApi } from './api';
|
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
2023-12-05 23:03:51 +08:00
|
|
|
|
import TagTreeSelect from '../component/TagTreeSelect.vue';
|
2023-03-06 16:59:57 +08:00
|
|
|
|
import SshTunnelSelect from '../component/SshTunnelSelect.vue';
|
2023-07-06 20:59:22 +08:00
|
|
|
|
import AuthCertSelect from './authcert/AuthCertSelect.vue';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
visible: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
},
|
|
|
|
|
|
machine: {
|
|
|
|
|
|
type: [Boolean, Object],
|
2022-10-26 20:49:29 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
title: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
},
|
2023-07-06 20:59:22 +08:00
|
|
|
|
});
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
//定义事件
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const emit = defineEmits(['update:visible', 'cancel', 'val-change']);
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const rules = {
|
2023-07-06 20:59:22 +08:00
|
|
|
|
tagId: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请选择标签',
|
2023-12-05 23:03:51 +08:00
|
|
|
|
trigger: ['change'],
|
2023-07-06 20:59:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2023-03-06 16:59:57 +08:00
|
|
|
|
name: [
|
2022-10-29 20:08:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
message: '请输入别名',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
trigger: ['change', 'blur'],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
],
|
2024-04-06 04:03:38 +00:00
|
|
|
|
protocol: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请选择机器类型',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2023-03-06 16:59:57 +08:00
|
|
|
|
ip: [
|
2022-10-29 20:08:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
message: '请输入主机ip和端口',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
trigger: ['change', 'blur'],
|
2021-12-11 11:19:47 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
],
|
2023-03-06 16:59:57 +08:00
|
|
|
|
authCertId: [
|
2022-10-29 20:08:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
message: '请选择授权凭证',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
trigger: ['change', 'blur'],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
],
|
|
|
|
|
|
username: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
message: '请输入授权用户名',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
trigger: ['change', 'blur'],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
],
|
2023-07-06 20:59:22 +08:00
|
|
|
|
};
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const machineForm: any = ref(null);
|
2023-03-06 16:59:57 +08:00
|
|
|
|
const authCertSelectRef: any = ref(null);
|
2023-12-05 23:03:51 +08:00
|
|
|
|
const tagSelectRef: any = ref(null);
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
2024-04-06 04:03:38 +00:00
|
|
|
|
const defaultForm = {
|
|
|
|
|
|
id: null,
|
|
|
|
|
|
code: '',
|
|
|
|
|
|
tagPath: '',
|
|
|
|
|
|
ip: null,
|
|
|
|
|
|
port: 22,
|
|
|
|
|
|
protocol: 1, // 1.ssh 2.rdp
|
|
|
|
|
|
name: null,
|
|
|
|
|
|
authCertId: null as any,
|
|
|
|
|
|
username: '',
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
tagId: [],
|
|
|
|
|
|
remark: '',
|
|
|
|
|
|
sshTunnelMachineId: null as any,
|
|
|
|
|
|
enableRecorder: -1,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
|
dialogVisible: false,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
tabActiveName: 'basic',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
sshTunnelMachineList: [] as any,
|
2023-03-06 16:59:57 +08:00
|
|
|
|
authCerts: [] as any,
|
|
|
|
|
|
authType: 1,
|
2024-04-06 04:03:38 +00:00
|
|
|
|
form: defaultForm,
|
2023-12-11 01:00:09 +08:00
|
|
|
|
submitForm: {},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
pwd: '',
|
|
|
|
|
|
});
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2023-12-11 01:00:09 +08:00
|
|
|
|
const { dialogVisible, tabActiveName, form, submitForm } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
|
|
const { isFetching: testConnBtnLoading, execute: testConnExec } = machineApi.testConn.useApi(submitForm);
|
|
|
|
|
|
const { isFetching: saveBtnLoading, execute: saveMachineExec } = machineApi.saveMachine.useApi(submitForm);
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
watch(props, async (newValue: any) => {
|
|
|
|
|
|
state.dialogVisible = newValue.visible;
|
|
|
|
|
|
if (!state.dialogVisible) {
|
2024-04-06 04:03:38 +00:00
|
|
|
|
state.form = defaultForm;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-06 16:59:57 +08:00
|
|
|
|
state.tabActiveName = 'basic';
|
2022-10-29 20:08:15 +08:00
|
|
|
|
if (newValue.machine) {
|
|
|
|
|
|
state.form = { ...newValue.machine };
|
2024-02-29 22:12:50 +08:00
|
|
|
|
state.form.tagId = newValue.machine.tags.map((t: any) => t.tagId);
|
2023-03-06 16:59:57 +08:00
|
|
|
|
// 如果凭证类型为公共的,则表示使用授权凭证认证
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const authCertId = (state.form as any).authCertId;
|
2023-03-06 16:59:57 +08:00
|
|
|
|
if (authCertId > 0) {
|
|
|
|
|
|
state.authType = 2;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.authType = 1;
|
|
|
|
|
|
}
|
2022-10-29 20:08:15 +08:00
|
|
|
|
} else {
|
2023-03-06 16:59:57 +08:00
|
|
|
|
state.authType = 1;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-07-23 16:41:04 +08:00
|
|
|
|
|
2023-03-06 16:59:57 +08:00
|
|
|
|
const changeAuthMethod = (val: any) => {
|
|
|
|
|
|
if (state.form.id) {
|
|
|
|
|
|
if (val == 2) {
|
|
|
|
|
|
state.form.authCertId = null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.form.password = '';
|
|
|
|
|
|
}
|
2022-10-29 20:08:15 +08:00
|
|
|
|
}
|
2023-07-06 20:59:22 +08:00
|
|
|
|
};
|
2022-08-02 21:44:01 +08:00
|
|
|
|
|
2023-03-06 16:59:57 +08:00
|
|
|
|
const testConn = async () => {
|
|
|
|
|
|
machineForm.value.validate(async (valid: boolean) => {
|
2023-12-11 01:00:09 +08:00
|
|
|
|
if (!valid) {
|
2023-03-06 16:59:57 +08:00
|
|
|
|
ElMessage.error('请正确填写信息');
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
|
|
|
|
|
state.submitForm = getReqForm();
|
|
|
|
|
|
await testConnExec();
|
|
|
|
|
|
ElMessage.success('连接成功');
|
2023-03-06 16:59:57 +08:00
|
|
|
|
});
|
2023-07-06 20:59:22 +08:00
|
|
|
|
};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const btnOk = async () => {
|
|
|
|
|
|
machineForm.value.validate(async (valid: boolean) => {
|
2023-12-11 01:00:09 +08:00
|
|
|
|
if (!valid) {
|
2022-10-29 20:08:15 +08:00
|
|
|
|
ElMessage.error('请正确填写信息');
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
|
|
|
|
|
state.submitForm = getReqForm();
|
|
|
|
|
|
await saveMachineExec();
|
|
|
|
|
|
ElMessage.success('保存成功');
|
|
|
|
|
|
emit('val-change', submitForm);
|
|
|
|
|
|
cancel();
|
2022-10-29 20:08:15 +08:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2023-03-06 16:59:57 +08:00
|
|
|
|
const getReqForm = () => {
|
|
|
|
|
|
const reqForm: any = { ...state.form };
|
|
|
|
|
|
// 如果为密码认证,则置空授权凭证id
|
|
|
|
|
|
if (state.authType == 1) {
|
|
|
|
|
|
reqForm.authCertId = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!state.form.sshTunnelMachineId || state.form.sshTunnelMachineId <= 0) {
|
2023-07-06 20:59:22 +08:00
|
|
|
|
reqForm.sshTunnelMachineId = -1;
|
2023-03-06 16:59:57 +08:00
|
|
|
|
}
|
2023-07-06 20:59:22 +08:00
|
|
|
|
return reqForm;
|
|
|
|
|
|
};
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
2024-04-06 04:03:38 +00:00
|
|
|
|
const handleChangeProtocol = (val: any) => {
|
|
|
|
|
|
if (val == 1) {
|
|
|
|
|
|
state.form.port = 22;
|
|
|
|
|
|
} else if (val == 2) {
|
|
|
|
|
|
state.form.port = 3389;
|
|
|
|
|
|
} else if (val == 3) {
|
|
|
|
|
|
state.form.port = 5901;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const cancel = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
emit('cancel');
|
|
|
|
|
|
};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</script>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
<style lang="scss"></style>
|