fix: 优化了概览页、监控页选项排序

pull/450/head
ssongliu 2023-03-29 21:50:08 +08:00 committed by ssongliu
parent b06058ec18
commit c927132aa6
10 changed files with 118 additions and 174 deletions

View File

@ -1,6 +1,7 @@
package v1 package v1
import ( import (
"sort"
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
@ -88,6 +89,7 @@ func (b *BaseApi) GetNetworkOptions(c *gin.Context) {
for _, net := range netStat { for _, net := range netStat {
options = append(options, net.Name) options = append(options, net.Name)
} }
sort.Strings(options)
helper.SuccessWithData(c, options) helper.SuccessWithData(c, options)
} }
@ -98,5 +100,6 @@ func (b *BaseApi) GetIOOptions(c *gin.Context) {
for _, net := range diskStat { for _, net := range diskStat {
options = append(options, net.Name) options = append(options, net.Name)
} }
sort.Strings(options)
helper.SuccessWithData(c, options) helper.SuccessWithData(c, options)
} }

View File

@ -3,13 +3,6 @@ package dto
import "time" import "time"
type DashboardBase struct { type DashboardBase struct {
HaloID uint `json:"haloID"`
DateeaseID uint `json:"dateeaseID"`
JumpServerID uint `json:"jumpserverID"`
MeterSphereID uint `json:"metersphereID"`
KubeoperatorID uint `json:"kubeoperatorID"`
KubepiID uint `json:"kubepiID"`
WebsiteNumber int `json:"websiteNumber"` WebsiteNumber int `json:"websiteNumber"`
DatabaseNumber int `json:"databaseNumber"` DatabaseNumber int `json:"databaseNumber"`
CronjobNumber int `json:"cronjobNumber"` CronjobNumber int `json:"cronjobNumber"`

View File

@ -39,27 +39,6 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
ss, _ := json.Marshal(hostInfo) ss, _ := json.Marshal(hostInfo)
baseInfo.VirtualizationSystem = string(ss) baseInfo.VirtualizationSystem = string(ss)
apps, err := appRepo.GetBy()
if err != nil {
return nil, err
}
for _, app := range apps {
switch app.Key {
case "dateease":
baseInfo.DateeaseID = app.ID
case "halo":
baseInfo.HaloID = app.ID
case "metersphere":
baseInfo.MeterSphereID = app.ID
case "jumpserver":
baseInfo.JumpServerID = app.ID
case "kubeoperator":
baseInfo.KubeoperatorID = app.ID
case "kubepi":
baseInfo.KubepiID = app.ID
}
}
appInstall, err := appInstallRepo.ListBy() appInstall, err := appInstallRepo.ListBy()
if err != nil { if err != nil {
return nil, err return nil, err
@ -169,10 +148,10 @@ func loadDiskInfo() []dto.DiskInfo {
return datas return datas
} }
var excludes = []string{"/mnt/cdrom", "/boot", "/boot/efi", "/dev", "/dev/shm", "/run/lock", "/run", "/run/shm", "/run/user"} var excludes = []string{"/mnt/cdrom", "/boot", "/boot/efi", "/dev", "/dev/shm", "/run/lock", "/run", "/run/shm", "/run/user"}
for _, part := range parts { for i := 0; i < len(parts); i++ {
isExclude := false isExclude := false
for _, exclude := range excludes { for _, exclude := range excludes {
if part.Mountpoint == exclude { if parts[i].Mountpoint == exclude {
isExclude = true isExclude = true
break break
} }
@ -180,11 +159,11 @@ func loadDiskInfo() []dto.DiskInfo {
if isExclude { if isExclude {
continue continue
} }
state, _ := disk.Usage("/") state, _ := disk.Usage(parts[i].Mountpoint)
var itemData dto.DiskInfo var itemData dto.DiskInfo
itemData.Path = part.Mountpoint itemData.Path = parts[i].Mountpoint
itemData.Type = part.Fstype itemData.Type = parts[i].Fstype
itemData.Device = part.Device itemData.Device = parts[i].Device
itemData.Total = state.Total itemData.Total = state.Total
itemData.Free = state.Free itemData.Free = state.Free
itemData.Used = state.Used itemData.Used = state.Used

View File

@ -9171,33 +9171,15 @@ var doc = `{
"databaseNumber": { "databaseNumber": {
"type": "integer" "type": "integer"
}, },
"dateeaseID": {
"type": "integer"
},
"haloID": {
"type": "integer"
},
"hostname": { "hostname": {
"type": "string" "type": "string"
}, },
"jumpserverID": {
"type": "integer"
},
"kernelArch": { "kernelArch": {
"type": "string" "type": "string"
}, },
"kernelVersion": { "kernelVersion": {
"type": "string" "type": "string"
}, },
"kubeoperatorID": {
"type": "integer"
},
"kubepiID": {
"type": "integer"
},
"metersphereID": {
"type": "integer"
},
"os": { "os": {
"type": "string" "type": "string"
}, },
@ -9239,20 +9221,11 @@ var doc = `{
"cpuUsedPercent": { "cpuUsedPercent": {
"type": "number" "type": "number"
}, },
"free": { "diskData": {
"type": "integer" "type": "array",
}, "items": {
"inodesFree": { "$ref": "#/definitions/dto.DiskInfo"
"type": "integer" }
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
}, },
"ioCount": { "ioCount": {
"type": "integer" "type": "integer"
@ -9305,11 +9278,40 @@ var doc = `{
"timeSinceUptime": { "timeSinceUptime": {
"type": "string" "type": "string"
}, },
"uptime": {
"type": "integer"
}
}
},
"dto.DiskInfo": {
"type": "object",
"properties": {
"device": {
"type": "string"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
},
"path": {
"type": "string"
},
"total": { "total": {
"type": "integer" "type": "integer"
}, },
"uptime": { "type": {
"type": "integer" "type": "string"
}, },
"used": { "used": {
"type": "integer" "type": "integer"

View File

@ -9157,33 +9157,15 @@
"databaseNumber": { "databaseNumber": {
"type": "integer" "type": "integer"
}, },
"dateeaseID": {
"type": "integer"
},
"haloID": {
"type": "integer"
},
"hostname": { "hostname": {
"type": "string" "type": "string"
}, },
"jumpserverID": {
"type": "integer"
},
"kernelArch": { "kernelArch": {
"type": "string" "type": "string"
}, },
"kernelVersion": { "kernelVersion": {
"type": "string" "type": "string"
}, },
"kubeoperatorID": {
"type": "integer"
},
"kubepiID": {
"type": "integer"
},
"metersphereID": {
"type": "integer"
},
"os": { "os": {
"type": "string" "type": "string"
}, },
@ -9225,20 +9207,11 @@
"cpuUsedPercent": { "cpuUsedPercent": {
"type": "number" "type": "number"
}, },
"free": { "diskData": {
"type": "integer" "type": "array",
}, "items": {
"inodesFree": { "$ref": "#/definitions/dto.DiskInfo"
"type": "integer" }
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
}, },
"ioCount": { "ioCount": {
"type": "integer" "type": "integer"
@ -9291,11 +9264,40 @@
"timeSinceUptime": { "timeSinceUptime": {
"type": "string" "type": "string"
}, },
"uptime": {
"type": "integer"
}
}
},
"dto.DiskInfo": {
"type": "object",
"properties": {
"device": {
"type": "string"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
},
"path": {
"type": "string"
},
"total": { "total": {
"type": "integer" "type": "integer"
}, },
"uptime": { "type": {
"type": "integer" "type": "string"
}, },
"used": { "used": {
"type": "integer" "type": "integer"

View File

@ -443,24 +443,12 @@ definitions:
$ref: '#/definitions/dto.DashboardCurrent' $ref: '#/definitions/dto.DashboardCurrent'
databaseNumber: databaseNumber:
type: integer type: integer
dateeaseID:
type: integer
haloID:
type: integer
hostname: hostname:
type: string type: string
jumpserverID:
type: integer
kernelArch: kernelArch:
type: string type: string
kernelVersion: kernelVersion:
type: string type: string
kubeoperatorID:
type: integer
kubepiID:
type: integer
metersphereID:
type: integer
os: os:
type: string type: string
platform: platform:
@ -488,16 +476,10 @@ definitions:
type: number type: number
cpuUsedPercent: cpuUsedPercent:
type: number type: number
free: diskData:
type: integer items:
inodesFree: $ref: '#/definitions/dto.DiskInfo'
type: integer type: array
inodesTotal:
type: integer
inodesUsed:
type: integer
inodesUsedPercent:
type: number
ioCount: ioCount:
type: integer type: integer
ioReadBytes: ioReadBytes:
@ -532,10 +514,29 @@ definitions:
type: string type: string
timeSinceUptime: timeSinceUptime:
type: string type: string
total:
type: integer
uptime: uptime:
type: integer type: integer
type: object
dto.DiskInfo:
properties:
device:
type: string
free:
type: integer
inodesFree:
type: integer
inodesTotal:
type: integer
inodesUsed:
type: integer
inodesUsedPercent:
type: number
path:
type: string
total:
type: integer
type:
type: string
used: used:
type: integer type: integer
usedPercent: usedPercent:

View File

@ -1,12 +1,5 @@
export namespace Dashboard { export namespace Dashboard {
export interface BaseInfo { export interface BaseInfo {
haloID: number;
dateeaseID: number;
jumpserverID: number;
metersphereID: number;
kubeoperatorID: number;
kubepiID: number;
websiteNumber: number; websiteNumber: number;
databaseNumber: number; databaseNumber: number;
cronjobNumber: number; cronjobNumber: number;

View File

@ -41,7 +41,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { App } from '@/api/interface/app'; import { App } from '@/api/interface/app';
import { Dashboard } from '@/api/interface/dashboard';
import { SearchApp } from '@/api/modules/app'; import { SearchApp } from '@/api/modules/app';
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -57,26 +56,10 @@ let req = reactive({
recommend: true, recommend: true,
}); });
const baseInfo = ref({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
});
let loading = ref(false); let loading = ref(false);
let apps = ref<App.App[]>([]); let apps = ref<App.App[]>([]);
const acceptParams = (base: Dashboard.BaseInfo): void => { const acceptParams = (): void => {
baseInfo.value.haloID = base.haloID;
baseInfo.value.dateeaseID = base.dateeaseID;
baseInfo.value.jumpserverID = base.jumpserverID;
baseInfo.value.metersphereID = base.metersphereID;
baseInfo.value.kubeoperatorID = base.kubeoperatorID;
baseInfo.value.kubepiID = base.kubepiID;
search(req); search(req);
}; };

View File

@ -234,13 +234,6 @@ const searchInfo = reactive({
}); });
const baseInfo = ref<Dashboard.BaseInfo>({ const baseInfo = ref<Dashboard.BaseInfo>({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
websiteNumber: 0, websiteNumber: 0,
databaseNumber: 0, databaseNumber: 0,
cronjobNumber: 0, cronjobNumber: 0,
@ -341,7 +334,7 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
currentInfo.value = baseInfo.value.currentInfo; currentInfo.value = baseInfo.value.currentInfo;
onLoadCurrentInfo(); onLoadCurrentInfo();
statuRef.value.acceptParams(currentInfo.value, baseInfo.value); statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
appRef.value.acceptParams(baseInfo.value); appRef.value.acceptParams();
if (isInit) { if (isInit) {
// window.addEventListener('resize', changeChartSize); // window.addEventListener('resize', changeChartSize);
timer = setInterval(async () => { timer = setInterval(async () => {

View File

@ -111,18 +111,11 @@
import { Dashboard } from '@/api/interface/dashboard'; import { Dashboard } from '@/api/interface/dashboard';
import i18n from '@/lang'; import i18n from '@/lang';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { onBeforeUnmount, onMounted, ref } from 'vue'; import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
import { GlobalStore } from '@/store'; import { GlobalStore } from '@/store';
const globalStore = GlobalStore(); const globalStore = GlobalStore();
const baseInfo = ref<Dashboard.BaseInfo>({ const baseInfo = ref<Dashboard.BaseInfo>({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
websiteNumber: 0, websiteNumber: 0,
databaseNumber: 0, databaseNumber: 0,
cronjobNumber: 0, cronjobNumber: 0,
@ -181,6 +174,7 @@ const acceptParams = (current: Dashboard.CurrentInfo, base: Dashboard.BaseInfo):
freshChart('cpu', 'CPU', formatNumber(currentInfo.value.cpuUsedPercent)); freshChart('cpu', 'CPU', formatNumber(currentInfo.value.cpuUsedPercent));
freshChart('memory', i18n.global.t('monitor.memory'), formatNumber(currentInfo.value.MemoryUsedPercent)); freshChart('memory', i18n.global.t('monitor.memory'), formatNumber(currentInfo.value.MemoryUsedPercent));
freshChart('load', i18n.global.t('home.load'), formatNumber(currentInfo.value.loadUsagePercent)); freshChart('load', i18n.global.t('home.load'), formatNumber(currentInfo.value.loadUsagePercent));
nextTick(() => {
for (let i = 0; i < currentInfo.value.diskData.length; i++) { for (let i = 0; i < currentInfo.value.diskData.length; i++) {
freshChart( freshChart(
'disk' + i, 'disk' + i,
@ -188,6 +182,7 @@ const acceptParams = (current: Dashboard.CurrentInfo, base: Dashboard.BaseInfo):
formatNumber(currentInfo.value.diskData[i].usedPercent), formatNumber(currentInfo.value.diskData[i].usedPercent),
); );
} }
});
}; };
const freshChart = (chartName: string, Title: string, Data: number) => { const freshChart = (chartName: string, Title: string, Data: number) => {