-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
799 lines (699 loc) · 29.5 KB
/
script.js
File metadata and controls
799 lines (699 loc) · 29.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
// Network Insights - 全球协调AI助手 JavaScript
// 与Java后端API集成
// API基础URL
const API_BASE_URL = 'http://localhost:8080/api';
// 当前选择的语言
let currentLanguage = 'zh';
// 支持的语言映射
const languageMap = {
'zh': '中文',
'en': 'English',
'de': 'Deutsch',
'fr': 'Français',
'ja': '日本語',
'ko': '한국어',
'es': 'Español',
'it': 'Italiano',
'pt': 'Português',
'ru': 'Русский'
};
// 多语言文本包
const i18nDict = {
zh: {
// 导航
'nav.home': '首页',
'nav.features': '功能',
'nav.chat': 'AI助手',
'nav.about': '关于',
// 英雄区域
'hero.title': '全球协调AI助手',
'hero.subtitle': '让全球团队协作更智能、更高效。通过AI驱动的对话式界面,快速获取项目状态、联系团队成员、获取实时报告。',
'hero.startChat': '开始对话',
'hero.learnMore': '了解更多',
// 功能区域
'features.title': '核心功能',
'features.smartQA.title': '智能问答',
'features.smartQA.desc': '快速获取项目状态、货物位置、系统状态等实时信息',
'features.teamCom.title': '团队沟通辅助',
'features.teamCom.desc': '自动识别并连接相关团队成员,促进跨部门协作',
'features.reports.title': '智能报告',
'features.reports.desc': '自动生成每日/每周全球协调报告,识别瓶颈和机会',
'features.translation.title': '语言辅助',
'features.translation.desc': '实时翻译多语言消息,消除全球团队沟通障碍',
'features.example': '示例:',
// 聊天区域
'chat.title': 'AI助手对话',
'chat.aiAssistant': 'Network AI助手',
'chat.online': '在线',
'chat.selectLanguage': '选择语言:',
'chat.inputPlaceholder': '输入你的问题...',
'chat.quickActions.shipment': '查询货物状态',
'chat.quickActions.contact': '联系团队',
'chat.quickActions.report': '生成报告',
'chat.welcome.hello': '你好!我是Network Insights AI助手。我可以帮你:',
'chat.welcome.item1': '查询项目状态和货物位置',
'chat.welcome.item2': '联系相关团队成员',
'chat.welcome.item3': '生成协调报告',
'chat.welcome.item4': '翻译多语言消息',
'chat.welcome.ask': '有什么我可以帮助你的吗?',
// 关于区域
'about.title': '关于Network Insights',
'about.desc1': 'Network Insights是一个专为跨国公司设计的智能协调平台。我们理解全球团队协作的挑战,因此开发了这个AI驱动的解决方案。',
'about.desc2': '通过自然语言处理、实时数据分析和智能推荐,我们帮助全球团队更高效地沟通、协调和决策。',
'about.stats.availability': '全天候服务',
'about.stats.languages': '支持语言',
'about.stats.uptime': '系统可用性',
// 页脚
'footer.tagline': '让全球协作更智能',
'footer.product': '产品',
'footer.features': '功能特性',
'footer.aiAssistant': 'AI助手',
'footer.about': '关于我们',
'footer.support': '支持',
'footer.help': '帮助中心',
'footer.contact': '联系我们',
'footer.privacy': '隐私政策',
'footer.copyright': '© 2024 Network Insights. 保留所有权利。'
},
en: {
// Navigation
'nav.home': 'Home',
'nav.features': 'Features',
'nav.chat': 'AI Assistant',
'nav.about': 'About',
// Hero section
'hero.title': 'Global Coordination AI Assistant',
'hero.subtitle': 'Make global team collaboration smarter and more efficient. Through AI-driven conversational interface, quickly get project status, contact team members, and get real-time reports.',
'hero.startChat': 'Start Chat',
'hero.learnMore': 'Learn More',
// Features section
'features.title': 'Core Features',
'features.smartQA.title': 'Smart Q&A',
'features.smartQA.desc': 'Quickly get real-time information about project status, cargo location, system status, etc.',
'features.teamCom.title': 'Team Communication Assistant',
'features.teamCom.desc': 'Automatically identify and connect relevant team members to promote cross-departmental collaboration',
'features.reports.title': 'Smart Reports',
'features.reports.desc': 'Automatically generate daily/weekly global coordination reports to identify bottlenecks and opportunities',
'features.translation.title': 'Language Assistant',
'features.translation.desc': 'Real-time translation of multilingual messages to eliminate global team communication barriers',
'features.example': 'Example:',
// Chat section
'chat.title': 'AI Assistant Chat',
'chat.aiAssistant': 'Network AI Assistant',
'chat.online': 'Online',
'chat.selectLanguage': 'Select Language:',
'chat.inputPlaceholder': 'Enter your question...',
'chat.quickActions.shipment': 'Query Shipment Status',
'chat.quickActions.contact': 'Contact Team',
'chat.quickActions.report': 'Generate Report',
'chat.welcome.hello': 'Hi! I am the Network Insights AI assistant. I can help you with:',
'chat.welcome.item1': 'Checking project status and shipment location',
'chat.welcome.item2': 'Contacting relevant team members',
'chat.welcome.item3': 'Generating coordination reports',
'chat.welcome.item4': 'Translating multilingual messages',
'chat.welcome.ask': 'How can I help you today?',
// About section
'about.title': 'About Network Insights',
'about.desc1': 'Network Insights is an intelligent coordination platform designed for multinational companies. We understand the challenges of global team collaboration, so we developed this AI-driven solution.',
'about.desc2': 'Through natural language processing, real-time data analysis and intelligent recommendations, we help global teams communicate, coordinate and make decisions more efficiently.',
'about.stats.availability': '24/7 Service',
'about.stats.languages': 'Supported Languages',
'about.stats.uptime': 'System Uptime',
// Footer
'footer.tagline': 'Making Global Collaboration Smarter',
'footer.product': 'Product',
'footer.features': 'Features',
'footer.aiAssistant': 'AI Assistant',
'footer.about': 'About Us',
'footer.support': 'Support',
'footer.help': 'Help Center',
'footer.contact': 'Contact Us',
'footer.privacy': 'Privacy Policy',
'footer.copyright': '© 2024 Network Insights. All rights reserved.'
},
de: {
// Navigation
'nav.home': 'Start',
'nav.features': 'Funktionen',
'nav.chat': 'KI-Assistent',
'nav.about': 'Über',
// Hero section
'hero.title': 'Globaler Koordinations-KI-Assistent',
'hero.subtitle': 'Machen Sie die globale Teamzusammenarbeit intelligenter und effizienter. Durch KI-gesteuerte Gesprächsoberfläche schnell Projektstatus abrufen, Teammitglieder kontaktieren und Echtzeitberichte erhalten.',
'hero.startChat': 'Chat starten',
'hero.learnMore': 'Mehr erfahren',
// Features section
'features.title': 'Kernfunktionen',
'features.smartQA.title': 'Intelligente Q&A',
'features.smartQA.desc': 'Schnell Echtzeitinformationen über Projektstatus, Frachtstandort, Systemstatus usw. abrufen',
'features.teamCom.title': 'Team-Kommunikationsassistent',
'features.teamCom.desc': 'Automatisch relevante Teammitglieder identifizieren und verbinden, um bereichsübergreifende Zusammenarbeit zu fördern',
'features.reports.title': 'Intelligente Berichte',
'features.reports.desc': 'Automatisch tägliche/wöchentliche globale Koordinationsberichte generieren, um Engpässe und Chancen zu identifizieren',
'features.translation.title': 'Sprachassistent',
'features.translation.desc': 'Echtzeitübersetzung mehrsprachiger Nachrichten zur Beseitigung globaler Teamkommunikationsbarrieren',
'features.example': 'Beispiel:',
// Chat section
'chat.title': 'KI-Assistenten-Chat',
'chat.aiAssistant': 'Network KI-Assistent',
'chat.online': 'Online',
'chat.selectLanguage': 'Sprache wählen:',
'chat.inputPlaceholder': 'Geben Sie Ihre Frage ein...',
'chat.quickActions.shipment': 'Frachtstatus abfragen',
'chat.quickActions.contact': 'Team kontaktieren',
'chat.quickActions.report': 'Bericht generieren',
'chat.welcome.hello': 'Hallo! Ich bin der Network Insights KI-Assistent. Ich kann dir helfen mit:',
'chat.welcome.item1': 'Projektstatus und Frachtstandort prüfen',
'chat.welcome.item2': 'Relevante Teammitglieder kontaktieren',
'chat.welcome.item3': 'Koordinationsberichte erstellen',
'chat.welcome.item4': 'Mehrsprachige Nachrichten übersetzen',
'chat.welcome.ask': 'Wobei kann ich dir heute helfen?',
// About section
'about.title': 'Über Network Insights',
'about.desc1': 'Network Insights ist eine intelligente Koordinationsplattform für multinationale Unternehmen. Wir verstehen die Herausforderungen der globalen Teamzusammenarbeit und haben daher diese KI-gesteuerte Lösung entwickelt.',
'about.desc2': 'Durch natürliche Sprachverarbeitung, Echtzeitdatenanalyse und intelligente Empfehlungen helfen wir globalen Teams, effizienter zu kommunizieren, zu koordinieren und Entscheidungen zu treffen.',
'about.stats.availability': '24/7-Service',
'about.stats.languages': 'Unterstützte Sprachen',
'about.stats.uptime': 'Systemverfügbarkeit',
// Footer
'footer.tagline': 'Globale Zusammenarbeit intelligenter machen',
'footer.product': 'Produkt',
'footer.features': 'Funktionen',
'footer.aiAssistant': 'KI-Assistent',
'footer.about': 'Über uns',
'footer.support': 'Support',
'footer.help': 'Hilfezentrum',
'footer.contact': 'Kontakt',
'footer.privacy': 'Datenschutz',
'footer.copyright': '© 2024 Network Insights. Alle Rechte vorbehalten.'
}
};
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
initializeLanguage();
initializeChat();
initializeNavigation();
initializeAnimations();
initializeNavLanguageDropdown();
});
// 初始化语言设置
function initializeLanguage() {
// 从localStorage获取保存的语言,否则使用浏览器语言或默认中文
const savedLanguage = localStorage.getItem('language');
const browserLanguage = navigator.language.split('-')[0];
if (savedLanguage && i18nDict[savedLanguage]) {
currentLanguage = savedLanguage;
} else if (i18nDict[browserLanguage]) {
currentLanguage = browserLanguage;
} else {
currentLanguage = 'zh'; // 默认中文
}
// 设置语言选择器
const languageSelect = document.getElementById('languageSelect');
if (languageSelect) {
languageSelect.value = currentLanguage;
}
// 应用语言
applyLanguage(currentLanguage);
}
// 应用语言到整个页面
function applyLanguage(lang) {
// 更新所有带data-i18n的元素
document.querySelectorAll('[data-i18n]').forEach(element => {
const key = element.getAttribute('data-i18n');
const text = i18nDict[lang]?.[key] || i18nDict['zh']?.[key] || element.textContent;
element.textContent = text;
});
// 更新所有带data-i18n-placeholder的元素
document.querySelectorAll('[data-i18n-placeholder]').forEach(element => {
const key = element.getAttribute('data-i18n-placeholder');
const placeholder = i18nDict[lang]?.[key] || i18nDict['zh']?.[key] || element.placeholder;
element.placeholder = placeholder;
});
// 若欢迎消息存在,更新其中的列表与文本(已通过data-i18n会自动更新)
const welcome = document.getElementById('welcomeMessage');
if (welcome) {
// 触发一次layout刷新,保证新语言立即展示
welcome.style.opacity = '0.99';
setTimeout(() => { welcome.style.opacity = '1'; }, 0);
}
// 更新当前语言变量
currentLanguage = lang;
// 保存到localStorage
localStorage.setItem('language', lang);
}
// 右上角语言下拉
function initializeNavLanguageDropdown() {
const btn = document.getElementById('navLangBtn');
const menu = document.getElementById('navLangMenu');
if (!btn || !menu) return;
btn.addEventListener('click', () => {
const open = menu.style.display === 'block';
menu.style.display = open ? 'none' : 'block';
btn.setAttribute('aria-expanded', String(!open));
});
// 点击菜单项切换语言
menu.querySelectorAll('.lang-item').forEach(item => {
item.addEventListener('click', () => {
const lang = item.getAttribute('data-lang');
if (lang && i18nDict[lang]) {
applyLanguage(lang);
showLanguageChangeNotification();
}
menu.style.display = 'none';
btn.setAttribute('aria-expanded', 'false');
});
});
// 点击外部关闭
document.addEventListener('click', (e) => {
if (!menu.contains(e.target) && !btn.contains(e.target)) {
menu.style.display = 'none';
btn.setAttribute('aria-expanded', 'false');
}
});
}
// 初始化聊天功能
function initializeChat() {
const messageInput = document.getElementById('messageInput');
const sendButton = document.getElementById('sendButton');
// 发送按钮点击事件
sendButton.addEventListener('click', sendMessage);
// 输入框回车事件
messageInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendMessage();
}
});
// 输入框聚焦效果
messageInput.addEventListener('focus', function() {
this.parentElement.style.transform = 'scale(1.02)';
});
messageInput.addEventListener('blur', function() {
this.parentElement.style.transform = 'scale(1)';
});
}
// 发送消息函数
async function sendMessage() {
const messageInput = document.getElementById('messageInput');
const message = messageInput.value.trim();
if (message === '') return;
// 添加用户消息到聊天界面
addMessageToChat(message, 'user');
// 清空输入框
messageInput.value = '';
// 显示加载状态
showTypingIndicator();
try {
// 尝试调用Java后端API
const response = await fetch(`${API_BASE_URL}/chat/message?language=${currentLanguage}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
content: message,
sender: 'user',
language: currentLanguage
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const aiMessage = await response.json();
// 移除加载状态
hideTypingIndicator();
// 添加AI回复到聊天界面
addMessageToChat(aiMessage.content, 'ai');
} catch (error) {
console.log('后端服务不可用,使用模拟数据:', error.message);
hideTypingIndicator();
// 使用模拟AI回复
const aiResponse = generateMockAIResponse(message);
addMessageToChat(aiResponse, 'ai');
}
}
// 生成模拟AI回复
function generateMockAIResponse(message) {
const lowerMessage = message.toLowerCase();
// 根据关键词匹配回复类型
if (containsKeywords(lowerMessage, ['货物', 'shipment', '物流', 'cargo', 'freight'])) {
return getMockResponse('货物');
} else if (containsKeywords(lowerMessage, ['联系', 'contact', '团队', 'team', '谁', 'who'])) {
return getMockResponse('联系');
} else if (containsKeywords(lowerMessage, ['报告', 'report', '总结', 'summary', '状态', 'status'])) {
return getMockResponse('报告');
} else if (containsKeywords(lowerMessage, ['翻译', 'translate', '语言', 'language'])) {
return getMockResponse('翻译');
} else {
return getMockResponse('默认');
}
}
// 检查消息是否包含关键词
function containsKeywords(message, keywords) {
return keywords.some(keyword => message.includes(keyword));
}
// 获取模拟回复
function getMockResponse(category) {
const responses = {
'货物': [
'货物#342目前在新加坡港口,预计今晚9点启航。',
'货物#123已到达德国汉堡港,正在清关。',
'货物#456目前在太平洋上,预计3天后到达洛杉矶。',
'货物#789已从上海港出发,正在前往鹿特丹。'
],
'联系': [
'欧洲网络问题请联系Anna,她在法兰克福团队。我可以帮你发送消息给她。',
'亚太地区物流问题请联系David,他在新加坡办公室。',
'北美技术支持请联系Sarah,她在纽约团队。',
'系统维护问题请联系Mike,他是我们的技术主管。'
],
'报告': [
'今天的全球协调报告:\n• 亚太地区延误率:5%\n• 欧洲地区沟通频率:+15%\n• 北美地区系统稳定性:99.8%\n• 建议关注:德国港口拥堵情况',
'本周协调总结:\n• 全球项目完成率:92%\n• 跨时区沟通效率提升:20%\n• 语言翻译使用率:85%\n• 需要改进:时区协调会议安排',
'实时状态更新:\n• 在线团队:45个\n• 活跃项目:128个\n• 待处理协调任务:12个\n• 系统负载:正常'
],
'翻译': [
'已为你翻译:\n英文:"Good morning, how is the project going?"\n中文:"早上好,项目进展如何?"',
'语言检测:检测到德语消息\n翻译结果:\n"Guten Morgen, wie läuft das Projekt?"\n"早上好,项目进展如何?"',
'多语言支持:已为你的团队启用中文、英文、德文、法文、日文翻译功能。'
],
'默认': [
'我理解你的问题。让我为你查找相关信息...',
'这是一个很好的问题!让我帮你分析一下。',
'我正在处理你的请求,请稍等片刻。',
'让我为你提供最准确的信息。'
]
};
const categoryResponses = responses[category] || responses['默认'];
return categoryResponses[Math.floor(Math.random() * categoryResponses.length)];
}
// 快速提问函数
async function askQuestion(question) {
const messageInput = document.getElementById('messageInput');
messageInput.value = question;
await sendMessage();
}
// 语言切换函数
function changeLanguage() {
const languageSelect = document.getElementById('languageSelect');
const newLanguage = languageSelect.value;
// 应用新语言到整个页面
applyLanguage(newLanguage);
// 显示语言切换通知
showLanguageChangeNotification();
}
// 显示语言切换通知
function showLanguageChangeNotification() {
const notification = document.createElement('div');
notification.className = 'language-notification';
notification.textContent = `语言已切换为: ${languageMap[currentLanguage]}`;
document.body.appendChild(notification);
// 3秒后移除通知
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 3000);
}
// 显示打字指示器
function showTypingIndicator() {
const chatMessages = document.getElementById('chatMessages');
const typingDiv = document.createElement('div');
typingDiv.id = 'typingIndicator';
typingDiv.className = 'chat-message ai-message typing-indicator';
typingDiv.innerHTML = `
<div class="message-avatar ai-avatar">
<i class="fas fa-robot"></i>
</div>
<div class="message-content">
<div class="typing-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
`;
chatMessages.appendChild(typingDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// 隐藏打字指示器
function hideTypingIndicator() {
const typingIndicator = document.getElementById('typingIndicator');
if (typingIndicator) {
typingIndicator.remove();
}
}
// 添加消息到聊天界面
function addMessageToChat(message, sender) {
const chatMessages = document.getElementById('chatMessages');
const messageDiv = document.createElement('div');
messageDiv.className = `chat-message ${sender}-message`;
const avatar = document.createElement('div');
avatar.className = 'message-avatar';
if (sender === 'ai') {
avatar.className += ' ai-avatar';
avatar.innerHTML = '<i class="fas fa-robot"></i>';
} else {
avatar.innerHTML = '<i class="fas fa-user"></i>';
}
const content = document.createElement('div');
content.className = 'message-content';
content.textContent = message;
messageDiv.appendChild(avatar);
messageDiv.appendChild(content);
// 添加动画效果
messageDiv.style.opacity = '0';
messageDiv.style.transform = 'translateY(20px)';
chatMessages.appendChild(messageDiv);
// 滚动到底部
chatMessages.scrollTop = chatMessages.scrollHeight;
// 触发动画
setTimeout(() => {
messageDiv.style.transition = 'all 0.3s ease';
messageDiv.style.opacity = '1';
messageDiv.style.transform = 'translateY(0)';
}, 100);
}
// 检测语言函数
async function detectLanguage(text) {
try {
const response = await fetch(`${API_BASE_URL}/chat/detect-language`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(text)
});
if (response.ok) {
return await response.text();
}
} catch (error) {
console.error('语言检测失败:', error);
}
return 'zh'; // 默认返回中文
}
// 翻译文本函数
async function translateText(text, sourceLang, targetLang) {
try {
const response = await fetch(`${API_BASE_URL}/chat/translate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: text,
sourceLanguage: sourceLang,
targetLanguage: targetLang
})
});
if (response.ok) {
return await response.text();
}
} catch (error) {
console.error('翻译失败:', error);
}
return text; // 翻译失败时返回原文
}
// 初始化导航功能
function initializeNavigation() {
// 平滑滚动到指定区域
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// 滚动到聊天区域
function scrollToChat() {
const chatSection = document.getElementById('chat');
chatSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// 聚焦到输入框
setTimeout(() => {
const messageInput = document.getElementById('messageInput');
messageInput.focus();
}, 1000);
}
// 滚动到功能区域
function scrollToFeatures() {
const featuresSection = document.getElementById('features');
featuresSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
// 初始化动画效果
function initializeAnimations() {
// 观察器用于触发动画
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.animation = 'slideInUp 0.6s ease-out';
entry.target.style.opacity = '1';
}
});
}, {
threshold: 0.1
});
// 观察所有功能卡片
const featureCards = document.querySelectorAll('.feature-card');
featureCards.forEach(card => {
card.style.opacity = '0';
observer.observe(card);
});
// 观察统计数字
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach(stat => {
observer.observe(stat);
stat.addEventListener('animationstart', () => {
animateNumber(stat);
});
});
}
// 数字动画效果
function animateNumber(element) {
const target = parseInt(element.textContent.replace(/[^\d]/g, ''));
const duration = 2000;
const start = performance.now();
function updateNumber(currentTime) {
const elapsed = currentTime - start;
const progress = Math.min(elapsed / duration, 1);
const current = Math.floor(progress * target);
if (element.textContent.includes('24/7')) {
element.textContent = '24/7';
} else if (element.textContent.includes('50+')) {
element.textContent = '50+';
} else if (element.textContent.includes('99.9%')) {
element.textContent = '99.9%';
} else {
element.textContent = current;
}
if (progress < 1) {
requestAnimationFrame(updateNumber);
}
}
requestAnimationFrame(updateNumber);
}
// 添加一些交互式效果
document.addEventListener('DOMContentLoaded', function() {
// 为功能卡片添加悬停效果
const featureCards = document.querySelectorAll('.feature-card');
featureCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// 为按钮添加点击效果
const buttons = document.querySelectorAll('button');
buttons.forEach(button => {
button.addEventListener('click', function() {
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = 'scale(1)';
}, 150);
});
});
// 添加打字机效果到AI消息
const aiMessages = document.querySelectorAll('.ai-message .message-content');
aiMessages.forEach(message => {
if (message.textContent.length > 50) {
const text = message.textContent;
message.textContent = '';
typeText(message, text, 30);
}
});
});
// 打字机效果
function typeText(element, text, speed) {
let i = 0;
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// 添加一些实用的工具函数
const NetworkInsights = {
// 模拟获取实时数据
getRealTimeData: function() {
return {
onlineTeams: Math.floor(Math.random() * 20) + 30,
activeProjects: Math.floor(Math.random() * 50) + 100,
systemLoad: Math.random() * 100,
lastUpdate: new Date().toLocaleTimeString()
};
},
// 模拟发送通知
sendNotification: function(message) {
if ('Notification' in window) {
if (Notification.permission === 'granted') {
new Notification('Network Insights', {
body: message,
icon: '/favicon.ico'
});
} else if (Notification.permission !== 'denied') {
Notification.requestPermission().then(permission => {
if (permission === 'granted') {
new Notification('Network Insights', {
body: message,
icon: '/favicon.ico'
});
}
});
}
}
},
// 模拟多语言检测
detectLanguage: function(text) {
const chineseRegex = /[\u4e00-\u9fff]/;
const englishRegex = /[a-zA-Z]/;
const germanRegex = /[äöüßÄÖÜ]/;
if (chineseRegex.test(text)) return '中文';
if (germanRegex.test(text)) return '德文';
if (englishRegex.test(text)) return '英文';
return '未知';
}
};
// 导出到全局作用域
window.NetworkInsights = NetworkInsights;
window.scrollToChat = scrollToChat;
window.scrollToFeatures = scrollToFeatures;
window.askQuestion = askQuestion;
window.sendMessage = sendMessage;