diff --git a/crates/app_operation_system/src/router.rs b/crates/app_operation_system/src/router.rs index 9b63112..8f8ab08 100644 --- a/crates/app_operation_system/src/router.rs +++ b/crates/app_operation_system/src/router.rs @@ -3,14 +3,30 @@ use tower_http::services::ServeDir; use crate::app::AppState; -const WEB_ROOT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/web"); +async fn no_cache( + req: axum::extract::Request, + next: axum::middleware::Next, +) -> axum::response::Response { + let mut response = next.run(req).await; + response.headers_mut().insert( + axum::http::header::CACHE_CONTROL, + axum::http::HeaderValue::from_static("no-store"), + ); + response +} pub fn build_router(state: AppState) -> Router { Router::new() .route("/api/health", get(health_check)) - .nest_service( + .nest( "/ui", - ServeDir::new(WEB_ROOT).append_index_html_on_directories(true), + Router::new() + .fallback_service( + ServeDir::new("web/ops") + .append_index_html_on_directories(true) + .fallback(ServeDir::new("web/core")), + ) + .layer(axum::middleware::from_fn(no_cache)), ) .with_state(state) } diff --git a/crates/app_operation_system/web/index.html b/crates/app_operation_system/web/index.html deleted file mode 100644 index 1471a65..0000000 --- a/crates/app_operation_system/web/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - PLC Control Operation System - - -
-

Operation System

-

This web root is a placeholder for the operation-system app skeleton.

-
- - diff --git a/web/ops/html/topbar.html b/web/ops/html/topbar.html new file mode 100644 index 0000000..13ab23e --- /dev/null +++ b/web/ops/html/topbar.html @@ -0,0 +1,9 @@ +
+
运转系统
+
+
+ + 连接中… +
+
+
diff --git a/web/ops/index.html b/web/ops/index.html new file mode 100644 index 0000000..852278d --- /dev/null +++ b/web/ops/index.html @@ -0,0 +1,18 @@ + + + + + + 运转系统 + + + +
+ +
+
运转系统页面开发中
+
+ + + + diff --git a/web/ops/js/app.js b/web/ops/js/app.js new file mode 100644 index 0000000..74140f4 --- /dev/null +++ b/web/ops/js/app.js @@ -0,0 +1,5 @@ +function bootstrap() { + console.log("Operation system app initialized"); +} + +bootstrap(); diff --git a/web/ops/js/index.js b/web/ops/js/index.js new file mode 100644 index 0000000..727497c --- /dev/null +++ b/web/ops/js/index.js @@ -0,0 +1,20 @@ +async function loadPartial(slot) { + const response = await fetch(slot.dataset.partial); + if (!response.ok) { + throw new Error(`Failed to load partial: ${slot.dataset.partial}`); + } + + const html = await response.text(); + slot.insertAdjacentHTML("beforebegin", html); + slot.remove(); +} + +async function bootstrapPage() { + const slots = Array.from(document.querySelectorAll("[data-partial]")); + await Promise.all(slots.map((slot) => loadPartial(slot))); + await import("./app.js"); +} + +bootstrapPage().catch((error) => { + document.body.innerHTML = `
${error.message || String(error)}
`; +});