2022-05-17 20:23:08 +08:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2023-07-06 20:59:22 +08:00
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="38%" :destroy-on-close="true">
|
2022-07-20 23:25:52 +08:00
|
|
|
<el-form :model="form" ref="mongoForm" :rules="rules" label-width="85px">
|
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="标签" required>
|
|
|
|
|
<tag-tree-select
|
|
|
|
|
@change-tag="
|
|
|
|
|
(tagIds) => {
|
|
|
|
|
form.tagId = tagIds;
|
|
|
|
|
tagSelectRef.validate();
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
multiple
|
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 18:19:17 +08:00
|
|
|
<el-form-item prop="code" label="编号" required>
|
|
|
|
|
<el-input
|
|
|
|
|
:disabled="form.id"
|
|
|
|
|
v-model.trim="form.code"
|
|
|
|
|
placeholder="请输入机器编号 (数字字母下划线), 不可修改"
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
></el-input>
|
|
|
|
|
</el-form-item>
|
2023-03-06 16:59:57 +08:00
|
|
|
<el-form-item prop="name" label="名称" required>
|
|
|
|
|
<el-input v-model.trim="form.name" placeholder="请输入名称" auto-complete="off"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item prop="uri" label="uri" required>
|
2023-07-06 20:59:22 +08:00
|
|
|
<el-input
|
|
|
|
|
type="textarea"
|
|
|
|
|
:rows="2"
|
|
|
|
|
v-model.trim="form.uri"
|
|
|
|
|
placeholder="形如 mongodb://username:password@host1:port1"
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
></el-input>
|
2023-03-06 16:59:57 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-tab-pane>
|
2022-07-20 23:25:52 +08:00
|
|
|
|
2023-03-06 16:59:57 +08:00
|
|
|
<el-tab-pane label="其他配置" name="other">
|
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>
|
2022-05-17 20:23:08 +08:00
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
2023-12-11 01:00:09 +08:00
|
|
|
<el-button @click="testConn" :loading="testConnBtnLoading" type="success">测试连接</el-button>
|
2022-05-17 20:23:08 +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>
|
2022-05-17 20:23:08 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { toRefs, reactive, watch, ref } from 'vue';
|
2022-05-17 20:23:08 +08:00
|
|
|
import { mongoApi } 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';
|
2024-04-06 18:19:17 +08:00
|
|
|
import { ResourceCodePattern } from '@/common/pattern';
|
2022-05-17 20:23:08 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const props = defineProps({
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
2022-10-26 20:49:29 +08:00
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
mongo: {
|
|
|
|
|
type: [Boolean, Object],
|
|
|
|
|
},
|
|
|
|
|
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 = {
|
|
|
|
|
tagId: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请选择标签',
|
|
|
|
|
trigger: ['change', 'blur'],
|
2022-05-17 20:23:08 +08:00
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
],
|
2024-04-06 18:19:17 +08:00
|
|
|
code: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入编码',
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
pattern: ResourceCodePattern.pattern,
|
|
|
|
|
message: ResourceCodePattern.message,
|
|
|
|
|
trigger: ['blur'],
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-10-29 20:08:15 +08:00
|
|
|
name: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入名称',
|
|
|
|
|
trigger: ['change', 'blur'],
|
2022-05-17 20:23:08 +08:00
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
],
|
|
|
|
|
uri: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入mongo uri',
|
|
|
|
|
trigger: ['change', 'blur'],
|
2022-05-17 20:23:08 +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 mongoForm: any = ref(null);
|
2023-12-05 23:03:51 +08:00
|
|
|
const tagSelectRef: any = ref(null);
|
|
|
|
|
|
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
|
|
|
form: {
|
|
|
|
|
id: null,
|
2023-12-05 23:03:51 +08:00
|
|
|
code: '',
|
2022-10-29 20:08:15 +08:00
|
|
|
name: null,
|
|
|
|
|
uri: null,
|
2023-03-06 16:59:57 +08:00
|
|
|
sshTunnelMachineId: null as any,
|
2023-12-05 23:03:51 +08:00
|
|
|
tagId: [],
|
2022-05-17 20:23:08 +08:00
|
|
|
},
|
2023-12-11 01:00:09 +08:00
|
|
|
submitForm: {},
|
2022-10-29 20:08:15 +08:00
|
|
|
});
|
2022-05-17 20:23:08 +08:00
|
|
|
|
2023-12-11 01:00:09 +08:00
|
|
|
const { dialogVisible, tabActiveName, form, submitForm } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
const { isFetching: testConnBtnLoading, execute: testConnExec } = mongoApi.testConn.useApi(submitForm);
|
|
|
|
|
const { isFetching: saveBtnLoading, execute: saveMongoExec } = mongoApi.saveMongo.useApi(submitForm);
|
2022-05-17 20:23:08 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
watch(props, async (newValue: any) => {
|
|
|
|
|
state.dialogVisible = newValue.visible;
|
|
|
|
|
if (!state.dialogVisible) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-06 16:59:57 +08:00
|
|
|
state.tabActiveName = 'basic';
|
2022-10-29 20:08:15 +08:00
|
|
|
if (newValue.mongo) {
|
|
|
|
|
state.form = { ...newValue.mongo };
|
2024-02-29 22:12:50 +08:00
|
|
|
state.form.tagId = newValue.mongo.tags.map((t: any) => t.tagId);
|
2022-10-29 20:08:15 +08:00
|
|
|
} else {
|
|
|
|
|
state.form = { db: 0 } as any;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-07-20 23:25:52 +08:00
|
|
|
|
2023-11-12 20:14:44 +08:00
|
|
|
const getReqForm = () => {
|
|
|
|
|
const reqForm = { ...state.form };
|
|
|
|
|
if (!state.form.sshTunnelMachineId || state.form.sshTunnelMachineId <= 0) {
|
|
|
|
|
reqForm.sshTunnelMachineId = -1;
|
|
|
|
|
}
|
|
|
|
|
return reqForm;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const testConn = async () => {
|
2022-10-29 20:08:15 +08:00
|
|
|
mongoForm.value.validate(async (valid: boolean) => {
|
2023-12-11 01:00:09 +08:00
|
|
|
if (!valid) {
|
2023-11-12 20:14:44 +08:00
|
|
|
ElMessage.error('请正确填写信息');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
|
|
|
state.submitForm = getReqForm();
|
|
|
|
|
await testConnExec();
|
|
|
|
|
ElMessage.success('连接成功');
|
2023-11-12 20:14:44 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const btnOk = async () => {
|
|
|
|
|
mongoForm.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 saveMongoExec();
|
|
|
|
|
ElMessage.success('保存成功');
|
|
|
|
|
emit('val-change', state.form);
|
|
|
|
|
cancel();
|
2022-10-29 20:08:15 +08:00
|
|
|
});
|
|
|
|
|
};
|
2022-05-17 20:23:08 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const cancel = () => {
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
emit('cancel');
|
|
|
|
|
};
|
2022-05-17 20:23:08 +08:00
|
|
|
</script>
|
2023-03-06 16:59:57 +08:00
|
|
|
<style lang="scss"></style>
|