feat(webui): standardize content loading states
Use consistent delayed placeholders across data-backed console surfaces. Avoid flashing loading UI for fast local responses while keeping slower transitions stable. Keep failures visible and prevent gated content from opening on incomplete checks.
This commit is contained in:
22 files changed
+2493
-1527
No files matched your search
@@ -6,10 +6,12 @@
|
||||
// Scales to many channels (40+): collapsed by default to a one-line summary of
|
||||
// selected channels as removable chips; expanded into a searchable, bulk-
|
||||
// actionable, height-bounded scroll list so it never blows up the page.
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { AnimatePresence, motion } from 'motion/react';
|
||||
import { ChevronDown, Loader2, Search, X } from 'lucide-react';
|
||||
import { ChevronDown, Search, X } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
@@ -29,24 +31,27 @@ const CHIP_CAP = 8;
|
||||
export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInProps) {
|
||||
const api = useApi();
|
||||
const [channels, setChannels] = useState<NotificationChannel[] | null>(null);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [query, setQuery] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const cfg = await api.notifications.getConfig();
|
||||
if (!cancelled) setChannels(cfg.channels);
|
||||
} catch {
|
||||
if (!cancelled) setChannels([]);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
const load = useCallback(async () => {
|
||||
setChannels(null);
|
||||
setLoadError(null);
|
||||
try {
|
||||
const cfg = await api.notifications.getConfig();
|
||||
setChannels(cfg.channels);
|
||||
} catch (error) {
|
||||
console.error('load notification opt-ins failed', error);
|
||||
setLoadError(error instanceof Error ? error.message : '加载通知渠道失败');
|
||||
setChannels([]);
|
||||
}
|
||||
}, [api]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const selected = useMemo(() => new Set(selectedIds), [selectedIds]);
|
||||
|
||||
const toggle = (id: string, on: boolean) => {
|
||||
@@ -105,124 +110,136 @@ export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInPr
|
||||
/>
|
||||
</button>
|
||||
|
||||
{channels === null ? (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Loader2 className="size-3.5 animate-spin" /> 加载渠道…
|
||||
</div>
|
||||
) : total === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">还没有全局渠道——先到「设置 → 通知」添加。</p>
|
||||
) : (
|
||||
<>
|
||||
{/* collapsed: selected channels as removable chips */}
|
||||
{!expanded &&
|
||||
(selectedCount === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">未选择任何渠道。展开以选择。</p>
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selectedChips.slice(0, CHIP_CAP).map((ch) => (
|
||||
<Badge key={ch.id} variant="secondary" className="max-w-[12rem] pr-1">
|
||||
<span className="truncate">{ch.name}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggle(ch.id, false)}
|
||||
aria-label={`移除 ${ch.name}`}
|
||||
className="ml-0.5 rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-foreground/10 hover:text-foreground"
|
||||
>
|
||||
<X className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
{selectedCount > CHIP_CAP && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpanded(true)}
|
||||
className="rounded-full px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground"
|
||||
>
|
||||
+{selectedCount - CHIP_CAP} 更多
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* expanded: search + bulk + bounded scroll list */}
|
||||
<AnimatePresence initial={false}>
|
||||
{expanded && (
|
||||
<motion.div
|
||||
initial={{ height: 0, opacity: 0 }}
|
||||
animate={{ height: 'auto', opacity: 1 }}
|
||||
exit={{ height: 0, opacity: 0 }}
|
||||
transition={{ duration: 0.22 }}
|
||||
className="overflow-hidden"
|
||||
>
|
||||
<div className="flex flex-col gap-3 pt-1">
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
该账号上线 / 下线时向选中的渠道推送通知。渠道在「设置 → 通知」中全局定义。
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder="搜索渠道…"
|
||||
className="h-8 pl-8 text-xs"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={selectAll}
|
||||
className="rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
全选
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={clearAll}
|
||||
className="rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
清空
|
||||
</button>
|
||||
<SkeletonSwap
|
||||
ready={channels !== null}
|
||||
lines={2}
|
||||
lineHeight={20}
|
||||
reserve={40}
|
||||
label="通知渠道"
|
||||
className={channels !== null ? 'skeleton-swap-fluid min-h-[40px]' : ''}
|
||||
>
|
||||
{channels !== null ? (
|
||||
loadError ? (
|
||||
<div role="alert" className="flex items-center justify-between gap-3 text-xs text-destructive">
|
||||
<span>{loadError}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>重试</Button>
|
||||
</div>
|
||||
) : total === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">还没有全局渠道——先到「设置 → 通知」添加。</p>
|
||||
) : (
|
||||
<>
|
||||
{/* collapsed: selected channels as removable chips */}
|
||||
{!expanded &&
|
||||
(selectedCount === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">未选择任何渠道。展开以选择。</p>
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selectedChips.slice(0, CHIP_CAP).map((ch) => (
|
||||
<Badge key={ch.id} variant="secondary" className="max-w-[12rem] pr-1">
|
||||
<span className="truncate">{ch.name}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggle(ch.id, false)}
|
||||
aria-label={`移除 ${ch.name}`}
|
||||
className="ml-0.5 rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-foreground/10 hover:text-foreground"
|
||||
>
|
||||
<X className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
{selectedCount > CHIP_CAP && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpanded(true)}
|
||||
className="rounded-full px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground"
|
||||
>
|
||||
+{selectedCount - CHIP_CAP} 更多
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{filtered.length === 0 ? (
|
||||
<p className="py-4 text-center text-xs text-muted-foreground">无匹配渠道</p>
|
||||
) : (
|
||||
<ScrollArea className="max-h-64 rounded-lg border bg-background/40">
|
||||
<div className="divide-y divide-border/60">
|
||||
{filtered.map((ch) => (
|
||||
<div
|
||||
key={ch.id}
|
||||
className="flex items-center justify-between gap-3 px-3 py-2"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm">{ch.name || ch.id}</span>
|
||||
{!ch.enabled && (
|
||||
<span className="shrink-0 text-micro text-muted-foreground">(已全局禁用)</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="truncate text-meta text-muted-foreground">{ch.url}</p>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
// Globally-disabled channel: lock the switch and force it off
|
||||
// (it can never fire, so the per-account opt-in must read off).
|
||||
value={ch.enabled && selected.has(ch.id)}
|
||||
onChange={(v) => toggle(ch.id, v)}
|
||||
ariaLabel={`为该账号启用渠道 ${ch.name || ch.id}`}
|
||||
disabled={!ch.enabled}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
{/* expanded: search + bulk + bounded scroll list */}
|
||||
<AnimatePresence initial={false}>
|
||||
{expanded && (
|
||||
<motion.div
|
||||
initial={{ height: 0, opacity: 0 }}
|
||||
animate={{ height: 'auto', opacity: 1 }}
|
||||
exit={{ height: 0, opacity: 0 }}
|
||||
transition={{ duration: 0.22 }}
|
||||
className="overflow-hidden"
|
||||
>
|
||||
<div className="flex flex-col gap-3 pt-1">
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
该账号上线 / 下线时向选中的渠道推送通知。渠道在「设置 → 通知」中全局定义。
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder="搜索渠道…"
|
||||
className="h-8 pl-8 text-xs"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={selectAll}
|
||||
className="rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
全选
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={clearAll}
|
||||
className="rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
清空
|
||||
</button>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</>
|
||||
)}
|
||||
|
||||
{filtered.length === 0 ? (
|
||||
<p className="py-4 text-center text-xs text-muted-foreground">无匹配渠道</p>
|
||||
) : (
|
||||
<ScrollArea className="max-h-64 rounded-lg border bg-background/40">
|
||||
<div className="divide-y divide-border/60">
|
||||
{filtered.map((ch) => (
|
||||
<div
|
||||
key={ch.id}
|
||||
className="flex items-center justify-between gap-3 px-3 py-2"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm">{ch.name || ch.id}</span>
|
||||
{!ch.enabled && (
|
||||
<span className="shrink-0 text-micro text-muted-foreground">(已全局禁用)</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="truncate text-meta text-muted-foreground">{ch.url}</p>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
// Globally-disabled channel: lock the switch and force it off
|
||||
// (it can never fire, so the per-account opt-in must read off).
|
||||
value={ch.enabled && selected.has(ch.id)}
|
||||
onChange={(v) => toggle(ch.id, v)}
|
||||
ariaLabel={`为该账号启用渠道 ${ch.name || ch.id}`}
|
||||
disabled={!ch.enabled}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
|
||||
|
||||
const CROSSFADE = {
|
||||
type: 'spring',
|
||||
stiffness: 260,
|
||||
damping: 34,
|
||||
mass: 0.8,
|
||||
} as const;
|
||||
|
||||
const WIDTHS = [100, 93, 97, 88, 95, 91] as const;
|
||||
|
||||
function widthFor(index: number, total: number) {
|
||||
if (total > 1 && index === total - 1) return 62;
|
||||
return WIDTHS[(index * 7 + 3) % WIDTHS.length];
|
||||
}
|
||||
|
||||
export type UseSkeletonSwapOptions = {
|
||||
ready: boolean;
|
||||
delay?: number;
|
||||
minVisible?: number;
|
||||
};
|
||||
|
||||
export function useSkeletonSwap({
|
||||
ready,
|
||||
delay = 120,
|
||||
minVisible = 380,
|
||||
}: UseSkeletonSwapOptions) {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const shownAt = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ready) {
|
||||
if (visible) return;
|
||||
const t = setTimeout(() => {
|
||||
shownAt.current = performance.now();
|
||||
setVisible(true);
|
||||
}, delay);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
|
||||
if (!visible) return;
|
||||
const rest = Math.max(0, minVisible - (performance.now() - shownAt.current));
|
||||
const t = setTimeout(() => setVisible(false), rest);
|
||||
return () => clearTimeout(t);
|
||||
}, [ready, visible, delay, minVisible]);
|
||||
|
||||
return { showSkeleton: visible, busy: !ready };
|
||||
}
|
||||
|
||||
export type SkeletonSwapProps = {
|
||||
ready: boolean;
|
||||
children: React.ReactNode;
|
||||
lines?: number;
|
||||
lineHeight?: number;
|
||||
barHeight?: number;
|
||||
reserve?: number;
|
||||
delay?: number;
|
||||
minVisible?: number;
|
||||
label?: string;
|
||||
skeleton?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function SkeletonSwap({
|
||||
ready,
|
||||
children,
|
||||
lines = 3,
|
||||
lineHeight = 21,
|
||||
barHeight = 9,
|
||||
reserve,
|
||||
delay = 120,
|
||||
minVisible = 380,
|
||||
label,
|
||||
skeleton,
|
||||
className = '',
|
||||
}: SkeletonSwapProps) {
|
||||
const { showSkeleton } = useSkeletonSwap({ ready, delay, minVisible });
|
||||
const reduced = useReducedMotion();
|
||||
|
||||
const shell = useRef<HTMLDivElement>(null);
|
||||
const body = useRef<HTMLDivElement>(null);
|
||||
const [scrollable, setScrollable] = useState(false);
|
||||
|
||||
const box = reserve ?? lines * lineHeight;
|
||||
|
||||
useEffect(() => {
|
||||
const el = shell.current;
|
||||
const inner = body.current;
|
||||
if (!el || typeof ResizeObserver === 'undefined') return;
|
||||
|
||||
const check = () => setScrollable(el.scrollHeight - el.clientHeight > 1);
|
||||
check();
|
||||
|
||||
const ro = new ResizeObserver(check);
|
||||
ro.observe(el);
|
||||
if (inner) ro.observe(inner);
|
||||
return () => ro.disconnect();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={shell}
|
||||
aria-busy={!ready}
|
||||
aria-label={label}
|
||||
tabIndex={scrollable ? 0 : undefined}
|
||||
style={{ height: box }}
|
||||
className={`relative grid overflow-y-auto overscroll-contain text-foreground ${className}`}
|
||||
>
|
||||
<motion.div
|
||||
ref={body}
|
||||
aria-hidden={showSkeleton || undefined}
|
||||
inert={showSkeleton || undefined}
|
||||
className="col-start-1 row-start-1 min-w-0"
|
||||
initial={false}
|
||||
animate={
|
||||
reduced
|
||||
? { opacity: showSkeleton ? 0 : 1 }
|
||||
: {
|
||||
opacity: showSkeleton ? 0 : 1,
|
||||
scale: showSkeleton ? 0.99 : 1,
|
||||
filter: showSkeleton ? 'blur(4px)' : 'blur(0px)',
|
||||
}
|
||||
}
|
||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||
style={{
|
||||
transformOrigin: 'top left',
|
||||
pointerEvents: showSkeleton ? 'none' : undefined,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
|
||||
<AnimatePresence initial={false}>
|
||||
{showSkeleton ? (
|
||||
<motion.div
|
||||
key="skeleton"
|
||||
aria-hidden
|
||||
className="pointer-events-none col-start-1 row-start-1 w-full self-start"
|
||||
initial={reduced ? { opacity: 1 } : { opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={reduced ? { opacity: 0 } : { opacity: 0, filter: 'blur(3px)' }}
|
||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||
>
|
||||
{skeleton ?? (
|
||||
<div className="w-full">
|
||||
{Array.from({ length: lines }, (_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="flex items-center"
|
||||
style={{ height: lineHeight }}
|
||||
>
|
||||
<div
|
||||
className="rounded-[5px] bg-muted"
|
||||
style={{
|
||||
height: barHeight,
|
||||
width: `${widthFor(i, lines)}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
) : null}
|
||||
</AnimatePresence>
|
||||
|
||||
{label ? (
|
||||
<span role="status" className="sr-only">
|
||||
{ready ? `${label} loaded` : ''}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Bell, CheckCircle2, XCircle } from 'lucide-react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
@@ -15,6 +16,7 @@ export function DeliveriesWidget() {
|
||||
const api = useApi();
|
||||
const { formatClock } = useTheme();
|
||||
const [records, setRecords] = useState<NotificationDeliveryRecord[] | null>(null);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
@@ -27,10 +29,17 @@ export function DeliveriesWidget() {
|
||||
api.notifications
|
||||
.recent(50)
|
||||
.then((r) => {
|
||||
if (active) setRecords(r);
|
||||
if (active) {
|
||||
setLoadError(null);
|
||||
setRecords(r);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) setRecords((prev) => prev ?? []);
|
||||
.catch((error) => {
|
||||
console.error('load recent notification deliveries failed', error);
|
||||
if (active) {
|
||||
setLoadError(error instanceof Error ? error.message : '加载最近投递失败');
|
||||
setRecords((prev) => prev ?? []);
|
||||
}
|
||||
})
|
||||
.finally(() => { inFlight = false; });
|
||||
};
|
||||
@@ -55,40 +64,58 @@ export function DeliveriesWidget() {
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{records === null ? (
|
||||
<p className="py-10 text-center text-sm text-muted-foreground">加载中…</p>
|
||||
) : records.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无投递记录</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 text-meta">
|
||||
{records.map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
{r.ok ? (
|
||||
<CheckCircle2 className="size-3.5 shrink-0 text-emerald-500" />
|
||||
) : (
|
||||
<XCircle className="size-3.5 shrink-0 text-destructive" />
|
||||
)}
|
||||
<span className="shrink-0 font-mono tabular-nums text-muted-foreground">{formatClock(r.time)}</span>
|
||||
<span
|
||||
className={cn(
|
||||
'shrink-0 font-medium',
|
||||
r.event === 'online' ? 'text-emerald-600' : 'text-amber-600',
|
||||
)}
|
||||
>
|
||||
{r.event === 'online' ? '上线' : '下线'}
|
||||
</span>
|
||||
<span className="shrink-0 font-mono">{r.uin}</span>
|
||||
<span className="ml-auto min-w-0 truncate text-muted-foreground" title={r.error ?? r.channelId}>
|
||||
{r.channelId}
|
||||
{!r.ok && r.error && <span className="text-xs text-destructive"> · {r.error}</span>}
|
||||
</span>
|
||||
<SkeletonSwap
|
||||
ready={records !== null}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
label="最近投递"
|
||||
className={records !== null ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{records !== null ? (
|
||||
loadError && records.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{loadError}
|
||||
</p>
|
||||
) : records.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无投递记录</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 text-meta">
|
||||
{loadError && (
|
||||
<p role="alert" className="mb-1 rounded-lg border border-destructive/30 bg-destructive/10 px-2 py-1.5 font-sans text-xs text-destructive">
|
||||
{loadError};当前显示上次成功读取的投递记录。
|
||||
</p>
|
||||
)}
|
||||
{records.map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
{r.ok ? (
|
||||
<CheckCircle2 className="size-3.5 shrink-0 text-emerald-500" />
|
||||
) : (
|
||||
<XCircle className="size-3.5 shrink-0 text-destructive" />
|
||||
)}
|
||||
<span className="shrink-0 font-mono tabular-nums text-muted-foreground">{formatClock(r.time)}</span>
|
||||
<span
|
||||
className={cn(
|
||||
'shrink-0 font-medium',
|
||||
r.event === 'online' ? 'text-emerald-600' : 'text-amber-600',
|
||||
)}
|
||||
>
|
||||
{r.event === 'online' ? '上线' : '下线'}
|
||||
</span>
|
||||
<span className="shrink-0 font-mono">{r.uin}</span>
|
||||
<span className="ml-auto min-w-0 truncate text-muted-foreground" title={r.error ?? r.channelId}>
|
||||
{r.channelId}
|
||||
{!r.ok && r.error && <span className="text-xs text-destructive"> · {r.error}</span>}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -10,10 +10,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { Check, Loader2, MousePointerClick, Plus, Save } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ScrollableTabList } from '@/components/ui/tabs';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type {
|
||||
AdapterStatus,
|
||||
@@ -41,9 +41,19 @@ type DialogState =
|
||||
// index: null → create with `seed`, otherwise edit the item at that position.
|
||||
|
||||
export function ConfigPage() {
|
||||
const { qqList, connections, selectedUin, setSelectedUin } = useAppState();
|
||||
const {
|
||||
qqList,
|
||||
connections,
|
||||
selectedUin,
|
||||
setSelectedUin,
|
||||
resources,
|
||||
refreshQqList,
|
||||
} = useAppState();
|
||||
const {
|
||||
config,
|
||||
loading,
|
||||
loadError,
|
||||
reload,
|
||||
setConfig,
|
||||
dirty,
|
||||
requestSwitchUin,
|
||||
@@ -57,7 +67,6 @@ export function ConfigPage() {
|
||||
selectedUin,
|
||||
onSelectedUinChange: setSelectedUin,
|
||||
});
|
||||
|
||||
const { pages, setPages } = useLayout();
|
||||
const [activeTab, setActiveTabState] = useState<TabKey>(() => {
|
||||
const t = pages.configTab;
|
||||
@@ -169,99 +178,136 @@ export function ConfigPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex gap-4">
|
||||
<AccountSidebar
|
||||
accounts={qqList}
|
||||
selectedUin={selectedUin}
|
||||
onSelect={requestSwitchUin}
|
||||
collapsed={sidebarCollapsed}
|
||||
onToggleCollapsed={() => setSidebarCollapsed((v) => !v)}
|
||||
/>
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
{!selectedUin ? (
|
||||
<EmptyState />
|
||||
) : !config ? (
|
||||
<LoadingSkeleton />
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
lines={7}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
reserve={196}
|
||||
label="账号列表"
|
||||
className={resources.qqList.ready ? 'skeleton-swap-fluid min-h-[196px]' : ''}
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
resources.qqList.error && qqList.length === 0 ? (
|
||||
<ConfigLoadError message={resources.qqList.error} onRetry={refreshQqList} />
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
<HeaderBar
|
||||
selectedUin={selectedUin}
|
||||
dirty={dirty}
|
||||
saveStatus={saveStatus}
|
||||
saveStatusTone={saveStatusTone}
|
||||
onSave={immediateSave}
|
||||
activeTab={activeTab}
|
||||
onCreate={
|
||||
activeTab !== 'general' ? () => openCreate(activeTab as NetworkKind) : undefined
|
||||
}
|
||||
/>
|
||||
<div className="flex flex-col gap-3">
|
||||
{resources.qqList.error && (
|
||||
<div role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.qqList.error};当前显示上次成功读取的账号列表。
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-4">
|
||||
<AccountSidebar
|
||||
accounts={qqList}
|
||||
selectedUin={selectedUin}
|
||||
onSelect={requestSwitchUin}
|
||||
collapsed={sidebarCollapsed}
|
||||
onToggleCollapsed={() => setSidebarCollapsed((v) => !v)}
|
||||
/>
|
||||
|
||||
<TabStrip
|
||||
activeTab={activeTab}
|
||||
onChange={setActiveTab}
|
||||
counts={countMap(config.networks)}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
{!selectedUin ? (
|
||||
<EmptyState />
|
||||
) : (
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
reserve={196}
|
||||
label="账号配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[196px]' : 'w-full'}
|
||||
>
|
||||
{!loading ? (
|
||||
loadError || !config ? (
|
||||
<ConfigLoadError message={loadError ?? '账号配置不可用'} onRetry={reload} />
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
<HeaderBar
|
||||
selectedUin={selectedUin}
|
||||
dirty={dirty}
|
||||
saveStatus={saveStatus}
|
||||
saveStatusTone={saveStatusTone}
|
||||
onSave={immediateSave}
|
||||
activeTab={activeTab}
|
||||
onCreate={
|
||||
activeTab !== 'general' ? () => openCreate(activeTab as NetworkKind) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<div
|
||||
id={`config-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`config-tab-${activeTab}`}
|
||||
>
|
||||
{activeTab === 'general' ? (
|
||||
<GeneralSettingsTab config={config} onChange={setConfig} />
|
||||
) : (
|
||||
<NetworkTabView
|
||||
kind={activeTab}
|
||||
config={config}
|
||||
statusByName={liveStatusByName}
|
||||
onCreateClick={() => openCreate(activeTab)}
|
||||
onEdit={(idx) => openEdit(activeTab, idx)}
|
||||
onDelete={(idx) => handleDelete(activeTab, idx)}
|
||||
onToggleEnabled={(idx, v) => handleToggleEnabled(activeTab, idx, v)}
|
||||
<TabStrip
|
||||
activeTab={activeTab}
|
||||
onChange={setActiveTab}
|
||||
counts={countMap(config.networks)}
|
||||
/>
|
||||
|
||||
<div
|
||||
id={`config-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`config-tab-${activeTab}`}
|
||||
>
|
||||
{activeTab === 'general' ? (
|
||||
<GeneralSettingsTab config={config} onChange={setConfig} />
|
||||
) : (
|
||||
<NetworkTabView
|
||||
kind={activeTab}
|
||||
config={config}
|
||||
statusByName={liveStatusByName}
|
||||
onCreateClick={() => openCreate(activeTab)}
|
||||
onEdit={(idx) => openEdit(activeTab, idx)}
|
||||
onDelete={(idx) => handleDelete(activeTab, idx)}
|
||||
onToggleEnabled={(idx, v) => handleToggleEnabled(activeTab, idx, v)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Single dialog covers create + edit across all 4 kinds. */}
|
||||
{dialog.open && config && (
|
||||
<NodeEditDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog({ open: false })}
|
||||
kind={dialog.kind}
|
||||
initial={dialog.seed}
|
||||
isEdit={dialog.index != null}
|
||||
otherNames={otherNames(config.networks, dialog.kind, dialog.index)}
|
||||
onSubmit={(item) => {
|
||||
if (dialog.index == null) handleCreate(dialog.kind, item);
|
||||
else handleEdit(dialog.kind, dialog.index, item);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingSwitchUin != null}
|
||||
onOpenChange={(open) => !open && cancelSwitch()}
|
||||
title="放弃未保存的修改?"
|
||||
description={
|
||||
<>
|
||||
<p>
|
||||
当前会话 <code className="font-mono">{selectedUin}</code> 还有未保存的修改。
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
切换到 <code className="font-mono">{pendingSwitchAccount?.uin ?? pendingSwitchUin}</code>
|
||||
{pendingSwitchAccount?.nickname ? `(${pendingSwitchAccount.nickname})` : ''} 会丢弃这些修改。
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
confirmText="放弃并切换"
|
||||
destructive
|
||||
onConfirm={confirmSwitch}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Single dialog covers create + edit across all 4 kinds. */}
|
||||
{dialog.open && config && (
|
||||
<NodeEditDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog({ open: false })}
|
||||
kind={dialog.kind}
|
||||
initial={dialog.seed}
|
||||
isEdit={dialog.index != null}
|
||||
otherNames={otherNames(config.networks, dialog.kind, dialog.index)}
|
||||
onSubmit={(item) => {
|
||||
if (dialog.index == null) handleCreate(dialog.kind, item);
|
||||
else handleEdit(dialog.kind, dialog.index, item);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingSwitchUin != null}
|
||||
onOpenChange={(open) => !open && cancelSwitch()}
|
||||
title="放弃未保存的修改?"
|
||||
description={
|
||||
<>
|
||||
<p>
|
||||
当前会话 <code className="font-mono">{selectedUin}</code> 还有未保存的修改。
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
切换到 <code className="font-mono">{pendingSwitchAccount?.uin ?? pendingSwitchUin}</code>
|
||||
{pendingSwitchAccount?.nickname ? `(${pendingSwitchAccount.nickname})` : ''} 会丢弃这些修改。
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
confirmText="放弃并切换"
|
||||
destructive
|
||||
onConfirm={confirmSwitch}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -494,13 +540,13 @@ function EmptyState() {
|
||||
);
|
||||
}
|
||||
|
||||
function LoadingSkeleton() {
|
||||
function ConfigLoadError({ message, onRetry }: { message: string; onRetry: () => void }) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-20" />
|
||||
<Skeleton className="h-20" />
|
||||
<div className="flex h-64 flex-col items-center justify-center gap-3 rounded-xl border border-dashed text-muted-foreground">
|
||||
<p className="max-w-md text-center text-sm text-destructive">{message}</p>
|
||||
<Button variant="outline" size="sm" onClick={onRetry}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ActionTester } from '@/components/debug/action-tester';
|
||||
import { MessageComposer } from '@/components/debug/message-composer';
|
||||
import { LiveActivity } from '@/components/debug/live-activity';
|
||||
import { ApiBrowser } from '@/components/debug/api-browser';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useApi } from '@/lib/api';
|
||||
import type { DebugActionDoc, QQInfo } from '@/types';
|
||||
|
||||
@@ -20,6 +21,8 @@ export function DebugPage() {
|
||||
const api = useApi();
|
||||
const [accounts, setAccounts] = useState<QQInfo[]>([]);
|
||||
const [docs, setDocs] = useState<DebugActionDoc[]>([]);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [tab, setTab] = useState<Tab>('tester');
|
||||
const [preset, setPreset] = useState<{ name: string; nonce: number } | undefined>();
|
||||
|
||||
@@ -29,7 +32,12 @@ export function DebugPage() {
|
||||
const [qq, acts] = await Promise.all([api.qqList(), api.debug.actions()]);
|
||||
setAccounts(qq);
|
||||
setDocs(acts.actions);
|
||||
} catch { /* surfaced lazily on invoke */ }
|
||||
} catch (error) {
|
||||
console.error('load debug tools', error);
|
||||
setLoadError(error instanceof Error ? error.message : '加载开发者工具失败');
|
||||
} finally {
|
||||
setReady(true);
|
||||
}
|
||||
})();
|
||||
}, [api]);
|
||||
|
||||
@@ -66,15 +74,35 @@ export function DebugPage() {
|
||||
/>
|
||||
</motion.header>
|
||||
|
||||
{/* Tester / compose / activity stay MOUNTED and toggle via CSS so the
|
||||
live feed's SSE never drops (it must capture events fired from other
|
||||
tabs) and in-progress params/messages survive a peek at another tab.
|
||||
ApiBrowser has no state worth preserving and is heavy (~520 rows), so
|
||||
it mounts on demand. */}
|
||||
<div className={cn(tab !== 'tester' && 'hidden')}><ActionTester accounts={accounts} docs={docs} presetAction={preset} /></div>
|
||||
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
||||
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
||||
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
||||
{loadError && (
|
||||
<div role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||
{loadError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={224}
|
||||
lines={8}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
label="开发者工具数据"
|
||||
className={ready ? 'skeleton-swap-fluid' : ''}
|
||||
>
|
||||
{ready ? (
|
||||
<>
|
||||
{/* Tester / compose / activity stay MOUNTED and toggle via CSS so the
|
||||
live feed's SSE never drops (it must capture events fired from other
|
||||
tabs) and in-progress params/messages survive a peek at another tab.
|
||||
ApiBrowser has no state worth preserving and is heavy (~520 rows), so
|
||||
it mounts on demand. */}
|
||||
<div className={cn(tab !== 'tester' && 'hidden')}><ActionTester accounts={accounts} docs={docs} presetAction={preset} /></div>
|
||||
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
||||
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
||||
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
||||
</>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
||||
import { useApi } from '@/lib/api';
|
||||
@@ -107,10 +108,14 @@ export function LogsPage() {
|
||||
const prefs = pages.logs;
|
||||
|
||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
||||
const [logsReady, setLogsReady] = useState(false);
|
||||
const [logsError, setLogsError] = useState<string | null>(null);
|
||||
const [streamStatus, setStreamStatus] = useState('连接中');
|
||||
const [filter, setFilter] = useState('');
|
||||
const [confirmClear, setConfirmClear] = useState(false);
|
||||
const [serverLevel, setServerLevel] = useState<LogLevel | null>(null);
|
||||
const [serverLevelReady, setServerLevelReady] = useState(false);
|
||||
const [serverLevelError, setServerLevelError] = useState<string | null>(null);
|
||||
const [levelBusy, setLevelBusy] = useState(false);
|
||||
const [confirmTrace, setConfirmTrace] = useState(false);
|
||||
const [traceExportBusy, setTraceExportBusy] = useState(false);
|
||||
@@ -133,23 +138,39 @@ export function LogsPage() {
|
||||
const enabled = useMemo(() => new Set(prefs.visibleLevels as LogLevel[]), [prefs.visibleLevels]);
|
||||
|
||||
const loadLogs = useCallback(async () => {
|
||||
setLogsError(null);
|
||||
try {
|
||||
// Backfill is capped at the server's ring-buffer size (1000); `maxLines`
|
||||
// can exceed that, but only the live SSE stream grows the view past 1000.
|
||||
setLogs(await api.logs.list(Math.min(1000, maxLinesRef.current)));
|
||||
} catch (e) {
|
||||
console.error('logs', e);
|
||||
setLogsError(e instanceof Error ? e.message : '加载日志失败');
|
||||
} finally {
|
||||
setLogsReady(true);
|
||||
}
|
||||
}, [api]);
|
||||
|
||||
useEffect(() => { void loadLogs(); }, [loadLogs]);
|
||||
|
||||
useEffect(() => {
|
||||
api.logs.getLevel().then(({ level }) => setServerLevel(level)).catch((err) => {
|
||||
console.error('getLevel', err);
|
||||
});
|
||||
const loadServerLevel = useCallback(async () => {
|
||||
setServerLevelReady(false);
|
||||
setServerLevelError(null);
|
||||
try {
|
||||
const { level } = await api.logs.getLevel();
|
||||
setServerLevel(level);
|
||||
} catch (error) {
|
||||
console.error('get server log level failed', error);
|
||||
setServerLevelError(error instanceof Error ? error.message : '加载服务端日志级别失败');
|
||||
} finally {
|
||||
setServerLevelReady(true);
|
||||
}
|
||||
}, [api]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadServerLevel();
|
||||
}, [loadServerLevel]);
|
||||
|
||||
const applyServerLevel = useCallback(async (lv: LogLevel) => {
|
||||
if (lv === serverLevel || levelBusy) return;
|
||||
setLevelBusy(true);
|
||||
@@ -587,29 +608,50 @@ export function LogsPage() {
|
||||
<span className="text-xs font-medium text-foreground">服务端日志级别</span>
|
||||
<span className="text-xs text-muted-foreground">· 普通日志仅影响控制台 / 实时流;首次登录凭据始终可见;文件等级由环境变量决定,默认为 debug</span>
|
||||
</div>
|
||||
<div className="inline-flex flex-wrap gap-1 rounded-lg bg-muted/60 p-1">
|
||||
{LEVELS.map((lv) => {
|
||||
const active = serverLevel === lv;
|
||||
return (
|
||||
<button
|
||||
key={lv}
|
||||
type="button"
|
||||
onClick={() => void changeServerLevel(lv)}
|
||||
disabled={levelBusy || serverLevel === null}
|
||||
aria-pressed={active}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-[background-color,color,box-shadow,opacity] duration-150 ease-out cursor-pointer disabled:cursor-not-allowed disabled:opacity-50',
|
||||
active
|
||||
? cn('bg-card shadow-sm ring-1 ring-border/60', levelClass[lv])
|
||||
: 'text-muted-foreground/70 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<span className={cn('size-1.5 rounded-full', active ? 'bg-current' : 'bg-muted-foreground/30')} />
|
||||
{lv.toUpperCase()}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={serverLevelReady}
|
||||
reserve={34}
|
||||
lines={1}
|
||||
lineHeight={34}
|
||||
barHeight={8}
|
||||
label="服务端日志级别"
|
||||
className={serverLevelReady ? 'skeleton-swap-fluid min-h-[34px]' : 'w-72 max-w-full'}
|
||||
>
|
||||
{serverLevelReady ? (
|
||||
serverLevelError ? (
|
||||
<div role="alert" className="flex flex-wrap items-center gap-2 text-xs text-destructive">
|
||||
<span>{serverLevelError}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void loadServerLevel()}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="inline-flex flex-wrap gap-1 rounded-lg bg-muted/60 p-1">
|
||||
{LEVELS.map((lv) => {
|
||||
const active = serverLevel === lv;
|
||||
return (
|
||||
<button
|
||||
key={lv}
|
||||
type="button"
|
||||
onClick={() => void changeServerLevel(lv)}
|
||||
disabled={levelBusy || serverLevel === null}
|
||||
aria-pressed={active}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-[background-color,color,box-shadow,opacity] duration-150 ease-out cursor-pointer disabled:cursor-not-allowed disabled:opacity-50',
|
||||
active
|
||||
? cn('bg-card shadow-sm ring-1 ring-border/60', levelClass[lv])
|
||||
: 'text-muted-foreground/70 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<span className={cn('size-1.5 rounded-full', active ? 'bg-current' : 'bg-muted-foreground/30')} />
|
||||
{lv.toUpperCase()}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
|
||||
{/* Highlight rules */}
|
||||
@@ -674,7 +716,7 @@ export function LogsPage() {
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-muted/20">
|
||||
{/* Column header lives OUTSIDE the scroll viewport so the virtualizer's
|
||||
scroll element contains only the rows (no sticky-offset math). */}
|
||||
{filtered.length > 0 && (
|
||||
{logsReady && filtered.length > 0 && (
|
||||
<div className="hidden items-center gap-3 border-b border-border/60 bg-card/60 px-3 py-2 font-mono text-micro font-medium uppercase tracking-wider text-muted-foreground/70 sm:flex">
|
||||
<span className="w-[104px] shrink-0">时间</span>
|
||||
<span className="w-[76px] shrink-0">级别</span>
|
||||
@@ -682,75 +724,100 @@ export function LogsPage() {
|
||||
<span className="flex-1">消息</span>
|
||||
</div>
|
||||
)}
|
||||
{logsReady && logsError && logs.length > 0 && (
|
||||
<div role="alert" className="border-b border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{logsError};当前显示已读取和实时接收的日志。
|
||||
</div>
|
||||
)}
|
||||
<ScrollArea viewportRef={scrollRef} className="min-h-0 flex-1" viewportClassName={cn('[&>div]:!block', maskCls)}>
|
||||
<div className="font-mono text-xs">
|
||||
{filtered.length === 0 ? (
|
||||
<div className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-muted-foreground">
|
||||
{logs.length === 0 ? (
|
||||
<>
|
||||
<Inbox className="size-9 opacity-30" />
|
||||
<span className="text-sm">暂无日志</span>
|
||||
</>
|
||||
<SkeletonSwap
|
||||
ready={logsReady}
|
||||
reserve={240}
|
||||
lines={8}
|
||||
lineHeight={30}
|
||||
barHeight={10}
|
||||
label="运行日志"
|
||||
className={logsReady ? 'skeleton-swap-fluid min-h-60' : ''}
|
||||
>
|
||||
{logsReady ? (
|
||||
<div className="font-mono text-xs">
|
||||
{logsError && logs.length === 0 ? (
|
||||
<div role="alert" className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-destructive">
|
||||
<TriangleAlert className="size-9 opacity-70" />
|
||||
<span className="text-sm">{logsError}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void loadLogs()} className="rounded-lg">
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<div className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-muted-foreground">
|
||||
{logs.length === 0 ? (
|
||||
<>
|
||||
<Inbox className="size-9 opacity-30" />
|
||||
<span className="text-sm">暂无日志</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SearchX className="size-9 opacity-30" />
|
||||
<span className="text-sm">没有符合筛选条件的日志</span>
|
||||
<Button variant="outline" size="sm" onClick={clearFilters} className="rounded-lg">清除筛选</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<SearchX className="size-9 opacity-30" />
|
||||
<span className="text-sm">没有符合筛选条件的日志</span>
|
||||
<Button variant="outline" size="sm" onClick={clearFilters} className="rounded-lg">清除筛选</Button>
|
||||
</>
|
||||
<div className="relative w-full" style={{ height: rowVirtualizer.getTotalSize() }}>
|
||||
{rowVirtualizer.getVirtualItems().map((vRow) => {
|
||||
const log = filtered[vRow.index];
|
||||
if (!log) return null; // guard a transient count/measurement skew
|
||||
const hl = matchHighlight(log.message, prefs.highlightRules);
|
||||
// Entrance is decided entirely by animatingRef (populated in
|
||||
// the flush from real arrivals, pruned at 260ms), so it fires
|
||||
// on the first paint, never replays on scroll-into-view, and
|
||||
// is immune to filter/idle churn. Outer = positioning +
|
||||
// measurement (its translateY); inner = visual row + the
|
||||
// transform-based entrance, kept separate so they never collide.
|
||||
const entering = animatingRef.current.has(log.id);
|
||||
return (
|
||||
<div
|
||||
key={log.id}
|
||||
data-index={vRow.index}
|
||||
ref={rowVirtualizer.measureElement}
|
||||
className="absolute left-0 top-0 w-full"
|
||||
style={{ transform: `translateY(${vRow.start}px)` }}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col gap-0.5 border-b border-border/30 px-3 py-1.5 transition-colors hover:bg-accent/40 sm:flex-row sm:items-start sm:gap-3 sm:py-1',
|
||||
entering && 'log-row-in',
|
||||
)}
|
||||
style={hl ? { boxShadow: `inset 3px 0 0 ${hl}`, backgroundColor: `color-mix(in oklab, ${hl} 8%, transparent)` } : undefined}
|
||||
>
|
||||
<div className="flex items-center gap-3 sm:contents">
|
||||
<span className="w-[104px] shrink-0 tabular-nums text-muted-foreground">{formatClock(log.time)}</span>
|
||||
<span className={cn('flex w-[76px] shrink-0 items-center gap-1.5 font-semibold', levelClass[log.level])}>
|
||||
<span className="size-1.5 shrink-0 rounded-full bg-current" />
|
||||
{log.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground sm:w-28 sm:flex-none sm:shrink-0">[{log.scope}]</span>
|
||||
</div>
|
||||
<span
|
||||
className={cn('min-w-0 flex-1 leading-5', prefs.wrap ? 'whitespace-pre-wrap break-all' : 'truncate')}
|
||||
title={prefs.wrap ? undefined : log.message}
|
||||
>
|
||||
{log.req !== undefined && (
|
||||
<span className="mr-1.5 rounded bg-primary/10 px-1 text-micro text-primary tabular-nums" title="请求关联号">#{log.req}</span>
|
||||
)}
|
||||
{log.message}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative w-full" style={{ height: rowVirtualizer.getTotalSize() }}>
|
||||
{rowVirtualizer.getVirtualItems().map((vRow) => {
|
||||
const log = filtered[vRow.index];
|
||||
if (!log) return null; // guard a transient count/measurement skew
|
||||
const hl = matchHighlight(log.message, prefs.highlightRules);
|
||||
// Entrance is decided entirely by animatingRef (populated in
|
||||
// the flush from real arrivals, pruned at 260ms), so it fires
|
||||
// on the first paint, never replays on scroll-into-view, and
|
||||
// is immune to filter/idle churn. Outer = positioning +
|
||||
// measurement (its translateY); inner = visual row + the
|
||||
// transform-based entrance, kept separate so they never collide.
|
||||
const entering = animatingRef.current.has(log.id);
|
||||
return (
|
||||
<div
|
||||
key={log.id}
|
||||
data-index={vRow.index}
|
||||
ref={rowVirtualizer.measureElement}
|
||||
className="absolute left-0 top-0 w-full"
|
||||
style={{ transform: `translateY(${vRow.start}px)` }}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col gap-0.5 border-b border-border/30 px-3 py-1.5 transition-colors hover:bg-accent/40 sm:flex-row sm:items-start sm:gap-3 sm:py-1',
|
||||
entering && 'log-row-in',
|
||||
)}
|
||||
style={hl ? { boxShadow: `inset 3px 0 0 ${hl}`, backgroundColor: `color-mix(in oklab, ${hl} 8%, transparent)` } : undefined}
|
||||
>
|
||||
<div className="flex items-center gap-3 sm:contents">
|
||||
<span className="w-[104px] shrink-0 tabular-nums text-muted-foreground">{formatClock(log.time)}</span>
|
||||
<span className={cn('flex w-[76px] shrink-0 items-center gap-1.5 font-semibold', levelClass[log.level])}>
|
||||
<span className="size-1.5 shrink-0 rounded-full bg-current" />
|
||||
{log.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground sm:w-28 sm:flex-none sm:shrink-0">[{log.scope}]</span>
|
||||
</div>
|
||||
<span
|
||||
className={cn('min-w-0 flex-1 leading-5', prefs.wrap ? 'whitespace-pre-wrap break-all' : 'truncate')}
|
||||
title={prefs.wrap ? undefined : log.message}
|
||||
>
|
||||
{log.req !== undefined && (
|
||||
<span className="mr-1.5 rounded bg-primary/10 px-1 text-micro text-primary tabular-nums" title="请求关联号">#{log.req}</span>
|
||||
)}
|
||||
{log.message}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Progress } from '@/components/ui/progress';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn, formatBytes, formatUptime } from '@/lib/utils';
|
||||
import type { AppPath } from '@/router';
|
||||
import type {
|
||||
@@ -64,7 +64,7 @@ function renderWidget(block: UiLayoutItem): ReactNode {
|
||||
}
|
||||
|
||||
export function OverviewPage() {
|
||||
const { qqList, processList } = useAppState();
|
||||
const { qqList, processList, resources } = useAppState();
|
||||
const {
|
||||
overviewBlocks, setOverviewBlocks, overviewMobile, setOverviewMobile,
|
||||
resetLayout, editing, setEditing,
|
||||
@@ -153,7 +153,7 @@ export function OverviewPage() {
|
||||
)}
|
||||
|
||||
{/* First-run nudge — always shown (not a grid widget) so it can't be hidden. */}
|
||||
{qqList.length === 0 && (
|
||||
{resources.qqList.ready && !resources.qqList.error && qqList.length === 0 && (
|
||||
<motion.div initial={off ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }}>
|
||||
<Link
|
||||
to="/processes"
|
||||
@@ -475,7 +475,7 @@ function shortDistro(distro: string): string {
|
||||
}
|
||||
|
||||
function StatTile({
|
||||
icon, label, value, subtext, details, accent = false, to,
|
||||
icon, label, value, subtext, details, accent = false, to, ready = true,
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
label: string;
|
||||
@@ -484,6 +484,7 @@ function StatTile({
|
||||
details?: string;
|
||||
accent?: boolean;
|
||||
to?: AppPath;
|
||||
ready?: boolean;
|
||||
}) {
|
||||
const copy = (
|
||||
<>
|
||||
@@ -502,10 +503,32 @@ function StatTile({
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
{details ? (
|
||||
<StatTileDetails label={label} details={details}>{copy}</StatTileDetails>
|
||||
{details && ready ? (
|
||||
<StatTileDetails label={label} details={details}>
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={52}
|
||||
lines={3}
|
||||
lineHeight={17}
|
||||
barHeight={8}
|
||||
label={label}
|
||||
className="skeleton-swap-fluid"
|
||||
>
|
||||
{copy}
|
||||
</SkeletonSwap>
|
||||
</StatTileDetails>
|
||||
) : (
|
||||
<div className="min-w-0 flex-1">{copy}</div>
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={52}
|
||||
lines={3}
|
||||
lineHeight={17}
|
||||
barHeight={8}
|
||||
label={label}
|
||||
className={ready ? 'skeleton-swap-fluid min-w-0 flex-1' : 'min-w-0 flex-1'}
|
||||
>
|
||||
{ready ? copy : null}
|
||||
</SkeletonSwap>
|
||||
)}
|
||||
{to && <ArrowRight className="optical-forward size-4 shrink-0 text-muted-foreground/60" />}
|
||||
</CardContent>
|
||||
@@ -521,7 +544,7 @@ function StatTile({
|
||||
}
|
||||
|
||||
function StatTileWidget({ id }: { id: string }) {
|
||||
const { qqList, processList, systemInfo } = useAppState();
|
||||
const { qqList, processList, systemInfo, resources } = useAppState();
|
||||
const { status } = useSession();
|
||||
const online = status === '已连接';
|
||||
|
||||
@@ -541,8 +564,11 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<Users className="size-5" />}
|
||||
label="在线账号"
|
||||
value={qqList.length}
|
||||
subtext={`已接入 ${qqList.length} 个会话`}
|
||||
ready={resources.qqList.ready}
|
||||
value={resources.qqList.error && qqList.length === 0 ? '—' : qqList.length}
|
||||
subtext={resources.qqList.error
|
||||
? qqList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||
: `已接入 ${qqList.length} 个会话`}
|
||||
/>
|
||||
);
|
||||
case 'stat:processes': {
|
||||
@@ -552,19 +578,25 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<PlugZap className="size-5" />}
|
||||
label="进程注入"
|
||||
value={`${onlineProcs} 在线`}
|
||||
subtext={`${processList.length} 进程 · ${loadableProcs} 可注入`}
|
||||
ready={resources.processList.ready}
|
||||
value={resources.processList.error && processList.length === 0 ? '—' : `${onlineProcs} 在线`}
|
||||
subtext={resources.processList.error
|
||||
? processList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||
: `${processList.length} 进程 · ${loadableProcs} 可注入`}
|
||||
to="/processes"
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'stat:host': {
|
||||
const value = systemInfo?.hostname ?? '—';
|
||||
const subtext = systemInfo ? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}` : '加载中';
|
||||
const subtext = systemInfo
|
||||
? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}`
|
||||
: resources.systemInfo.error ? '加载失败' : '加载中';
|
||||
return (
|
||||
<StatTile
|
||||
icon={<Server className="size-5" />}
|
||||
label="主机名"
|
||||
ready={resources.systemInfo.ready}
|
||||
value={value}
|
||||
subtext={subtext}
|
||||
details={systemInfo
|
||||
@@ -580,6 +612,7 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<MonitorCog className="size-5" />}
|
||||
label="系统运行"
|
||||
ready={resources.systemInfo.ready}
|
||||
value={systemUptime}
|
||||
subtext={processUptime ? `进程 ${processUptime}` : undefined}
|
||||
details={processUptime
|
||||
@@ -598,7 +631,7 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
const HOST_GRID_COLS: Record<number, string> = { 1: 'lg:grid-cols-1', 2: 'lg:grid-cols-2', 3: 'lg:grid-cols-3' };
|
||||
|
||||
function HostBlock({ config }: { config: HostConfig }) {
|
||||
const { systemInfo, refreshSystem } = useAppState();
|
||||
const { systemInfo, refreshSystem, resources } = useAppState();
|
||||
const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length;
|
||||
return (
|
||||
<Card className="flex h-full flex-col">
|
||||
@@ -607,8 +640,10 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
<CardTitle>主机资源</CardTitle>
|
||||
<CardDescription>
|
||||
{systemInfo
|
||||
? `${systemInfo.cpu.model.trim()} · ${systemInfo.cpu.cores} 核 · Node ${systemInfo.nodeVersion}`
|
||||
: '正在采集主机信息…'}
|
||||
? `${systemInfo.cpu.model.trim()} · ${systemInfo.cpu.cores} 核 · Node ${systemInfo.nodeVersion}${
|
||||
resources.systemInfo.error ? ' · 更新失败,显示上次数据' : ''
|
||||
}`
|
||||
: resources.systemInfo.error ?? '正在采集主机信息…'}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={refreshSystem}>
|
||||
@@ -631,34 +666,50 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
<Progress value={systemInfo?.cpu.average ?? 0} />
|
||||
<p className="mt-2 text-meta text-muted-foreground tabular-nums">
|
||||
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
|
||||
</p>
|
||||
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
|
||||
<div
|
||||
className="mt-3 grid"
|
||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
||||
>
|
||||
{systemInfo.cpu.perCore.map((p, i) => (
|
||||
<div
|
||||
key={i}
|
||||
title={`Core ${i}: ${p.toFixed(1)}%`}
|
||||
className="grid aspect-square place-items-center rounded-md transition-[background] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
|
||||
style={{
|
||||
background: `color-mix(in oklab, var(--primary) ${Math.min(100, Math.max(0, p)).toFixed(1)}%, color-mix(in oklab, var(--muted) 80%, transparent))`,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="text-micro leading-none tabular-nums"
|
||||
style={{ color: 'color-mix(in oklab, var(--foreground) 55%, transparent)' }}
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={112}
|
||||
lines={4}
|
||||
lineHeight={28}
|
||||
barHeight={9}
|
||||
label="CPU 使用率"
|
||||
className="skeleton-swap-fluid min-h-[112px]"
|
||||
>
|
||||
{systemInfo ? (
|
||||
<>
|
||||
<Progress value={systemInfo.cpu.average} />
|
||||
<p className="mt-2 text-meta text-muted-foreground tabular-nums">
|
||||
负载: {systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ')}
|
||||
</p>
|
||||
{systemInfo.cpu.perCore.length > 0 && (
|
||||
<div
|
||||
className="mt-3 grid"
|
||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
||||
>
|
||||
{i}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{systemInfo.cpu.perCore.map((p, i) => (
|
||||
<div
|
||||
key={i}
|
||||
title={`Core ${i}: ${p.toFixed(1)}%`}
|
||||
className="grid aspect-square place-items-center rounded-md transition-[background] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
|
||||
style={{
|
||||
background: `color-mix(in oklab, var(--primary) ${Math.min(100, Math.max(0, p)).toFixed(1)}%, color-mix(in oklab, var(--muted) 80%, transparent))`,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="text-micro leading-none tabular-nums"
|
||||
style={{ color: 'color-mix(in oklab, var(--foreground) 55%, transparent)' }}
|
||||
>
|
||||
{i}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
{/* Memory */}
|
||||
@@ -673,39 +724,51 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
{systemInfo ? (() => {
|
||||
const m = systemInfo.memory;
|
||||
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
||||
const other = Math.max(0, m.used - rss);
|
||||
const segs = [
|
||||
{ key: 'proc', label: '本进程', bytes: rss, grow: (rss / m.total) * 100, color: 'var(--primary)' },
|
||||
{ key: 'other', label: '其他已用', bytes: other, grow: (other / m.total) * 100, color: 'color-mix(in oklab, var(--primary) 45%, transparent)' },
|
||||
{ key: 'free', label: '空闲', bytes: m.free, grow: (m.free / m.total) * 100, color: 'color-mix(in oklab, var(--muted) 85%, transparent)' },
|
||||
];
|
||||
return (
|
||||
<>
|
||||
<div className="mt-1.5 flex h-3 gap-0.5">
|
||||
{segs.map((seg) => (
|
||||
<span
|
||||
key={seg.key}
|
||||
className="rounded-[3px]"
|
||||
style={{ flexGrow: seg.grow, minWidth: 2, background: seg.color }}
|
||||
title={`${seg.label} ${formatBytes(seg.bytes)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-x-3.5 gap-y-1 text-meta text-muted-foreground">
|
||||
{segs.map((seg) => (
|
||||
<span key={seg.key} className="inline-flex items-center gap-1.5">
|
||||
<i className="size-2 rounded-[2px]" style={{ background: seg.color }} />
|
||||
{seg.label}
|
||||
<b className="font-semibold text-foreground tabular-nums">{formatBytes(seg.bytes)}</b>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
})() : <Progress value={0} />}
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={72}
|
||||
lines={3}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="内存使用"
|
||||
className="skeleton-swap-fluid min-h-[72px]"
|
||||
>
|
||||
{systemInfo ? (() => {
|
||||
const m = systemInfo.memory;
|
||||
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
||||
const other = Math.max(0, m.used - rss);
|
||||
const segs = [
|
||||
{ key: 'proc', label: '本进程', bytes: rss, grow: (rss / m.total) * 100, color: 'var(--primary)' },
|
||||
{ key: 'other', label: '其他已用', bytes: other, grow: (other / m.total) * 100, color: 'color-mix(in oklab, var(--primary) 45%, transparent)' },
|
||||
{ key: 'free', label: '空闲', bytes: m.free, grow: (m.free / m.total) * 100, color: 'color-mix(in oklab, var(--muted) 85%, transparent)' },
|
||||
];
|
||||
return (
|
||||
<>
|
||||
<div className="mt-1.5 flex h-3 gap-0.5">
|
||||
{segs.map((seg) => (
|
||||
<span
|
||||
key={seg.key}
|
||||
className="rounded-[3px]"
|
||||
style={{ flexGrow: seg.grow, minWidth: 2, background: seg.color }}
|
||||
title={`${seg.label} ${formatBytes(seg.bytes)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-x-3.5 gap-y-1 text-meta text-muted-foreground">
|
||||
{segs.map((seg) => (
|
||||
<span key={seg.key} className="inline-flex items-center gap-1.5">
|
||||
<i className="size-2 rounded-[2px]" style={{ background: seg.color }} />
|
||||
{seg.label}
|
||||
<b className="font-semibold text-foreground tabular-nums">{formatBytes(seg.bytes)}</b>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
})() : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
{/* Runtime */}
|
||||
@@ -720,29 +783,36 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
{!systemInfo ? (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-4 w-1/2" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1.5 text-xs">
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">RSS</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={88}
|
||||
lines={3}
|
||||
lineHeight={29}
|
||||
barHeight={9}
|
||||
label="运行进程"
|
||||
className={resources.systemInfo.ready ? 'skeleton-swap-fluid min-h-[88px]' : ''}
|
||||
>
|
||||
{systemInfo ? (
|
||||
<div className="space-y-1.5 text-xs">
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">RSS</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">堆内存</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">外部内存</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">堆内存</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">外部内存</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
@@ -753,7 +823,7 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
// ─────────────── online sessions ───────────────
|
||||
|
||||
function SessionsBlock({ config }: { config: SessionsConfig }) {
|
||||
const { qqList } = useAppState();
|
||||
const { qqList, resources } = useAppState();
|
||||
const off = useTheme().appearance.disableMotion;
|
||||
const list = useMemo(() => {
|
||||
const f = config.filter.trim().toLowerCase();
|
||||
@@ -775,37 +845,60 @@ function SessionsBlock({ config }: { config: SessionsConfig }) {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1">
|
||||
{list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Users className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ScrollArea className="h-full" viewportClassName="[&>div]:!block">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{list.map((q, idx) => (
|
||||
<motion.div
|
||||
key={q.uin}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.04, duration: 0.22 }}
|
||||
whileHover={off ? undefined : { y: -2 }}
|
||||
className="flex items-center gap-3 rounded-xl border bg-card/40 p-3"
|
||||
>
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(q.uin)} alt={q.nickname || q.uin} />
|
||||
<AvatarFallback>{(q.nickname || q.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-semibold">{q.nickname}</div>
|
||||
<div className="truncate font-mono text-meta text-muted-foreground tabular-nums">{q.uin}</div>
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="在线会话"
|
||||
className={resources.qqList.ready ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
resources.qqList.error && qqList.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{resources.qqList.error}
|
||||
</p>
|
||||
) : list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Users className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{resources.qqList.error && (
|
||||
<p role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.qqList.error};当前显示上次成功读取的在线会话。
|
||||
</p>
|
||||
)}
|
||||
<ScrollArea className="h-full" viewportClassName="[&>div]:!block">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{list.map((q, idx) => (
|
||||
<motion.div
|
||||
key={q.uin}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.04, duration: 0.22 }}
|
||||
whileHover={off ? undefined : { y: -2 }}
|
||||
className="flex items-center gap-3 rounded-xl border bg-card/40 p-3"
|
||||
>
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(q.uin)} alt={q.nickname || q.uin} />
|
||||
<AvatarFallback>{(q.nickname || q.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-semibold">{q.nickname}</div>
|
||||
<div className="truncate font-mono text-meta text-muted-foreground tabular-nums">{q.uin}</div>
|
||||
</div>
|
||||
<span className="size-2 shrink-0 animate-pulse rounded-full bg-success shadow-[0_0_8px_color-mix(in_oklab,var(--success)_60%,transparent)]" />
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
<span className="size-2 shrink-0 animate-pulse rounded-full bg-success shadow-[0_0_8px_color-mix(in_oklab,var(--success)_60%,transparent)]" />
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@@ -837,7 +930,7 @@ const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = {
|
||||
};
|
||||
|
||||
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
const { connections } = useAppState();
|
||||
const { connections, resources } = useAppState();
|
||||
const list = useMemo(() => {
|
||||
const f = config.filter.trim().toLowerCase();
|
||||
// Optionally drop healthy adapters, then accounts left with none.
|
||||
@@ -869,51 +962,72 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
{list.map((acc) => (
|
||||
<div key={acc.uin} className="flex flex-col gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
||||
<span className="font-mono text-meta text-muted-foreground tabular-nums">{acc.uin}</span>
|
||||
</div>
|
||||
{acc.databaseMigration && acc.databaseMigration.phase !== 'complete' && (
|
||||
<DatabaseMigrationProgress migration={acc.databaseMigration} />
|
||||
)}
|
||||
{acc.adapters.length > 0 ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{acc.adapters.map((adp) => (
|
||||
<div key={adp.name} className="flex items-center gap-2 rounded-xl border bg-card/40 px-3 py-2">
|
||||
<span className={cn('shrink-0 rounded px-1.5 py-0.5 text-micro font-medium', CONN_STATUS_STYLE[adp.status])}>
|
||||
{CONN_STATUS_LABEL[adp.status]}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm font-medium">{adp.name}</span>
|
||||
<span className="shrink-0 text-micro text-muted-foreground">{ADAPTER_KIND_LABEL[adp.kind]}</span>
|
||||
</div>
|
||||
<div className="truncate text-meta text-muted-foreground">{adp.detail}</div>
|
||||
{adp.lastError && adp.lastErrorAt && (
|
||||
<div className="truncate text-xs text-destructive/80">
|
||||
{new Date(adp.lastErrorAt).toLocaleString()} · {adp.lastError}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : acc.databaseMigration?.usable !== false ? (
|
||||
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
|
||||
) : null}
|
||||
<SkeletonSwap
|
||||
ready={resources.connections.ready}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="OneBot 连接"
|
||||
className={resources.connections.ready ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{resources.connections.ready ? (
|
||||
resources.connections.error && connections.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{resources.connections.error}
|
||||
</p>
|
||||
) : list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
{resources.connections.error && (
|
||||
<p role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.connections.error};当前显示上次成功读取的连接状态。
|
||||
</p>
|
||||
)}
|
||||
{list.map((acc) => (
|
||||
<div key={acc.uin} className="flex flex-col gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
||||
<span className="font-mono text-meta text-muted-foreground tabular-nums">{acc.uin}</span>
|
||||
</div>
|
||||
{acc.databaseMigration && acc.databaseMigration.phase !== 'complete' && (
|
||||
<DatabaseMigrationProgress migration={acc.databaseMigration} />
|
||||
)}
|
||||
{acc.adapters.length > 0 ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{acc.adapters.map((adp) => (
|
||||
<div key={adp.name} className="flex items-center gap-2 rounded-xl border bg-card/40 px-3 py-2">
|
||||
<span className={cn('shrink-0 rounded px-1.5 py-0.5 text-micro font-medium', CONN_STATUS_STYLE[adp.status])}>
|
||||
{CONN_STATUS_LABEL[adp.status]}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm font-medium">{adp.name}</span>
|
||||
<span className="shrink-0 text-micro text-muted-foreground">{ADAPTER_KIND_LABEL[adp.kind]}</span>
|
||||
</div>
|
||||
<div className="truncate text-meta text-muted-foreground">{adp.detail}</div>
|
||||
{adp.lastError && adp.lastErrorAt && (
|
||||
<div className="truncate text-xs text-destructive/80">
|
||||
{new Date(adp.lastErrorAt).toLocaleString()} · {adp.lastError}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : acc.databaseMigration?.usable !== false ? (
|
||||
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@@ -1013,7 +1127,7 @@ function LinkWidget({ config }: { config: LinkConfig }) {
|
||||
}
|
||||
|
||||
function AccountWidget({ config }: { config: AccountConfig }) {
|
||||
const { qqList } = useAppState();
|
||||
const { qqList, resources } = useAppState();
|
||||
const acct = qqList.find((q) => q.uin === config.uin);
|
||||
if (!config.uin) {
|
||||
return (
|
||||
@@ -1027,20 +1141,34 @@ function AccountWidget({ config }: { config: AccountConfig }) {
|
||||
}
|
||||
return (
|
||||
<Card className="h-full overflow-hidden">
|
||||
<CardContent className="flex h-full items-center gap-3 p-4">
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
||||
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-semibold">{acct?.nickname || '未接入账号'}</p>
|
||||
<p className="truncate font-mono text-meta text-muted-foreground tabular-nums">{config.uin}</p>
|
||||
</div>
|
||||
<span
|
||||
title={acct ? '在线' : '未接入'}
|
||||
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||
/>
|
||||
</CardContent>
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
reserve={72}
|
||||
lines={3}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="账号状态"
|
||||
className="skeleton-swap-fill"
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
<CardContent className="flex h-full items-center gap-3 p-4">
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
||||
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-semibold">
|
||||
{resources.qqList.error ? '账号状态加载失败' : acct?.nickname || '未接入账号'}
|
||||
</p>
|
||||
<p className="truncate font-mono text-meta text-muted-foreground tabular-nums">{config.uin}</p>
|
||||
</div>
|
||||
<span
|
||||
title={acct ? '在线' : resources.qqList.error ? '状态未知' : '未接入'}
|
||||
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||
/>
|
||||
</CardContent>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1062,24 +1190,32 @@ const ALERT_LEVEL_CLASS: Record<LogLevel, string> = {
|
||||
function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
||||
const api = useApi();
|
||||
const { formatClock } = useTheme();
|
||||
const [alerts, setAlerts] = useState<LogEntry[]>([]);
|
||||
const [alerts, setAlerts] = useState<LogEntry[] | null>(null);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const { count } = config;
|
||||
const levelsKey = config.levels.join(',');
|
||||
|
||||
useEffect(() => {
|
||||
const levels = new Set(levelsKey.split(',') as LogLevel[]);
|
||||
let active = true;
|
||||
setAlerts(null);
|
||||
setLoadError(null);
|
||||
api.logs
|
||||
.list(Math.max(200, count * 4))
|
||||
.then((list) => {
|
||||
if (!active) return;
|
||||
setAlerts(list.filter((l) => levels.has(l.level)).slice(-count));
|
||||
})
|
||||
.catch(() => { /* ignore */ });
|
||||
.catch((error) => {
|
||||
if (!active) return;
|
||||
console.error('load recent alerts failed', error);
|
||||
setLoadError(error instanceof Error ? error.message : '加载最近告警失败');
|
||||
setAlerts((previous) => previous ?? []);
|
||||
});
|
||||
const stop = api.logs.stream({
|
||||
onLine: (entry) => {
|
||||
if (!levels.has(entry.level)) return;
|
||||
setAlerts((prev) => [...prev.filter((a) => a.id !== entry.id), entry].slice(-count));
|
||||
setAlerts((prev) => [...(prev ?? []).filter((a) => a.id !== entry.id), entry].slice(-count));
|
||||
},
|
||||
});
|
||||
return () => { active = false; stop(); };
|
||||
@@ -1099,24 +1235,45 @@ function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
||||
</Link>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{alerts.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无告警</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 font-mono text-meta">
|
||||
{alerts.map((a) => (
|
||||
<div key={a.id} className="flex gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatClock(a.time)}</span>
|
||||
<span className={cn('shrink-0 font-semibold', ALERT_LEVEL_CLASS[a.level])}>
|
||||
{a.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate" title={a.message}>[{a.scope}] {a.message}</span>
|
||||
<SkeletonSwap
|
||||
ready={alerts !== null}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="最近告警"
|
||||
className={alerts !== null ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{alerts !== null ? (
|
||||
loadError && alerts.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{loadError}
|
||||
</p>
|
||||
) : alerts.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无告警</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 font-mono text-meta">
|
||||
{loadError && (
|
||||
<p role="alert" className="mb-1 rounded-lg border border-destructive/30 bg-destructive/10 px-2 py-1.5 font-sans text-xs text-destructive">
|
||||
{loadError};当前显示已收到的实时告警。
|
||||
</p>
|
||||
)}
|
||||
{alerts.map((a) => (
|
||||
<div key={a.id} className="flex gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatClock(a.time)}</span>
|
||||
<span className={cn('shrink-0 font-semibold', ALERT_LEVEL_CLASS[a.level])}>
|
||||
{a.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate" title={a.message}>[{a.scope}] {a.message}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { HookProcessInfo } from '@/types';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
@@ -48,7 +49,7 @@ function processBadgeVariant(status: HookProcessInfo['status']) {
|
||||
* regardless of which page is mounted.
|
||||
*/
|
||||
export function ProcessesPage() {
|
||||
const { processList, processOps, refreshProcesses } = useAppState();
|
||||
const { processList, processOps, refreshProcesses, resources } = useAppState();
|
||||
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
|
||||
const { pages, setPages } = useLayout();
|
||||
const off = useTheme().appearance.disableMotion;
|
||||
@@ -95,7 +96,12 @@ export function ProcessesPage() {
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={refreshProcesses}
|
||||
disabled={!resources.processList.ready}
|
||||
>
|
||||
<RefreshCw className="size-3.5" /> 刷新
|
||||
</Button>
|
||||
</div>
|
||||
@@ -111,129 +117,154 @@ export function ProcessesPage() {
|
||||
{processActionStatus}
|
||||
</motion.div>
|
||||
)}
|
||||
{processList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Cpu className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
||||
<p className="text-xs text-muted-foreground/80">请确认 QQ 已启动后点击右上角刷新</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2 2xl:grid-cols-3">
|
||||
{sorted.map((proc, idx) => {
|
||||
const op = statusOf(proc.pid);
|
||||
const loading = op === 'load' || proc.status === 'loading';
|
||||
const unloading = op === 'unload';
|
||||
const refreshing = op === 'refresh';
|
||||
const busy = op != null || proc.status === 'loading';
|
||||
const isOnline = proc.status === 'online';
|
||||
const canUnload = proc.injected;
|
||||
// Refresh is meaningful whenever a hook may exist (so the user
|
||||
// can re-check the pipe and trigger a reconnect on demand).
|
||||
const showRefresh = proc.injected || proc.status === 'connecting' || proc.status === 'disconnected';
|
||||
return (
|
||||
<motion.div
|
||||
key={proc.pid}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.025, duration: 0.22 }}
|
||||
className="flex flex-col gap-3 rounded-xl border bg-card/50 p-3.5 transition-colors hover:bg-accent/20 sm:flex-row sm:items-center"
|
||||
>
|
||||
{/* icon + info stay horizontal; on phones the actions drop to
|
||||
a second row so name / PID / path get the full width
|
||||
instead of collapsing to "Q..". */}
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<div
|
||||
className={cn(
|
||||
'flex size-10 shrink-0 items-center justify-center rounded-xl',
|
||||
isOnline
|
||||
? 'bg-success/15 text-success'
|
||||
: proc.status === 'error'
|
||||
? 'bg-destructive/15 text-destructive'
|
||||
: 'bg-primary/10 text-primary'
|
||||
)}
|
||||
>
|
||||
{isOnline ? (
|
||||
<CheckCircle2 className="size-5" />
|
||||
) : proc.status === 'error' ? (
|
||||
<AlertCircle className="size-5" />
|
||||
) : (
|
||||
<Cpu className="size-5" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 truncate text-sm font-semibold">{proc.name || 'QQ.exe'}</span>
|
||||
<Badge variant={processBadgeVariant(proc.status)} className="shrink-0 whitespace-nowrap">
|
||||
{processStatusLabel[proc.status]}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-meta text-muted-foreground tabular-nums">
|
||||
PID {proc.pid}
|
||||
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
|
||||
</div>
|
||||
{proc.path && (
|
||||
<div className="truncate text-meta text-muted-foreground/80" title={proc.path}>
|
||||
{proc.path}
|
||||
</div>
|
||||
)}
|
||||
{proc.error && (
|
||||
<div className="mt-0.5 truncate text-xs text-destructive" title={proc.error}>
|
||||
{proc.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setProbeDialog({ pid: proc.pid, name: proc.name || `PID ${proc.pid}` })}
|
||||
>
|
||||
<Eye className="size-3.5" /> 探测登录
|
||||
</Button>
|
||||
{showRefresh && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
disabled={busy}
|
||||
aria-label={`刷新进程 ${proc.pid} 管道状态`}
|
||||
title="刷新管道状态 / 重连"
|
||||
onClick={() => refresh(proc.pid)}
|
||||
className="size-8 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{refreshing ? (
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant={canUnload ? 'outline' : 'default'}
|
||||
disabled={busy}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
kind: canUnload ? 'unload' : 'load',
|
||||
pid: proc.pid,
|
||||
name: proc.name || `PID ${proc.pid}`,
|
||||
})
|
||||
}
|
||||
className={cn(
|
||||
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
|
||||
)}
|
||||
>
|
||||
{(loading || unloading) && <Loader2 className="size-3.5 animate-spin" />}
|
||||
{!loading && !unloading && canUnload && <Unplug className="size-3.5" />}
|
||||
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
|
||||
</Button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
{resources.processList.error && processList.length > 0 && (
|
||||
<div role="alert" className="mb-3 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.processList.error};当前显示上次成功读取的进程状态。
|
||||
</div>
|
||||
)}
|
||||
<SkeletonSwap
|
||||
ready={resources.processList.ready}
|
||||
reserve={192}
|
||||
lines={6}
|
||||
lineHeight={32}
|
||||
barHeight={10}
|
||||
label="进程列表"
|
||||
className={resources.processList.ready ? 'skeleton-swap-fluid min-h-[192px]' : ''}
|
||||
>
|
||||
{resources.processList.ready ? (
|
||||
resources.processList.error && processList.length === 0 ? (
|
||||
<div role="alert" className="flex flex-col items-center justify-center gap-3 rounded-xl border border-destructive/30 bg-destructive/10 py-16 text-destructive">
|
||||
<AlertCircle className="size-8 opacity-70" strokeWidth={1.5} />
|
||||
<p className="text-sm">{resources.processList.error}</p>
|
||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : processList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Cpu className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
||||
<p className="text-xs text-muted-foreground/80">请确认 QQ 已启动后点击右上角刷新</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2 2xl:grid-cols-3">
|
||||
{sorted.map((proc, idx) => {
|
||||
const op = statusOf(proc.pid);
|
||||
const loading = op === 'load' || proc.status === 'loading';
|
||||
const unloading = op === 'unload';
|
||||
const refreshing = op === 'refresh';
|
||||
const busy = op != null || proc.status === 'loading';
|
||||
const isOnline = proc.status === 'online';
|
||||
const canUnload = proc.injected;
|
||||
// Refresh is meaningful whenever a hook may exist (so the user
|
||||
// can re-check the pipe and trigger a reconnect on demand).
|
||||
const showRefresh = proc.injected || proc.status === 'connecting' || proc.status === 'disconnected';
|
||||
return (
|
||||
<motion.div
|
||||
key={proc.pid}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.025, duration: 0.22 }}
|
||||
className="flex flex-col gap-3 rounded-xl border bg-card/50 p-3.5 transition-colors hover:bg-accent/20 sm:flex-row sm:items-center"
|
||||
>
|
||||
{/* icon + info stay horizontal; on phones the actions drop to
|
||||
a second row so name / PID / path get the full width
|
||||
instead of collapsing to "Q..". */}
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<div
|
||||
className={cn(
|
||||
'flex size-10 shrink-0 items-center justify-center rounded-xl',
|
||||
isOnline
|
||||
? 'bg-success/15 text-success'
|
||||
: proc.status === 'error'
|
||||
? 'bg-destructive/15 text-destructive'
|
||||
: 'bg-primary/10 text-primary'
|
||||
)}
|
||||
>
|
||||
{isOnline ? (
|
||||
<CheckCircle2 className="size-5" />
|
||||
) : proc.status === 'error' ? (
|
||||
<AlertCircle className="size-5" />
|
||||
) : (
|
||||
<Cpu className="size-5" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 truncate text-sm font-semibold">{proc.name || 'QQ.exe'}</span>
|
||||
<Badge variant={processBadgeVariant(proc.status)} className="shrink-0 whitespace-nowrap">
|
||||
{processStatusLabel[proc.status]}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-meta text-muted-foreground tabular-nums">
|
||||
PID {proc.pid}
|
||||
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
|
||||
</div>
|
||||
{proc.path && (
|
||||
<div className="truncate text-meta text-muted-foreground/80" title={proc.path}>
|
||||
{proc.path}
|
||||
</div>
|
||||
)}
|
||||
{proc.error && (
|
||||
<div className="mt-0.5 truncate text-xs text-destructive" title={proc.error}>
|
||||
{proc.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setProbeDialog({ pid: proc.pid, name: proc.name || `PID ${proc.pid}` })}
|
||||
>
|
||||
<Eye className="size-3.5" /> 探测登录
|
||||
</Button>
|
||||
{showRefresh && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
disabled={busy}
|
||||
aria-label={`刷新进程 ${proc.pid} 管道状态`}
|
||||
title="刷新管道状态 / 重连"
|
||||
onClick={() => refresh(proc.pid)}
|
||||
className="size-8 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{refreshing ? (
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant={canUnload ? 'outline' : 'default'}
|
||||
disabled={busy}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
kind: canUnload ? 'unload' : 'load',
|
||||
pid: proc.pid,
|
||||
name: proc.name || `PID ${proc.pid}`,
|
||||
})
|
||||
}
|
||||
className={cn(
|
||||
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
|
||||
)}
|
||||
>
|
||||
{(loading || unloading) && <Loader2 className="size-3.5 animate-spin" />}
|
||||
{!loading && !unloading && canUnload && <Unplug className="size-3.5" />}
|
||||
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
|
||||
</Button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
||||
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
@@ -739,6 +740,7 @@ function FontField({
|
||||
const listId = useId();
|
||||
const [fonts, setFonts] = useState<string[] | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [fontLoadError, setFontLoadError] = useState<string | null>(null);
|
||||
const canQuery = typeof (window as FontQueryWindow).queryLocalFonts === 'function';
|
||||
const isCustom = value === FONT_CUSTOM_ID;
|
||||
|
||||
@@ -747,16 +749,17 @@ function FontField({
|
||||
{ value: FONT_CUSTOM_ID, label: '自定义' },
|
||||
];
|
||||
|
||||
// Lazily enumerate local fonts the first time the field is focused. A denied
|
||||
// permission (or any failure) just leaves the plain text box — no error UI.
|
||||
// Lazily enumerate local fonts the first time the field is focused.
|
||||
const loadFonts = async () => {
|
||||
if (fonts !== null || loading || !canQuery) return;
|
||||
setLoading(true);
|
||||
setFontLoadError(null);
|
||||
try {
|
||||
const arr = await (window as FontQueryWindow).queryLocalFonts!();
|
||||
setFonts(Array.from(new Set(arr.map((f) => f.family))).sort((x, y) => x.localeCompare(y)));
|
||||
} catch {
|
||||
setFonts([]);
|
||||
} catch (error) {
|
||||
console.error('Failed to enumerate local fonts', error);
|
||||
setFontLoadError('无法读取本机字体,请检查浏览器权限后重试。');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -784,11 +787,32 @@ function FontField({
|
||||
{fonts.map((f) => <option key={f} value={f} />)}
|
||||
</datalist>
|
||||
)}
|
||||
<p className="text-xs leading-snug text-muted-foreground">
|
||||
{canQuery
|
||||
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
||||
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
||||
</p>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
reserve={28}
|
||||
lines={1}
|
||||
label="本机字体"
|
||||
className={!loading ? 'skeleton-swap-fluid' : ''}
|
||||
>
|
||||
{fontLoadError ? (
|
||||
<div className="flex items-center gap-2 text-xs leading-snug text-destructive">
|
||||
<span>{fontLoadError}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="shrink-0 font-medium underline underline-offset-2"
|
||||
onClick={() => void loadFonts()}
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs leading-snug text-muted-foreground">
|
||||
{canQuery
|
||||
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
||||
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
||||
</p>
|
||||
)}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -1250,7 +1274,7 @@ function assetHint(latest: string, platform?: string, arch?: string): string | n
|
||||
// Advisory software update, shown as a grouped list. Read-only: links to the
|
||||
// GitHub release; SnowLuma never downloads or applies anything itself.
|
||||
function UpdateGroup() {
|
||||
const { updateInfo, refreshUpdate, systemInfo } = useAppState();
|
||||
const { updateInfo, refreshUpdate, systemInfo, resources } = useAppState();
|
||||
const { runAction } = useActionFeedback();
|
||||
const [checking, setChecking] = useState(false);
|
||||
|
||||
@@ -1286,7 +1310,8 @@ function UpdateGroup() {
|
||||
const disabledCheck = updateInfo?.error === 'disabled';
|
||||
|
||||
let status: ReactNode;
|
||||
if (!updateInfo) status = <span className="text-muted-foreground">正在检查…</span>;
|
||||
if (!updateInfo && resources.updateInfo.error) status = <span className="text-muted-foreground">无法检查</span>;
|
||||
else if (!updateInfo) status = null;
|
||||
else if (disabledCheck) status = <span className="text-muted-foreground">检查已关闭</span>;
|
||||
else if (updateInfo.error) status = <span className="text-muted-foreground">无法检查</span>;
|
||||
else if (updateInfo.hasUpdate && updateInfo.latest) status = <span className="font-medium text-primary">发现新版本</span>;
|
||||
@@ -1337,7 +1362,17 @@ function UpdateGroup() {
|
||||
</SettingRow>
|
||||
<SettingRow label="检查更新">
|
||||
<div className="flex items-center gap-2.5 text-[12px]">
|
||||
{status}
|
||||
<SkeletonSwap
|
||||
ready={resources.updateInfo.ready}
|
||||
reserve={24}
|
||||
lines={1}
|
||||
lineHeight={24}
|
||||
barHeight={8}
|
||||
label="更新状态"
|
||||
className={resources.updateInfo.ready ? 'skeleton-swap-fluid min-h-6 min-w-24' : 'w-24'}
|
||||
>
|
||||
{resources.updateInfo.ready ? status : null}
|
||||
</SkeletonSwap>
|
||||
{!disabledCheck && (
|
||||
<Button variant="outline" size="sm" onClick={onCheck} disabled={checking}>
|
||||
{checking ? <Loader2 className="size-4 animate-spin" /> : <RefreshCw className="size-4" />}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Eye, Loader2, User, UserX } from 'lucide-react';
|
||||
import { Eye, User, UserX } from 'lucide-react';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -92,54 +93,57 @@ export function ProcessProbeDialog({ pid, processName, open, onOpenChange, onLoa
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
{loading && (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="size-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && error && (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||
<UserX className="size-8" strokeWidth={1.5} />
|
||||
<p className="text-sm">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && info && (
|
||||
<div className="space-y-4">
|
||||
{info.loggedIn ? (
|
||||
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
||||
<Avatar className="size-14">
|
||||
<AvatarImage src={qqAvatarUrl(info.uin)} alt={info.uin} />
|
||||
<AvatarFallback>
|
||||
<User className="size-6" />
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-semibold">{info.nickName || info.uin}</span>
|
||||
<Badge variant="success">已登录</Badge>
|
||||
</div>
|
||||
<div className="mt-1 text-sm text-muted-foreground">UIN: {info.uin}</div>
|
||||
{info.uid && (
|
||||
<div className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
||||
UID: {info.uid}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-1 text-xs text-muted-foreground">端口: {info.port}</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
reserve={128}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
label="登录状态"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-32' : ''}
|
||||
>
|
||||
{!loading ? (
|
||||
error ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||
<UserX className="size-8" strokeWidth={1.5} />
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-medium">等待登录</p>
|
||||
<p className="mt-1 text-xs">端口 {info.port} 已响应,但未检测到登录账号</p>
|
||||
</div>
|
||||
<p className="text-sm">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
) : info ? (
|
||||
<div className="space-y-4">
|
||||
{info.loggedIn ? (
|
||||
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
||||
<Avatar className="size-14">
|
||||
<AvatarImage src={qqAvatarUrl(info.uin)} alt={info.uin} />
|
||||
<AvatarFallback>
|
||||
<User className="size-6" />
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-semibold">{info.nickName || info.uin}</span>
|
||||
<Badge variant="success">已登录</Badge>
|
||||
</div>
|
||||
<div className="mt-1 text-sm text-muted-foreground">UIN: {info.uin}</div>
|
||||
{info.uid && (
|
||||
<div className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
||||
UID: {info.uid}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-1 text-xs text-muted-foreground">端口: {info.port}</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||
<UserX className="size-8" strokeWidth={1.5} />
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-medium">等待登录</p>
|
||||
<p className="mt-1 text-xs">端口 {info.port} 已响应,但未检测到登录账号</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)}>
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
// URL); the store reconciles on the next load. Invalid entries are flagged
|
||||
// client-side and simply dropped by the server on save.
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { AlertTriangle, KeyRound, Loader2, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { AlertTriangle, KeyRound, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -42,7 +43,8 @@ export function GlobalConfigPanel() {
|
||||
setLoadFailed(false);
|
||||
try {
|
||||
setConfig(await api.globalConfig.get());
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error('load global config failed', error);
|
||||
setLoadFailed(true);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -103,23 +105,26 @@ export function GlobalConfigPanel() {
|
||||
}, 500);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
if (loading || !config) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (loadFailed || !config) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">加载全局配置失败</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="全局配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||
>
|
||||
{!loading && (loadFailed || !config) ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">加载全局配置失败</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,101 +133,110 @@ export function GlobalConfigPanel() {
|
||||
commit({ ...config, rkey: { fallbackServers: next } }, false);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* rkey fallback servers */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<KeyRound className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="全局配置"
|
||||
className="skeleton-swap-fluid min-h-[156px]"
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* rkey fallback servers */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<KeyRound className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
图片 / 文件下载链接需要服务器签发的 <code className="font-mono">rkey</code>。SnowLuma 默认走内核获取;
|
||||
当内核在你的环境下持续取不到时,会按顺序向这里配置的 HTTP 端点回退。
|
||||
<strong className="font-medium text-foreground/80">默认留空=关闭</strong>,不配置就不会联系任何第三方。
|
||||
<strong className="font-medium text-foreground/80">默认留空=关闭</strong>,不配置就不会联系任何第三方。
|
||||
建议填你自建的端点。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 border-t pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>rkey 回退服务器</Label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setServers([...servers, ''])}
|
||||
>
|
||||
<Plus className="size-3.5" /> 添加
|
||||
</Button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{servers.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed px-3 py-4 text-center text-xs text-muted-foreground">
|
||||
<div className="flex flex-col gap-2 border-t pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>rkey 回退服务器</Label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setServers([...servers, ''])}
|
||||
>
|
||||
<Plus className="size-3.5" /> 添加
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{servers.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed px-3 py-4 text-center text-xs text-muted-foreground">
|
||||
未配置回退服务器(rkey 回退已关闭)
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{servers.map((url, i) => {
|
||||
const invalid = url.trim().length > 0 && !isHttpUrl(url.trim());
|
||||
return (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder="https://your-rkey-server.example/rkeys"
|
||||
value={url}
|
||||
aria-invalid={invalid}
|
||||
className={cn('font-mono text-xs', invalid && 'border-destructive focus-visible:ring-destructive')}
|
||||
onChange={(e) => setServers(servers.map((s, idx) => (idx === i ? e.target.value : s)))}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="删除"
|
||||
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setServers(servers.filter((_, idx) => idx !== i))}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{servers.map((url, i) => {
|
||||
const invalid = url.trim().length > 0 && !isHttpUrl(url.trim());
|
||||
return (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder="https://your-rkey-server.example/rkeys"
|
||||
value={url}
|
||||
aria-invalid={invalid}
|
||||
className={cn('font-mono text-xs', invalid && 'border-destructive focus-visible:ring-destructive')}
|
||||
onChange={(e) => setServers(servers.map((s, idx) => (idx === i ? e.target.value : s)))}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="删除"
|
||||
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setServers(servers.filter((_, idx) => idx !== i))}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
端点需返回 <code className="font-mono">{'{ group_rkey, private_rkey, expired_time }'}</code>
|
||||
(兼容 NapCat rkey 服务格式)。非 http(s) 链接会被忽略。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* music sign URL */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Music className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>音乐分享卡片的签名服务,对所有账号统一生效。留空则使用内置默认服务。</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>音乐签名服务 URL</Label>
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder={MUSIC_SIGN_DEFAULT}
|
||||
value={config.musicSignUrl}
|
||||
aria-invalid={config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())}
|
||||
className={cn(
|
||||
'font-mono text-xs',
|
||||
config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())
|
||||
&& 'border-destructive focus-visible:ring-destructive',
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
onChange={(e) => commit({ ...config, musicSignUrl: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
内置默认:<code className="font-mono">{MUSIC_SIGN_DEFAULT}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
</div>
|
||||
{/* music sign URL */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Music className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>音乐分享卡片的签名服务,对所有账号统一生效。留空则使用内置默认服务。</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>音乐签名服务 URL</Label>
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder={MUSIC_SIGN_DEFAULT}
|
||||
value={config.musicSignUrl}
|
||||
aria-invalid={config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())}
|
||||
className={cn(
|
||||
'font-mono text-xs',
|
||||
config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())
|
||||
&& 'border-destructive focus-visible:ring-destructive',
|
||||
)}
|
||||
onChange={(e) => commit({ ...config, musicSignUrl: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
内置默认:<code className="font-mono">{MUSIC_SIGN_DEFAULT}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
@@ -2,11 +2,12 @@
|
||||
// info-only cards (name / url / template + an inline enable toggle); creating
|
||||
// and editing always go through a dialog. All changes auto-save (debounced),
|
||||
// like the per-account config page — no explicit save button.
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { Bell, Loader2, Pencil, Plus, Send, Trash2 } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
@@ -48,23 +49,22 @@ export function NotificationsPanel() {
|
||||
const saveTimer = useRef<number | null>(null);
|
||||
const saveGen = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const cfg = await api.notifications.getConfig();
|
||||
if (!cancelled) setConfig(cfg);
|
||||
} catch {
|
||||
if (!cancelled) setMsg({ kind: 'err', text: '加载通知配置失败' });
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
setConfig(await api.notifications.getConfig());
|
||||
} catch (error) {
|
||||
console.error('load notifications config failed', error);
|
||||
setMsg({ kind: 'err', text: '加载通知配置失败' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [api, setMsg]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (saveTimer.current) clearTimeout(saveTimer.current);
|
||||
@@ -111,9 +111,23 @@ export function NotificationsPanel() {
|
||||
|
||||
if (loading || !config) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="通知配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||
>
|
||||
{!loading && !config ? (
|
||||
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||
<span>{msg?.text ?? '加载通知配置失败'}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -172,89 +186,98 @@ export function NotificationsPanel() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Global settings */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Bell className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="通知配置"
|
||||
className="skeleton-swap-fluid min-h-[156px]"
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Global settings */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Bell className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
账号上线 / 下线时向启用的渠道 POST 一条通知(机械转发,仅去抖防刷屏)。渠道在此全局定义,每个账号在其「配置」页勾选启用哪些。
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>去抖窗口(秒)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={3600}
|
||||
className="w-32 tabular-nums"
|
||||
value={config.debounceSeconds}
|
||||
onChange={(e) => {
|
||||
const n = Math.trunc(Number(e.target.value));
|
||||
commit({ ...config, debounceSeconds: Number.isFinite(n) ? Math.min(3600, Math.max(0, n)) : 0 });
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>去抖窗口(秒)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={3600}
|
||||
className="w-32 tabular-nums"
|
||||
value={config.debounceSeconds}
|
||||
onChange={(e) => {
|
||||
const n = Math.trunc(Number(e.target.value));
|
||||
commit({ ...config, debounceSeconds: Number.isFinite(n) ? Math.min(3600, Math.max(0, n)) : 0 });
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
下线后在该秒数内自愈则不发;超时才发「下线」,恢复时再发「上线」。<code className="font-mono">0</code> = 立即发、不去抖。
|
||||
</p>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Channels */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold tracking-tight">通知渠道</h3>
|
||||
{channels.length > 0 && (
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 新增渠道
|
||||
</Button>
|
||||
{/* Channels */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold tracking-tight">通知渠道</h3>
|
||||
{channels.length > 0 && (
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 新增渠道
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{channels.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">还没有通知渠道</p>
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 创建第一个
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{channels.map((ch, i) => (
|
||||
<ChannelCard
|
||||
key={ch.id}
|
||||
channel={ch}
|
||||
testing={testing === ch.id}
|
||||
onToggle={(v) => setChannels(
|
||||
channels.map((c, idx) => (idx === i ? { ...c, enabled: v } : c)),
|
||||
{ title: '正在更新通知渠道', successTitle: '通知渠道已更新' },
|
||||
)}
|
||||
onTest={() => void test(ch.id)}
|
||||
onEdit={() => openEdit(i)}
|
||||
onDelete={() => setChannels(
|
||||
channels.filter((_, idx) => idx !== i),
|
||||
{ title: '正在删除通知渠道', successTitle: '通知渠道已删除' },
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{channels.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">还没有通知渠道</p>
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 创建第一个
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{channels.map((ch, i) => (
|
||||
<ChannelCard
|
||||
key={ch.id}
|
||||
channel={ch}
|
||||
testing={testing === ch.id}
|
||||
onToggle={(v) => setChannels(
|
||||
channels.map((c, idx) => (idx === i ? { ...c, enabled: v } : c)),
|
||||
{ title: '正在更新通知渠道', successTitle: '通知渠道已更新' },
|
||||
)}
|
||||
onTest={() => void test(ch.id)}
|
||||
onEdit={() => openEdit(i)}
|
||||
onDelete={() => setChannels(
|
||||
channels.filter((_, idx) => idx !== i),
|
||||
{ title: '正在删除通知渠道', successTitle: '通知渠道已删除' },
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
|
||||
{dialog.open && (
|
||||
<NotificationChannelDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog((d) => ({ ...d, open: false }))}
|
||||
isEdit={dialog.index != null}
|
||||
initial={dialog.seed}
|
||||
otherIds={otherIds(dialog.index)}
|
||||
onSubmit={submitChannel}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
|
||||
{dialog.open && (
|
||||
<NotificationChannelDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog((d) => ({ ...d, open: false }))}
|
||||
isEdit={dialog.index != null}
|
||||
initial={dialog.seed}
|
||||
otherIds={otherIds(dialog.index)}
|
||||
onSubmit={submitChannel}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { useFlashMessage } from '@/hooks/use-flash-message';
|
||||
import { useApi } from '@/lib/api';
|
||||
@@ -107,12 +108,16 @@ export function StoragePanel() {
|
||||
};
|
||||
|
||||
const load = async (showSpinner = false): Promise<boolean> => {
|
||||
if (showSpinner) setRefreshing(true);
|
||||
if (showSpinner) {
|
||||
if (data === null) setLoading(true);
|
||||
else setRefreshing(true);
|
||||
}
|
||||
try {
|
||||
const overview = await api.storage.get();
|
||||
applyOverview(overview);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('load storage overview failed', error);
|
||||
setMsg({
|
||||
kind: 'err',
|
||||
text: error instanceof Error ? error.message : '加载存储信息失败',
|
||||
@@ -222,26 +227,28 @@ export function StoragePanel() {
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
if (loading || !data) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" />
|
||||
加载存储信息…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
||||
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
||||
<Button variant="outline" onClick={() => void load(true)}>
|
||||
<RefreshCw className="size-4" />
|
||||
重试
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="存储信息"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||
>
|
||||
{!loading && !data ? (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
||||
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
||||
<Button variant="outline" onClick={() => void load(true)}>
|
||||
<RefreshCw className="size-4" />
|
||||
重试
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -259,310 +266,319 @@ export function StoragePanel() {
|
||||
) as Record<AccountStorageCategory, number>;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
{msg && (
|
||||
<div
|
||||
role="status"
|
||||
className={cn(
|
||||
'rounded-lg px-3 py-2 text-xs',
|
||||
msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300',
|
||||
)}
|
||||
>
|
||||
{msg.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<HardDrive className="size-4" />
|
||||
存储概览
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
只统计 SnowLuma 管理的日志、账号数据库和文件传输临时数据。
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => void load(true)}
|
||||
disabled={refreshing || saving || operation !== null}
|
||||
className="shrink-0"
|
||||
>
|
||||
<RefreshCw className={cn('size-4', refreshing && 'animate-spin')} />
|
||||
刷新
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-5">
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
||||
<Metric label="受管数据总量" value={formatBytes(snapshot.totals.managedBytes)} />
|
||||
<Metric label="日志" value={formatBytes(snapshot.totals.logsBytes)} />
|
||||
<Metric label="账号数据库" value={formatBytes(snapshot.totals.accountDataBytes)} />
|
||||
<Metric label="传输临时数据" value={formatBytes(snapshot.totals.temporaryBytes)} />
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="text-sm font-medium">日志容量</p>
|
||||
<p className="mt-0.5 text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(snapshot.logs.totalBytes)} / {formatBytes(snapshot.logs.maxTotalBytes)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant={toneBadgeVariant(logPresentation.tone)}>
|
||||
{logPresentation.label}
|
||||
</Badge>
|
||||
</div>
|
||||
<Progress
|
||||
value={logPresentation.percent}
|
||||
aria-label="日志容量使用率"
|
||||
indicatorClassName={toneProgressClass(logPresentation.tone)}
|
||||
/>
|
||||
<div className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
||||
<span>{snapshot.logs.fileCount} 个文件</span>
|
||||
<span>{snapshot.logs.activeFileCount} 个活动文件</span>
|
||||
<span>丢弃 {snapshot.logs.droppedLines} 行磁盘日志</span>
|
||||
</div>
|
||||
{snapshot.logs.lastError && (
|
||||
<div className="mt-3 flex items-start gap-2 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
<AlertTriangle className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span className="break-words">{snapshot.logs.lastError}</span>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="存储信息"
|
||||
className="skeleton-swap-fluid min-h-[182px]"
|
||||
>
|
||||
<div className="flex flex-col gap-5">
|
||||
{msg && (
|
||||
<div
|
||||
role="status"
|
||||
className={cn(
|
||||
'rounded-lg px-3 py-2 text-xs',
|
||||
msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300',
|
||||
)}
|
||||
>
|
||||
{msg.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.lastCleanup && <LastCleanupSummary cleanup={data.lastCleanup} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<FileClock className="size-4" />
|
||||
日志策略
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
总量上限始终生效;保留天数设为 0 时仅按总量淘汰。保存后立即应用。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-max" className="flex flex-wrap items-center gap-1">
|
||||
日志总量上限(MB)
|
||||
<EnvironmentBadge locked={isLocked('logMaxTotalMb')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-max"
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={maxTotalMb}
|
||||
onChange={(event) => setMaxTotalMb(event.target.value)}
|
||||
disabled={isLocked('logMaxTotalMb') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-days" className="flex flex-wrap items-center gap-1">
|
||||
保留天数
|
||||
<EnvironmentBadge locked={isLocked('logRetainDays')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-days"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={retainDays}
|
||||
onChange={(event) => setRetainDays(event.target.value)}
|
||||
disabled={isLocked('logRetainDays') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex min-h-11 items-center justify-between gap-4 rounded-lg bg-muted/35 px-3 py-2">
|
||||
<Card>
|
||||
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<p className="flex flex-wrap items-center gap-1 text-sm font-medium">
|
||||
按账号额外写入日志
|
||||
<EnvironmentBadge locked={isLocked('logPerUin')} />
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
||||
开启后,同一条带账号上下文的日志还会写入账号子目录,占用会增加。
|
||||
</p>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<HardDrive className="size-4" />
|
||||
存储概览
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
只统计 SnowLuma 管理的日志、账号数据库和文件传输临时数据。
|
||||
</CardDescription>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={perUin}
|
||||
onChange={setPerUin}
|
||||
ariaLabel="按账号额外写入日志"
|
||||
disabled={isLocked('logPerUin') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => void saveSettings()}
|
||||
disabled={
|
||||
saving
|
||||
|| operation !== null
|
||||
|| data.settings.envOverrides.length === 3
|
||||
}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => void load(true)}
|
||||
disabled={refreshing || saving || operation !== null}
|
||||
className="shrink-0"
|
||||
>
|
||||
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
|
||||
保存并应用
|
||||
<RefreshCw className={cn('size-4', refreshing && 'animate-spin')} />
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Trash2 className="size-4" />
|
||||
全局数据清理
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
日志清理会轮转活动文件;临时数据清理会自动跳过正在进行的上传和下载。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-border/60 p-0">
|
||||
<CleanupRow
|
||||
icon={FileClock}
|
||||
title="日志"
|
||||
description={`${snapshot.logs.fileCount} 个文件 · ${formatBytes(snapshot.logs.totalBytes)}`}
|
||||
busy={operation === 'logs'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'logs' },
|
||||
title: '清理全部日志?',
|
||||
description: 'SnowLuma 会先轮转活动日志,再删除旧日志,只保留新建的空文件。',
|
||||
})}
|
||||
/>
|
||||
<CleanupRow
|
||||
icon={Activity}
|
||||
title="文件传输临时数据"
|
||||
description={`${snapshot.temporary.fileCount} 个文件 · ${formatBytes(snapshot.temporary.totalBytes)} · ${snapshot.temporary.activeItemCount} 个活动传输`}
|
||||
busy={operation === 'temporary'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'temporary' },
|
||||
title: '清理非活动临时数据?',
|
||||
description: '正在上传或下载的项目会保留,其余 SnowLuma 文件传输临时数据将被删除。',
|
||||
})}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Database className="size-4" />
|
||||
账号数据
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
仅清理选中的数据库分类。账号必须离线,配置、凭据和聊天内容导出不在此页面提供。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{snapshot.accounts.length === 0 ? (
|
||||
<div className="rounded-lg bg-muted/35 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
尚未发现账号数据库。
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-5">
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
||||
<Metric label="受管数据总量" value={formatBytes(snapshot.totals.managedBytes)} />
|
||||
<Metric label="日志" value={formatBytes(snapshot.totals.logsBytes)} />
|
||||
<Metric label="账号数据库" value={formatBytes(snapshot.totals.accountDataBytes)} />
|
||||
<Metric label="传输临时数据" value={formatBytes(snapshot.totals.temporaryBytes)} />
|
||||
</div>
|
||||
) : (
|
||||
snapshot.accounts.map((account) => (
|
||||
<AccountStorageCard
|
||||
key={account.uin}
|
||||
account={account}
|
||||
operation={operation}
|
||||
saving={saving}
|
||||
onRequest={(category) => {
|
||||
const info = CATEGORY_INFO[category];
|
||||
setPendingCleanup({
|
||||
request: { scope: 'account', category, uin: account.uin },
|
||||
title: `清理 ${account.nickname || account.uin} 的${info.label}?`,
|
||||
description: `将删除账号 ${account.uin} 的${info.label}数据库及其边车文件,其他分类和配置不受影响。`,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
{snapshot.accounts.length > 0 && (
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-3 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="flex items-center gap-2 text-sm font-medium">
|
||||
<Users className="size-4" />
|
||||
全部账号
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
{onlineCount > 0
|
||||
? `${onlineCount} 个账号仍在线,全部账号清理暂不可用`
|
||||
: '选择一个分类,并在弹窗中输入确认短语'}
|
||||
<p className="text-sm font-medium">日志容量</p>
|
||||
<p className="mt-0.5 text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(snapshot.logs.totalBytes)} / {formatBytes(snapshot.logs.maxTotalBytes)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant={toneBadgeVariant(logPresentation.tone)}>
|
||||
{logPresentation.label}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{CATEGORIES.map((category) => (
|
||||
<Button
|
||||
key={category}
|
||||
variant="outline"
|
||||
onClick={() => setAllAccountsCategory(category)}
|
||||
disabled={
|
||||
operation !== null
|
||||
<Progress
|
||||
value={logPresentation.percent}
|
||||
aria-label="日志容量使用率"
|
||||
indicatorClassName={toneProgressClass(logPresentation.tone)}
|
||||
/>
|
||||
<div className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
||||
<span>{snapshot.logs.fileCount} 个文件</span>
|
||||
<span>{snapshot.logs.activeFileCount} 个活动文件</span>
|
||||
<span>丢弃 {snapshot.logs.droppedLines} 行磁盘日志</span>
|
||||
</div>
|
||||
{snapshot.logs.lastError && (
|
||||
<div className="mt-3 flex items-start gap-2 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
<AlertTriangle className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span className="break-words">{snapshot.logs.lastError}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{data.lastCleanup && <LastCleanupSummary cleanup={data.lastCleanup} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<FileClock className="size-4" />
|
||||
日志策略
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
总量上限始终生效;保留天数设为 0 时仅按总量淘汰。保存后立即应用。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-max" className="flex flex-wrap items-center gap-1">
|
||||
日志总量上限(MB)
|
||||
<EnvironmentBadge locked={isLocked('logMaxTotalMb')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-max"
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={maxTotalMb}
|
||||
onChange={(event) => setMaxTotalMb(event.target.value)}
|
||||
disabled={isLocked('logMaxTotalMb') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-days" className="flex flex-wrap items-center gap-1">
|
||||
保留天数
|
||||
<EnvironmentBadge locked={isLocked('logRetainDays')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-days"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={retainDays}
|
||||
onChange={(event) => setRetainDays(event.target.value)}
|
||||
disabled={isLocked('logRetainDays') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex min-h-11 items-center justify-between gap-4 rounded-lg bg-muted/35 px-3 py-2">
|
||||
<div className="min-w-0">
|
||||
<p className="flex flex-wrap items-center gap-1 text-sm font-medium">
|
||||
按账号额外写入日志
|
||||
<EnvironmentBadge locked={isLocked('logPerUin')} />
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
||||
开启后,同一条带账号上下文的日志还会写入账号子目录,占用会增加。
|
||||
</p>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={perUin}
|
||||
onChange={setPerUin}
|
||||
ariaLabel="按账号额外写入日志"
|
||||
disabled={isLocked('logPerUin') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => void saveSettings()}
|
||||
disabled={
|
||||
saving
|
||||
|| operation !== null
|
||||
|| data.settings.envOverrides.length === 3
|
||||
}
|
||||
>
|
||||
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
|
||||
保存并应用
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Trash2 className="size-4" />
|
||||
全局数据清理
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
日志清理会轮转活动文件;临时数据清理会自动跳过正在进行的上传和下载。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-border/60 p-0">
|
||||
<CleanupRow
|
||||
icon={FileClock}
|
||||
title="日志"
|
||||
description={`${snapshot.logs.fileCount} 个文件 · ${formatBytes(snapshot.logs.totalBytes)}`}
|
||||
busy={operation === 'logs'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'logs' },
|
||||
title: '清理全部日志?',
|
||||
description: 'SnowLuma 会先轮转活动日志,再删除旧日志,只保留新建的空文件。',
|
||||
})}
|
||||
/>
|
||||
<CleanupRow
|
||||
icon={Activity}
|
||||
title="文件传输临时数据"
|
||||
description={`${snapshot.temporary.fileCount} 个文件 · ${formatBytes(snapshot.temporary.totalBytes)} · ${snapshot.temporary.activeItemCount} 个活动传输`}
|
||||
busy={operation === 'temporary'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'temporary' },
|
||||
title: '清理非活动临时数据?',
|
||||
description: '正在上传或下载的项目会保留,其余 SnowLuma 文件传输临时数据将被删除。',
|
||||
})}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Database className="size-4" />
|
||||
账号数据
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
仅清理选中的数据库分类。账号必须离线,配置、凭据和聊天内容导出不在此页面提供。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{snapshot.accounts.length === 0 ? (
|
||||
<div className="rounded-lg bg-muted/35 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
尚未发现账号数据库。
|
||||
</div>
|
||||
) : (
|
||||
snapshot.accounts.map((account) => (
|
||||
<AccountStorageCard
|
||||
key={account.uin}
|
||||
account={account}
|
||||
operation={operation}
|
||||
saving={saving}
|
||||
onRequest={(category) => {
|
||||
const info = CATEGORY_INFO[category];
|
||||
setPendingCleanup({
|
||||
request: { scope: 'account', category, uin: account.uin },
|
||||
title: `清理 ${account.nickname || account.uin} 的${info.label}?`,
|
||||
description: `将删除账号 ${account.uin} 的${info.label}数据库及其边车文件,其他分类和配置不受影响。`,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
{snapshot.accounts.length > 0 && (
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-3 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<p className="flex items-center gap-2 text-sm font-medium">
|
||||
<Users className="size-4" />
|
||||
全部账号
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
{onlineCount > 0
|
||||
? `${onlineCount} 个账号仍在线,全部账号清理暂不可用`
|
||||
: '选择一个分类,并在弹窗中输入确认短语'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{CATEGORIES.map((category) => (
|
||||
<Button
|
||||
key={category}
|
||||
variant="outline"
|
||||
onClick={() => setAllAccountsCategory(category)}
|
||||
disabled={
|
||||
operation !== null
|
||||
|| saving
|
||||
|| onlineCount > 0
|
||||
|| allCategoryBytes[category] === 0
|
||||
}
|
||||
className="justify-between"
|
||||
>
|
||||
<span>清理全部{CATEGORY_INFO[category].label}</span>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(allCategoryBytes[category])}
|
||||
</span>
|
||||
</Button>
|
||||
))}
|
||||
}
|
||||
className="justify-between"
|
||||
>
|
||||
<span>清理全部{CATEGORY_INFO[category].label}</span>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(allCategoryBytes[category])}
|
||||
</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingCleanup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setPendingCleanup(null);
|
||||
}}
|
||||
title={pendingCleanup?.title ?? ''}
|
||||
description={pendingCleanup?.description}
|
||||
confirmText="确认清理"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingCleanup) return;
|
||||
await runCleanup(pendingCleanup.request);
|
||||
setPendingCleanup(null);
|
||||
}}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={pendingCleanup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setPendingCleanup(null);
|
||||
}}
|
||||
title={pendingCleanup?.title ?? ''}
|
||||
description={pendingCleanup?.description}
|
||||
confirmText="确认清理"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingCleanup) return;
|
||||
await runCleanup(pendingCleanup.request);
|
||||
setPendingCleanup(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
<AllAccountsCleanupDialog
|
||||
category={allAccountsCategory}
|
||||
busy={operation?.startsWith('allAccounts:') ?? false}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setAllAccountsCategory(null);
|
||||
}}
|
||||
onConfirm={async (category) => {
|
||||
await runCleanup({
|
||||
scope: 'allAccounts',
|
||||
category,
|
||||
confirmation: ALL_ACCOUNTS_CONFIRMATION,
|
||||
});
|
||||
setAllAccountsCategory(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<AllAccountsCleanupDialog
|
||||
category={allAccountsCategory}
|
||||
busy={operation?.startsWith('allAccounts:') ?? false}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setAllAccountsCategory(null);
|
||||
}}
|
||||
onConfirm={async (category) => {
|
||||
await runCleanup({
|
||||
scope: 'allAccounts',
|
||||
category,
|
||||
confirmation: ALL_ACCOUNTS_CONFIRMATION,
|
||||
});
|
||||
setAllAccountsCategory(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import { motion } from 'motion/react';
|
||||
import { AlertTriangle, Database, Download, Loader2, Lock, Pencil, Save, ShieldCheck, Trash2, Upload } from 'lucide-react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -57,7 +58,8 @@ export function SystemPanel() {
|
||||
setTrustProxy(res.settings.trustProxy);
|
||||
setTlsEnabled(res.settings.tlsEnabled);
|
||||
return true;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error('load system settings failed', error);
|
||||
setMsg({ kind: 'err', text: '加载系统设置失败' });
|
||||
return false;
|
||||
} finally {
|
||||
@@ -211,8 +213,33 @@ export function SystemPanel() {
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground"><Loader2 className="h-4 w-4 animate-spin" /> 加载中…</div>;
|
||||
if (loading || !data) {
|
||||
return (
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="系统设置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||
>
|
||||
{!loading && !data ? (
|
||||
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||
<span>{msg?.text ?? '加载系统设置失败'}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
void load();
|
||||
}}
|
||||
>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
const EnvBadge = ({ field }: { field: string }) =>
|
||||
@@ -221,190 +248,199 @@ export function SystemPanel() {
|
||||
: null;
|
||||
|
||||
return (
|
||||
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
||||
{/* restart-to-apply notice */}
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||||
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
<span>监听相关设置(端口 / 绑定地址 / HTTPS)属服务级配置,保存后需<strong>重启 SnowLuma</strong> 才生效;本机无自动重启。</span>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="系统设置"
|
||||
className="skeleton-swap-fluid min-h-[182px]"
|
||||
>
|
||||
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
||||
{/* restart-to-apply notice */}
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||||
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
<span>监听相关设置(端口 / 绑定地址 / HTTPS)属服务级配置,保存后需<strong>重启 SnowLuma</strong> 才生效;本机无自动重启。</span>
|
||||
</div>
|
||||
|
||||
{msg && (
|
||||
<div className={cn('rounded-lg px-3 py-2 text-xs', msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300')}>{msg.text}</div>
|
||||
)}
|
||||
{msg && (
|
||||
<div className={cn('rounded-lg px-3 py-2 text-xs', msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300')}>{msg.text}</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm">服务监听</CardTitle>
|
||||
<CardDescription>WebUI 当前监听端口:{data?.listeningPort}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">端口<EnvBadge field="webuiPort" /></Label>
|
||||
<Input value={port} onChange={(e) => setPort(e.target.value)} inputMode="numeric" placeholder="5099" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">绑定地址<EnvBadge field="webuiHost" /></Label>
|
||||
<Select value={host} onChange={(e) => setHost(e.target.value)}>
|
||||
<option value="0.0.0.0">0.0.0.0(所有网卡)</option>
|
||||
<option value="127.0.0.1">127.0.0.1(仅本机)</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">信任代理 (trust-proxy)<EnvBadge field="trustProxy" /></Label>
|
||||
<Input value={trustProxy} onChange={(e) => setTrustProxy(e.target.value)} placeholder="留空=只信任 socket 对端;1=信任反代头" />
|
||||
<p className="text-xs text-muted-foreground">仅在 WebUI 位于受信任反向代理之后时才设为 1 / loopback / IP 列表。</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button onClick={saveSettings} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm">服务监听</CardTitle>
|
||||
<CardDescription>WebUI 当前监听端口:{data?.listeningPort}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">端口<EnvBadge field="webuiPort" /></Label>
|
||||
<Input value={port} onChange={(e) => setPort(e.target.value)} inputMode="numeric" placeholder="5099" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">绑定地址<EnvBadge field="webuiHost" /></Label>
|
||||
<Select value={host} onChange={(e) => setHost(e.target.value)}>
|
||||
<option value="0.0.0.0">0.0.0.0(所有网卡)</option>
|
||||
<option value="127.0.0.1">127.0.0.1(仅本机)</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">信任代理 (trust-proxy)<EnvBadge field="trustProxy" /></Label>
|
||||
<Input value={trustProxy} onChange={(e) => setTrustProxy(e.target.value)} placeholder="留空=只信任 socket 对端;1=信任反代头" />
|
||||
<p className="text-xs text-muted-foreground">仅在 WebUI 位于受信任反向代理之后时才设为 1 / loopback / IP 列表。</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button onClick={saveSettings} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<ShieldCheck className="h-4 w-4" /> HTTPS / TLS
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{data?.hasCert ? '已安装证书。' : '尚未安装证书。'} 启用 TLS 需先安装有效的证书与私钥(PEM)。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>启用 HTTPS</Label>
|
||||
<ToggleSwitch value={tlsEnabled} onChange={setTlsEnabled} ariaLabel="启用 HTTPS" />
|
||||
</div>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<ShieldCheck className="h-4 w-4" /> HTTPS / TLS
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{data?.hasCert ? '已安装证书。' : '尚未安装证书。'} 启用 TLS 需先安装有效的证书与私钥(PEM)。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>启用 HTTPS</Label>
|
||||
<ToggleSwitch value={tlsEnabled} onChange={setTlsEnabled} ariaLabel="启用 HTTPS" />
|
||||
</div>
|
||||
|
||||
{data?.hasCert && !editingCert ? (
|
||||
{data?.hasCert && !editingCert ? (
|
||||
// Cert already installed — don't re-render the sensitive PEM. Show a
|
||||
// summary + actions; private key is never sent back to the client.
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
|
||||
<ShieldCheck className="h-4 w-4 text-emerald-500" />
|
||||
<span>证书与私钥已安装(出于安全不回显,未改变)。</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCert(true)} className="gap-1.5">
|
||||
<Pencil className="h-4 w-4" /> 更改证书
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setConfirmDeleteCert(true)} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && editingCert && (
|
||||
<Button variant="outline" onClick={() => { setEditingCert(false); setCertPem(''); setKeyPem(''); }} className="gap-1.5">
|
||||
取消
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
|
||||
<ShieldCheck className="h-4 w-4 text-emerald-500" />
|
||||
<span>证书与私钥已安装(出于安全不回显,未改变)。</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCert(true)} className="gap-1.5">
|
||||
<Pencil className="h-4 w-4" /> 更改证书
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" onClick={() => setConfirmDeleteCert(true)} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && editingCert && (
|
||||
<Button variant="outline" onClick={() => { setEditingCert(false); setCertPem(''); setKeyPem(''); }} className="gap-1.5">
|
||||
取消
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
私钥仅写入服务器 config/key.pem(0600 权限),不会回显。证书无效时保存会被拒绝;若启用了 TLS 但证书加载失败,启动时会自动回退到 HTTP。
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm"><Database className="h-4 w-4" /> 配置备份 / 恢复</CardTitle>
|
||||
<CardDescription>备份外观、通知、系统设置和证书等配置;敏感开关还会包含 OneBot 配置。不含消息数据库。</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>导出时包含敏感配置</Label>
|
||||
<ToggleSwitch value={exportCreds} onChange={setExportCreds} ariaLabel="导出包含敏感配置" />
|
||||
</div>
|
||||
{exportCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将额外包含 WebUI 登录状态、TLS 私钥,以及带访问令牌的 OneBot 配置,请妥善保管。</p>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<div>
|
||||
<Button onClick={exportBackup} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Download className="h-4 w-4" />} 导出备份
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm"><Database className="h-4 w-4" /> 配置备份 / 恢复</CardTitle>
|
||||
<CardDescription>备份外观、通知、系统设置和证书等配置;敏感开关还会包含 OneBot 配置。不含消息数据库。</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>导出时包含敏感配置</Label>
|
||||
<ToggleSwitch value={exportCreds} onChange={setExportCreds} ariaLabel="导出包含敏感配置" />
|
||||
</div>
|
||||
{exportCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将额外包含 WebUI 登录状态、TLS 私钥,以及带访问令牌的 OneBot 配置,请妥善保管。</p>
|
||||
)}
|
||||
<div>
|
||||
<Button onClick={exportBackup} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Download className="h-4 w-4" />} 导出备份
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="h-px bg-border" />
|
||||
<div className="h-px bg-border" />
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>恢复时一并恢复敏感配置</Label>
|
||||
<ToggleSwitch value={restoreCreds} onChange={setRestoreCreds} ariaLabel="恢复包含敏感配置" />
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>恢复时一并恢复敏感配置</Label>
|
||||
<ToggleSwitch value={restoreCreds} onChange={setRestoreCreds} ariaLabel="恢复包含敏感配置" />
|
||||
</div>
|
||||
{restoreCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将覆盖当前 WebUI 登录状态、TLS 私钥与 OneBot 配置(含访问令牌);若备份口令未知可能登不进。</p>
|
||||
)}
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) setPendingBackup(file);
|
||||
e.target.value = '';
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Button variant="outline" onClick={() => fileRef.current?.click()} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />} 选择备份文件并恢复
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">恢复前会校验本次要恢复的配置;写入过程中出错会自动回滚,成功后临时快照会删除。恢复后需重启生效。</p>
|
||||
</div>
|
||||
{restoreCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将覆盖当前 WebUI 登录状态、TLS 私钥与 OneBot 配置(含访问令牌);若备份口令未知可能登不进。</p>
|
||||
)}
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) setPendingBackup(file);
|
||||
e.target.value = '';
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Button variant="outline" onClick={() => fileRef.current?.click()} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />} 选择备份文件并恢复
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">恢复前会校验本次要恢复的配置;写入过程中出错会自动回滚,成功后临时快照会删除。恢复后需重启生效。</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmDeleteCert}
|
||||
onOpenChange={setConfirmDeleteCert}
|
||||
title="删除 TLS 证书?"
|
||||
description="将移除服务器上的证书与私钥。若 HTTPS 仍处于启用状态,下次启动将无法继续使用当前证书。"
|
||||
confirmText="删除证书"
|
||||
destructive
|
||||
onConfirm={deleteCert}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={confirmDeleteCert}
|
||||
onOpenChange={setConfirmDeleteCert}
|
||||
title="删除 TLS 证书?"
|
||||
description="将移除服务器上的证书与私钥。若 HTTPS 仍处于启用状态,下次启动将无法继续使用当前证书。"
|
||||
confirmText="删除证书"
|
||||
destructive
|
||||
onConfirm={deleteCert}
|
||||
/>
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingBackup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingBackup(null);
|
||||
}}
|
||||
title="恢复配置备份?"
|
||||
description={
|
||||
pendingBackup
|
||||
? `将从 ${pendingBackup.name} 覆盖当前系统配置${restoreCreds ? ',包括敏感配置、TLS 私钥与 OneBot 配置' : ''}。成功后需要重启 SnowLuma。`
|
||||
: ''
|
||||
}
|
||||
confirmText="确认恢复"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingBackup) return;
|
||||
await importBackup(pendingBackup);
|
||||
setPendingBackup(null);
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
<ConfirmDialog
|
||||
open={pendingBackup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingBackup(null);
|
||||
}}
|
||||
title="恢复配置备份?"
|
||||
description={
|
||||
pendingBackup
|
||||
? `将从 ${pendingBackup.name} 覆盖当前系统配置${restoreCreds ? ',包括敏感配置、TLS 私钥与 OneBot 配置' : ''}。成功后需要重启 SnowLuma。`
|
||||
: ''
|
||||
}
|
||||
confirmText="确认恢复"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingBackup) return;
|
||||
await importBackup(pendingBackup);
|
||||
setPendingBackup(null);
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
@@ -7,7 +7,8 @@
|
||||
// the raw-value input so the picker never traps you.
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { AnimatePresence, motion } from 'motion/react';
|
||||
import { ChevronDown, Loader2, RefreshCw, Search } from 'lucide-react';
|
||||
import { ChevronDown, RefreshCw, Search } from 'lucide-react';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export interface PickerOption {
|
||||
@@ -51,6 +52,7 @@ export function Picker({
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
const searchRef = useRef<HTMLInputElement>(null);
|
||||
const suppressTriggerClick = useRef(false);
|
||||
const waitingForOptions = Boolean(loading && options.length === 0);
|
||||
|
||||
const selected = options.find((o) => o.value === value);
|
||||
|
||||
@@ -177,59 +179,66 @@ export function Picker({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{loading && options.length === 0 ? (
|
||||
<div className="flex items-center justify-center gap-2 py-8 text-sm text-muted-foreground">
|
||||
<Loader2 className="h-4 w-4 animate-spin" /> 加载中…
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="px-3 py-6 text-center text-xs text-muted-foreground">
|
||||
<p className="text-destructive">{error}</p>
|
||||
<p className="mt-1">可直接在上方输入号码后回车使用</p>
|
||||
</div>
|
||||
) : totalRows === 0 ? (
|
||||
<div className="px-3 py-6 text-center text-xs text-muted-foreground">无匹配项{query && ';输入完整号码可直接使用'}</div>
|
||||
) : (
|
||||
<div
|
||||
ref={listRef}
|
||||
role="listbox"
|
||||
onScroll={(e) => setScrollTop((e.target as HTMLDivElement).scrollTop)}
|
||||
className="overflow-auto"
|
||||
style={{ height: viewH }}
|
||||
>
|
||||
<div style={{ height: totalRows * ROW_H, position: 'relative' }}>
|
||||
{rows.map(({ idx, opt }) => (
|
||||
<div
|
||||
key={opt ? opt.value : `__raw-${idx}`}
|
||||
role="option"
|
||||
aria-selected={idx === active}
|
||||
onMouseEnter={() => setActive(idx)}
|
||||
onPointerDown={(e) => {
|
||||
e.preventDefault();
|
||||
suppressTriggerClick.current = true;
|
||||
choose(idx);
|
||||
}}
|
||||
className={cn(
|
||||
'absolute left-0 right-0 flex cursor-pointer items-center gap-2.5 px-3',
|
||||
idx === active ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50',
|
||||
)}
|
||||
style={{ top: idx * ROW_H, height: ROW_H }}
|
||||
>
|
||||
{opt ? (
|
||||
<>
|
||||
{opt.avatar
|
||||
? <img src={opt.avatar} alt="" className="media-outline h-7 w-7 shrink-0 rounded-full" />
|
||||
: <span className="media-outline h-7 w-7 shrink-0 rounded-full bg-muted" />}
|
||||
<span className="min-w-0 flex-1 truncate text-sm">{opt.label}</span>
|
||||
{opt.sub && <span className="shrink-0 font-mono text-meta text-muted-foreground tabular-nums">{opt.sub}</span>}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-sm">使用 <span className="font-mono text-primary">{rawRow}</span></span>
|
||||
)}
|
||||
<SkeletonSwap
|
||||
ready={!waitingForOptions}
|
||||
lines={4}
|
||||
lineHeight={28}
|
||||
reserve={112}
|
||||
label={ariaLabel}
|
||||
className={waitingForOptions ? 'mx-3 my-2' : 'skeleton-swap-fluid'}
|
||||
>
|
||||
{!waitingForOptions ? (
|
||||
error ? (
|
||||
<div className="px-3 py-6 text-center text-xs text-muted-foreground">
|
||||
<p className="text-destructive">{error}</p>
|
||||
<p className="mt-1">可直接在上方输入号码后回车使用</p>
|
||||
</div>
|
||||
) : totalRows === 0 ? (
|
||||
<div className="px-3 py-6 text-center text-xs text-muted-foreground">无匹配项{query && ';输入完整号码可直接使用'}</div>
|
||||
) : (
|
||||
<div
|
||||
ref={listRef}
|
||||
role="listbox"
|
||||
onScroll={(e) => setScrollTop((e.target as HTMLDivElement).scrollTop)}
|
||||
className="overflow-auto"
|
||||
style={{ height: viewH }}
|
||||
>
|
||||
<div style={{ height: totalRows * ROW_H, position: 'relative' }}>
|
||||
{rows.map(({ idx, opt }) => (
|
||||
<div
|
||||
key={opt ? opt.value : `__raw-${idx}`}
|
||||
role="option"
|
||||
aria-selected={idx === active}
|
||||
onMouseEnter={() => setActive(idx)}
|
||||
onPointerDown={(e) => {
|
||||
e.preventDefault();
|
||||
suppressTriggerClick.current = true;
|
||||
choose(idx);
|
||||
}}
|
||||
className={cn(
|
||||
'absolute left-0 right-0 flex cursor-pointer items-center gap-2.5 px-3',
|
||||
idx === active ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50',
|
||||
)}
|
||||
style={{ top: idx * ROW_H, height: ROW_H }}
|
||||
>
|
||||
{opt ? (
|
||||
<>
|
||||
{opt.avatar
|
||||
? <img src={opt.avatar} alt="" className="media-outline h-7 w-7 shrink-0 rounded-full" />
|
||||
: <span className="media-outline h-7 w-7 shrink-0 rounded-full bg-muted" />}
|
||||
<span className="min-w-0 flex-1 truncate text-sm">{opt.label}</span>
|
||||
{opt.sub && <span className="shrink-0 font-mono text-meta text-muted-foreground tabular-nums">{opt.sub}</span>}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-sm">使用 <span className="font-mono text-primary">{rawRow}</span></span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
Reference in new issue
Block a user