exec.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html lang="zh-Hans-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>应用启动页</title>
  7. <link
  8. rel="icon"
  9. type="image/svg+xml"
  10. href="data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8cmVjdCB4PSIyIiB5PSIyIiB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHJ4PSIxMCIgcnk9IjEwIgogICAgZmlsbD0iIzQyNDI0MiIKICAgIHN0cm9rZT0iIzAwNjk1YyIKICAgIHN0cm9rZS13aWR0aD0iNCIvPgo8L3N2Zz4="
  11. />
  12. <style>
  13. * {
  14. margin: 0;
  15. padding: 0;
  16. box-sizing: border-box;
  17. }
  18. :root,
  19. body {
  20. background-color: #000;
  21. height: 100vh;
  22. display: flex;
  23. justify-content: center;
  24. align-items: center;
  25. font-family: sans-serif;
  26. cursor: none;
  27. }
  28. .loader-container {
  29. display: flex;
  30. flex-direction: column;
  31. align-items: center;
  32. gap: 2rem;
  33. }
  34. .app-icon {
  35. width: 96px;
  36. height: 96px;
  37. border-radius: 16px;
  38. background: #222;
  39. display: flex;
  40. align-items: center;
  41. justify-content: center;
  42. overflow: hidden;
  43. }
  44. .app-icon img {
  45. max-width: 100%;
  46. max-height: 100%;
  47. }
  48. .app-icon {
  49. position: relative;
  50. z-index: 0;
  51. border-radius: 16px;
  52. overflow: hidden;
  53. }
  54. .app-icon::before {
  55. content: "";
  56. position: absolute;
  57. z-index: -2;
  58. left: -50%;
  59. top: -50%;
  60. width: 200%;
  61. height: 200%;
  62. background-repeat: no-repeat;
  63. background-size: 50% 50%, 50% 50%;
  64. background-position: 0 0, 100% 0, 100% 100%, 0 100%;
  65. background-image: linear-gradient(transparent, transparent),
  66. linear-gradient(#424242, #424242), linear-gradient(#00695c, #00695c),
  67. linear-gradient(#64ffda, #64ffda);
  68. animation: rotate 4s linear infinite;
  69. }
  70. .app-icon::after {
  71. content: "";
  72. position: absolute;
  73. z-index: -1;
  74. left: 4px;
  75. top: 4px;
  76. width: calc(100% - 8px);
  77. height: calc(100% - 8px);
  78. background: #222;
  79. border-radius: 12px;
  80. }
  81. @keyframes rotate {
  82. 100% {
  83. transform: rotate(1turn);
  84. }
  85. }
  86. .status-text {
  87. display: none;
  88. color: #64ffda;
  89. font-size: 1.2rem;
  90. text-align: center;
  91. margin-top: 1rem;
  92. }
  93. </style>
  94. </head>
  95. <body>
  96. <div class="loader-container">
  97. <div class="app-icon" id="appIcon">
  98. <!-- 图标将通过 JS 动态替换 -->
  99. </div>
  100. <div class="status-text" id="statusText">加载应用程序……</div>
  101. </div>
  102. <script>
  103. document.addEventListener("DOMContentLoaded", async () => {
  104. const urlParams = new URLSearchParams(window.location.search);
  105. const appId = urlParams.get("id");
  106. const appIcon = document.getElementById("appIcon");
  107. const statusText = document.getElementById("statusText");
  108. // 如果没有提供 ID 或 ID 为空,跳转到 index.html
  109. if (!appId) {
  110. statusText.textContent = "未指定应用程序 ID,跳转中……";
  111. await preloadAndNavigate("index.html");
  112. return;
  113. }
  114. try {
  115. // 加载应用程序索引
  116. const response = await fetch("index.json");
  117. if (!response.ok) throw new Error("无法加载应用程序索引");
  118. const indexData = await response.json();
  119. const packages = indexData.packages || [];
  120. const appInfo = packages.find((pkg) => pkg.id === appId);
  121. if (!appInfo) {
  122. throw new Error(`未找到 ID 为 ${appId} 的应用程序`);
  123. }
  124. // 显示应用程序图标
  125. if (appInfo.icon) {
  126. const iconUrl = `${appInfo.location}/${appInfo.icon}`;
  127. appIcon.innerHTML = `<img src="${iconUrl}" alt="${appInfo.name}">`;
  128. }
  129. statusText.textContent = `启动 ${appInfo.name || appId}……`;
  130. // 获取元数据以确定入口点
  131. const metaResponse = await fetch(`${appInfo.location}/metadata.json`);
  132. if (!metaResponse.ok) throw new Error("无法加载应用程序元数据");
  133. const metadata = await metaResponse.json();
  134. const entryPoint = metadata.entry;
  135. if (!entryPoint) {
  136. throw new Error("应用程序元数据中未指定入口点");
  137. }
  138. // 预加载并导航到应用程序
  139. const appUrl = `${appInfo.location}/${entryPoint}`;
  140. await preloadAndNavigate(appUrl);
  141. } catch (error) {
  142. console.error("启动错误:", error);
  143. statusText.textContent = `错误: ${error.message},3 秒后跳转至首页`;
  144. appIcon.innerHTML = "❌";
  145. // 错误处理:3 秒后跳转到首页
  146. setTimeout(async () => {
  147. await preloadAndNavigate("index.html");
  148. }, 3000);
  149. }
  150. });
  151. // 预加载页面并导航
  152. // TODO: 实现真正的预加载和 ajax 或其他异步刷新方式
  153. async function preloadAndNavigate(url) {
  154. try {
  155. // 预加载目标页面
  156. const preloadResponse = await fetch(url);
  157. if (!preloadResponse.ok) throw new Error("预加载失败");
  158. // 延迟导航以显示加载状态
  159. setTimeout(() => {
  160. window.location.href = url;
  161. }, 1000);
  162. } catch (error) {
  163. console.error("导航错误:", error);
  164. // 如果预加载失败,直接跳转
  165. window.location.href = "index.html";
  166. }
  167. }
  168. </script>
  169. </body>
  170. </html>