feat(webui): show saved and applied config state
Surface whether a OneBot configuration was persisted, applied live, or left degraded. Keep failed adapters and apply errors visible in the config and overview pages instead of reporting a false success.
This commit is contained in:
7 files changed
+145
-24
No files matched your search
@@ -17,12 +17,14 @@ const LIVE_STYLE: Record<AdapterStatus['status'], string> = {
|
||||
ok: 'bg-success/10 text-success',
|
||||
warn: 'bg-warning/10 text-warning',
|
||||
down: 'bg-destructive/10 text-destructive',
|
||||
degraded: 'bg-destructive/10 text-destructive',
|
||||
disabled: 'bg-muted text-muted-foreground',
|
||||
};
|
||||
const LIVE_LABEL: Record<AdapterStatus['status'], string> = {
|
||||
ok: '正常',
|
||||
warn: '注意',
|
||||
down: '异常',
|
||||
degraded: '应用失败',
|
||||
disabled: '未启用',
|
||||
};
|
||||
|
||||
@@ -74,7 +76,9 @@ export function NodeSummaryCard<T extends AdapterCommon>({
|
||||
{liveStatus && (
|
||||
<span
|
||||
className={cn('rounded px-1.5 py-0.5 text-[10px] font-medium', LIVE_STYLE[liveStatus.status])}
|
||||
title={liveStatus.detail}
|
||||
title={liveStatus.lastError
|
||||
? `${liveStatus.detail}\n${liveStatus.lastErrorAt ? new Date(liveStatus.lastErrorAt).toLocaleString() : '时间未知'} · ${liveStatus.lastError}`
|
||||
: liveStatus.detail}
|
||||
>
|
||||
{LIVE_LABEL[liveStatus.status]} · {liveStatus.detail}
|
||||
</span>
|
||||
@@ -118,4 +122,3 @@ export function NodeSummaryCard<T extends AdapterCommon>({
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ export function ConfigPage() {
|
||||
cancelSwitch,
|
||||
save,
|
||||
saveStatus,
|
||||
saveStatusTone,
|
||||
} = useOneBotInstanceConfig(qqList, {
|
||||
selectedUin,
|
||||
onSelectedUinChange: setSelectedUin,
|
||||
@@ -187,6 +188,7 @@ export function ConfigPage() {
|
||||
selectedUin={selectedUin}
|
||||
dirty={dirty}
|
||||
saveStatus={saveStatus}
|
||||
saveStatusTone={saveStatusTone}
|
||||
onSave={immediateSave}
|
||||
activeTab={activeTab}
|
||||
onCreate={
|
||||
@@ -262,12 +264,13 @@ interface HeaderBarProps {
|
||||
selectedUin: string;
|
||||
dirty: boolean;
|
||||
saveStatus: string;
|
||||
saveStatusTone: 'idle' | 'saving' | 'success' | 'warning' | 'error';
|
||||
onSave: () => void;
|
||||
activeTab: TabKey;
|
||||
onCreate?: () => void;
|
||||
}
|
||||
|
||||
function HeaderBar({ selectedUin, dirty, saveStatus, onSave, activeTab, onCreate }: HeaderBarProps) {
|
||||
function HeaderBar({ selectedUin, dirty, saveStatus, saveStatusTone, onSave, activeTab, onCreate }: HeaderBarProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
@@ -279,11 +282,13 @@ function HeaderBar({ selectedUin, dirty, saveStatus, onSave, activeTab, onCreate
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{(saveStatus || dirty) && (
|
||||
<span className="inline-flex items-center gap-1.5 text-[11px] font-medium">
|
||||
{saveStatus === '保存中...' ? (
|
||||
{saveStatusTone === 'saving' ? (
|
||||
<><Loader2 className="size-3.5 animate-spin text-muted-foreground" /><span className="text-muted-foreground">保存中</span></>
|
||||
) : saveStatus === '保存成功' ? (
|
||||
<><Check className="size-3.5 text-success" /><span className="text-success">已保存</span></>
|
||||
) : saveStatus ? (
|
||||
) : saveStatusTone === 'success' ? (
|
||||
<><Check className="size-3.5 text-success" /><span className="text-success">{saveStatus}</span></>
|
||||
) : saveStatusTone === 'warning' ? (
|
||||
<><span className="size-1.5 rounded-full bg-warning" /><span className="text-warning">{saveStatus}</span></>
|
||||
) : saveStatusTone === 'error' ? (
|
||||
<><span className="size-1.5 rounded-full bg-destructive" /><span className="text-destructive">{saveStatus}</span></>
|
||||
) : (
|
||||
<><span className="size-1.5 rounded-full bg-warning" /><span className="text-warning">未保存</span></>
|
||||
|
||||
@@ -731,17 +731,24 @@ const CONN_STATUS_STYLE: Record<AdapterStatusLevel, string> = {
|
||||
ok: 'bg-success/10 text-success',
|
||||
warn: 'bg-warning/10 text-warning',
|
||||
down: 'bg-destructive/10 text-destructive',
|
||||
degraded: 'bg-destructive/10 text-destructive',
|
||||
disabled: 'bg-muted text-muted-foreground',
|
||||
};
|
||||
const CONN_STATUS_LABEL: Record<AdapterStatusLevel, string> = {
|
||||
ok: '正常', warn: '注意', down: '异常', disabled: '未启用',
|
||||
ok: '正常', warn: '注意', down: '异常', degraded: '应用失败', disabled: '未启用',
|
||||
};
|
||||
const ADAPTER_KIND_LABEL: Record<AdapterStatus['kind'], string> = {
|
||||
httpServer: 'HTTP 服务端', httpClient: 'HTTP 上报', wsServer: 'WS 服务端', wsClient: 'WS 客户端',
|
||||
};
|
||||
|
||||
// Worst-status-first ordering (down → warn → disabled → ok).
|
||||
const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = { down: 0, warn: 1, disabled: 2, ok: 3 };
|
||||
const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = {
|
||||
degraded: 0,
|
||||
down: 1,
|
||||
warn: 2,
|
||||
disabled: 3,
|
||||
ok: 4,
|
||||
};
|
||||
|
||||
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
const { connections } = useAppState();
|
||||
@@ -804,6 +811,11 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
<span className="shrink-0 text-[10px] text-muted-foreground">{ADAPTER_KIND_LABEL[adp.kind]}</span>
|
||||
</div>
|
||||
<div className="truncate text-[11px] text-muted-foreground">{adp.detail}</div>
|
||||
{adp.lastError && adp.lastErrorAt && (
|
||||
<div className="truncate text-[10px] text-destructive/80">
|
||||
{new Date(adp.lastErrorAt).toLocaleString()} · {adp.lastError}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user