细节调整及优化(26.8.3)
This commit is contained in:
1 parent
0a19b4b38a
commit
4dd60f42a1
72 files changed
+4779
-1395
No files matched your search
@@ -5,8 +5,10 @@ import {
|
||||
ShieldCheck, ShieldOff, Zap, Thermometer, Clock, ChevronDown,
|
||||
ArrowDown, ArrowUp, Wifi, FolderOpen, Copy, ListChecks,
|
||||
Monitor as MonitorIcon, GripVertical, SlidersHorizontal,
|
||||
Eye, EyeOff, MousePointerClick,
|
||||
Eye, EyeOff, MousePointerClick, Plus, PencilLine,
|
||||
CircuitBoard, BatteryFull,
|
||||
} from '@lucide/vue'
|
||||
import type { LucideIcon } from '@lucide/vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { VueDraggable } from 'vue-draggable-plus'
|
||||
@@ -23,8 +25,10 @@ import {
|
||||
type AlertConfig,
|
||||
DEFAULT_COLOR_THEME,
|
||||
} from '@/stores/monitorStore'
|
||||
import { STORAGE_KEYS } from '@/lib/constants'
|
||||
import { useModuleTabs } from '@/lib/use-module-tabs'
|
||||
import { fmt, tempColor, loadColor, fmtSpeed, typeLabel, groupDisplayName, groupIcon } from './format'
|
||||
import { fmt, tempColor, fmtSpeed, typeLabel, groupDisplayName, groupIcon } from './format'
|
||||
import OverviewCard, { type OverviewCardView } from './OverviewCard.vue'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
@@ -193,6 +197,183 @@ const storageDrives = computed<StorageDrive[]>(() => {
|
||||
const downSpeed = computed(() => fmtSpeed(store.networkSpeed?.downloadBps ?? null))
|
||||
const upSpeed = computed(() => fmtSpeed(store.networkSpeed?.uploadBps ?? null))
|
||||
|
||||
// ===== 概览页卡片化布局(模板化卡片 + 自由添加/排序) =====
|
||||
|
||||
/** 概览卡片类型 id */
|
||||
type OverviewCardId = 'cpu' | 'gpu' | 'memory' | 'network' | 'storage' | 'motherboard' | 'battery' | 'psu'
|
||||
|
||||
/** 卡片目录:可添加的全部硬件卡片 */
|
||||
const OVERVIEW_CARD_CATALOG: { id: OverviewCardId; name: string; desc: string; icon: LucideIcon }[] = [
|
||||
{ id: 'cpu', name: 'CPU', desc: '温度 / 功耗 / 负载', icon: Cpu },
|
||||
{ id: 'gpu', name: 'GPU', desc: '温度 / 功耗 / 负载', icon: Gauge },
|
||||
{ id: 'memory', name: '内存', desc: '用量 / 负载', icon: MemoryStick },
|
||||
{ id: 'network', name: '网络', desc: '下载 / 上传速率', icon: Wifi },
|
||||
{ id: 'storage', name: '存储', desc: '各硬盘温度 / 容量 / 使用率', icon: HardDrive },
|
||||
{ id: 'motherboard', name: '主板', desc: '温度 / 风扇', icon: CircuitBoard },
|
||||
{ id: 'battery', name: '电池', desc: '电量 / 充放电功率', icon: BatteryFull },
|
||||
{ id: 'psu', name: '电源', desc: '输出功率', icon: Zap },
|
||||
]
|
||||
|
||||
const OVERVIEW_CARDS_VERSION = 1
|
||||
/** 默认显示的卡片(用户需求:cpu/gpu/内存/网络) */
|
||||
const DEFAULT_OVERVIEW_CARDS: OverviewCardId[] = ['cpu', 'gpu', 'memory', 'network']
|
||||
|
||||
/** 加载持久化的卡片列表(过滤未知 id,空则回退默认) */
|
||||
function loadOverviewCards(): OverviewCardId[] {
|
||||
try {
|
||||
const saved = localStorage.getItem(STORAGE_KEYS.monitorOverviewCards)
|
||||
if (!saved) return [...DEFAULT_OVERVIEW_CARDS]
|
||||
const parsed = JSON.parse(saved)
|
||||
if (parsed?.version !== OVERVIEW_CARDS_VERSION) return [...DEFAULT_OVERVIEW_CARDS]
|
||||
const ids: string[] = Array.isArray(parsed.cards) ? parsed.cards : []
|
||||
const valid = ids.filter(id => OVERVIEW_CARD_CATALOG.some(c => c.id === id)) as OverviewCardId[]
|
||||
return valid.length ? valid : [...DEFAULT_OVERVIEW_CARDS]
|
||||
} catch {
|
||||
return [...DEFAULT_OVERVIEW_CARDS]
|
||||
}
|
||||
}
|
||||
|
||||
/** 当前显示的卡片列表(顺序即显示顺序) */
|
||||
const overviewCards = ref<OverviewCardId[]>(loadOverviewCards())
|
||||
|
||||
function saveOverviewCards() {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEYS.monitorOverviewCards, JSON.stringify({
|
||||
version: OVERVIEW_CARDS_VERSION,
|
||||
cards: overviewCards.value,
|
||||
}))
|
||||
} catch { /* 忽略 localStorage 写入失败 */ }
|
||||
}
|
||||
|
||||
/** 编辑模式:显示拖拽把手/移除按钮,启用拖拽排序 */
|
||||
const overviewEditing = ref(false)
|
||||
/** 添加卡片 Popover 开关 */
|
||||
const overviewAddOpen = ref(false)
|
||||
|
||||
/** 尚未添加的卡片(添加菜单内容) */
|
||||
const addableOverviewCards = computed(() =>
|
||||
OVERVIEW_CARD_CATALOG.filter(c => !overviewCards.value.includes(c.id))
|
||||
)
|
||||
|
||||
function addOverviewCard(id: OverviewCardId) {
|
||||
if (overviewCards.value.includes(id)) return
|
||||
overviewCards.value.push(id)
|
||||
saveOverviewCards()
|
||||
overviewAddOpen.value = false
|
||||
}
|
||||
|
||||
function removeOverviewCard(id: string) {
|
||||
overviewCards.value = overviewCards.value.filter(c => c !== id)
|
||||
saveOverviewCards()
|
||||
}
|
||||
|
||||
/** 拖拽排序结束:持久化新顺序 */
|
||||
function onOverviewDragEnd() {
|
||||
saveOverviewCards()
|
||||
}
|
||||
|
||||
// --- 主板/电池/电源数据提取(卡片用) ---
|
||||
|
||||
/** 主板分组(motherboard 为空时回退 superio / embeddedcontroller) */
|
||||
const boardGroup = computed(() =>
|
||||
store.groupById['motherboard'] ?? store.groupById['superio'] ?? store.groupById['embeddedcontroller'] ?? null
|
||||
)
|
||||
const boardName = computed(() => boardGroup.value?.sensors[0]?.hardwareName ?? null)
|
||||
const boardTemp = computed(() =>
|
||||
boardGroup.value?.sensors.find(s => s.type === 'temperature' && s.value != null)?.value ?? null
|
||||
)
|
||||
const boardFan = computed(() =>
|
||||
boardGroup.value?.sensors.find(s => s.type === 'fan' && s.value != null)?.value ?? null
|
||||
)
|
||||
|
||||
const batteryLevel = computed(() => {
|
||||
const g = store.groupById['battery']
|
||||
if (!g) return null
|
||||
return g.sensors.find(s => s.name === 'Battery Level' && s.type === 'level')?.value
|
||||
?? g.sensors.find(s => s.type === 'level')?.value
|
||||
?? null
|
||||
})
|
||||
const batteryCharge = computed(() => store.findSensorValue('battery', { name: 'Battery Charge', type: 'power' }))
|
||||
const batteryDischarge = computed(() => store.findSensorValue('battery', { name: 'Battery Discharge', type: 'power' }))
|
||||
const batteryName = computed(() => store.groupById['battery']?.sensors[0]?.hardwareName ?? null)
|
||||
|
||||
const psuPower = computed(() => store.findSensorValue('psu', { type: 'power' }))
|
||||
const psuName = computed(() => store.groupById['psu']?.sensors[0]?.hardwareName ?? null)
|
||||
|
||||
/** 构建各卡片视图数据(从上面的 computed 提取值并格式化) */
|
||||
function buildOverviewCardView(id: OverviewCardId): OverviewCardView {
|
||||
switch (id) {
|
||||
case 'cpu':
|
||||
return {
|
||||
id, title: 'CPU', icon: Cpu, subtitle: cpuModel.value,
|
||||
main: { label: '封装温度', labelIcon: Thermometer, text: fmt(cpuTemp.value, 0), unit: '°C', colorClass: tempColor(cpuTemp.value) },
|
||||
subs: [{ label: '功耗', labelIcon: Zap, text: fmt(cpuPower.value, 1), unit: 'W' }],
|
||||
load: { label: '总负载', value: cpuLoad.value },
|
||||
}
|
||||
case 'gpu':
|
||||
return {
|
||||
id, title: 'GPU', icon: Gauge, subtitle: gpuModel.value,
|
||||
main: { label: '核心温度', labelIcon: Thermometer, text: fmt(gpuTemp.value, 0), unit: '°C', colorClass: tempColor(gpuTemp.value) },
|
||||
subs: [{ label: '功耗', labelIcon: Zap, text: fmt(gpuPower.value, 1), unit: 'W' }],
|
||||
load: { label: '3D 负载', value: gpuLoad.value },
|
||||
}
|
||||
case 'memory':
|
||||
return {
|
||||
id, title: '内存', icon: MemoryStick,
|
||||
subtitle: memTotalGB.value != null ? `${fmt(memTotalGB.value, 0)} GB` : null,
|
||||
subtitleFull: memModuleModels.value.join(', ') || null,
|
||||
main: { label: '已使用', labelIcon: MemoryStick, text: fmt(memUsedGB.value, 1), unit: ` / ${fmt(memTotalGB.value, 1)} GB` },
|
||||
subs: [],
|
||||
load: { label: '负载', value: memLoad.value },
|
||||
}
|
||||
case 'network':
|
||||
return {
|
||||
id, title: '网络', icon: Wifi,
|
||||
main: { label: '下载', labelIcon: ArrowDown, text: downSpeed.value.value, unit: downSpeed.value.unit, colorClass: 'text-sky-500' },
|
||||
subs: [{ label: '上传', labelIcon: ArrowUp, text: upSpeed.value.value, unit: upSpeed.value.unit, colorClass: 'text-violet-500' }],
|
||||
load: null,
|
||||
}
|
||||
case 'storage':
|
||||
return {
|
||||
id, title: '存储', icon: HardDrive,
|
||||
subtitle: storageDrives.value.length ? `${storageDrives.value.length} 个设备` : null,
|
||||
main: { label: '', text: '' },
|
||||
subs: [],
|
||||
load: null,
|
||||
wide: true,
|
||||
}
|
||||
case 'motherboard':
|
||||
return {
|
||||
id, title: '主板', icon: CircuitBoard, subtitle: boardName.value,
|
||||
main: { label: '温度', labelIcon: Thermometer, text: fmt(boardTemp.value, 0), unit: '°C', colorClass: tempColor(boardTemp.value) },
|
||||
subs: [{ label: '风扇', text: fmt(boardFan.value, 0), unit: 'RPM' }],
|
||||
load: null,
|
||||
}
|
||||
case 'battery':
|
||||
return {
|
||||
id, title: '电池', icon: BatteryFull, subtitle: batteryName.value,
|
||||
main: { label: '电量', labelIcon: BatteryFull, text: fmt(batteryLevel.value, 0), unit: '%' },
|
||||
subs: [
|
||||
{ label: '充电', labelIcon: Zap, text: fmt(batteryCharge.value, 1), unit: 'W' },
|
||||
{ label: '放电', labelIcon: Zap, text: fmt(batteryDischarge.value, 1), unit: 'W' },
|
||||
],
|
||||
load: null,
|
||||
}
|
||||
case 'psu':
|
||||
return {
|
||||
id, title: '电源', icon: Zap, subtitle: psuName.value,
|
||||
main: { label: '输出功率', labelIcon: Zap, text: fmt(psuPower.value, 1), unit: 'W' },
|
||||
subs: [],
|
||||
load: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 当前卡片视图列表(与 overviewCards 顺序一一对应) */
|
||||
const overviewCardViews = computed<OverviewCardView[]>(() =>
|
||||
overviewCards.value.map(buildOverviewCardView)
|
||||
)
|
||||
|
||||
// ===== 连接状态徽章 =====
|
||||
const stateMeta: Record<ConnectionState, { text: string; class: string }> = {
|
||||
idle: { text: '未启动', class: 'bg-muted text-muted-foreground' },
|
||||
@@ -1139,249 +1320,155 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<p class="text-sm">正在加载...</p>
|
||||
</div>
|
||||
|
||||
<!-- 始终显示卡片网格,未启动时数据以占位符显示,保持画面完整 -->
|
||||
<div v-else key="content" class="grid grid-cols-1 md:grid-cols-3 gap-2.5">
|
||||
<!-- CPU(温度 + 功耗 + 频率,未读数据以 -- 占位) -->
|
||||
<Card class="py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center justify-between text-sm">
|
||||
<span class="flex items-center gap-1.5"><Cpu class="size-4 text-primary" />CPU</span>
|
||||
<Tooltip>
|
||||
<template v-else>
|
||||
<!-- ===== Kernel 状态栏(置顶紧凑横条) ===== -->
|
||||
<Card class="py-0 gap-0 mb-2.5">
|
||||
<CardContent class="px-3.5 py-2 flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs">
|
||||
<span class="flex items-center gap-1.5 font-medium text-sm">
|
||||
<Activity class="size-4 text-primary" />Kernel
|
||||
</span>
|
||||
<span :class="['px-2 py-0.5 rounded-full', stateMeta[store.connState].class]">
|
||||
{{ stateMeta[store.connState].text }}
|
||||
</span>
|
||||
<Badge :variant="store.snapshot?.isAdmin ? 'default' : 'outline'" :class="store.snapshot?.isAdmin ? 'bg-emerald-500 hover:bg-emerald-500' : ''">
|
||||
{{ store.snapshot?.isAdmin ? '管理员' : '普通' }}
|
||||
</Badge>
|
||||
<Badge v-if="store.status?.thingElevated" variant="outline" class="border-emerald-500/50 text-emerald-600 dark:text-emerald-400">
|
||||
<ShieldCheck class="size-2.5 mr-0.5" />提权
|
||||
</Badge>
|
||||
<span class="text-muted-foreground">PID: <span class="font-mono text-foreground">{{ store.status?.pid ?? '--' }}</span></span>
|
||||
<span class="text-muted-foreground">传感器: <span class="font-mono text-foreground">{{ store.status?.sensorCount ?? '--' }}</span></span>
|
||||
<span class="text-muted-foreground">重启: <span class="font-mono text-foreground">{{ store.status?.restartCount ?? 0 }}</span></span>
|
||||
<span class="text-muted-foreground">事件: <span class="font-mono text-foreground">{{ store.eventCount }}</span></span>
|
||||
<div class="flex items-center gap-1.5 ml-auto">
|
||||
<!-- 启动中 loading(starting=true 但状态还没变为 loading 时显示) -->
|
||||
<Button v-if="store.starting && store.connState === 'idle'" size="xs" variant="outline" disabled>
|
||||
<Loader2 class="size-3 animate-spin" />启动中
|
||||
</Button>
|
||||
<!-- 启动按钮(未运行且非启动中时显示) -->
|
||||
<Button v-if="store.connState === 'idle' && !store.starting" size="xs" :disabled="store.starting" @click="handleStart">
|
||||
<Play class="size-3" />启动
|
||||
</Button>
|
||||
<!-- 提权按钮(标志未启用时显示:设置标志 + 以管理员权限重启 Thing) -->
|
||||
<Tooltip v-if="!store.elevateOnLaunch">
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-xs text-muted-foreground font-normal truncate ml-2">{{ cpuModel ?? '--' }}</span>
|
||||
<Button size="xs" variant="outline" class="gap-1 text-emerald-600 dark:text-emerald-400 border-emerald-500/40 hover:bg-emerald-500/10" :disabled="store.starting" @click="handleElevateSelf">
|
||||
<Loader2 v-if="store.starting" class="size-3 animate-spin" />
|
||||
<ShieldCheck v-else class="size-3" />提权
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ cpuModel ?? '' }}</TooltipContent>
|
||||
<TooltipContent class="max-w-[480px] break-words">以管理员权限重启 Thing(弹 UAC,ThingHK 子进程继承权限,后续启动自动提权,崩溃自动重启)</TooltipContent>
|
||||
</Tooltip>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5 space-y-1.5">
|
||||
<!-- 温度 + 功耗 -->
|
||||
<div class="flex items-end justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1"><Thermometer class="size-3" />封装温度</div>
|
||||
<div :class="['text-2xl font-bold tabular-nums leading-tight', tempColor(cpuTemp)]">
|
||||
{{ fmt(cpuTemp, 0) }}<span class="text-sm font-normal">°C</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1 justify-end"><Zap class="size-3" />功耗</div>
|
||||
<div class="text-base font-medium tabular-nums">{{ fmt(cpuPower, 1) }}<span class="text-xs text-muted-foreground ml-0.5">W</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 负载 -->
|
||||
<div>
|
||||
<div class="flex items-center justify-between text-xs mb-0.5">
|
||||
<span class="text-muted-foreground flex items-center gap-1"><Gauge class="size-3" />总负载</span>
|
||||
<span :class="['font-medium tabular-nums', loadColor(cpuLoad)]">{{ fmt(cpuLoad, 0) }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="cpuLoad ?? 0" class="h-1.5" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<!-- GPU(结构与 CPU 一致:温度 + 功耗,未读数据以 -- 占位) -->
|
||||
<Card class="py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center justify-between text-sm">
|
||||
<span class="flex items-center gap-1.5"><Gauge class="size-4 text-primary" />GPU</span>
|
||||
<Tooltip>
|
||||
<!-- 取消提权按钮(标志已启用时显示:清除标志,下次启动不触发 UAC) -->
|
||||
<Tooltip v-else>
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-xs text-muted-foreground font-normal truncate ml-2">{{ gpuModel ?? '--' }}</span>
|
||||
<Button size="xs" variant="outline" class="gap-1 text-muted-foreground hover:text-foreground" @click="handleCancelElevation">
|
||||
<ShieldOff class="size-3" />取消提权
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ gpuModel ?? '' }}</TooltipContent>
|
||||
<TooltipContent class="max-w-[480px] break-words">取消提权,下次启动将以普通权限运行(不影响当前会话)</TooltipContent>
|
||||
</Tooltip>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5 space-y-1.5">
|
||||
<!-- 温度 + 功耗(与 CPU 卡片结构一致) -->
|
||||
<div class="flex items-end justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1"><Thermometer class="size-3" />核心温度</div>
|
||||
<div :class="['text-2xl font-bold tabular-nums leading-tight', tempColor(gpuTemp)]">
|
||||
{{ fmt(gpuTemp, 0) }}<span class="text-sm font-normal">°C</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1 justify-end"><Zap class="size-3" />功耗</div>
|
||||
<div class="text-base font-medium tabular-nums">{{ fmt(gpuPower, 1) }}<span class="text-xs text-muted-foreground ml-0.5">W</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 负载 -->
|
||||
<div>
|
||||
<div class="flex items-center justify-between text-xs mb-0.5">
|
||||
<span class="text-muted-foreground flex items-center gap-1"><Gauge class="size-3" />3D 负载</span>
|
||||
<span :class="['font-medium tabular-nums', loadColor(gpuLoad)]">{{ fmt(gpuLoad, 0) }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="gpuLoad ?? 0" class="h-1.5" />
|
||||
<Button size="xs" variant="outline" :disabled="store.starting || store.stopping || store.connState === 'idle'" @click="handleRefresh">
|
||||
<RefreshCw class="size-3" />刷新
|
||||
</Button>
|
||||
<Button size="xs" variant="outline" :disabled="store.starting || store.stopping || store.connState === 'idle'" @click="handleStop">
|
||||
<Square class="size-3" />停止
|
||||
</Button>
|
||||
<Separator orientation="vertical" class="h-4 mx-0.5" />
|
||||
<!-- 编辑布局开关:拖拽排序 / 删除卡片 -->
|
||||
<Button
|
||||
size="xs"
|
||||
:variant="overviewEditing ? 'default' : 'outline'"
|
||||
:title="overviewEditing ? '完成编辑' : '编辑卡片布局(拖拽排序 / 删除)'"
|
||||
@click="overviewEditing = !overviewEditing"
|
||||
>
|
||||
<PencilLine class="size-3" />{{ overviewEditing ? '完成' : '编辑布局' }}
|
||||
</Button>
|
||||
<!-- 添加卡片 -->
|
||||
<Popover v-model:open="overviewAddOpen">
|
||||
<PopoverTrigger as-child>
|
||||
<Button size="xs" variant="outline" :disabled="!addableOverviewCards.length" title="添加硬件卡片">
|
||||
<Plus class="size-3" />添加卡片
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="w-64 p-1.5" align="end">
|
||||
<button
|
||||
v-for="c in addableOverviewCards"
|
||||
:key="c.id"
|
||||
class="w-full flex items-center gap-2.5 rounded-md px-2.5 py-2 text-sm hover:bg-accent transition-colors text-left"
|
||||
@click="addOverviewCard(c.id)"
|
||||
>
|
||||
<component :is="c.icon" class="size-4 text-primary shrink-0" />
|
||||
<span class="min-w-0">
|
||||
<span class="block truncate">{{ c.name }}</span>
|
||||
<span class="block text-xs text-muted-foreground truncate">{{ c.desc }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<div v-if="!addableOverviewCards.length" class="px-2.5 py-2 text-xs text-muted-foreground text-center">所有卡片均已添加</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<!-- 内存(主指标大字 + 进度条,未读数据以 -- 占位) -->
|
||||
<Card class="py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center justify-between text-sm">
|
||||
<span class="flex items-center gap-1.5"><MemoryStick class="size-4 text-primary" />内存</span>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-xs text-muted-foreground font-normal truncate ml-2">
|
||||
{{ memTotalGB != null ? fmt(memTotalGB, 0) + ' GB' : '--' }}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ memModuleModels.join(', ') }}</TooltipContent>
|
||||
</Tooltip>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5 space-y-1.5">
|
||||
<!-- 已使用 / 总容量(主指标,与 CPU 温度对齐) -->
|
||||
<div class="flex items-end justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1"><MemoryStick class="size-3" />已使用</div>
|
||||
<div class="text-2xl font-bold tabular-nums leading-tight">
|
||||
{{ fmt(memUsedGB, 1) }}<span class="text-sm font-normal text-muted-foreground"> / {{ fmt(memTotalGB, 1) }} GB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 负载进度条(与 CPU 负载对齐) -->
|
||||
<div>
|
||||
<div class="flex items-center justify-between text-xs mb-0.5">
|
||||
<span class="text-muted-foreground flex items-center gap-1"><Gauge class="size-3" />负载</span>
|
||||
<span :class="['font-medium tabular-nums', loadColor(memLoad)]">{{ fmt(memLoad, 0) }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="memLoad ?? 0" class="h-1.5" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<!-- 网络(跨3列,下载/上传速率,独立于 Kernel 由 Tauri 后台推送) -->
|
||||
<Card class="md:col-span-3 py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center gap-1.5 text-sm">
|
||||
<Wifi class="size-4 text-primary" />网络
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<!-- 下载 -->
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1 mb-0.5"><ArrowDown class="size-3 text-sky-500" />下载</div>
|
||||
<div class="text-2xl font-bold tabular-nums leading-tight text-sky-500">
|
||||
{{ downSpeed.value }}<span class="text-sm font-normal text-muted-foreground ml-0.5">{{ downSpeed.unit }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 上传 -->
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground flex items-center gap-1 mb-0.5"><ArrowUp class="size-3 text-violet-500" />上传</div>
|
||||
<div class="text-2xl font-bold tabular-nums leading-tight text-violet-500">
|
||||
{{ upSpeed.value }}<span class="text-sm font-normal text-muted-foreground ml-0.5">{{ upSpeed.unit }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<!-- 存储(跨3列):列出各硬盘温度/容量/使用率,未读到以占位符显示 -->
|
||||
<Card class="md:col-span-3 py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center gap-1.5 text-sm">
|
||||
<HardDrive class="size-4 text-primary" />存储
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5">
|
||||
<div v-if="storageDrives.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
|
||||
<div v-for="drive in storageDrives" :key="drive.name" class="border rounded-md p-2 space-y-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-xs font-medium truncate">{{ drive.name }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ drive.name }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<span :class="['text-xs font-mono tabular-nums shrink-0', tempColor(drive.temp)]">{{ fmt(drive.temp, 0) }}°C</span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center justify-between text-xs mb-0.5">
|
||||
<span class="text-muted-foreground">使用率</span>
|
||||
<span class="font-mono tabular-nums">{{ fmt(drive.usedPct, 0) }}%</span>
|
||||
<!-- ===== 硬件信息卡片网格(模板化,可编辑:拖拽排序 / 删除 / 添加) ===== -->
|
||||
<VueDraggable
|
||||
v-model="overviewCards"
|
||||
:animation="200"
|
||||
:force-fallback="true"
|
||||
handle=".overview-drag-handle"
|
||||
ghost-class="opacity-40"
|
||||
chosen-class="drag-chosen"
|
||||
:disabled="!overviewEditing"
|
||||
class="grid grid-cols-1 md:grid-cols-4 gap-2.5"
|
||||
@end="onOverviewDragEnd()"
|
||||
>
|
||||
<OverviewCard
|
||||
v-for="view in overviewCardViews"
|
||||
:key="view.id"
|
||||
:view="view"
|
||||
:editing="overviewEditing"
|
||||
@remove="removeOverviewCard(view.id)"
|
||||
>
|
||||
<!-- 存储卡:多盘列表 -->
|
||||
<template v-if="view.id === 'storage'" #body>
|
||||
<div v-if="storageDrives.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
|
||||
<div v-for="drive in storageDrives" :key="drive.name" class="border rounded-md p-2 space-y-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-xs font-medium truncate">{{ drive.name }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ drive.name }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<span :class="['text-xs font-mono tabular-nums shrink-0', tempColor(drive.temp)]">{{ fmt(drive.temp, 0) }}°C</span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center justify-between text-xs mb-0.5">
|
||||
<span class="text-muted-foreground">使用率</span>
|
||||
<span class="font-mono tabular-nums">{{ fmt(drive.usedPct, 0) }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="drive.usedPct ?? 0" class="h-1" />
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>容量</span>
|
||||
<span class="font-mono tabular-nums">{{ fmt(drive.usedGB, 1) }} / {{ fmt(drive.totalGB, 1) }} GB</span>
|
||||
</div>
|
||||
<Progress :model-value="drive.usedPct ?? 0" class="h-1" />
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>容量</span>
|
||||
<span class="font-mono tabular-nums">{{ fmt(drive.usedGB, 1) }} / {{ fmt(drive.totalGB, 1) }} GB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 无数据占位(保持卡片结构完整) -->
|
||||
<div v-else class="text-xs text-muted-foreground py-2 text-center">暂无存储数据</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<!-- Kernel 状态卡片(跨3列,含启动/停止/刷新/提权按钮) -->
|
||||
<Card class="md:col-span-3 py-0 gap-0">
|
||||
<CardHeader class="pb-1.5 px-3.5 pt-2.5">
|
||||
<CardTitle class="flex items-center justify-between text-sm">
|
||||
<span class="flex items-center gap-1.5"><Activity class="size-4 text-primary" />Kernel 状态</span>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span :class="['text-xs px-2 py-0.5 rounded-full', stateMeta[store.connState].class]">
|
||||
{{ stateMeta[store.connState].text }}
|
||||
</span>
|
||||
<Badge :variant="store.snapshot?.isAdmin ? 'default' : 'outline'" :class="store.snapshot?.isAdmin ? 'bg-emerald-500 hover:bg-emerald-500' : ''">
|
||||
{{ store.snapshot?.isAdmin ? '管理员' : '普通' }}
|
||||
</Badge>
|
||||
<Badge v-if="store.status?.thingElevated" variant="outline" class="text-xs border-emerald-500/50 text-emerald-600 dark:text-emerald-400">
|
||||
<ShieldCheck class="size-2.5 mr-0.5" />提权
|
||||
</Badge>
|
||||
</div>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="px-3.5 pb-2.5">
|
||||
<div class="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs">
|
||||
<span class="text-muted-foreground">PID: <span class="font-mono text-foreground">{{ store.status?.pid ?? '--' }}</span></span>
|
||||
<span class="text-muted-foreground">传感器: <span class="font-mono text-foreground">{{ store.status?.sensorCount ?? '--' }}</span></span>
|
||||
<span class="text-muted-foreground">重启: <span class="font-mono text-foreground">{{ store.status?.restartCount ?? 0 }}</span></span>
|
||||
<span class="text-muted-foreground">事件: <span class="font-mono text-foreground">{{ store.eventCount }}</span></span>
|
||||
<div class="flex items-center gap-1.5 ml-auto">
|
||||
<!-- 启动中 loading(starting=true 但状态还没变为 loading 时显示) -->
|
||||
<Button v-if="store.starting && store.connState === 'idle'" size="xs" variant="outline" disabled>
|
||||
<Loader2 class="size-3 animate-spin" />启动中
|
||||
</Button>
|
||||
<!-- 启动按钮(未运行且非启动中时显示) -->
|
||||
<Button v-if="store.connState === 'idle' && !store.starting" size="xs" :disabled="store.starting" @click="handleStart">
|
||||
<Play class="size-3" />启动
|
||||
</Button>
|
||||
<!-- 提权按钮(标志未启用时显示:设置标志 + 以管理员权限重启 Thing) -->
|
||||
<Tooltip v-if="!store.elevateOnLaunch">
|
||||
<TooltipTrigger as-child>
|
||||
<Button size="xs" variant="outline" class="gap-1 text-emerald-600 dark:text-emerald-400 border-emerald-500/40 hover:bg-emerald-500/10" :disabled="store.starting" @click="handleElevateSelf">
|
||||
<Loader2 v-if="store.starting" class="size-3 animate-spin" />
|
||||
<ShieldCheck v-else class="size-3" />提权
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent class="max-w-[480px] break-words">以管理员权限重启 Thing(弹 UAC,ThingHK 子进程继承权限,后续启动自动提权,崩溃自动重启)</TooltipContent>
|
||||
</Tooltip>
|
||||
<!-- 取消提权按钮(标志已启用时显示:清除标志,下次启动不触发 UAC) -->
|
||||
<Tooltip v-else>
|
||||
<TooltipTrigger as-child>
|
||||
<Button size="xs" variant="outline" class="gap-1 text-muted-foreground hover:text-foreground" @click="handleCancelElevation">
|
||||
<ShieldOff class="size-3" />取消提权
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent class="max-w-[480px] break-words">取消提权,下次启动将以普通权限运行(不影响当前会话)</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button size="xs" variant="outline" :disabled="store.starting || store.stopping || store.connState === 'idle'" @click="handleRefresh">
|
||||
<RefreshCw class="size-3" />刷新
|
||||
</Button>
|
||||
<Button size="xs" variant="outline" :disabled="store.starting || store.stopping || store.connState === 'idle'" @click="handleStop">
|
||||
<Square class="size-3" />停止
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div v-else class="text-xs text-muted-foreground py-2 text-center">暂无存储数据</div>
|
||||
</template>
|
||||
</OverviewCard>
|
||||
<!-- 空占位(全部卡片移除后显示) -->
|
||||
<Card v-if="!overviewCards.length" class="col-span-full py-0 gap-0 no-drag">
|
||||
<CardContent class="py-8 text-center text-sm text-muted-foreground">
|
||||
暂无卡片,点击上方"添加卡片"添加硬件
|
||||
</CardContent>
|
||||
</Card>
|
||||
</VueDraggable>
|
||||
|
||||
<!-- 断线提示 -->
|
||||
<Card v-if="store.connState === 'disconnected'" class="md:col-span-3 border-orange-500/40 py-0 gap-0">
|
||||
<Card v-if="store.connState === 'disconnected'" class="mt-2.5 border-orange-500/40 py-0 gap-0">
|
||||
<CardContent class="pt-3 flex items-start gap-2 text-sm">
|
||||
<AlertTriangle class="size-4 text-orange-500 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
@@ -1392,7 +1479,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
</Card>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<Card v-if="store.errorMsg" class="md:col-span-3 border-red-500/40 py-0 gap-0">
|
||||
<Card v-if="store.errorMsg" class="mt-2.5 border-red-500/40 py-0 gap-0">
|
||||
<CardContent class="pt-3 flex items-start gap-2 text-sm">
|
||||
<AlertTriangle class="size-4 text-red-500 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
@@ -1401,7 +1488,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
</ScrollArea>
|
||||
</TabsContent>
|
||||
|
||||
|
||||
Reference in new issue
Block a user