| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <!DOCTYPE html>
- <html lang="zh-Hans-CN">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>应用启动页</title>
- <link
- rel="icon"
- type="image/svg+xml"
- href="data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8cmVjdCB4PSIyIiB5PSIyIiB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHJ4PSIxMCIgcnk9IjEwIgogICAgZmlsbD0iIzQyNDI0MiIKICAgIHN0cm9rZT0iIzAwNjk1YyIKICAgIHN0cm9rZS13aWR0aD0iNCIvPgo8L3N2Zz4="
- />
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- :root,
- body {
- background-color: #000;
- height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- font-family: sans-serif;
- cursor: none;
- }
- .loader-container {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 2rem;
- }
- .app-icon {
- width: 96px;
- height: 96px;
- border-radius: 16px;
- background: #222;
- display: flex;
- align-items: center;
- justify-content: center;
- overflow: hidden;
- }
- .app-icon img {
- max-width: 100%;
- max-height: 100%;
- }
- .app-icon {
- position: relative;
- z-index: 0;
- border-radius: 16px;
- overflow: hidden;
- }
- .app-icon::before {
- content: "";
- position: absolute;
- z-index: -2;
- left: -50%;
- top: -50%;
- width: 200%;
- height: 200%;
- background-repeat: no-repeat;
- background-size: 50% 50%, 50% 50%;
- background-position: 0 0, 100% 0, 100% 100%, 0 100%;
- background-image: linear-gradient(transparent, transparent),
- linear-gradient(#424242, #424242), linear-gradient(#00695c, #00695c),
- linear-gradient(#64ffda, #64ffda);
- animation: rotate 4s linear infinite;
- }
- .app-icon::after {
- content: "";
- position: absolute;
- z-index: -1;
- left: 4px;
- top: 4px;
- width: calc(100% - 8px);
- height: calc(100% - 8px);
- background: #222;
- border-radius: 12px;
- }
- @keyframes rotate {
- 100% {
- transform: rotate(1turn);
- }
- }
- .status-text {
- display: none;
- color: #64ffda;
- font-size: 1.2rem;
- text-align: center;
- margin-top: 1rem;
- }
- </style>
- </head>
- <body>
- <div class="loader-container">
- <div class="app-icon" id="appIcon">
- <!-- 图标将通过 JS 动态替换 -->
- </div>
- <div class="status-text" id="statusText">加载应用程序……</div>
- </div>
- <script>
- document.addEventListener("DOMContentLoaded", async () => {
- const urlParams = new URLSearchParams(window.location.search);
- const appId = urlParams.get("id");
- const appIcon = document.getElementById("appIcon");
- const statusText = document.getElementById("statusText");
- // 如果没有提供 ID 或 ID 为空,跳转到 index.html
- if (!appId) {
- statusText.textContent = "未指定应用程序 ID,跳转中……";
- await preloadAndNavigate("index.html");
- return;
- }
- try {
- // 加载应用程序索引
- const response = await fetch("index.json");
- if (!response.ok) throw new Error("无法加载应用程序索引");
- const indexData = await response.json();
- const packages = indexData.packages || [];
- const appInfo = packages.find((pkg) => pkg.id === appId);
- if (!appInfo) {
- throw new Error(`未找到 ID 为 ${appId} 的应用程序`);
- }
- // 显示应用程序图标
- if (appInfo.icon) {
- const iconUrl = `${appInfo.location}/${appInfo.icon}`;
- appIcon.innerHTML = `<img src="${iconUrl}" alt="${appInfo.name}">`;
- }
- statusText.textContent = `启动 ${appInfo.name || appId}……`;
- // 获取元数据以确定入口点
- const metaResponse = await fetch(`${appInfo.location}/metadata.json`);
- if (!metaResponse.ok) throw new Error("无法加载应用程序元数据");
- const metadata = await metaResponse.json();
- const entryPoint = metadata.entry;
- if (!entryPoint) {
- throw new Error("应用程序元数据中未指定入口点");
- }
- // 预加载并导航到应用程序
- const appUrl = `${appInfo.location}/${entryPoint}`;
- await preloadAndNavigate(appUrl);
- } catch (error) {
- console.error("启动错误:", error);
- statusText.textContent = `错误: ${error.message},3 秒后跳转至首页`;
- appIcon.innerHTML = "❌";
- // 错误处理:3 秒后跳转到首页
- setTimeout(async () => {
- await preloadAndNavigate("index.html");
- }, 3000);
- }
- });
- // 预加载页面并导航
- // TODO: 实现真正的预加载和 ajax 或其他异步刷新方式
- async function preloadAndNavigate(url) {
- try {
- // 预加载目标页面
- const preloadResponse = await fetch(url);
- if (!preloadResponse.ok) throw new Error("预加载失败");
- // 延迟导航以显示加载状态
- setTimeout(() => {
- window.location.href = url;
- }, 1000);
- } catch (error) {
- console.error("导航错误:", error);
- // 如果预加载失败,直接跳转
- window.location.href = "index.html";
- }
- }
- </script>
- </body>
- </html>
|