2021-07-28 18:03:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2022-07-20 23:25:52 +08:00
|
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="38%">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-form :model="form" ref="redisForm" :rules="rules" label-width="85px">
|
2021-07-28 18:03:19 +08:00
|
|
|
|
<el-form-item prop="projectId" label="项目:" required>
|
|
|
|
|
|
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
|
|
|
|
|
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
<el-form-item prop="envId" label="环境:" required>
|
|
|
|
|
|
<el-select @change="changeEnv" style="width: 100%" v-model="form.envId" placeholder="请选择环境">
|
|
|
|
|
|
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2022-07-10 12:14:06 +08:00
|
|
|
|
<el-form-item prop="mode" label="mode:" required>
|
|
|
|
|
|
<el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
|
|
|
|
|
|
<el-option label="standalone" value="standalone"> </el-option>
|
|
|
|
|
|
<el-option label="cluster" value="cluster"> </el-option>
|
2022-08-23 18:50:07 +08:00
|
|
|
|
<el-option label="sentinel" value="sentinel"> </el-option>
|
2022-07-10 12:14:06 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
<el-form-item prop="host" label="host:" required>
|
2022-07-18 20:36:31 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
v-model.trim="form.host"
|
2022-08-23 18:50:07 +08:00
|
|
|
|
placeholder="请输入host:port;sentinel模式为: mastername=sentinelhost:port,若集群或哨兵需设多个节点可使用','分割"
|
2022-07-18 20:36:31 +08:00
|
|
|
|
auto-complete="off"
|
|
|
|
|
|
type="textarea"
|
|
|
|
|
|
></el-input>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="password" label="密码:">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
show-password
|
|
|
|
|
|
v-model.trim="form.password"
|
2022-07-18 20:36:31 +08:00
|
|
|
|
placeholder="请输入密码, 修改操作可不填"
|
2021-07-28 18:03:19 +08:00
|
|
|
|
autocomplete="new-password"
|
2022-08-02 21:44:01 +08:00
|
|
|
|
><template v-if="form.id && form.id != 0" #suffix>
|
|
|
|
|
|
<el-popover @hide="pwd = ''" placement="right" title="原密码" :width="200" trigger="click" :content="pwd">
|
|
|
|
|
|
<template #reference>
|
|
|
|
|
|
<el-link @click="getPwd" :underline="false" type="primary" class="mr5">原密码</el-link>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-popover>
|
|
|
|
|
|
</template></el-input
|
|
|
|
|
|
>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="db" label="库号:" required>
|
2022-03-15 22:27:39 +08:00
|
|
|
|
<el-input v-model.number="form.db" placeholder="请输入库号"></el-input>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-form-item>
|
2022-07-10 12:14:06 +08:00
|
|
|
|
<el-form-item prop="remark" label="备注:">
|
|
|
|
|
|
<el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
|
|
|
|
|
|
</el-form-item>
|
2022-07-20 23:25:52 +08:00
|
|
|
|
<el-form-item prop="enableSshTunnel" label="SSH隧道:">
|
|
|
|
|
|
<el-col :span="3">
|
|
|
|
|
|
<el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
|
|
|
|
|
|
<el-col :span="19" v-if="form.enableSshTunnel == 1">
|
|
|
|
|
|
<el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in sshTunnelMachineList"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="`${item.ip}:${item.port} [${item.name}]`"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
>
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-form-item>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="dialog-footer">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
2022-07-18 20:36:31 +08:00
|
|
|
|
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
|
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
|
|
|
|
|
import { redisApi } from './api';
|
|
|
|
|
|
import { projectApi } from '../project/api.ts';
|
2022-07-20 23:25:52 +08:00
|
|
|
|
import { machineApi } from '../machine/api.ts';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
import { ElMessage } from 'element-plus';
|
2022-07-18 20:36:31 +08:00
|
|
|
|
import { RsaEncrypt } from '@/common/rsa';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
name: 'RedisEdit',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
visible: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
},
|
|
|
|
|
|
projects: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
},
|
|
|
|
|
|
redis: {
|
|
|
|
|
|
type: [Boolean, Object],
|
|
|
|
|
|
},
|
|
|
|
|
|
title: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
setup(props: any, { emit }) {
|
|
|
|
|
|
const redisForm: any = ref(null);
|
|
|
|
|
|
const state = reactive({
|
2021-09-08 17:55:57 +08:00
|
|
|
|
dialogVisible: false,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
projects: [],
|
|
|
|
|
|
envs: [],
|
2022-07-20 23:25:52 +08:00
|
|
|
|
sshTunnelMachineList: [],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
form: {
|
|
|
|
|
|
id: null,
|
|
|
|
|
|
name: null,
|
2022-07-18 20:36:31 +08:00
|
|
|
|
mode: 'standalone',
|
2022-08-23 18:50:07 +08:00
|
|
|
|
host: '',
|
2021-07-28 18:03:19 +08:00
|
|
|
|
password: null,
|
|
|
|
|
|
project: null,
|
|
|
|
|
|
projectId: null,
|
|
|
|
|
|
envId: null,
|
|
|
|
|
|
env: null,
|
2022-07-18 20:36:31 +08:00
|
|
|
|
remark: '',
|
2022-07-20 23:25:52 +08:00
|
|
|
|
enableSshTunnel: null,
|
|
|
|
|
|
sshTunnelMachineId: null,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
2022-08-02 21:44:01 +08:00
|
|
|
|
pwd: '',
|
2021-07-28 18:03:19 +08:00
|
|
|
|
btnLoading: false,
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
projectId: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请选择项目',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
envId: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请选择环境',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
host: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请输入主机ip:port',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
db: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请输入库号',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2022-07-10 12:14:06 +08:00
|
|
|
|
mode: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请输入模式',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-09-08 17:55:57 +08:00
|
|
|
|
watch(props, async (newValue) => {
|
|
|
|
|
|
state.dialogVisible = newValue.visible;
|
2022-07-20 23:25:52 +08:00
|
|
|
|
if (!state.dialogVisible) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.projects = newValue.projects;
|
|
|
|
|
|
if (newValue.redis) {
|
|
|
|
|
|
getEnvs(newValue.redis.projectId);
|
|
|
|
|
|
state.form = { ...newValue.redis };
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.envs = [];
|
2022-07-20 23:25:52 +08:00
|
|
|
|
state.form = { db: 0, enableSshTunnel: -1 } as any;
|
2021-07-28 18:03:19 +08:00
|
|
|
|
}
|
2022-07-20 23:25:52 +08:00
|
|
|
|
getSshTunnelMachines();
|
2021-07-28 18:03:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-07-20 23:25:52 +08:00
|
|
|
|
const getSshTunnelMachines = async () => {
|
|
|
|
|
|
if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
|
|
|
|
|
|
const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
|
|
|
|
|
|
state.sshTunnelMachineList = res.list;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
const getEnvs = async (projectId: any) => {
|
|
|
|
|
|
state.envs = await projectApi.projectEnvs.request({ projectId });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-08-02 21:44:01 +08:00
|
|
|
|
const getPwd = async () => {
|
|
|
|
|
|
state.pwd = await redisApi.getRedisPwd.request({ id: state.form.id });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
const changeProject = (projectId: number) => {
|
|
|
|
|
|
for (let p of state.projects as any) {
|
|
|
|
|
|
if (p.id == projectId) {
|
|
|
|
|
|
state.form.project = p.name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-12 10:34:16 +08:00
|
|
|
|
state.form.envId = null;
|
|
|
|
|
|
state.form.env = null;
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.envs = [];
|
|
|
|
|
|
getEnvs(projectId);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const changeEnv = (envId: number) => {
|
|
|
|
|
|
for (let p of state.envs as any) {
|
|
|
|
|
|
if (p.id == envId) {
|
|
|
|
|
|
state.form.env = p.name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const btnOk = async () => {
|
2022-07-18 20:36:31 +08:00
|
|
|
|
redisForm.value.validate(async (valid: boolean) => {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
if (valid) {
|
2022-07-18 20:36:31 +08:00
|
|
|
|
const reqForm = { ...state.form };
|
2022-08-23 18:50:07 +08:00
|
|
|
|
if (reqForm.mode == 'sentinel' && reqForm.host.split('=').length != 2) {
|
|
|
|
|
|
ElMessage.error('sentinel模式host需为: mastername=sentinelhost:sentinelport模式');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-07-18 20:36:31 +08:00
|
|
|
|
reqForm.password = await RsaEncrypt(reqForm.password);
|
|
|
|
|
|
redisApi.saveRedis.request(reqForm).then(() => {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
ElMessage.success('保存成功');
|
|
|
|
|
|
emit('val-change', state.form);
|
|
|
|
|
|
state.btnLoading = true;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
state.btnLoading = false;
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
|
|
|
|
cancel();
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error('请正确填写信息');
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const cancel = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
emit('cancel');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
|
redisForm,
|
2022-07-20 23:25:52 +08:00
|
|
|
|
getSshTunnelMachines,
|
2022-08-02 21:44:01 +08:00
|
|
|
|
getPwd,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
changeProject,
|
|
|
|
|
|
changeEnv,
|
|
|
|
|
|
btnOk,
|
|
|
|
|
|
cancel,
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
</style>
|