-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastNavGenerator.py
More file actions
6661 lines (5918 loc) · 243 KB
/
FastNavGenerator.py
File metadata and controls
6661 lines (5918 loc) · 243 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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
导航网站生成器 - JSON 配置文件版本(支持二级路由)
支持本地文件夹打开功能、发布说明时间轴和版本接口
支持二级分类导航
开发者: @wanqiang.liu
"""
import datetime
import argparse
import sys
import os
import json
from collections import defaultdict
class JavaScriptManager:
"""JavaScript 代码管理器"""
@staticmethod
def get_main_script():
"""获取主 JavaScript 脚本"""
return """
// 主初始化函数
function initNavigation() {
initCategoryNavigation();
initSubcategoryNavigation();
initReleaseNotes();
initLayoutControls();
initTagFilters();
initLocalFolderFeatures();
initInterfaceRoutes();
initIconReference();
initUsageTooltip();
initKeyboardShortcuts();
initNotificationSystem();
}
"""
@staticmethod
def get_category_navigation_script():
"""分类导航脚本"""
return """
// 1. 分类导航功能
function initCategoryNavigation() {
document.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', (e) => {
e.preventDefault();
// 移除所有active类
document.querySelectorAll('.nav-item').forEach(nav => nav.classList.remove('active'));
document.querySelectorAll('.category-section').forEach(section => section.classList.remove('active'));
// 添加active类
item.classList.add('active');
const category = item.getAttribute('data-category');
const categorySection = document.getElementById(category);
if (categorySection) {
categorySection.classList.add('active');
// 触发页面切换事件
const event = new CustomEvent('categoryChanged', {
detail: { category: category }
});
document.dispatchEvent(event);
}
// 检查是否有二级分类,如果有则初始化
initSubcategoryForCategory(category);
});
});
}
"""
@staticmethod
def get_subcategory_navigation_script():
"""二级分类导航脚本"""
return """
// 1.1 二级分类导航功能
function initSubcategoryNavigation() {
// 二级分类项点击事件
document.addEventListener('click', function(e) {
if (e.target.closest('.subcategory-item')) {
const item = e.target.closest('.subcategory-item');
const subcategory = item.getAttribute('data-subcategory');
const mainCategory = item.closest('.category-section').id;
// 更新二级分类激活状态
item.closest('.subcategory-list').querySelectorAll('.subcategory-item').forEach(subItem => {
subItem.classList.remove('active');
});
item.classList.add('active');
// 显示对应的内容
showSubcategoryContent(mainCategory, subcategory);
}
});
}
// 初始化分类的二级导航
function initSubcategoryForCategory(categoryName) {
const categorySection = document.getElementById(categoryName);
if (!categorySection) return;
// 检查是否有二级分类
const hasSubcategories = categorySection.classList.contains('has-subcategories');
if (!hasSubcategories) return;
// 默认选中"全部"
const defaultSubcategory = categorySection.querySelector('.subcategory-item[data-subcategory="全部"]');
if (defaultSubcategory) {
defaultSubcategory.click();
}
}
// 显示二级分类内容
function showSubcategoryContent(mainCategory, subcategory) {
const categorySection = document.getElementById(mainCategory);
if (!categorySection) return;
// 获取所有卡片容器
const allCardsContainer = categorySection.querySelector('.cards-container');
const subcategoryContainers = categorySection.querySelectorAll('.subcategory-cards');
if (subcategory === '全部') {
// 显示所有卡片
if (allCardsContainer) {
allCardsContainer.style.display = 'grid';
}
// 隐藏所有二级分类的卡片容器
subcategoryContainers.forEach(container => {
container.style.display = 'none';
});
} else {
// 隐藏所有卡片容器
if (allCardsContainer) {
allCardsContainer.style.display = 'none';
}
// 显示选中的二级分类卡片
subcategoryContainers.forEach(container => {
if (container.getAttribute('data-subcategory') === subcategory) {
container.style.display = 'grid';
} else {
container.style.display = 'none';
}
});
}
// 更新筛选器状态
updateTagFiltersForSubcategory(mainCategory, subcategory);
}
// 更新标签筛选器
function updateTagFiltersForSubcategory(mainCategory, subcategory) {
const categorySection = document.getElementById(mainCategory);
if (!categorySection) return;
// 获取当前显示的卡片容器
let cardsContainer;
if (subcategory === '全部') {
cardsContainer = categorySection.querySelector('.cards-container');
} else {
cardsContainer = categorySection.querySelector(`.subcategory-cards[data-subcategory="${subcategory}"]`);
}
if (!cardsContainer) return;
// 收集当前显示卡片的标签
const allTags = new Set();
const visibleCards = cardsContainer.querySelectorAll('.link-card');
visibleCards.forEach(card => {
const cardTags = card.getAttribute('data-tags');
if (cardTags) {
cardTags.split(',').forEach(tag => {
if (tag.trim()) allTags.add(tag.trim());
});
}
});
// 更新标签筛选器
const tagFilters = categorySection.querySelector('.tag-filters');
if (tagFilters) {
// 重建标签筛选器
tagFilters.innerHTML = '<div class="tag-filter active" data-tag="全部">全部</div>';
Array.from(allTags).sort().forEach(tag => {
tagFilters.innerHTML += `<div class="tag-filter" data-tag="${tag}">${tag}</div>`;
});
// 重新绑定事件
initTagFiltersForContainer(tagFilters);
}
}
// 初始化标签筛选器
function initTagFiltersForContainer(container) {
container.querySelectorAll('.tag-filter').forEach(filter => {
filter.addEventListener('click', function() {
const tag = this.getAttribute('data-tag');
const categorySection = container.closest('.category-section');
// 获取当前激活的二级分类
const activeSubcategory = categorySection.querySelector('.subcategory-item.active');
const subcategory = activeSubcategory ? activeSubcategory.getAttribute('data-subcategory') : '全部';
// 获取对应的卡片容器
let cardsContainer;
if (subcategory === '全部') {
cardsContainer = categorySection.querySelector('.cards-container');
} else {
cardsContainer = categorySection.querySelector(`.subcategory-cards[data-subcategory="${subcategory}"]`);
}
if (!cardsContainer) return;
// 更新按钮状态
container.querySelectorAll('.tag-filter').forEach(f => f.classList.remove('active'));
this.classList.add('active');
// 筛选卡片
const cards = cardsContainer.querySelectorAll('.link-card');
cards.forEach(card => {
if (tag === '全部') {
card.style.display = 'flex';
} else {
const cardTags = card.getAttribute('data-tags');
if (cardTags && cardTags.includes(tag)) {
card.style.display = 'flex';
} else {
card.style.display = 'none';
}
}
});
});
});
}
"""
@staticmethod
def get_release_notes_script():
"""发布说明脚本"""
return """
// 2. 发布说明功能
function initReleaseNotes() {
// 发布类型卡片点击事件
document.querySelectorAll('.release-type-card').forEach(card => {
card.addEventListener('click', (e) => {
e.preventDefault();
// 移除所有active类
document.querySelectorAll('.release-type-card').forEach(c => c.classList.remove('active'));
// 添加active类
card.classList.add('active');
const releaseType = card.getAttribute('data-release-type');
showReleaseTimeline(releaseType);
});
});
}
// 显示发布类型时间轴
function showReleaseTimeline(releaseType) {
// 隐藏所有时间轴
document.querySelectorAll('.timeline').forEach(timeline => {
timeline.style.display = 'none';
});
// 显示选中的时间轴
const targetTimeline = document.getElementById(`timeline-${releaseType}`);
if (targetTimeline) {
targetTimeline.style.display = 'block';
}
}
"""
@staticmethod
def get_layout_controls_script():
"""布局控制脚本"""
return """
// 3. 布局切换功能
function initLayoutControls() {
document.querySelectorAll('.layout-btn').forEach(btn => {
btn.addEventListener('click', function() {
const layout = this.getAttribute('data-layout');
const categorySection = this.closest('.category-section');
// 更新按钮状态
this.parentElement.querySelectorAll('.layout-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
// 获取当前激活的二级分类
const activeSubcategory = categorySection.querySelector('.subcategory-item.active');
const subcategory = activeSubcategory ? activeSubcategory.getAttribute('data-subcategory') : '全部';
// 获取对应的卡片容器
let cardsContainer;
if (subcategory === '全部') {
cardsContainer = categorySection.querySelector('.cards-container');
} else {
cardsContainer = categorySection.querySelector(`.subcategory-cards[data-subcategory="${subcategory}"]`);
}
if (cardsContainer) {
// 切换布局
cardsContainer.className = (subcategory === '全部' ? 'cards-container ' : 'subcategory-cards ') + layout + '-layout';
}
});
});
}
"""
@staticmethod
def get_tag_filters_script():
"""标签筛选脚本"""
return """
// 4. 标签筛选功能
function initTagFilters() {
// 在主分类切换时初始化标签筛选器
document.addEventListener('categoryChanged', function() {
setTimeout(() => {
const activeCategory = document.querySelector('.category-section.active');
if (activeCategory) {
const tagFilters = activeCategory.querySelector('.tag-filters');
if (tagFilters) {
initTagFiltersForContainer(tagFilters);
}
}
}, 100);
});
}
"""
@staticmethod
def get_local_folder_script():
"""本地文件夹功能脚本"""
return """
// 5. 本地文件夹功能
function initLocalFolderFeatures() {
// 复制路径功能
document.querySelectorAll('.copy-path-btn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation();
const path = this.getAttribute('data-path');
copyToClipboard(path);
showNotification('路径已复制到剪贴板', 'success');
});
});
// 本地文件夹右键菜单
document.querySelectorAll('.card-actions.local-folder a.local-path').forEach(link => {
link.addEventListener('contextmenu', function(e) {
e.preventDefault();
const card = this.closest('.link-card');
const path = card.getAttribute('data-original-path');
showFolderOptions(path);
});
});
// 双击卡片标题复制路径(仅限本地文件夹)
document.querySelectorAll('.link-card[data-is-local="true"] h3').forEach(title => {
title.addEventListener('dblclick', function() {
const card = this.closest('.link-card');
const path = card.getAttribute('data-original-path');
copyToClipboard(path);
showNotification('路径已复制到剪贴板', 'success');
});
});
}
"""
@staticmethod
def get_interface_routes_script():
"""版本接口脚本"""
return """
// 6. 版本接口功能
function initInterfaceRoutes() {
// 视图切换功能
document.querySelectorAll('.view-filter').forEach(filter => {
filter.addEventListener('click', function() {
const view = this.getAttribute('data-view');
const container = this.closest('.interface-route-container');
const filters = container.querySelectorAll('.view-filter');
// 更新按钮状态
filters.forEach(f => f.classList.remove('active'));
this.classList.add('active');
// 切换视图内容
const viewContents = container.querySelectorAll('.view-content');
viewContents.forEach(content => {
if (content.getAttribute('data-view') === view) {
content.style.display = 'block';
} else {
content.style.display = 'none';
}
});
});
});
// 分支筛选功能
document.querySelectorAll('.branch-filter').forEach(filter => {
filter.addEventListener('click', function() {
const branch = this.getAttribute('data-branch');
const container = this.closest('.interface-route-container');
const filters = container.querySelectorAll('.branch-filter');
// 更新按钮状态
filters.forEach(f => f.classList.remove('active'));
this.classList.add('active');
// 筛选表格行
const activeView = container.querySelector('.view-filter.active').getAttribute('data-view');
const tableContainer = container.querySelector(`.view-content[data-view="${activeView}"]`);
if (branch === 'all') {
// 显示所有行
tableContainer.querySelectorAll('tr[data-branch]').forEach(row => {
row.style.display = '';
});
tableContainer.querySelectorAll('.branch-group').forEach(group => {
group.style.display = 'block';
});
} else {
if (activeView === 'unified') {
// 统一视图:筛选行
tableContainer.querySelectorAll('tr[data-branch]').forEach(row => {
if (row.getAttribute('data-branch') === branch) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
} else {
// 分组视图:筛选分组
tableContainer.querySelectorAll('.branch-group').forEach(group => {
if (group.getAttribute('data-branch') === branch) {
group.style.display = 'block';
} else {
group.style.display = 'none';
}
});
}
}
});
});
}
"""
@staticmethod
def get_icon_reference_script():
"""图标引用脚本"""
return """
// 7. 图标引用功能
function initIconReference() {
// 统一复制函数
function copyIcon(value) {
copyToClipboard(value);
if (value.length <= 2) {
// 可能是emoji
showNotification(`Emoji已复制: ${value}`, 'success');
} else {
// 可能是SVG ID
showNotification(`SVG图标ID已复制: ${value}`, 'success');
}
}
// 修改图标项点击事件
document.addEventListener('click', (e) => {
const iconItem = e.target.closest('.icon-item');
if (iconItem) {
if (iconItem.classList.contains('svg-item')) {
// SVG图标:复制ID
const iconId = iconItem.getAttribute('data-icon-id');
if (iconId) {
copyToClipboard(iconId);
showNotification(`SVG图标ID已复制: ${iconId}`, 'success');
}
} else {
// Emoji图标:复制emoji
const icon = iconItem.getAttribute('data-icon');
if (icon) {
copyToClipboard(icon);
showNotification(`Emoji已复制: ${icon}`, 'success');
}
}
}
});
}
"""
@staticmethod
def get_usage_tooltip_script():
"""使用提示脚本"""
return """
// 8. 使用提示功能
function initUsageTooltip() {
// 简洁版使用说明功能
function toggleUsageTooltip() {
const tooltip = document.getElementById('usageTooltip');
tooltip.classList.toggle('show');
}
// 绑定点击事件
const helpBtn = document.querySelector('.usage-help');
if (helpBtn) {
helpBtn.addEventListener('click', toggleUsageTooltip);
}
// 点击页面其他地方关闭工具提示
document.addEventListener('click', (e) => {
const tooltip = document.getElementById('usageTooltip');
const helpBtn = document.querySelector('.usage-help');
if (tooltip && tooltip.classList.contains('show') &&
!tooltip.contains(e.target) &&
!helpBtn.contains(e.target)) {
tooltip.classList.remove('show');
}
});
// ESC键关闭工具提示
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
const tooltip = document.getElementById('usageTooltip');
if (tooltip) {
tooltip.classList.remove('show');
}
}
});
}
"""
@staticmethod
def get_keyboard_shortcuts_script():
"""键盘快捷键脚本"""
return """
// 9. 键盘快捷键功能
function initKeyboardShortcuts() {
document.addEventListener('keydown', (e) => {
// Alt + 数字 切换分类
if (e.altKey) {
const categories = Array.from(document.querySelectorAll('.nav-item'));
const index = parseInt(e.key) - 1;
if (index >= 0 && index < categories.length) {
categories[index].click();
}
}
// ESC 键关闭模态框和工具提示
if (e.key === 'Escape') {
hideModal();
const tooltip = document.getElementById('usageTooltip');
if (tooltip) {
tooltip.classList.remove('show');
}
}
});
}
"""
@staticmethod
def get_notification_system_script():
"""通知系统脚本"""
return """
// 10. 通知系统功能
function initNotificationSystem() {
// 这个函数是全局可用的,其他模块会调用它
}
// 工具函数:复制到剪贴板
function copyToClipboard(text) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text);
} else {
// 备用方法
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
} catch (err) {
console.error('复制失败:', err);
}
document.body.removeChild(textArea);
}
}
// 工具函数:显示通知
function showNotification(message, type = 'success') {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.className = 'notification ' + type;
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 3000);
}
// 工具函数:显示文件夹选项
function showFolderOptions(path) {
document.getElementById('modalFolderPath').textContent = path;
document.getElementById('folderOptionsModal').classList.add('show');
}
// 工具函数:隐藏模态框
function hideModal() {
document.getElementById('folderOptionsModal').classList.remove('show');
}
"""
@staticmethod
def get_modal_script():
"""模态框功能脚本"""
return """
// 模态框功能
document.getElementById('modalCopyPath').addEventListener('click', function() {
const path = document.getElementById('modalFolderPath').textContent;
copyToClipboard(path);
showNotification('路径已复制到剪贴板', 'success');
hideModal();
});
document.getElementById('modalOpenDefault').addEventListener('click', function() {
const path = document.getElementById('modalFolderPath').textContent;
// 转换为 file:// URL 并打开
let fileUrl = path;
if (!fileUrl.startsWith('file://')) {
if (fileUrl.startsWith('/')) {
fileUrl = 'file://' + fileUrl;
} else {
fileUrl = 'file:///' + fileUrl.replace(/\\\\/g, '/');
}
}
window.open(fileUrl, '_blank');
hideModal();
});
document.getElementById('modalCancel').addEventListener('click', hideModal);
document.getElementById('folderOptionsModal').addEventListener('click', function(e) {
if (e.target === this) hideModal();
});
"""
@staticmethod
def get_onload_script():
"""页面加载后执行的脚本"""
return """
// 页面加载完成后初始化所有功能
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM加载完成,开始初始化...');
// 初始化所有功能模块
initNavigation();
// 检查当前页面是否是模块信息页面
const activeSection = document.querySelector('.category-section.active');
if (activeSection) {
const categoryType = activeSection.getAttribute('data-category-type');
if (categoryType === 'ModuleInfo') {
console.log('检测到模块信息页面,执行额外初始化...');
// 确保模块信息功能已初始化
setTimeout(() => {
if (typeof initModuleInfo === 'function') {
initModuleInfo();
}
updateCategoryCounts();
}, 100);
}
}
// 绑定模态框事件(确保在DOM加载后)
const modalCopyBtn = document.getElementById('modalCopyPath');
const modalOpenBtn = document.getElementById('modalOpenDefault');
const modalCancelBtn = document.getElementById('modalCancel');
const modalOverlay = document.getElementById('folderOptionsModal');
if (modalCopyBtn) {
modalCopyBtn.addEventListener('click', function() {
const path = document.getElementById('modalFolderPath').textContent;
copyToClipboard(path);
showNotification('路径已复制到剪贴板', 'success');
hideModal();
});
}
if (modalOpenBtn) {
modalOpenBtn.addEventListener('click', function() {
const path = document.getElementById('modalFolderPath').textContent;
let fileUrl = path;
if (!fileUrl.startsWith('file://')) {
if (fileUrl.startsWith('/')) {
fileUrl = 'file://' + fileUrl;
} else {
fileUrl = 'file:///' + fileUrl.replace(/\\\\/g, '/');
}
}
window.open(fileUrl, '_blank');
hideModal();
});
}
if (modalCancelBtn) {
modalCancelBtn.addEventListener('click', hideModal);
}
if (modalOverlay) {
modalOverlay.addEventListener('click', function(e) {
if (e.target === this) hideModal();
});
}
// 绑定使用提示按钮
const helpBtn = document.querySelector('.usage-help');
if (helpBtn) {
helpBtn.addEventListener('click', function() {
const tooltip = document.getElementById('usageTooltip');
if (tooltip) {
tooltip.classList.toggle('show');
}
});
}
// 添加页面切换监听
document.addEventListener('categoryChanged', function() {
setTimeout(() => {
const activeSection = document.querySelector('.category-section.active');
if (activeSection && activeSection.querySelector('.module-info-container')) {
console.log('切换到模块信息页面,重新初始化...');
if (typeof initModuleInfo === 'function') {
initModuleInfo();
}
if (typeof updateCategoryCounts === 'function') {
updateCategoryCounts();
}
}
}, 50);
});
});
"""
@staticmethod
def get_module_info_script():
"""模块信息页面脚本"""
return """
// 模块信息页面功能
function initModuleInfo() {
console.log('初始化模块信息页面...');
// 分类标签点击事件 - 使用事件委托
document.addEventListener('click', function(e) {
const categoryTab = e.target.closest('.category-tab');
if (categoryTab) {
e.preventDefault();
const category = categoryTab.getAttribute('data-category');
// 更新按钮状态
document.querySelectorAll('.category-tab').forEach(t => t.classList.remove('active'));
categoryTab.classList.add('active');
// 筛选模块卡片
filterModulesByCategory(category);
}
});
// 搜索功能 - 实时搜索
const searchInput = document.getElementById('moduleSearch');
if (searchInput) {
searchInput.addEventListener('input', function() {
const activeCategory = document.querySelector('.category-tab.active');
if (activeCategory) {
const category = activeCategory.getAttribute('data-category');
filterModulesByCategory(category);
}
});
}
// 初始化分类计数
updateCategoryCounts();
}
// 按分类筛选模块
function filterModulesByCategory(category) {
console.log('按分类筛选:', category);
const searchInput = document.getElementById('moduleSearch');
const searchTerm = searchInput ? searchInput.value.toLowerCase().trim() : '';
const modules = document.querySelectorAll('.module-card');
let visibleCount = 0;
modules.forEach(module => {
const moduleCategories = module.getAttribute('data-categories');
const moduleName = module.querySelector('.module-name').textContent.toLowerCase();
const moduleDesc = module.querySelector('.module-description').textContent.toLowerCase();
const moduleId = module.querySelector('.module-id')?.textContent.toLowerCase() || '';
// 检查分类匹配
const categoryMatch = category === '全部' ||
(moduleCategories && moduleCategories.includes(category));
// 检查搜索匹配
const searchMatch = searchTerm === '' ||
moduleName.includes(searchTerm) ||
moduleDesc.includes(searchTerm) ||
moduleId.includes(searchTerm);
if (categoryMatch && searchMatch) {
module.style.display = 'block';
visibleCount++;
} else {
module.style.display = 'none';
}
});
console.log('显示模块数量:', visibleCount);
// 如果没有显示任何模块,显示提示
const container = document.querySelector('.module-cards-container');
let emptyState = container.querySelector('.empty-state');
if (visibleCount === 0) {
if (!emptyState) {
emptyState = document.createElement('div');
emptyState.className = 'empty-state';
emptyState.style.cssText = 'grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--text-secondary);';
emptyState.innerHTML = `
<i>🔍</i>
<p>未找到匹配的模块</p>
<p style="font-size: 0.9em; margin-top: 10px; opacity: 0.7;">
当前分类: ${category} | 搜索词: ${searchTerm || '(无)'}
</p>
`;
container.appendChild(emptyState);
}
} else if (emptyState) {
emptyState.remove();
}
}
// 更新分类计数
function updateCategoryCounts() {
console.log('更新分类计数...');
const categories = document.querySelectorAll('.category-tab');
categories.forEach(tab => {
const category = tab.getAttribute('data-category');
if (category === '全部') {
const countSpan = tab.querySelector('.category-count');
if (countSpan) {
const modules = document.querySelectorAll('.module-card');
countSpan.textContent = modules.length;
}
return;
}
const modules = document.querySelectorAll('.module-card');
let count = 0;
modules.forEach(module => {
const moduleCategories = module.getAttribute('data-categories');
if (moduleCategories && moduleCategories.includes(category)) {
count++;
}
});
const countSpan = tab.querySelector('.category-count');
if (countSpan) {
countSpan.textContent = count;
}
});
}
// 工具函数:根据属性类型获取图标
function getAttributeIcon(attributeType) {
const iconMap = {
'owner': '👤',
'version': '🏷️',
'status': '📊',
'language': '💻',
'framework': '⚙️',
'repository': '📦',
'documentation': '📚',
'dependency': '🔗',
'接口': '🔌',
'协议': '📄',
'端口': '🔌',
'性能': '⚡',
'安全性': '🔒',
'部署': '🚀',
'监控': '📈',
'测试': '🧪',
'维护': '🔧',
'创建时间': '📅',
'更新时间': '🔄',
'负责人': '👤',
'团队': '👥',
'邮件': '📧',
'电话': '📞',
'部门': '🏢',
'位置': '📍'
};
return iconMap[attributeType] || '📋';
}
"""
@staticmethod
def get_all_scripts():
"""获取所有 JavaScript 脚本"""
scripts = [
JavaScriptManager.get_main_script(),
JavaScriptManager.get_category_navigation_script(),
JavaScriptManager.get_subcategory_navigation_script(),
JavaScriptManager.get_release_notes_script(),
JavaScriptManager.get_layout_controls_script(),
JavaScriptManager.get_tag_filters_script(),
JavaScriptManager.get_local_folder_script(),
JavaScriptManager.get_interface_routes_script(),
JavaScriptManager.get_icon_reference_script(),
JavaScriptManager.get_usage_tooltip_script(),
JavaScriptManager.get_keyboard_shortcuts_script(),
JavaScriptManager.get_notification_system_script(),
JavaScriptManager.get_modal_script(),
JavaScriptManager.get_onload_script(),
JavaScriptManager.get_module_info_script()
]
# 将所有脚本合并成一个字符串
return "\n".join(scripts)
class CSSManager:
"""CSS样式管理器"""
@staticmethod
def get_base_styles():
"""基础样式"""
return """
:root {
--primary-color: #6366f1;
--primary-hover: #4f46e5;
--bg-color: #ffffff;
--sidebar-bg: #f8fafc;
--card-bg: #ffffff;
--text-primary: #374151;
--text-secondary: #6b7280;
--border-color: #e5e7eb;
--shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
--border-radius: 8px;
--transition: all 0.2s ease;
--success-color: #10b981;
--warning-color: #f59e0b;
--error-color: #ef4444;
--copy-btn-color: #8b5cf6;
--copy-btn-hover: #7c3aed;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: var(--bg-color);
color: var(--text-primary);
display: flex;
min-height: 100vh;
line-height: 1.6;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
"""
@staticmethod
def get_layout_styles():
"""布局样式"""
return """
/* 侧边栏样式 */
.sidebar {
width: 280px;
background: var(--sidebar-bg);
border-right: 1px solid var(--border-color);
padding: 30px 0;
height: 100vh;