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
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user