diff --git a/service/api/api_v1/common/apiData/systemApiStructs/monitor.go b/service/api/api_v1/common/apiData/systemApiStructs/monitor.go new file mode 100644 index 0000000..f39f325 --- /dev/null +++ b/service/api/api_v1/common/apiData/systemApiStructs/monitor.go @@ -0,0 +1,5 @@ +package systemApiStructs + +type MonitorGetDiskStateByPathReq struct { + Path string `json:"path"` +} diff --git a/service/api/api_v1/system/monitor.go b/service/api/api_v1/system/monitor.go index e47308f..7a14d2c 100644 --- a/service/api/api_v1/system/monitor.go +++ b/service/api/api_v1/system/monitor.go @@ -1,14 +1,21 @@ package system import ( + "sun-panel/api/api_v1/common/apiData/systemApiStructs" "sun-panel/api/api_v1/common/apiReturn" "sun-panel/global" + "sun-panel/lib/monitor" + "time" "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" ) type MonitorApi struct{} +const cacheSecond = 3 + +// 弃用 func (a *MonitorApi) GetAll(c *gin.Context) { if value, ok := global.SystemMonitor.Get("value"); ok { apiReturn.SuccessData(c, value) @@ -16,3 +23,74 @@ func (a *MonitorApi) GetAll(c *gin.Context) { } apiReturn.Error(c, "failed") } + +func (a *MonitorApi) GetCpuState(c *gin.Context) { + if v, ok := global.SystemMonitor.Get(global.SystemMonitor_CPU_INFO); ok { + global.Logger.Debugln("读取缓存的的CPU信息") + apiReturn.SuccessData(c, v) + return + } + cpuInfo, err := monitor.GetCPUInfo() + + if err != nil { + apiReturn.Error(c, "failed") + return + } + // 缓存 + global.SystemMonitor.Set(global.SystemMonitor_CPU_INFO, cpuInfo, cacheSecond*time.Second) + apiReturn.SuccessData(c, cpuInfo) +} + +func (a *MonitorApi) GetMemonyState(c *gin.Context) { + if v, ok := global.SystemMonitor.Get(global.SystemMonitor_MEMORY_INFO); ok { + global.Logger.Debugln("读取缓存的的RAM信息") + apiReturn.SuccessData(c, v) + return + } + memoryInfo, err := monitor.GetMemoryInfo() + + if err != nil { + apiReturn.Error(c, "failed") + return + } + + // 缓存 + global.SystemMonitor.Set(global.SystemMonitor_MEMORY_INFO, memoryInfo, cacheSecond*time.Second) + apiReturn.SuccessData(c, memoryInfo) +} + +func (a *MonitorApi) GetDiskStateByPath(c *gin.Context) { + + req := systemApiStructs.MonitorGetDiskStateByPathReq{} + if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil { + apiReturn.ErrorParamFomat(c, err.Error()) + return + } + + cacheDiskName := global.SystemMonitor_DISK_INFO + req.Path + + if v, ok := global.SystemMonitor.Get(cacheDiskName); ok { + global.Logger.Debugln("读取缓存的的DISK信息") + apiReturn.SuccessData(c, v) + return + } + + diskState, err := monitor.GetDiskInfoByPath(req.Path) + if err != nil { + apiReturn.Error(c, "failed") + return + } + + // 缓存 + global.SystemMonitor.Set(cacheDiskName, diskState, cacheSecond*time.Second) + apiReturn.SuccessData(c, diskState) +} + +func (a *MonitorApi) GetDiskMountpoints(c *gin.Context) { + if list, err := monitor.GetDiskMountpoints(); err != nil { + apiReturn.Error(c, err.Error()) + return + } else { + apiReturn.SuccessData(c, list) + } +} diff --git a/service/global/global.go b/service/global/global.go index 20d6910..b24a5c3 100644 --- a/service/global/global.go +++ b/service/global/global.go @@ -35,6 +35,6 @@ var ( Db *gorm.DB RedisDb *redis.Client SystemSetting *systemSetting.SystemSettingCache - SystemMonitor cache.Cacher[ModelSystemMonitor] + SystemMonitor cache.Cacher[interface{}] RateLimit *RateLimiter ) diff --git a/service/global/monitor.go b/service/global/monitor.go index daaa42c..e3e3db7 100644 --- a/service/global/monitor.go +++ b/service/global/monitor.go @@ -1,6 +1,14 @@ package global -import "sun-panel/lib/monitor" +import ( + "sun-panel/lib/monitor" +) + +const ( + SystemMonitor_CPU_INFO = "CPU_INFO" + SystemMonitor_MEMORY_INFO = "MEMORY_INFO" + SystemMonitor_DISK_INFO = "DISK_INFO" +) type ModelSystemMonitor struct { CPUInfo monitor.CPUInfo `json:"cpuInfo"` diff --git a/service/initialize/A_ENTER.go b/service/initialize/A_ENTER.go index 010b732..78abfd7 100644 --- a/service/initialize/A_ENTER.go +++ b/service/initialize/A_ENTER.go @@ -12,7 +12,6 @@ import ( "sun-panel/initialize/other" "sun-panel/initialize/redis" "sun-panel/initialize/runlog" - "sun-panel/initialize/systemMonitor" "sun-panel/initialize/systemSettingCache" "sun-panel/initialize/userToken" "sun-panel/lib/cmn" @@ -90,8 +89,7 @@ func InitApp() error { // 其他的初始化 global.VerifyCodeCachePool = other.InitVerifyCodeCachePool() global.SystemSetting = systemSettingCache.InItSystemSettingCache() - global.SystemMonitor = global.NewCache[global.ModelSystemMonitor](5*time.Hour, -1, "systemMonitorCache") - systemMonitor.Start(global.SystemMonitor, 3*time.Second) + global.SystemMonitor = global.NewCache[interface{}](5*time.Hour, -1, "systemMonitorCache") return nil } diff --git a/service/lib/monitor/monitor.go b/service/lib/monitor/monitor.go index 16c29df..72c2904 100644 --- a/service/lib/monitor/monitor.go +++ b/service/lib/monitor/monitor.go @@ -97,6 +97,24 @@ func GetDiskInfo() ([]DiskInfo, error) { return disks, nil } +func GetDiskMountpoints() ([]disk.PartitionStat, error) { + return disk.Partitions(true) +} + +func GetDiskInfoByPath(path string) (*DiskInfo, error) { + diskInfo := DiskInfo{} + usage, err := disk.Usage(path) + if err != nil { + return nil, err + } + diskInfo.Free = usage.Free + diskInfo.Mountpoint = usage.Path + diskInfo.Total = usage.Total + diskInfo.Used = usage.Used + diskInfo.UsedPercent = usage.UsedPercent + return &diskInfo, nil +} + // 获取网络统计信息 func GetNetIOCountersInfo() ([]NetIOCountersInfo, error) { netInfo := []NetIOCountersInfo{} diff --git a/service/router/system/monitor.go b/service/router/system/monitor.go index ced3291..d4f3ff0 100644 --- a/service/router/system/monitor.go +++ b/service/router/system/monitor.go @@ -9,11 +9,15 @@ import ( func InitMonitorRouter(router *gin.RouterGroup) { api := api_v1.ApiGroupApp.ApiSystem.MonitorApi - // r := router.Group("", middleware.LoginInterceptor) + r := router.Group("", middleware.LoginInterceptor) + r.POST("/system/monitor/getDiskMountpoints", api.GetDiskMountpoints) // 公开模式 rPublic := router.Group("", middleware.PublicModeInterceptor) { rPublic.POST("/system/monitor/getAll", api.GetAll) + rPublic.POST("/system/monitor/getCpuState", api.GetCpuState) + rPublic.POST("/system/monitor/getDiskStateByPath", api.GetDiskStateByPath) + rPublic.POST("/system/monitor/getMemonyState", api.GetMemonyState) } } diff --git a/src/api/system/systemMonitor.ts b/src/api/system/systemMonitor.ts index c7f6b20..0e17ff2 100644 --- a/src/api/system/systemMonitor.ts +++ b/src/api/system/systemMonitor.ts @@ -5,3 +5,28 @@ export function getAll() { url: '/system/monitor/getAll', }) } + +export function getCpuState() { + return post({ + url: '/system/monitor/getCpuState', + }) +} + +export function getDiskStateByPath(path: string) { + return post({ + url: '/system/monitor/getDiskStateByPath', + data: { path }, + }) +} + +export function getMemonyState() { + return post({ + url: '/system/monitor/getMemonyState', + }) +} + +export function getDiskMountpoints() { + return post({ + url: '/system/monitor/getDiskMountpoints', + }) +} diff --git a/src/components/common/ItemCard/index.vue b/src/components/common/ItemCard/index.vue new file mode 100644 index 0000000..7685a7f --- /dev/null +++ b/src/components/common/ItemCard/index.vue @@ -0,0 +1,53 @@ + + + diff --git a/src/components/common/index.ts b/src/components/common/index.ts index 990d2e8..72ff205 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -8,6 +8,7 @@ import RoundCardModal from './RoundCardModal/index.vue' import SvgIconOnline from './SvgIconOnline/index.vue' import JsonImportExport from './JsonImportExport/index.vue' import AppLoader from './AppLoader/index.vue' +import ItemCard from './ItemCard/index.vue' export { Verification, @@ -20,4 +21,5 @@ export { SvgIconOnline, JsonImportExport, AppLoader, + ItemCard, } diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue new file mode 100644 index 0000000..462fcb0 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue @@ -0,0 +1,59 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue new file mode 100644 index 0000000..41898d2 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue @@ -0,0 +1,69 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue new file mode 100644 index 0000000..1453808 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue @@ -0,0 +1,64 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue new file mode 100644 index 0000000..d02f466 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue @@ -0,0 +1,118 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/Edit/DiskEditor/index.vue b/src/components/deskModule/SystemMonitor/Edit/DiskEditor/index.vue new file mode 100644 index 0000000..db2e1ff --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/DiskEditor/index.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/src/components/deskModule/SystemMonitor/Edit/GenericProgressStyleEditor/index.vue b/src/components/deskModule/SystemMonitor/Edit/GenericProgressStyleEditor/index.vue new file mode 100644 index 0000000..bf23d44 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/GenericProgressStyleEditor/index.vue @@ -0,0 +1,101 @@ + + + + + diff --git a/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue b/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue new file mode 100644 index 0000000..0a529a6 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/Edit/index.vue b/src/components/deskModule/SystemMonitor/Edit/index.vue new file mode 100644 index 0000000..ee1a360 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/index.vue @@ -0,0 +1,146 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/common.ts b/src/components/deskModule/SystemMonitor/common.ts new file mode 100644 index 0000000..0df0cd4 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/common.ts @@ -0,0 +1,88 @@ +import type { MonitorData } from './typings' +import { useModuleConfig } from '@/store/modules' + +const modelName = 'systemMonitor' +const moduleConfig = useModuleConfig() + +export async function saveAll(value: MonitorData[]) { + return await moduleConfig.saveToCloud(modelName, { list: value }) +} + +export async function getAll(): Promise< MonitorData[]> { + const res = await moduleConfig.getValueByNameFromCloud<{ list: MonitorData[] }>(modelName) + if (res.code === 0 && res.data && res.data.list) + return res.data.list + return [] +} + +export async function add(value: MonitorData): Promise { + let success = true + let newData: MonitorData[] = [] + try { + const data = await getAll() + if (data) + newData = data + + newData.push(value) + const res = await saveAll(newData) + if (res.code !== 0) + console.log('save failed', res) + } + catch (error) { + console.error(error) + success = false + } + return success +} + +export async function saveByIndex(index: number | undefined, value: MonitorData): Promise { + if (!index) + index = 0 + + let success = true + let newData: MonitorData[] = [] + try { + const data = await getAll() + if (data) + newData = data + + newData[index] = value + const res = await saveAll(newData) + if (res.code !== 0) + console.log('save failed', res) + } + catch (error) { + console.error(error) + success = false + } + return success +} + +export async function getByIndex(index: number): Promise { + try { + const data = await getAll() + if (data[index]) + return data[index] + } + catch (error) { + + } + + return null +} + +export async function deleteByIndex(index: number): Promise { + let success = true + try { + const data = await getAll() + if (data[index]) + data.splice(index, 1) + await saveAll(data) + } + catch (error) { + success = false + console.error(error) + } + + return success +} diff --git a/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue b/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue new file mode 100644 index 0000000..58cf3ea --- /dev/null +++ b/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue @@ -0,0 +1,61 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue b/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue new file mode 100644 index 0000000..f42ec5e --- /dev/null +++ b/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue @@ -0,0 +1,57 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/index copy.vue b/src/components/deskModule/SystemMonitor/index copy.vue new file mode 100644 index 0000000..7c80e28 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/index copy.vue @@ -0,0 +1,171 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/index.vue index d2ccc9a..2e96314 100644 --- a/src/components/deskModule/SystemMonitor/index.vue +++ b/src/components/deskModule/SystemMonitor/index.vue @@ -1,176 +1,300 @@ + + diff --git a/src/components/deskModule/SystemMonitor/typings.ts b/src/components/deskModule/SystemMonitor/typings.ts new file mode 100644 index 0000000..2077144 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/typings.ts @@ -0,0 +1,33 @@ +export enum MonitorType { + 'cpu' = 'cpu', // 图标风格 + 'memory' = 'memory', // 详情风格 + 'disk' = 'disk', +} + +export interface CardStyle { + background: string +} + +export interface MonitorData { + monitorType: MonitorType + extendParam?: { [key: string]: [value:any] } | any + description?: string + // cardStyle: CardStyle +} + +export interface ProgressStyle { + color: string + railColor: string + height: number +} + +export interface GenericProgressStyleExtendParam { + progressColor: string + progressRailColor: string + color: string + backgroundColor: string +} + +export interface DiskExtendParam extends GenericProgressStyleExtendParam { + path: string +} diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 3988e25..5bbd3a8 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -40,6 +40,7 @@ export default { regularUser: '普通', admin: '管理', }, + leastOne: '请至少保留一项', }, setting: { setting: '设置', diff --git a/src/store/modules/moduleConfig/index.ts b/src/store/modules/moduleConfig/index.ts index 7b24926..cf8bcb8 100644 --- a/src/store/modules/moduleConfig/index.ts +++ b/src/store/modules/moduleConfig/index.ts @@ -33,10 +33,10 @@ export const useModuleConfig = defineStore('module-config-store', { }, // 保存到网络 - saveToCloud(name: string, value: any) { + async saveToCloud(name: string, value: any) { const moduleName = `module-${name}` // 保存至网络 - save(moduleName, value) + return save(moduleName, value) }, // 从网络同步 diff --git a/src/typings/systemMonitor.d.ts b/src/typings/systemMonitor.d.ts index 99def4a..7f42e47 100644 --- a/src/typings/systemMonitor.d.ts +++ b/src/typings/systemMonitor.d.ts @@ -34,4 +34,10 @@ declare namespace SystemMonitor { netIOCountersInfo: NetIOCountersInfo[] memoryInfo: MemoryInfo } + + interface Mountpoint{ + device:string + mountpoint:string + fstype:string + } } \ No newline at end of file diff --git a/src/utils/defaultData/index.ts b/src/utils/defaultData/index.ts new file mode 100644 index 0000000..17b24f9 --- /dev/null +++ b/src/utils/defaultData/index.ts @@ -0,0 +1,10 @@ +export const defautSwatchesBackground = [ + '#00000000', + '#000000', + '#ffffff', + '#18A058', + '#2080F0', + '#F0A020', + 'rgba(208, 48, 80, 1)', + '#C418D1FF', +] diff --git a/src/views/exception/test/zujian.vue b/src/views/exception/test/zujian.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/views/home/components/EditItem/IconEditor.vue b/src/views/home/components/EditItem/IconEditor.vue index 8c7b564..1ad87bd 100644 --- a/src/views/home/components/EditItem/IconEditor.vue +++ b/src/views/home/components/EditItem/IconEditor.vue @@ -41,6 +41,7 @@ const itemIconInfo = computed({ return v }, set() { + console.log('aaaa') handleChange() }, }) @@ -52,6 +53,7 @@ function handleIconTypeRadioChange(type: number) { } function handleChange() { + console.log('21222') emit('update:itemIcon', itemIconInfo.value || null) } diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 261cd10..f242922 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -333,9 +333,6 @@ function handleAddItem(itemIconGroupId?: number) { />
-
- -
- +
+ +
+ +