fix: 保存主机信息必须先通过连接测试 (#574)

pull/576/head
ssongliu 2023-04-11 12:04:25 +08:00 committed by GitHub
parent 7c236ccc3a
commit ab0f4380b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 5 deletions

View File

@ -79,7 +79,7 @@
<el-button @click="submitAddHost(hostInfoRef, 'testconn')"> <el-button @click="submitAddHost(hostInfoRef, 'testconn')">
{{ $t('terminal.testConn') }} {{ $t('terminal.testConn') }}
</el-button> </el-button>
<el-button type="primary" @click="submitAddHost(hostInfoRef, dialogData.title)"> <el-button type="primary" :disabled="!isOK" @click="submitAddHost(hostInfoRef, dialogData.title)">
{{ $t('commons.button.confirm') }} {{ $t('commons.button.confirm') }}
</el-button> </el-button>
</span> </span>
@ -89,7 +89,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, reactive } from 'vue'; import { ref, reactive, watch } from 'vue';
import type { ElForm } from 'element-plus'; import type { ElForm } from 'element-plus';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import { addHost, editHost, testByInfo } from '@/api/modules/host'; import { addHost, editHost, testByInfo } from '@/api/modules/host';
@ -98,7 +98,7 @@ import i18n from '@/lang';
import { MsgError, MsgSuccess } from '@/utils/message'; import { MsgError, MsgSuccess } from '@/utils/message';
const loading = ref(); const loading = ref();
const isOK = ref(false);
interface DialogProps { interface DialogProps {
title: string; title: string;
rowData?: any; rowData?: any;
@ -109,6 +109,15 @@ const drawerVisiable = ref(false);
const dialogData = ref<DialogProps>({ const dialogData = ref<DialogProps>({
title: '', title: '',
}); });
watch(
() => dialogData.value.rowData,
() => {
isOK.value = false;
},
{ deep: true },
);
const groupList = ref(); const groupList = ref();
const acceptParams = (params: DialogProps): void => { const acceptParams = (params: DialogProps): void => {
dialogData.value = params; dialogData.value = params;
@ -179,8 +188,10 @@ const submitAddHost = (formEl: FormInstance | undefined, ops: string) => {
await testByInfo(dialogData.value.rowData).then((res) => { await testByInfo(dialogData.value.rowData).then((res) => {
loading.value = false; loading.value = false;
if (res.data) { if (res.data) {
isOK.value = true;
MsgSuccess(i18n.global.t('terminal.connTestOk')); MsgSuccess(i18n.global.t('terminal.connTestOk'));
} else { } else {
isOK.value = false;
MsgError(i18n.global.t('terminal.connTestFailed')); MsgError(i18n.global.t('terminal.connTestFailed'));
} }
}); });

View File

@ -68,7 +68,7 @@
<el-button @click="submitAddHost(hostRef, 'testConn')"> <el-button @click="submitAddHost(hostRef, 'testConn')">
{{ $t('terminal.testConn') }} {{ $t('terminal.testConn') }}
</el-button> </el-button>
<el-button type="primary" @click="submitAddHost(hostRef, 'saveAndConn')"> <el-button type="primary" :disabled="!isOK" @click="submitAddHost(hostRef, 'saveAndConn')">
{{ $t('terminal.saveAndConn') }} {{ $t('terminal.saveAndConn') }}
</el-button> </el-button>
</span> </span>
@ -84,10 +84,11 @@ import { Rules } from '@/global/form-rules';
import { addHost, testByInfo } from '@/api/modules/host'; import { addHost, testByInfo } from '@/api/modules/host';
import DrawerHeader from '@/components/drawer-header/index.vue'; import DrawerHeader from '@/components/drawer-header/index.vue';
import i18n from '@/lang'; import i18n from '@/lang';
import { reactive, ref } from 'vue'; import { reactive, ref, watch } from 'vue';
import { MsgError, MsgSuccess } from '@/utils/message'; import { MsgError, MsgSuccess } from '@/utils/message';
const dialogVisiable = ref(); const dialogVisiable = ref();
const isOK = ref(false);
type FormInstance = InstanceType<typeof ElForm>; type FormInstance = InstanceType<typeof ElForm>;
const hostRef = ref<FormInstance>(); const hostRef = ref<FormInstance>();
@ -106,6 +107,14 @@ let hostInfo = reactive<Host.HostOperate>({
description: '', description: '',
}); });
watch(
() => hostInfo,
() => {
isOK.value = false;
},
{ deep: true },
);
const rules = reactive({ const rules = reactive({
addr: [Rules.host], addr: [Rules.host],
port: [Rules.requiredInput, Rules.port], port: [Rules.requiredInput, Rules.port],
@ -153,8 +162,10 @@ const submitAddHost = (formEl: FormInstance | undefined, ops: string) => {
case 'testConn': case 'testConn':
await testByInfo(hostInfo).then((res) => { await testByInfo(hostInfo).then((res) => {
if (res.data) { if (res.data) {
isOK.value = true;
MsgSuccess(i18n.global.t('terminal.connTestOk')); MsgSuccess(i18n.global.t('terminal.connTestOk'));
} else { } else {
isOK.value = false;
MsgError(i18n.global.t('terminal.connTestFailed')); MsgError(i18n.global.t('terminal.connTestFailed'));
} }
}); });