fix: no data on server status page #119
This commit is contained in:
parent
cd36dbda48
commit
042ef3075a
|
@ -291,7 +291,8 @@ func (b *browserService) getRedisClient(server string, db int) (item *connection
|
||||||
var ok bool
|
var ok bool
|
||||||
var client redis.UniversalClient
|
var client redis.UniversalClient
|
||||||
if item, ok = b.connMap[server]; ok {
|
if item, ok = b.connMap[server]; ok {
|
||||||
if item.db == db {
|
if item.db == db || db < 0 {
|
||||||
|
// return without switch database directly
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { get, isEmpty, map, mapValues, pickBy, split, sum, toArray, toNumber } from 'lodash'
|
import { get, isEmpty, map, mapValues, pickBy, split, sum, toArray, toNumber } from 'lodash'
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||||
import IconButton from '@/components/common/IconButton.vue'
|
import IconButton from '@/components/common/IconButton.vue'
|
||||||
import Filter from '@/components/icons/Filter.vue'
|
import Filter from '@/components/icons/Filter.vue'
|
||||||
import Refresh from '@/components/icons/Refresh.vue'
|
import Refresh from '@/components/icons/Refresh.vue'
|
||||||
|
@ -12,9 +12,12 @@ const props = defineProps({
|
||||||
|
|
||||||
const browserStore = useBrowserStore()
|
const browserStore = useBrowserStore()
|
||||||
const serverInfo = ref({})
|
const serverInfo = ref({})
|
||||||
const autoRefresh = ref(false)
|
const pageState = reactive({
|
||||||
const loading = ref(false) // loading status for refresh
|
auto: false,
|
||||||
const autoLoading = ref(false) // loading status for auto refresh
|
autoInterval: 5,
|
||||||
|
loading: false, // loading status for refresh
|
||||||
|
autoLoading: false, // loading status for auto refresh
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* refresh server status info
|
* refresh server status info
|
||||||
|
@ -23,16 +26,16 @@ const autoLoading = ref(false) // loading status for auto refresh
|
||||||
*/
|
*/
|
||||||
const refreshInfo = async (force) => {
|
const refreshInfo = async (force) => {
|
||||||
if (force) {
|
if (force) {
|
||||||
loading.value = true
|
pageState.loading = true
|
||||||
} else {
|
} else {
|
||||||
autoLoading.value = true
|
pageState.autoLoading = true
|
||||||
}
|
}
|
||||||
if (!isEmpty(props.server) && browserStore.isConnected(props.server)) {
|
if (!isEmpty(props.server) && browserStore.isConnected(props.server)) {
|
||||||
try {
|
try {
|
||||||
serverInfo.value = await browserStore.getServerInfo(props.server)
|
serverInfo.value = await browserStore.getServerInfo(props.server)
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
pageState.loading = false
|
||||||
autoLoading.value = false
|
pageState.autoLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,10 +44,10 @@ let intervalID
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
refreshInfo()
|
refreshInfo()
|
||||||
intervalID = setInterval(() => {
|
intervalID = setInterval(() => {
|
||||||
if (autoRefresh.value === true) {
|
if (pageState.auto === true) {
|
||||||
refreshInfo()
|
refreshInfo()
|
||||||
}
|
}
|
||||||
}, 5000)
|
}, pageState.autoInterval * 1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
@ -128,7 +131,7 @@ const infoFilter = ref('')
|
||||||
<n-tag size="small" type="primary">{{ redisMode }}</n-tag>
|
<n-tag size="small" type="primary">{{ redisMode }}</n-tag>
|
||||||
</template>
|
</template>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
<n-tooltip v-if="redisMode">
|
<n-tooltip v-if="role">
|
||||||
Role
|
Role
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<n-tag size="small" type="primary">{{ role }}</n-tag>
|
<n-tag size="small" type="primary">{{ role }}</n-tag>
|
||||||
|
@ -139,12 +142,12 @@ const infoFilter = ref('')
|
||||||
<template #header-extra>
|
<template #header-extra>
|
||||||
<n-space align="center" inline>
|
<n-space align="center" inline>
|
||||||
{{ $t('status.auto_refresh') }}
|
{{ $t('status.auto_refresh') }}
|
||||||
<n-switch v-model:value="autoRefresh" :loading="autoLoading" />
|
<n-switch v-model:value="pageState.auto" :loading="pageState.autoLoading" />
|
||||||
<n-tooltip>
|
<n-tooltip>
|
||||||
{{ $t('status.refresh') }}
|
{{ $t('status.refresh') }}
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<n-button
|
<n-button
|
||||||
:loading="autoLoading"
|
:loading="pageState.autoLoading"
|
||||||
circle
|
circle
|
||||||
size="small"
|
size="small"
|
||||||
tertiary
|
tertiary
|
||||||
|
@ -157,7 +160,7 @@ const infoFilter = ref('')
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</n-space>
|
</n-space>
|
||||||
</template>
|
</template>
|
||||||
<n-spin :show="loading">
|
<n-spin :show="pageState.loading">
|
||||||
<n-grid style="min-width: 500px" x-gap="5">
|
<n-grid style="min-width: 500px" x-gap="5">
|
||||||
<n-gi :span="6">
|
<n-gi :span="6">
|
||||||
<n-statistic :label="$t('status.uptime')" :value="uptime[0]">
|
<n-statistic :label="$t('status.uptime')" :value="uptime[0]">
|
||||||
|
@ -192,7 +195,7 @@ const infoFilter = ref('')
|
||||||
</template>
|
</template>
|
||||||
</n-input>
|
</n-input>
|
||||||
</template>
|
</template>
|
||||||
<n-spin :show="loading">
|
<n-spin :show="pageState.loading">
|
||||||
<n-tabs default-value="CPU" placement="left" type="line">
|
<n-tabs default-value="CPU" placement="left" type="line">
|
||||||
<n-tab-pane v-for="(v, k) in serverInfo" :key="k" :disabled="isEmpty(v)" :name="k">
|
<n-tab-pane v-for="(v, k) in serverInfo" :key="k" :disabled="isEmpty(v)" :name="k">
|
||||||
<n-data-table
|
<n-data-table
|
||||||
|
|
|
@ -347,7 +347,7 @@ const useBrowserStore = defineStore('browser', {
|
||||||
*/
|
*/
|
||||||
async getServerInfo(server) {
|
async getServerInfo(server) {
|
||||||
try {
|
try {
|
||||||
const { success, data } = await ServerInfo(server)
|
const { success, data, msg } = await ServerInfo(server)
|
||||||
if (success) {
|
if (success) {
|
||||||
/** @type {RedisServerState} **/
|
/** @type {RedisServerState} **/
|
||||||
const serverInst = this.servers[server]
|
const serverInst = this.servers[server]
|
||||||
|
@ -355,6 +355,8 @@ const useBrowserStore = defineStore('browser', {
|
||||||
serverInst.stats = data
|
serverInst.stats = data
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
} else if (!isEmpty(msg)) {
|
||||||
|
$message.warning(msg)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue