feat(web): 顶栏显示后端版本号
复用现有 /health 端点返回的 CARGO_PKG_VERSION,避免在 package.json 重复维护版本号;挂载时拉取一次,失败则不显示徽标。
This commit is contained in:
parent
f26ec49182
commit
7de9a8a054
@ -28,6 +28,7 @@ import { ConfigPage } from './components/Settings/ConfigPage';
|
|||||||
import { ConnectionStatus } from './components/ConnectionStatus';
|
import { ConnectionStatus } from './components/ConnectionStatus';
|
||||||
import { ChannelSelector } from './components/Header/ChannelSelector';
|
import { ChannelSelector } from './components/Header/ChannelSelector';
|
||||||
import { SessionSelector } from './components/Header/SessionSelector';
|
import { SessionSelector } from './components/Header/SessionSelector';
|
||||||
|
import { getVersion } from './api/config';
|
||||||
import { useWebSocket } from './hooks/useWebSocket';
|
import { useWebSocket } from './hooks/useWebSocket';
|
||||||
import { useChat } from './hooks/useChat';
|
import { useChat } from './hooks/useChat';
|
||||||
import type {
|
import type {
|
||||||
@ -47,6 +48,9 @@ function App() {
|
|||||||
const wsUrl = buildWsUrl(gatewaySettings);
|
const wsUrl = buildWsUrl(gatewaySettings);
|
||||||
const lastAutoSwitchedTopicRef = useRef<string | null>(null);
|
const lastAutoSwitchedTopicRef = useRef<string | null>(null);
|
||||||
|
|
||||||
|
// 后端版本号(来自 /health,源自 Cargo.toml 的 CARGO_PKG_VERSION);挂载时拉取一次,失败则不显示。
|
||||||
|
const [appVersion, setAppVersion] = useState<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
// 连接状态
|
// 连接状态
|
||||||
isConnected,
|
isConnected,
|
||||||
@ -204,6 +208,11 @@ function App() {
|
|||||||
localStorage.setItem('picobot-show-thinking', String(showThinking));
|
localStorage.setItem('picobot-show-thinking', String(showThinking));
|
||||||
}, [showThinking]);
|
}, [showThinking]);
|
||||||
|
|
||||||
|
// 拉取后端版本号(/health 返回 CARGO_PKG_VERSION),仅一次。
|
||||||
|
useEffect(() => {
|
||||||
|
getVersion().then(setAppVersion);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// ---- WebSocket 初始化 ----
|
// ---- WebSocket 初始化 ----
|
||||||
|
|
||||||
// Step 1: 连接建立后先请求通道列表
|
// Step 1: 连接建立后先请求通道列表
|
||||||
@ -616,6 +625,11 @@ function App() {
|
|||||||
<span className="text-[var(--text-primary)]">Pico</span>
|
<span className="text-[var(--text-primary)]">Pico</span>
|
||||||
<span className="text-[var(--accent-cyan)] glow-text">Bot</span>
|
<span className="text-[var(--accent-cyan)] glow-text">Bot</span>
|
||||||
</h1>
|
</h1>
|
||||||
|
{appVersion && (
|
||||||
|
<span className="text-xs font-mono text-[var(--text-muted)] select-none">
|
||||||
|
v{appVersion}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="h-4 w-px bg-[var(--divider-color)]" />
|
<div className="h-4 w-px bg-[var(--divider-color)]" />
|
||||||
<ConnectionStatus status={status} />
|
<ConnectionStatus status={status} />
|
||||||
|
|||||||
@ -37,3 +37,15 @@ export async function checkHealth(): Promise<boolean> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 从 /health 端点获取后端版本号(源自 Cargo.toml 的 CARGO_PKG_VERSION)。 */
|
||||||
|
export async function getVersion(): Promise<string | null> {
|
||||||
|
try {
|
||||||
|
const resp = await fetch(API.health);
|
||||||
|
if (!resp.ok) return null;
|
||||||
|
const data = (await resp.json()) as { status?: string; version?: string };
|
||||||
|
return data.version ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user