fix: Fix the issue of abnormal option switching on the monitoring page (#10913)

This commit is contained in:
ssongliu 2025-11-11 11:26:24 +08:00 committed by GitHub
parent 82a0f3a770
commit e17bbdd6a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 22 deletions

View file

@ -4,7 +4,8 @@ import "time"
type MonitorSearch struct { type MonitorSearch struct {
Param string `json:"param" validate:"required,oneof=all cpu memory load io network"` Param string `json:"param" validate:"required,oneof=all cpu memory load io network"`
Info string `json:"info"` IO string `json:"io"`
Network string `json:"network"`
StartTime time.Time `json:"startTime"` StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"` EndTime time.Time `json:"endTime"`
} }
@ -19,7 +20,7 @@ type Process struct {
Name string `json:"name"` Name string `json:"name"`
Pid int32 `json:"pid"` Pid int32 `json:"pid"`
Percent float64 `json:"percent"` Percent float64 `json:"percent"`
Memory uint64 `json:"memory"` Memory uint64 `json:"memory"`
Cmd string `json:"cmd"` Cmd string `json:"cmd"`
User string `json:"user"` User string `json:"user"`
} }

View file

@ -83,7 +83,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa
data = append(data, itemData) data = append(data, itemData)
} }
if req.Param == "all" || req.Param == "io" { if req.Param == "all" || req.Param == "io" {
bases, err := monitorRepo.GetIO(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime)) bases, err := monitorRepo.GetIO(repo.WithByName(req.IO), repo.WithByCreatedAt(req.StartTime, req.EndTime))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -97,7 +97,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa
data = append(data, itemData) data = append(data, itemData)
} }
if req.Param == "all" || req.Param == "network" { if req.Param == "all" || req.Param == "network" {
bases, err := monitorRepo.GetNetwork(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime)) bases, err := monitorRepo.GetNetwork(repo.WithByName(req.Network), repo.WithByCreatedAt(req.StartTime, req.EndTime))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -151,7 +151,8 @@ export namespace Host {
} }
export interface MonitorSearch { export interface MonitorSearch {
param: string; param: string;
info: string; io: string;
network: string;
startTime: Date; startTime: Date;
endTime: Date; endTime: Date;
} }

View file

@ -382,7 +382,7 @@ const search = async (changeToLatest: boolean) => {
if (!hasRecords.value) { if (!hasRecords.value) {
return; return;
} }
if (changeToLatest) { if (changeToLatest || !currentRecord.value) {
currentRecord.value = records.value[0]; currentRecord.value = records.value[0];
return; return;
} }

View file

@ -19,6 +19,15 @@
</el-card> </el-card>
<LayoutContent :title="$t('firewall.ipRule', 2)" :class="{ mask: !isActive }"> <LayoutContent :title="$t('firewall.ipRule', 2)" :class="{ mask: !isActive }">
<template #prompt>
<div v-if="!isBind">
<el-alert
type="info"
:closable="false"
:title="$t('firewall.basicStatus', ['1PANEL_BASIC'])"
/>
</div>
</template>
<template #leftToolBar> <template #leftToolBar>
<el-button type="primary" @click="onOpenDialog('create')"> <el-button type="primary" @click="onOpenDialog('create')">
{{ $t('firewall.createIpRule') }} {{ $t('firewall.createIpRule') }}
@ -111,7 +120,13 @@ import ImportDialog from '@/views/host/firewall/ip/import/index.vue';
import FireRouter from '@/views/host/firewall/index.vue'; import FireRouter from '@/views/host/firewall/index.vue';
import FireStatus from '@/views/host/firewall/status/index.vue'; import FireStatus from '@/views/host/firewall/status/index.vue';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref } from 'vue';
import { batchOperateRule, searchFireRule, updateAddrRule, updateFirewallDescription } from '@/api/modules/host'; import {
batchOperateRule,
loadChainStatus,
searchFireRule,
updateAddrRule,
updateFirewallDescription,
} from '@/api/modules/host';
import { Host } from '@/api/interface/host'; import { Host } from '@/api/interface/host';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import i18n from '@/lang'; import i18n from '@/lang';
@ -127,6 +142,7 @@ const fireName = ref();
const maskShow = ref(true); const maskShow = ref(true);
const isActive = ref(false); const isActive = ref(false);
const isBind = ref(false);
const fireStatusRef = ref(); const fireStatusRef = ref();
const opRef = ref(); const opRef = ref();
@ -156,6 +172,7 @@ const search = async () => {
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
loading.value = true; loading.value = true;
loadStatus();
await searchFireRule(params) await searchFireRule(params)
.then((res) => { .then((res) => {
loading.value = false; loading.value = false;
@ -167,6 +184,16 @@ const search = async () => {
}); });
}; };
const loadStatus = async () => {
if (fireName.value !== 'iptables') {
isBind.value = true;
return;
}
await loadChainStatus('1PANEL_BASIC').then((res) => {
isBind.value = res.data.isBind;
});
};
const dialogRef = ref(); const dialogRef = ref();
const onOpenDialog = async ( const onOpenDialog = async (
title: string, title: string,

View file

@ -307,6 +307,10 @@ const onChange = async (info: any) => {
}; };
const loadStatus = async () => { const loadStatus = async () => {
if (fireName.value !== 'iptables') {
isBind.value = true;
return;
}
await loadChainStatus('1PANEL_BASIC').then((res) => { await loadChainStatus('1PANEL_BASIC').then((res) => {
isBind.value = res.data.isBind; isBind.value = res.data.isBind;
}); });

View file

@ -249,7 +249,8 @@ const chartsOption = ref({ loadLoadChart: null, loadCPUChart: null, loadMemoryCh
const searchTime = ref(); const searchTime = ref();
const searchInfo = reactive<Host.MonitorSearch>({ const searchInfo = reactive<Host.MonitorSearch>({
param: '', param: '',
info: '', io: '',
network: '',
startTime: new Date(new Date().setHours(0, 0, 0, 0)), startTime: new Date(new Date().setHours(0, 0, 0, 0)),
endTime: new Date(), endTime: new Date(),
}); });
@ -281,11 +282,16 @@ const search = async (param: string) => {
break; break;
case 'io': case 'io':
searchTime.value = timeRangeIO.value; searchTime.value = timeRangeIO.value;
searchInfo.info = ioChoose.value; searchInfo.io = ioChoose.value || 'all';
break; break;
case 'network': case 'network':
searchTime.value = timeRangeNetwork.value; searchTime.value = timeRangeNetwork.value;
searchInfo.info = networkChoose.value; searchInfo.network = networkChoose.value || 'all';
break;
case 'all':
searchTime.value = timeRangeNetwork.value;
searchInfo.io = ioChoose.value || 'all';
searchInfo.network = networkChoose.value || 'all';
break; break;
} }
if (searchTime.value && searchTime.value.length === 2) { if (searchTime.value && searchTime.value.length === 2) {
@ -335,19 +341,17 @@ const changeIO = (item: string) => {
search('io'); search('io');
}; };
const loadNetworkOptions = async () => { const loadOptions = async () => {
const res = await getNetworkOptions(); const res = await getNetworkOptions();
netOptions.value = res.data; netOptions.value = res.data;
searchInfo.info = globalStore.defaultNetwork || (netOptions.value && netOptions.value[0]); searchInfo.network = globalStore.defaultNetwork || (netOptions.value && netOptions.value[0]);
networkChoose.value = searchInfo.info; networkChoose.value = searchInfo.network;
search('all');
}; const res1 = await getIOOptions();
ioOptions.value = res1.data;
searchInfo.io = globalStore.defaultIO || (ioOptions.value && ioOptions.value[0]);
ioChoose.value = searchInfo.io;
const loadIOOptions = async () => {
const res = await getIOOptions();
ioOptions.value = res.data;
searchInfo.info = globalStore.defaultIO || (ioOptions.value && ioOptions.value[0]);
ioChoose.value = searchInfo.info;
search('all'); search('all');
}; };
@ -711,8 +715,7 @@ function getSideWidth(b: boolean) {
} }
onMounted(() => { onMounted(() => {
loadNetworkOptions(); loadOptions();
loadIOOptions();
}); });
</script> </script>