wangfumin před 12 hodinami
rodič
revize
09fb5fcc85
1 změnil soubory, kde provedl 44 přidání a 0 odebrání
  1. 44 0
      index.html

+ 44 - 0
index.html

@@ -12,5 +12,49 @@
   <body>
     <div id="app"></div>
     <script type="module" src="/src/main.ts"></script>
+    <script>
+      // 获取URL参数中的app值
+      function getAppParam() {
+        const urlParams = new URLSearchParams(window.location.search);
+        return {fromRoute: urlParams.get('fromRoute')};
+      }
+  
+      // 根据app参数设置favicon
+      function setFavicon() {
+        const appParam = getAppParam();
+        // 获取基础路径
+        const basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
+        let faviconPath = basePath + 'favicon.ico'; // 默认图标
+        console.log(appParam, basePath, 6666)
+        if (appParam.fromRoute == 'fire') {
+          faviconPath = basePath + 'fire.ico';
+        } else if (appParam.fromRoute == 'crimical') {
+          faviconPath = basePath + 'police.ico';
+        } else if (appParam.fromRoute == 'xmfire') {
+          faviconPath = basePath + 'jmlogo.png';
+        } else if (appParam.fromRoute == 'czjfire') {
+          faviconPath = basePath + 'logo_big.ico';
+        }
+        
+        // 查找现有的favicon链接元素
+        let link = document.querySelector("link[rel~='icon']");
+        
+        // 如果没有找到,创建一个新的
+        if (!link) {
+          link = document.createElement('link');
+          link.rel = 'icon';
+          document.head.appendChild(link);
+        }
+        
+        // 设置favicon路径
+        link.href = faviconPath;
+      }
+  
+      // 页面加载时设置favicon
+      window.addEventListener('load', setFavicon);
+      
+      // 当URL通过History API变化时也更新favicon
+      window.addEventListener('popstate', setFavicon);
+    </script>
   </body>
 </html>