Sfoglia il codice sorgente

feat: 将 Dify chatbot 移至 App.vue onMounted 全局注入

weipengtao 6 mesi fa
parent
commit
a915eaf8bb
2 ha cambiato i file con 30 aggiunte e 22 eliminazioni
  1. 0 22
      public/index.html
  2. 30 0
      src/App.vue

+ 0 - 22
public/index.html

@@ -13,27 +13,5 @@
     </noscript>
     <div id="app"></div>
     <!-- built files will be auto injected -->
-    <script>
-      window.difyChatbotConfig = {
-        token: 'h8mBtz4IQMSuT3xm',
-        baseUrl: 'http://dify.seec.seecoder.cn',
-        systemVariables: {},
-        userVariables: {},
-      }
-    </script>
-    <script
-      src="http://dify.seec.seecoder.cn/embed.min.js"
-      id="h8mBtz4IQMSuT3xm"
-      defer>
-    </script>
-    <style>
-      #dify-chatbot-bubble-button {
-        background-color: #1C64F2 !important;
-      }
-      #dify-chatbot-bubble-window {
-        width: 24rem !important;
-        height: 40rem !important;
-      }
-    </style>
   </body>
 </html>

+ 30 - 0
src/App.vue

@@ -42,6 +42,36 @@ export default defineComponent({
       window.onbeforeunload = () => {
         localStorage.setItem('workspace', JSON.stringify(store.state.workspace));
       };
+
+      // Dify chatbot 配置与加载
+      (window as any).difyChatbotConfig = {
+        token: 'h8mBtz4IQMSuT3xm',
+        baseUrl: 'http://dify.seec.seecoder.cn',
+        systemVariables: {},
+        userVariables: {},
+      };
+      if (!document.getElementById('h8mBtz4IQMSuT3xm')) {
+        const script = document.createElement('script');
+        script.src = 'http://dify.seec.seecoder.cn/embed.min.js';
+        script.id = 'h8mBtz4IQMSuT3xm';
+        document.body.appendChild(script);
+      }
+
+      // Dify chatbot 样式
+      if (!document.getElementById('dify-chatbot-style')) {
+        const style = document.createElement('style');
+        style.id = 'dify-chatbot-style';
+        style.textContent = `
+          #dify-chatbot-bubble-button {
+            background-color: #1C64F2 !important;
+          }
+          #dify-chatbot-bubble-window {
+            width: 24rem !important;
+            height: 40rem !important;
+          }
+        `;
+        document.head.appendChild(style);
+      }
     });
   },
 });