From version 13.1
edited by Jiahao Lai
on 2026/03/26 15:47
on 2026/03/26 15:47
Change comment:
There is no comment for this version
To version 12.1
edited by Jiahao Lai
on 2026/03/26 15:46
on 2026/03/26 15:46
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -193,54 +193,47 @@ 193 193 194 194 <script> 195 195 document.addEventListener('DOMContentLoaded', function() { 196 - // 延长等待时间,确保配置和依赖完全加载 197 197 setTimeout(async () => { 198 198 try { 199 - // 1. 加载 marked.js 依赖 200 - await new Promise((resolve) => { 201 - const s = document.createElement('script'); 202 - s.src = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/marked/4.0.2/marked.min.js'; 203 - s.onload = resolve; 204 - document.body.appendChild(s); 198 + // 1. 先加载依赖库 marked.js(子 wiki 用的版本) 199 + await new Promise((resolve, reject) => { 200 + const markedScript = document.createElement('script'); 201 + markedScript.src = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/marked/4.0.2/marked.min.js'; 202 + markedScript.onload = resolve; 203 + markedScript.onerror = reject; 204 + document.body.appendChild(markedScript); 205 205 }); 206 + console.log("✅ marked.js 加载成功"); 206 206 207 207 // 2. 加载 CSS 208 208 await new Promise((resolve) => { 209 - const l = document.createElement('link'); 210 - l.rel = 'stylesheet'; 211 - l.href = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/application-ai-llm-chat-webjar/0.7.2/chatWidget.css'; 212 - l.onload = resolve; 213 - document.head.appendChild(l); 210 + const link = document.createElement('link'); 211 + link.rel = 'stylesheet'; 212 + link.href = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/application-ai-llm-chat-webjar/0.7.2/chatWidget.css'; 213 + link.onload = resolve; 214 + document.head.appendChild(link); 214 214 }); 215 215 216 216 // 3. 加载 chatWidget.js 217 217 await new Promise((resolve) => { 218 - const s = document.createElement('script'); 219 - s.src = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/application-ai-llm-chat-webjar/0.7.2/chatWidget.js'; 220 - s.onload = resolve; 221 - document.body.appendChild(s); 219 + const script = document.createElement('script'); 220 + script.src = 'https://docs.we-con.com.cn/webjars/wiki%3Awonway/application-ai-llm-chat-webjar/0.7.2/chatWidget.js'; 221 + script.onload = resolve; 222 + document.body.appendChild(script); 222 222 }); 223 223 224 - // 4. 循环等待,直到 LLM 配置就绪 225 - let retries = 0; 226 - const maxRetries = 20; // 最多等 20*200ms = 4秒 227 - const waitForLLM = () => { 228 - if (window.LLMChatWidget && typeof LLMChatWidget.init === 'function') { 229 - LLMChatWidget.init(); 230 - console.log("✅ 浮窗启动成功!"); 231 - } else if (retries < maxRetries) { 232 - retries++; 233 - setTimeout(waitForLLM, 200); 234 - } else { 235 - throw new Error("LLM 配置超时未就绪"); 236 - } 237 - }; 238 - waitForLLM(); 225 + // 4. 启动浮窗 226 + if (window.LLMChatWidget && typeof LLMChatWidget.init === 'function') { 227 + LLMChatWidget.init(); 228 + console.log("✅ 浮窗启动成功!"); 229 + } else { 230 + throw new Error("LLMChatWidget 未初始化"); 231 + } 239 239 } catch (e) { 240 - console.error("❌ 最终失败", e);241 - alert("浮窗加载失败:" + (e.message|| "未知错误"));233 + console.error("❌ 加载失败", e); 234 + alert("浮窗加载失败:" + e.message); 242 242 } 243 - }, 1 500);// 延长初始等待时间236 + }, 1000); 244 244 }); 245 245 </script> 246 246 {{/html}}