-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1895 lines (1666 loc) · 84 KB
/
Copy pathindex.html
File metadata and controls
1895 lines (1666 loc) · 84 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管锥国 - 数学工具集</title>
<!-- Material Design 组件库 -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet">
<!-- Plotly.js 3D渲染库 -->
<script src="https://cdn.plot.ly/plotly-2.20.0.min.js"></script>
<!-- AI相关库 -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"></script>
<script src="https://cdn.jsdelivr.net/npm/@xenova/transformers"></script>
<style>
body {
font-family: 'Roboto', 'Microsoft YaHei', sans-serif;
background-color: #f5f5f5;
color: #333;
min-height: 100vh;
display: flex;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
.container {
max-width: 1400px;
padding: 20px;
width: 100%;
}
.header {
background: linear-gradient(135deg, #4a148c 0%, #3f51b5 100%);
color: white;
padding: 20px 0;
margin-bottom: 20px;
}
.header-title {
margin: 0;
font-weight: 300;
font-size: 2.5rem;
}
.header-subtitle {
margin-top: 10px;
font-weight: 300;
opacity: 0.8;
}
.card {
border-radius: 8px;
height: 100%;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 17px 2px rgba(0,0,0,0.14),
0 3px 14px 2px rgba(0,0,0,0.12),
0 5px 5px -3px rgba(0,0,0,0.2);
}
.card .card-content {
height: 100%;
display: flex;
flex-direction: column;
}
.card .card-title {
font-weight: 500;
font-size: 1.5rem;
}
.card-description {
flex-grow: 1;
margin-bottom: 20px;
color: #666;
}
.tools-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.tool-card {
cursor: pointer;
padding: 15px;
margin-bottom: 0;
transition: all 0.2s ease;
border-left: 3px solid transparent;
}
.tool-card.active {
background-color: #e8f0fe;
border-left: 3px solid #3f51b5;
font-weight: 500;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.tool-card:hover:not(.active) {
background-color: #f5f5f5;
border-left: 3px solid #9fa8da;
}
.tool-icon {
font-size: 24px !important;
margin-right: 10px;
color: #3f51b5;
vertical-align: middle;
}
.coming-soon {
opacity: 0.6;
}
footer {
padding: 20px 0;
margin-top: 20px;
background-color: #f0f0f0;
text-align: center;
font-size: 0.9rem;
color: #666;
}
.app-container {
display: flex;
gap: 20px;
min-height: calc(100vh - 220px);
}
.sidebar {
flex: 0 0 300px;
}
.content-area {
flex: 1;
display: flex;
flex-direction: column;
background-color: #f8f9fa;
border-radius: 8px;
padding: 15px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.welcome-screen {
display: none;
}
.tool-content {
display: none;
}
/* 函数渲染器样式 */
.preview-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.preview-card {
flex: 1 1 65%;
min-width: 300px;
}
.controls-card {
flex: 1 1 30%;
min-width: 300px;
}
.preview {
height: 600px;
background-color: #fff;
border-radius: 4px;
overflow: hidden;
position: relative;
}
.loading {
font-size: 18px;
color: #666;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 10;
background: rgba(255,255,255,0.8);
padding: 15px;
border-radius: 5px;
display: none;
}
.function-examples {
margin-top: 20px;
}
.function-chip, .param-chip {
margin: 5px;
cursor: pointer;
user-select: none;
}
.parameter-value {
font-weight: bold;
margin-left: 10px;
}
.slider-label {
display: flex;
justify-content: space-between;
align-items: center;
}
.help-text {
font-size: 0.85rem;
color: #777;
margin: 5px 0 15px;
}
.tabs .tab a {
color: rgba(0, 0, 0, 0.7);
}
.tabs .tab a:hover {
color: rgba(0, 0, 0, 1);
}
.tabs .tab a.active {
color: #2196F3;
}
.tabs .indicator {
background-color: #2196F3;
}
#plot-container {
width: 100%;
height: 100%;
}
@media (max-width: 992px) {
.app-container {
flex-direction: column;
}
.sidebar {
flex: 1;
width: 100%;
}
.content-area {
flex: 1;
}
}
.ai-demo {
margin-top: 20px;
padding: 20px;
border: 1px solid #eee;
border-radius: 8px;
background-color: #fafafa;
}
.ai-result {
margin-top: 15px;
padding: 15px;
border-radius: 4px;
background-color: #f0f8ff;
}
.img-preview {
margin: 15px 0;
text-align: center;
}
.loading-spinner {
display: inline-block;
width: 40px;
height: 40px;
border: 4px solid rgba(0,0,0,0.1);
border-radius: 50%;
border-top-color: #3f51b5;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
#sentiment-result, #speech-result {
font-weight: bold;
margin-top: 10px;
}
.mic-btn {
width: 60px;
height: 60px;
border-radius: 50%;
background-color: #f44336;
color: white;
border: none;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s;
}
.mic-btn:hover {
transform: scale(1.1);
box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.mic-btn i {
font-size: 24px;
}
.mic-btn.recording {
background-color: #4CAF50;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
70% { box-shadow: 0 0 0 15px rgba(76, 175, 80, 0); }
100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}
.aicard {
display: flex;
flex-direction: column;
height: 100%;
}
.aicard-header {
border-bottom: 1px solid #eee;
padding-bottom: 15px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<h1 class="header-title">管锥国</h1>
<p class="header-subtitle">数学与数据科学工具集</p>
</div>
</header>
<main>
<div class="container">
<div class="app-container">
<!-- 左侧工具列表 -->
<div class="sidebar">
<div class="card">
<div class="card-content">
<span class="card-title">工具列表</span>
<div class="tools-list">
<!-- 函数渲染工具 -->
<div class="card tool-card hoverable active" data-tool="function-visualizer">
<i class="material-icons tool-icon">functions</i>
<span class="tool-title">函数渲染</span>
</div>
<!-- 多维数据表 -->
<div class="card tool-card hoverable coming-soon" data-tool="data-table">
<i class="material-icons tool-icon">grid_on</i>
<span class="tool-title">多维数据表</span>
</div>
<!-- Excel工具箱 -->
<div class="card tool-card hoverable" data-tool="excel-tools">
<i class="material-icons tool-icon">table_chart</i>
<span class="tool-title">Excel工具箱</span>
</div>
<!-- 统计分析工具 -->
<div class="card tool-card hoverable coming-soon" data-tool="statistics">
<i class="material-icons tool-icon">insert_chart</i>
<span class="tool-title">统计分析</span>
</div>
<!-- 数学符号工具 -->
<div class="card tool-card hoverable coming-soon" data-tool="math-symbols">
<i class="material-icons tool-icon">calculate</i>
<span class="tool-title">数学符号</span>
</div>
<!-- 机器学习演示 -->
<div class="card tool-card hoverable coming-soon" data-tool="ml-demo">
<i class="material-icons tool-icon">psychology</i>
<span class="tool-title">机器学习演示</span>
</div>
<!-- 图像识别 AI工具 -->
<div class="card tool-card hoverable" data-tool="image-recognition">
<i class="material-icons tool-icon">image_search</i>
<span class="tool-title">图像识别</span>
</div>
<!-- 情感分析 AI工具 -->
<div class="card tool-card hoverable" data-tool="sentiment-analysis">
<i class="material-icons tool-icon">psychology</i>
<span class="tool-title">情感分析</span>
</div>
<!-- 语音识别 AI工具 -->
<div class="card tool-card hoverable" data-tool="speech-recognition">
<i class="material-icons tool-icon">record_voice_over</i>
<span class="tool-title">语音识别</span>
</div>
</div>
</div>
</div>
</div>
<!-- 右侧内容区域 -->
<div class="content-area">
<!-- 欢迎屏幕已被移除 -->
<!-- 函数渲染工具 -->
<div id="function-visualizer" class="tool-content" style="display: block;">
<div class="preview-container">
<div class="card preview-card">
<div class="card-content">
<span class="card-title">函数预览</span>
<div class="preview" id="preview-box">
<div id="plot-container"></div>
<div class="loading" id="loading-indicator">渲染中...</div>
</div>
<div class="help-text center-align">
您可以直接用鼠标拖拽旋转视角,使用滚轮缩放
</div>
</div>
</div>
<div class="card controls-card">
<div class="card-content">
<span class="card-title">控制面板</span>
<ul class="tabs">
<li class="tab"><a class="active" href="#tab-surface">曲面函数</a></li>
<li class="tab"><a href="#tab-parametric">参数方程</a></li>
</ul>
<div id="tab-surface" class="col s12">
<div class="input-field">
<input type="text" id="function" value="0.5 * Math.sin(2 * Math.PI * x) * Math.cos(2 * Math.PI * y)">
<label for="function" class="active">函数表达式 z = f(x,y)</label>
<span class="help-text">
使用 x, y 作为变量,例如 Math.sin(x) + Math.cos(y)
</span>
</div>
<div class="function-examples">
<p>示例函数:</p>
<div class="chip function-chip" data-function="0.5 * Math.sin(2 * Math.PI * x) * Math.cos(2 * Math.PI * y)">
正弦-余弦波
</div>
<div class="chip function-chip" data-function="Math.sin(Math.sqrt(x*x + y*y))">
波纹函数
</div>
<div class="chip function-chip" data-function="Math.exp(-(x*x + y*y) / 2) / (2 * Math.PI)">
高斯分布
</div>
<div class="chip function-chip" data-function="Math.sin(3 * x) * Math.cos(3 * y) / 3">
正弦网格
</div>
<div class="chip function-chip" data-function="x*x - y*y">
双曲抛物面
</div>
<div class="chip function-chip" data-function="Math.sin(x*y)">
交互正弦
</div>
</div>
</div>
<div id="tab-parametric" class="col s12">
<div class="input-field">
<input type="text" id="param-x" value="Math.cos(u) * (4 + Math.cos(v))">
<label for="param-x" class="active">x(u,v)</label>
</div>
<div class="input-field">
<input type="text" id="param-y" value="Math.sin(u) * (4 + Math.cos(v))">
<label for="param-y" class="active">y(u,v)</label>
</div>
<div class="input-field">
<input type="text" id="param-z" value="Math.sin(v)">
<label for="param-z" class="active">z(u,v)</label>
</div>
<div class="input-field">
<input type="text" id="param-u-range" value="0,2*Math.PI,0.1">
<label for="param-u-range" class="active">u范围 (起点,终点,步长)</label>
</div>
<div class="input-field">
<input type="text" id="param-v-range" value="0,2*Math.PI,0.1">
<label for="param-v-range" class="active">v范围 (起点,终点,步长)</label>
</div>
<div class="function-examples">
<p>参数曲面示例:</p>
<div class="chip param-chip"
data-x="Math.cos(u) * (4 + Math.cos(v))"
data-y="Math.sin(u) * (4 + Math.cos(v))"
data-z="Math.sin(v)"
data-urange="0,2*Math.PI,0.1"
data-vrange="0,2*Math.PI,0.1">
圆环
</div>
<div class="chip param-chip"
data-x="Math.sin(u) * Math.cos(v)"
data-y="Math.sin(u) * Math.sin(v)"
data-z="Math.cos(u)"
data-urange="0,Math.PI,0.05"
data-vrange="0,2*Math.PI,0.05">
球体
</div>
<div class="chip param-chip"
data-x="(1 + 0.5*Math.cos(v)) * Math.cos(u)"
data-y="(1 + 0.5*Math.cos(v)) * Math.sin(u)"
data-z="0.5 * Math.sin(v)"
data-urange="0,2*Math.PI,0.05"
data-vrange="0,2*Math.PI,0.05">
莫比乌斯带
</div>
</div>
</div>
<div class="display-options">
<p>显示选项:</p>
<div class="input-field">
<select id="colorscale">
<option value="Viridis">Viridis (默认)</option>
<option value="Jet">Jet</option>
<option value="Hot">Hot</option>
<option value="Electric">Electric</option>
<option value="Portland">Portland</option>
<option value="Rainbow">Rainbow</option>
</select>
<label>颜色方案</label>
</div>
<div class="slider-label">
<label for="resolution">分辨率:</label>
<span id="resolution-value" class="parameter-value">40</span>
</div>
<p class="range-field">
<input type="range" id="resolution" min="10" max="100" step="5" value="40">
</p>
</div>
<button id="generate-btn" class="btn waves-effect waves-light blue darken-2" style="width: 100%;">
渲染函数
<i class="material-icons right">3d_rotation</i>
</button>
</div>
</div>
</div>
</div>
<!-- Excel工具箱 -->
<div id="excel-tools" class="tool-content">
<div class="card">
<div class="card-content">
<span class="card-title">Excel工具箱</span>
<p>使用AI帮助您生成Excel VBA代码和函数公式</p>
<div class="row" style="margin-top: 20px;">
<div class="col s12 m6">
<div class="card blue-grey lighten-5">
<div class="card-content">
<span class="card-title">VBA代码生成</span>
<div class="input-field">
<textarea id="vba-requirement" class="materialize-textarea"></textarea>
<label for="vba-requirement">请描述您需要的VBA功能</label>
<span class="helper-text">例如:"创建一个宏,循环遍历A列数据,如果单元格值大于100则在B列对应位置标红"</span>
</div>
<button id="generate-vba-btn" class="btn waves-effect waves-light blue darken-2" onclick="generateExcelCode('vba')">
生成VBA代码
<i class="material-icons right">code</i>
</button>
</div>
</div>
</div>
<div class="col s12 m6">
<div class="card blue-grey lighten-5">
<div class="card-content">
<span class="card-title">函数公式生成</span>
<div class="input-field">
<textarea id="formula-requirement" class="materialize-textarea"></textarea>
<label for="formula-requirement">请描述您需要的Excel函数功能</label>
<span class="helper-text">例如:"计算C列中所有满足条件(A列大于0且B列包含'测试'字样)的数值的平均值"</span>
</div>
<button id="generate-formula-btn" class="btn waves-effect waves-light green darken-2" onclick="generateExcelCode('formula')">
生成Excel公式
<i class="material-icons right">functions</i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col s12">
<div class="card-panel" id="excel-result">
<div class="ai-result">
<div id="excel-loading" style="text-align: center; display: none;">
<div class="loading-spinner"></div>
<p>正在生成代码...</p>
</div>
<div id="excel-code-result">
<p class="center-align grey-text">点击上方按钮生成代码</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 其他工具内容区域 -->
<div id="data-table" class="tool-content">
<div class="card">
<div class="card-content">
<span class="card-title">多维数据表</span>
<p>该功能正在开发中,敬请期待!</p>
<div class="center-align" style="margin-top: 30px;">
<i class="material-icons" style="font-size: 80px; color: #ddd;">grid_on</i>
</div>
</div>
</div>
</div>
<div id="statistics" class="tool-content">
<div class="card">
<div class="card-content">
<span class="card-title">统计分析</span>
<p>该功能正在开发中,敬请期待!</p>
<div class="center-align" style="margin-top: 30px;">
<i class="material-icons" style="font-size: 80px; color: #ddd;">insert_chart</i>
</div>
</div>
</div>
</div>
<div id="math-symbols" class="tool-content">
<div class="card">
<div class="card-content">
<span class="card-title">数学符号</span>
<p>该功能正在开发中,敬请期待!</p>
<div class="center-align" style="margin-top: 30px;">
<i class="material-icons" style="font-size: 80px; color: #ddd;">calculate</i>
</div>
</div>
</div>
</div>
<div id="ml-demo" class="tool-content">
<div class="card">
<div class="card-content">
<span class="card-title">机器学习演示</span>
<p>该功能正在开发中,敬请期待!</p>
<div class="center-align" style="margin-top: 30px;">
<i class="material-icons" style="font-size: 80px; color: #ddd;">psychology</i>
</div>
</div>
</div>
</div>
<!-- 图像识别工具内容 -->
<div id="image-recognition" class="tool-content">
<div class="card">
<div class="card-content aicard">
<div class="aicard-header">
<span class="card-title">图像识别</span>
<p>这是一个基于TensorFlow.js和MobileNet模型的图像识别工具,可以识别图像中的物体。</p>
</div>
<div class="ai-demo">
<div class="file-field input-field">
<div class="btn blue darken-2">
<span>选择图片</span>
<input type="file" id="image-input" accept="image/*">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="上传图片进行识别">
</div>
</div>
<div class="img-preview" id="preview"></div>
<div class="ai-result">
<div id="image-loading" style="text-align: center; display: none;">
<div class="loading-spinner"></div>
<p>正在处理图像...</p>
</div>
<div id="image-prediction">
<p>请上传一张图片进行识别</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 情感分析工具内容 -->
<div id="sentiment-analysis" class="tool-content">
<div class="card">
<div class="card-content aicard">
<div class="aicard-header">
<span class="card-title">情感分析</span>
<p>这个工具使用Transformers.js来分析文本的情感倾向。</p>
</div>
<div class="ai-demo">
<div class="input-field">
<textarea id="sentiment-input" class="materialize-textarea"></textarea>
<label for="sentiment-input">请输入要分析的文本</label>
</div>
<button id="analyze-btn" class="btn waves-effect waves-light blue darken-2">
分析情感
<i class="material-icons right">send</i>
</button>
<div class="ai-result">
<div id="sentiment-loading" style="text-align: center; display: none;">
<div class="loading-spinner"></div>
<p>正在分析文本...</p>
</div>
<div id="sentiment-result">
<p>请输入文本并点击"分析情感"按钮</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 语音识别工具内容 -->
<div id="speech-recognition" class="tool-content">
<div class="card">
<div class="card-content aicard">
<div class="aicard-header">
<span class="card-title">语音识别</span>
<p>使用浏览器的Web Speech API进行实时语音识别。</p>
</div>
<div class="ai-demo">
<div style="text-align: center; margin: 20px 0;">
<button id="start-speech" class="mic-btn">
<i class="material-icons">mic</i>
</button>
<p style="margin-top: 10px;">点击麦克风开始语音识别</p>
</div>
<div class="ai-result">
<h5>识别结果:</h5>
<div id="speech-result">
<p>等待语音输入...</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<p>管锥国 数学工具集 © 2023 | 由 <a href="https://github.com/GuanZhuiGuo" target="_blank">GuanZhuiGuo</a> 开发</p>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
// 全局函数定义 - 确保在任何时候都可用
function generateExcelCode(type) {
console.log(`开始生成${type}代码 - 全局调用`);
const requirementField = type === 'vba' ?
document.getElementById('vba-requirement') :
document.getElementById('formula-requirement');
if (!requirementField) {
console.error(`找不到${type}需求输入框`);
alert(`找不到${type}需求输入框`);
return;
}
const requirement = requirementField.value.trim();
if (!requirement) {
alert('请输入需求描述');
return;
}
const loadingEl = document.getElementById('excel-loading');
const resultEl = document.getElementById('excel-code-result');
if (!loadingEl || !resultEl) {
console.error('未找到加载指示器或结果显示元素');
alert('未找到加载指示器或结果显示元素');
return;
}
loadingEl.style.display = 'block';
resultEl.style.display = 'none';
// 使用增强的模拟模型生成代码
try {
// 模拟处理延时
setTimeout(() => {
let code = '';
if (type === 'vba') {
code = generateEnhancedVBACode(requirement);
} else {
code = generateEnhancedExcelFormula(requirement);
}
displayExcelResult(type, code);
if (loadingEl) loadingEl.style.display = 'none';
if (resultEl) resultEl.style.display = 'block';
}, 1200); // 模拟AI思考时间
} catch (error) {
console.error('代码生成错误:', error);
alert('代码生成错误: ' + error.message);
if (resultEl) {
resultEl.innerHTML = `
<div class="card-panel red lighten-4">
<span class="red-text text-darken-2">生成失败: ${error.message}</span>
</div>
`;
}
if (loadingEl) loadingEl.style.display = 'none';
if (resultEl) resultEl.style.display = 'block';
}
}
// 增强的VBA代码生成
function generateEnhancedVBACode(requirement) {
// 分析需求的关键词
const req = requirement.toLowerCase();
// 特定需求的精确匹配
if (req.includes('循环') && req.includes('a列') && (req.includes('大于100') || req.includes('>100'))) {
return `Sub 标记大于100的单元格()
' 作用: 循环遍历A列数据,如果单元格值大于100则在B列对应位置标红
' 创建者: Excel AI助手
' 创建日期: ${new Date().toLocaleDateString()}
Dim lastRow As Long
Dim i As Long
' 获取A列中最后一行的行号
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' 循环遍历A列中的每个单元格
For i = 1 To lastRow
' 检查当前单元格的值是否大于100
If IsNumeric(Cells(i, 1).Value) Then
If Cells(i, 1).Value > 100 Then
' 如果大于100,则在B列对应位置标红
Cells(i, 2).Interior.Color = RGB(255, 0, 0)
' 可选: 添加标记文本
Cells(i, 2).Value = "超过阈值"
End If
End If
Next i
MsgBox "处理完成!共处理 " & lastRow & " 行数据。", vbInformation
End Sub`;
} else if (req.includes('筛选') || req.includes('过滤')) {
// 分析筛选条件
let filterField = 1; // 默认A列
let filterValue = "100";
let operator = ">";
// 尝试找出列名
if (req.includes('b列')) filterField = 2;
if (req.includes('c列')) filterField = 3;
if (req.includes('d列')) filterField = 4;
// 尝试找出条件
if (req.includes('等于')) operator = "=";
if (req.includes('小于')) operator = "<";
if (req.includes('不等于')) operator = "<>";
// 尝试找出数值
const numMatch = req.match(/\d+/);
if (numMatch) filterValue = numMatch[0];
return `Sub 筛选数据()
' 作用: 对数据应用筛选条件
' 创建者: Excel AI助手
' 创建日期: ${new Date().toLocaleDateString()}
Dim ws As Worksheet
Set ws = ActiveSheet
' 检查是否有数据
If ws.UsedRange.Rows.Count <= 1 Then
MsgBox "没有足够的数据进行筛选!", vbExclamation
Exit Sub
End If
' 获取数据范围
Dim dataRange As Range
Set dataRange = ws.UsedRange
' 确保有表头行
Dim hasHeaders As Boolean
hasHeaders = True ' 假设第一行是表头
' 应用筛选
If ws.FilterMode Then
ws.ShowAllData ' 清除现有筛选
End If
' 启用自动筛选
dataRange.AutoFilter
' 应用筛选条件
dataRange.AutoFilter Field:=${filterField}, Criteria1:="${operator}${filterValue}"
MsgBox "筛选已应用:第" & ${filterField} & "列 " & "${operator}" & " " & "${filterValue}", vbInformation
End Sub`;
} else if (req.includes('求和') || req.includes('汇总')) {
// 分析求和条件
let sumRange = "A:A";
// 尝试找出列名
if (req.includes('a列')) sumRange = "A:A";
if (req.includes('b列')) sumRange = "B:B";
if (req.includes('c列')) sumRange = "C:C";
return `Sub 计算求和()
' 作用: 计算指定列的总和并显示结果
' 创建者: Excel AI助手
' 创建日期: ${new Date().toLocaleDateString()}
Dim ws As Worksheet
Set ws = ActiveSheet
' 检查是否有数据
If ws.UsedRange.Rows.Count <= 1 Then
MsgBox "没有足够的数据进行计算!", vbExclamation
Exit Sub
End If
' 计算总和
Dim totalSum As Double
totalSum = Application.WorksheetFunction.Sum(Range("${sumRange}"))
' 在合适的位置显示结果
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 2
ws.Cells(lastRow, 1).Value = "总和:"
ws.Cells(lastRow, 1).Font.Bold = True
ws.Cells(lastRow, 2).Value = totalSum
ws.Cells(lastRow, 2).NumberFormat = "#,##0.00"
ws.Cells(lastRow, 2).Font.Bold = True
' 添加底部边框
Range(ws.Cells(lastRow - 1, 1), ws.Cells(lastRow - 1, 2)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Range(ws.Cells(lastRow - 1, 1), ws.Cells(lastRow - 1, 2)).Borders(xlEdgeBottom).Weight = xlMedium
MsgBox "${sumRange}列的总和为: " & Format(totalSum, "#,##0.00"), vbInformation
End Sub`;
} else if (req.includes('导出') || req.includes('保存为') || req.includes('另存为')) {
// 分析导出格式
let exportFormat = "xlsx";
if (req.includes('csv')) exportFormat = "csv";
if (req.includes('pdf')) exportFormat = "pdf";
if (req.includes('文本') || req.includes('txt')) exportFormat = "txt";
return `Sub 导出工作表()
' 作用: 将当前工作表导出为${exportFormat}文件
' 创建者: Excel AI助手
' 创建日期: ${new Date().toLocaleDateString()}
Dim ws As Worksheet
Set ws = ActiveSheet
Dim saveFolder As String
Dim saveFileName As String
Dim fullPath As String
' 默认保存到桌面
saveFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\\"
' 创建文件名 (工作表名+日期)
saveFileName = ws.Name & "_" & Format(Date, "yyyymmdd")
' 完整路径
fullPath = saveFolder & saveFileName
' 根据格式选择导出方式
${exportFormat === 'xlsx' ? `
' 保存为Excel文件
ThisWorkbook.SaveAs fullPath & ".xlsx", xlOpenXMLWorkbook
MsgBox "工作表已保存为: " & fullPath & ".xlsx", vbInformation` : ''}
${exportFormat === 'csv' ? `
' 保存为CSV文件
ws.SaveAs fullPath & ".csv", xlCSV
MsgBox "工作表已导出为CSV: " & fullPath & ".csv", vbInformation` : ''}
${exportFormat === 'pdf' ? `
' 保存为PDF文件
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fullPath & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
MsgBox "工作表已导出为PDF: " & fullPath & ".pdf", vbInformation` : ''}
${exportFormat === 'txt' ? `
' 保存为文本文件
ws.SaveAs fullPath & ".txt", xlTextWindows
MsgBox "工作表已导出为文本文件: " & fullPath & ".txt", vbInformation` : ''}
End Sub`;
} else {
// 创建一个基于需求的通用模板
return `Sub 自定义操作()
' 作用: ${requirement}
' 创建者: Excel AI助手
' 创建日期: ${new Date().toLocaleDateString()}
Dim ws As Worksheet
Set ws = ActiveSheet
' ===== 初始化 =====