feat: initial import (exclude templates and runtime temp files)
This commit is contained in:
47
app/static/app.js
Normal file
47
app/static/app.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// Bootstrap loader for legacy /app.js entry.
|
||||
(function bootstrapXibaoWeb() {
|
||||
if (window.__XIBAO_BOOTSTRAPPING__) {
|
||||
return;
|
||||
}
|
||||
if (window.__XIBAO_MAIN_READY__) {
|
||||
return;
|
||||
}
|
||||
window.__XIBAO_BOOTSTRAPPING__ = true;
|
||||
|
||||
const currentSrc = String(document.currentScript?.src || "");
|
||||
const currentUrl = currentSrc ? new URL(currentSrc, window.location.href) : null;
|
||||
const currentPath = currentUrl ? String(currentUrl.pathname || "") : "";
|
||||
let basePath = "";
|
||||
if (currentPath.endsWith("/app.js")) {
|
||||
basePath = currentPath.slice(0, -"/app.js".length);
|
||||
}
|
||||
if (basePath === "/") {
|
||||
basePath = "";
|
||||
}
|
||||
window.__XIBAO_BASE_PATH__ = basePath;
|
||||
const version = currentUrl ? currentUrl.searchParams.get("v") : "";
|
||||
const qs = version ? `?v=${encodeURIComponent(version)}` : "";
|
||||
|
||||
function loadScript(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const s = document.createElement("script");
|
||||
s.src = src;
|
||||
s.async = false;
|
||||
s.onload = () => resolve();
|
||||
s.onerror = () => reject(new Error(`加载失败: ${src}`));
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
}
|
||||
|
||||
const scriptUrl = (path) => `${basePath}${path}`;
|
||||
|
||||
loadScript(scriptUrl(`/js/core/state.js${qs}`))
|
||||
.then(() => loadScript(scriptUrl(`/js/main.js${qs}`)))
|
||||
.catch((err) => {
|
||||
// Keep UI feedback simple; fallback to console for non-blocking visibility.
|
||||
console.error("[xibao] frontend bootstrap failed:", err);
|
||||
})
|
||||
.finally(() => {
|
||||
window.__XIBAO_BOOTSTRAPPING__ = false;
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user