2023-03-06 16:59:57 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div style="width: 100%">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-select
|
|
|
|
|
|
@focus="getSshTunnelMachines"
|
|
|
|
|
|
@change="change"
|
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
v-model="sshTunnelMachineId"
|
|
|
|
|
|
@clear="clear"
|
|
|
|
|
|
placeholder="请选择SSH隧道机器"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option v-for="item in sshTunnelMachineList" :key="item.id" :label="`${item.ip}:${item.port} [${item.name}]`" :value="item.id"> </el-option>
|
2023-03-06 16:59:57 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
import { toRefs, reactive, onMounted } from 'vue';
|
|
|
|
|
|
import { machineApi } from '../machine/api';
|
2024-04-29 12:50:49 +08:00
|
|
|
|
import { MachineProtocolEnum } from '../machine/enums';
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
modelValue: {
|
|
|
|
|
|
type: Number,
|
|
|
|
|
|
},
|
2023-07-06 20:59:22 +08:00
|
|
|
|
});
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
//定义事件
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const emit = defineEmits(['update:modelValue']);
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
|
|
|
|
|
// 单选则为id,多选为id数组
|
|
|
|
|
|
sshTunnelMachineId: null as any,
|
|
|
|
|
|
sshTunnelMachineList: [] as any,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const { sshTunnelMachineId, sshTunnelMachineList } = toRefs(state);
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
if (!props.modelValue || props.modelValue <= 0) {
|
|
|
|
|
|
state.sshTunnelMachineId = null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.sshTunnelMachineId = props.modelValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
await getSshTunnelMachines();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const getSshTunnelMachines = async () => {
|
|
|
|
|
|
if (state.sshTunnelMachineList.length == 0) {
|
2024-04-29 12:50:49 +08:00
|
|
|
|
const res = await machineApi.list.request({ pageNum: 1, pageSize: 100, protocol: MachineProtocolEnum.Ssh.value });
|
2023-03-06 16:59:57 +08:00
|
|
|
|
state.sshTunnelMachineList = res.list;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clear = () => {
|
|
|
|
|
|
state.sshTunnelMachineId = null;
|
|
|
|
|
|
change();
|
2023-07-06 20:59:22 +08:00
|
|
|
|
};
|
2023-03-06 16:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
const change = () => {
|
|
|
|
|
|
emit('update:modelValue', state.sshTunnelMachineId);
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss"></style>
|