[feat] more mborad and memory info
This commit is contained in:
@@ -71,9 +71,10 @@ interface GpuInfo {
|
||||
}
|
||||
|
||||
interface MemoryInfo {
|
||||
capacity?: number // 容量(字节)
|
||||
manufacturer?: string
|
||||
part_number?: string
|
||||
speed?: number // MHz
|
||||
speed?: number // MHz,实际频率 ConfiguredClockSpeed
|
||||
default_speed?: number // MHz,默认频率 Speed(如果存在)
|
||||
}
|
||||
|
||||
interface MonitorInfo {
|
||||
@@ -83,42 +84,55 @@ interface MonitorInfo {
|
||||
resolution_height?: number
|
||||
}
|
||||
|
||||
interface MotherboardInfo {
|
||||
manufacturer?: string // 制造商
|
||||
model?: string // 型号
|
||||
version?: string
|
||||
}
|
||||
|
||||
interface HardwareData {
|
||||
allSysData: AllSystemInfo
|
||||
computerInfo: ComputerInfo
|
||||
gpuInfo: GpuInfo | null
|
||||
memoryInfo: MemoryInfo[]
|
||||
monitorInfo: MonitorInfo[]
|
||||
motherboardInfo: MotherboardInfo | null
|
||||
}
|
||||
|
||||
// 硬件信息 fetcher
|
||||
const hardwareInfoFetcher = async (): Promise<HardwareData> => {
|
||||
// 并行获取系统信息、PowerShell 信息、GPU 信息、内存信息和显示器信息
|
||||
const [sys, computerInfoData, gpuInfoData, memoryInfoData, monitorInfoData] = await Promise.all([
|
||||
allSysInfo(),
|
||||
invoke<ComputerInfo>("get_computer_info").catch((error) => {
|
||||
console.error("获取 PowerShell 信息失败:", error)
|
||||
return {} as ComputerInfo
|
||||
}),
|
||||
invoke<GpuInfo | null>("get_gpu_info").catch((error) => {
|
||||
console.error("获取 GPU 信息失败:", error)
|
||||
return null
|
||||
}),
|
||||
invoke<MemoryInfo[]>("get_memory_info").catch((error) => {
|
||||
console.error("获取内存信息失败:", error)
|
||||
return [] as MemoryInfo[]
|
||||
}),
|
||||
invoke<MonitorInfo[]>("get_monitor_info").catch((error) => {
|
||||
console.error("获取显示器信息失败:", error)
|
||||
return [] as MonitorInfo[]
|
||||
}),
|
||||
])
|
||||
// 并行获取系统信息、PowerShell 信息、GPU 信息、内存信息、显示器信息和主板信息
|
||||
const [sys, computerInfoData, gpuInfoData, memoryInfoData, monitorInfoData, motherboardInfoData] =
|
||||
await Promise.all([
|
||||
allSysInfo(),
|
||||
invoke<ComputerInfo>("get_computer_info").catch((error) => {
|
||||
console.error("获取 PowerShell 信息失败:", error)
|
||||
return {} as ComputerInfo
|
||||
}),
|
||||
invoke<GpuInfo | null>("get_gpu_info").catch((error) => {
|
||||
console.error("获取 GPU 信息失败:", error)
|
||||
return null
|
||||
}),
|
||||
invoke<MemoryInfo[]>("get_memory_info").catch((error) => {
|
||||
console.error("获取内存信息失败:", error)
|
||||
return [] as MemoryInfo[]
|
||||
}),
|
||||
invoke<MonitorInfo[]>("get_monitor_info").catch((error) => {
|
||||
console.error("获取显示器信息失败:", error)
|
||||
return [] as MonitorInfo[]
|
||||
}),
|
||||
invoke<MotherboardInfo>("get_motherboard_info").catch((error) => {
|
||||
console.error("获取主板信息失败:", error)
|
||||
return { manufacturer: undefined, model: undefined, version: undefined } as MotherboardInfo
|
||||
}),
|
||||
])
|
||||
|
||||
console.log("系统信息:", sys)
|
||||
console.log("PowerShell 信息:", computerInfoData)
|
||||
console.log("GPU 信息:", gpuInfoData)
|
||||
console.log("内存信息:", memoryInfoData)
|
||||
console.log("显示器信息:", monitorInfoData)
|
||||
console.log("主板信息:", motherboardInfoData)
|
||||
|
||||
if (sys?.cpus) {
|
||||
console.log("CPU数据:", sys.cpus)
|
||||
@@ -134,11 +148,12 @@ const hardwareInfoFetcher = async (): Promise<HardwareData> => {
|
||||
gpuInfo: gpuInfoData,
|
||||
memoryInfo: memoryInfoData,
|
||||
monitorInfo: monitorInfoData,
|
||||
motherboardInfo: motherboardInfoData,
|
||||
}
|
||||
}
|
||||
|
||||
function HardwareInfoContent() {
|
||||
const { data, isLoading } = useSWR<HardwareData>("/api/hardware-info", hardwareInfoFetcher, {
|
||||
const { data, isLoading, isValidating } = useSWR<HardwareData>("/api/hardware-info", hardwareInfoFetcher, {
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
dedupingInterval: 5 * 60 * 1000, // 5分钟内相同请求去重
|
||||
@@ -149,6 +164,7 @@ function HardwareInfoContent() {
|
||||
const gpuInfo = data?.gpuInfo
|
||||
const memoryInfo = data?.memoryInfo || []
|
||||
const monitorInfo = data?.monitorInfo || []
|
||||
const motherboardInfo = data?.motherboardInfo
|
||||
|
||||
const formatBytes = (bytes?: number) => {
|
||||
if (!bytes) return "未知"
|
||||
@@ -227,8 +243,8 @@ function HardwareInfoContent() {
|
||||
})()
|
||||
: null
|
||||
|
||||
// 如果正在加载,显示 Skeleton 骨架屏
|
||||
if (isLoading) {
|
||||
// 如果正在加载或正在验证(包括刷新),显示 Skeleton 骨架屏
|
||||
if (isLoading || isValidating) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* 系统信息 Skeleton */}
|
||||
@@ -324,6 +340,7 @@ function HardwareInfoContent() {
|
||||
{allSysData?.total_memory && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="text-sm font-medium text-foreground-600">内存</div>
|
||||
{/* 第一行:总容量和已用内存 */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Chip>
|
||||
<span className="font-medium">总容量:</span> {formatBytes(allSysData.total_memory)}
|
||||
@@ -336,23 +353,34 @@ function HardwareInfoContent() {
|
||||
)}
|
||||
</Chip>
|
||||
)}
|
||||
{allSysData.total_memory !== undefined && allSysData.used_memory !== undefined && (
|
||||
<Chip>
|
||||
<span className="font-medium">可用:</span>{" "}
|
||||
{formatBytes(allSysData.total_memory - allSysData.used_memory)}
|
||||
</Chip>
|
||||
)}
|
||||
{memoryInfo.length > 0 && memoryInfo[0].part_number && (
|
||||
<Chip>
|
||||
<span className="font-medium">型号:</span> {memoryInfo[0].part_number}
|
||||
</Chip>
|
||||
)}
|
||||
{memoryInfo.length > 0 && memoryInfo[0].speed && (
|
||||
<Chip>
|
||||
<span className="font-medium">频率:</span> {memoryInfo[0].speed} MHz
|
||||
</Chip>
|
||||
)}
|
||||
</div>
|
||||
{/* 每个内存条的详细信息 */}
|
||||
{memoryInfo.length > 0 && (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{memoryInfo.map((mem, index) => (
|
||||
<div key={index} className="flex flex-wrap gap-2">
|
||||
{mem.capacity && (
|
||||
<Chip>
|
||||
<span className="font-medium">容量:</span> {formatBytes(mem.capacity)}
|
||||
</Chip>
|
||||
)}
|
||||
{mem.manufacturer && (
|
||||
<Chip>
|
||||
<span className="font-medium">制造商:</span> {mem.manufacturer}
|
||||
</Chip>
|
||||
)}
|
||||
{mem.speed && (
|
||||
<Chip>
|
||||
<span className="font-medium">频率:</span> {mem.speed} MHz
|
||||
{mem.default_speed && (
|
||||
<span className="ml-1">({mem.default_speed} MHz)</span>
|
||||
)}
|
||||
</Chip>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -410,13 +438,28 @@ function HardwareInfoContent() {
|
||||
)}
|
||||
|
||||
{/* 主板信息 */}
|
||||
{(computerInfo.CsManufacturer || computerInfo.BiosSMBIOSBIOSVersion) && (
|
||||
{(motherboardInfo?.model ||
|
||||
motherboardInfo?.manufacturer ||
|
||||
motherboardInfo?.version ||
|
||||
computerInfo.BiosSMBIOSBIOSVersion) && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="text-sm font-medium text-foreground-600">主板</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{computerInfo.CsManufacturer && (
|
||||
{motherboardInfo?.model && (
|
||||
<Chip>
|
||||
<span className="font-medium">制造商:</span> {computerInfo.CsManufacturer}
|
||||
<span className="font-medium">型号:</span> {motherboardInfo.model}
|
||||
</Chip>
|
||||
)}
|
||||
{motherboardInfo?.manufacturer && (
|
||||
<Chip>
|
||||
<span className="font-medium">品牌:</span> {motherboardInfo.manufacturer}
|
||||
</Chip>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{motherboardInfo?.version && (
|
||||
<Chip>
|
||||
<span className="font-medium">版本:</span> {motherboardInfo.version}
|
||||
</Chip>
|
||||
)}
|
||||
{computerInfo.BiosSMBIOSBIOSVersion && (
|
||||
|
||||
Reference in New Issue
Block a user