✨ 优化实例选择逻辑
This commit is contained in:
parent
54f54c1f55
commit
e33cffbfe7
@ -80,7 +80,7 @@ const useStore = defineStore({
|
|||||||
path: '/clients',
|
path: '/clients',
|
||||||
forceNew: true,
|
forceNew: true,
|
||||||
reconnectionDelay: 5000,
|
reconnectionDelay: 5000,
|
||||||
reconnectionAttempts: 3
|
reconnectionAttempts: 1000
|
||||||
})
|
})
|
||||||
this.HostStatusSocket = socketInstance
|
this.HostStatusSocket = socketInstance
|
||||||
socketInstance.on('connect', () => {
|
socketInstance.on('connect', () => {
|
||||||
@ -91,8 +91,7 @@ const useStore = defineStore({
|
|||||||
// console.log(data)
|
// console.log(data)
|
||||||
this.hostList.forEach(item => {
|
this.hostList.forEach(item => {
|
||||||
const { host } = item
|
const { host } = item
|
||||||
if (data[host] === null) return
|
return Object.assign(item, { monitorData: Object.freeze(data[host]) })
|
||||||
return Object.assign(item, { monitorData: data[host] })
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
socketInstance.on('token_verify_fail', (message) => {
|
socketInstance.on('token_verify_fail', (message) => {
|
||||||
|
@ -337,9 +337,10 @@ let sshList = computed(() => $store.sshList)
|
|||||||
|
|
||||||
const setDefaultData = () => {
|
const setDefaultData = () => {
|
||||||
if (!defaultData.value) return
|
if (!defaultData.value) return
|
||||||
let { host } = defaultData.value
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
let { host, monitorData, ...rest } = defaultData.value
|
||||||
oldHost.value = host
|
oldHost.value = host
|
||||||
Object.assign(hostForm.value, { ...defaultData.value })
|
Object.assign(hostForm.value, { host, ...rest })
|
||||||
}
|
}
|
||||||
|
|
||||||
const setBatchDefaultData = () => {
|
const setBatchDefaultData = () => {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-card shadow="always" class="host_card">
|
<el-card shadow="always" class="host_card">
|
||||||
<el-table ref="multipleTableRef" :data="tableData" @selection-change="handleSelectionChange">
|
<el-table
|
||||||
|
ref="tableRef"
|
||||||
|
:data="hosts"
|
||||||
|
@select="handleSelectionChange"
|
||||||
|
@select-all="handleSelectionChange"
|
||||||
|
>
|
||||||
<el-table-column type="selection" />
|
<el-table-column type="selection" />
|
||||||
<el-table-column prop="index" label="序号" width="100px" />
|
<el-table-column prop="index" label="序号" width="100px" />
|
||||||
<el-table-column label="名称">
|
<el-table-column label="名称">
|
||||||
@ -27,7 +32,6 @@
|
|||||||
content="请先配置ssh连接信息"
|
content="请先配置ssh连接信息"
|
||||||
placement="left"
|
placement="left"
|
||||||
>
|
>
|
||||||
<!-- <el-button type="warning">连接终端</el-button> -->
|
|
||||||
<el-button type="success" :disabled="!row.isConfig" @click="handleSSH(row)">连接终端</el-button>
|
<el-button type="success" :disabled="!row.isConfig" @click="handleSSH(row)">连接终端</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-button type="primary" @click="handleUpdate(row)">修改</el-button>
|
<el-button type="primary" @click="handleUpdate(row)">修改</el-button>
|
||||||
@ -39,7 +43,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, getCurrentInstance, reactive, watch } from 'vue'
|
import { ref, computed, getCurrentInstance, nextTick, watch } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
const { proxy: { $api, $router, $tools } } = getCurrentInstance()
|
const { proxy: { $api, $router, $tools } } = getCurrentInstance()
|
||||||
@ -57,21 +61,7 @@ const props = defineProps({
|
|||||||
|
|
||||||
const emit = defineEmits(['update-list', 'update-host', 'select-change',])
|
const emit = defineEmits(['update-list', 'update-host', 'select-change',])
|
||||||
|
|
||||||
let tableData = ref([])
|
let tableRef = ref(null)
|
||||||
|
|
||||||
const updateTableData = () => {
|
|
||||||
console.log('refresh server table data')
|
|
||||||
tableData.value = props.hosts?.map(item => {
|
|
||||||
let { monitorData, ...rest } = item
|
|
||||||
return { ...rest, connect: monitorData?.connect || false }
|
|
||||||
}) || []
|
|
||||||
}
|
|
||||||
|
|
||||||
const connectValues = computed(() => {
|
|
||||||
return props.hosts.map(item => item.monitorData?.connect).join(',')
|
|
||||||
})
|
|
||||||
// 监听到连接状态变化,刷新列表
|
|
||||||
watch(connectValues, updateTableData)
|
|
||||||
|
|
||||||
const hostInfo = computed(() => props.hostInfo || {})
|
const hostInfo = computed(() => props.hostInfo || {})
|
||||||
// const host = computed(() => hostInfo.value?.host)
|
// const host = computed(() => hostInfo.value?.host)
|
||||||
@ -117,9 +107,20 @@ const handleSSH = async ({ host }) => {
|
|||||||
$router.push({ path: '/terminal', query: { host } })
|
$router.push({ path: '/terminal', query: { host } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let selectHosts = ref([])
|
||||||
|
// 由于table数据内部字段更新后table组件会自动取消勾选,所以这里需要手动set勾选
|
||||||
|
watch(() => props.hosts, () => {
|
||||||
|
// console.log('hosts change')
|
||||||
|
nextTick(() => {
|
||||||
|
selectHosts.value.forEach(row => {
|
||||||
|
tableRef.value.toggleRowSelection && tableRef.value.toggleRowSelection(row, true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}, { immediate: true, deep: true })
|
||||||
|
|
||||||
const handleSelectionChange = (val) => {
|
const handleSelectionChange = (val) => {
|
||||||
// console.log(val)
|
// console.log('select: ', val)
|
||||||
// selectHosts.value = val
|
selectHosts.value = val
|
||||||
emit('select-change', val)
|
emit('select-change', val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user