feat(vnt-web): 新增 /api/version,顶栏版本号不再依赖组网状态

This commit is contained in:
lbl
2026-08-22 01:38:57 +08:00
parent 39a4e60d39
commit 0ccd045e78
6 changed files with 189 additions and 175 deletions
+6
View File
@@ -496,6 +496,7 @@ pub async fn run_http_server(
.allow_headers(Any); .allow_headers(Any);
let app = Router::new() let app = Router::new()
.route("/api/version", get(get_version))
.route("/api/info", get(get_info)) .route("/api/info", get(get_info))
.route("/api/peers", get(get_peers)) .route("/api/peers", get(get_peers))
.route("/api/routes", get(get_routes)) .route("/api/routes", get(get_routes))
@@ -1021,6 +1022,11 @@ async fn restart_vnt_handler(
} }
} }
/// 客户端版本号,与组网状态无关,任何时刻都可获取
async fn get_version() -> Json<ApiResponse<String>> {
Json(ApiResponse::success(env!("CARGO_PKG_VERSION").to_string()))
}
async fn get_info( async fn get_info(
State(state): State<HttpAppState>, State(state): State<HttpAppState>,
Query(req): Query<FileReq>, Query(req): Query<FileReq>,
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -19,7 +19,7 @@
if (dark) document.documentElement.classList.add("dark"); if (dark) document.documentElement.classList.add("dark");
})(); })();
</script> </script>
<script type="module" crossorigin src="/assets/index-CvlopnF8.js"></script> <script type="module" crossorigin src="/assets/index-DM6YOQ55.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-xUGHQxai.css"> <link rel="stylesheet" crossorigin href="/assets/index-xUGHQxai.css">
</head> </head>
<body> <body>
+3
View File
@@ -26,6 +26,9 @@ export const getRoutes = (fileName) =>
export const getStartStatus = (fileName) => export const getStartStatus = (fileName) =>
request(`/api/start/status?file_name=${encodeURIComponent(fileName)}`); request(`/api/start/status?file_name=${encodeURIComponent(fileName)}`);
// GET /api/version
export const getVersion = () => request("/api/version");
// GET /api/instances // GET /api/instances
export const getInstances = () => request("/api/instances"); export const getInstances = () => request("/api/instances");
+11 -6
View File
@@ -4,6 +4,7 @@ import {
getInstances, getInstances,
getInstanceInfo, getInstanceInfo,
getConfigList, getConfigList,
getVersion,
startVntApi, startVntApi,
stopVntApi, stopVntApi,
restartVntApi, restartVntApi,
@@ -54,13 +55,16 @@ export const useAppStore = defineStore("app", () => {
); );
return inst ? inst.config_name || inst.file_name : selectedInstance.value; return inst ? inst.config_name || inst.file_name : selectedInstance.value;
}); });
const version = computed(() => { // 客户端版本号,来自 /api/version,与组网状态无关
for (const key in instances.value) { const version = ref("");
const item = instances.value[key];
if (item && item.version) return item.version; const fetchVersion = async () => {
try {
version.value = (await getVersion()) || "";
} catch (e) {
console.error("Fetch version error", e);
} }
return ""; };
});
const isServerConnected = computed( const isServerConnected = computed(
() => () =>
!!( !!(
@@ -214,6 +218,7 @@ export const useAppStore = defineStore("app", () => {
const init = async () => { const init = async () => {
document.addEventListener("visibilitychange", visibilityHandler); document.addEventListener("visibilitychange", visibilityHandler);
fetchVersion();
await fetchInstances(); await fetchInstances();
fetchConfigList(); fetchConfigList();
// 页面加载时若有正在启动的实例,恢复其日志弹窗 // 页面加载时若有正在启动的实例,恢复其日志弹窗