-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
777 lines (718 loc) · 34.8 KB
/
index.html
File metadata and controls
777 lines (718 loc) · 34.8 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WeWalk心情旅行</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&display=swap');
body {
font-family: 'Noto Serif SC', 'Microsoft YaHei', Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #faf7f2; /* 优雅米色背景 */
color: #2c2417;
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23d4bc8a' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E"), linear-gradient(to bottom right, #faf7f2, #f1ede4);
min-height: 100vh;
}
.container {
max-width: 800px;
margin: 30px auto;
padding: 25px;
background-color: rgba(252, 249, 240, 0.95); /* 半透明背景 */
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1), 0 3px 10px rgba(0, 0, 0, 0.05);
border-radius: 12px;
border: 1px solid rgba(232, 225, 211, 0.7); /* 边框 */
backdrop-filter: blur(10px);
position: relative;
overflow: hidden;
}
.container::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, transparent, #d4bc8a, transparent);
opacity: 0.7;
}
h1 {
text-align: center;
color: #1a1207; /* 深黑色 */
margin-bottom: 30px;
font-weight: 600;
letter-spacing: 2px;
font-size: 2.2rem;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
position: relative;
padding-bottom: 15px;
}
h1::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 2px;
background: linear-gradient(to right, transparent, #d4bc8a, transparent);
}
.input-container {
margin-bottom: 30px;
position: relative;
}
label {
display: block;
margin-bottom: 12px;
font-size: 18px;
font-weight: 500;
color: #1a1207; /* 深黑色 */
letter-spacing: 0.5px;
}
textarea {
width: 100%;
height: 150px;
padding: 18px;
border: 1px solid #d4bc8a; /* 金色边框 */
border-radius: 10px;
resize: vertical;
font-size: 16px;
background-color: rgba(255, 253, 247, 0.8); /* 更浅的米色 */
color: #2c2417;
box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.05);
transition: all 0.3s ease;
font-family: 'Noto Serif SC', 'Microsoft YaHei', Arial, sans-serif;
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23d4bc8a' fill-opacity='0.03' fill-rule='evenodd'/%3E%3C/svg%3E");
}
textarea:focus {
border-color: #b49f65;
box-shadow: 0 0 10px rgba(212, 188, 138, 0.5);
outline: none;
}
.button-container {
text-align: center;
margin: 30px 0;
}
button {
background: linear-gradient(135deg, #2c2417 0%, #1a1207 100%); /* 黑色渐变 */
color: #f8f5ed; /* 米色文字 */
border: none;
padding: 14px 35px;
font-size: 16px;
cursor: pointer;
border-radius: 10px;
transition: all 0.3s;
margin: 0 5px;
letter-spacing: 1px;
font-weight: 500;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
position: relative;
overflow: hidden;
font-family: 'Noto Serif SC', 'Microsoft YaHei', Arial, sans-serif;
z-index: 1;
}
button::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
transition: 0.5s;
z-index: -1;
}
button::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(0deg, transparent, transparent, rgba(212, 188, 138, 0.1));
z-index: -2;
}
button:hover {
background: linear-gradient(135deg, #3a3225 0%, #2c2417 100%); /* 浅一点的黑色 */
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}
button:hover::before {
left: 100%;
}
.description {
text-align: center;
margin: 25px 0;
color: #777;
font-style: italic;
font-size: 15px;
line-height: 1.6;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
.route-container {
margin-top: 30px;
border: 1px solid #d4bc8a; /* 金色边框 */
padding: 28px;
border-radius: 10px;
background-color: rgba(255, 253, 247, 0.8); /* 更浅的米色 */
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05), inset 0 1px 2px rgba(255, 255, 255, 0.7);
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23d4bc8a' fill-opacity='0.03' fill-rule='evenodd'/%3E%3C/svg%3E");
}
.route-content {
max-height: 500px;
overflow-y: auto;
padding: 15px;
line-height: 1.8;
color: #2c2417;
}
.route-content::-webkit-scrollbar {
width: 6px;
}
.route-content::-webkit-scrollbar-track {
background: #f1ede4;
border-radius: 10px;
}
.route-content::-webkit-scrollbar-thumb {
background: #d4bc8a;
border-radius: 10px;
}
.module {
display: none;
transition: opacity 0.4s ease;
}
.page {
display: none;
transition: opacity 0.3s ease;
}
.active {
display: block;
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.loading {
text-align: center;
margin: 35px 0;
display: none;
}
.loading-spinner {
border: 4px solid rgba(232, 225, 211, 0.5); /* 淡米色 */
border-top: 4px solid #d4bc8a; /* 金色 */
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1.5s linear infinite;
margin: 0 auto;
box-shadow: 0 0 15px rgba(212, 188, 138, 0.1);
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* 标签页样式 */
.tabs {
display: flex;
justify-content: center;
margin-bottom: 35px;
border-bottom: 1px solid #d4bc8a; /* 金色边框 */
padding-bottom: 8px;
}
.tab {
padding: 14px 30px;
cursor: pointer;
font-size: 18px;
border: none;
background: none;
color: #958569;
transition: all 0.3s;
position: relative;
font-weight: 500;
letter-spacing: 1px;
}
.tab.active {
color: #1a1207; /* 黑色 */
font-weight: 600;
}
.tab.active:after {
content: '';
position: absolute;
bottom: -8px;
left: 0;
width: 100%;
height: 3px;
background: linear-gradient(to right, transparent, #d4bc8a, transparent);
}
.tab:hover:not(.active) {
color: #6a5c3f;
}
/* 导游页面样式 */
.photo-container {
margin: 30px 0;
text-align: center;
position: relative;
}
.photo-preview {
max-width: 100%;
max-height: 350px;
margin: 15px auto;
display: none;
border: 1px solid #d4bc8a; /* 金色边框 */
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
transition: all 0.3s;
filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.1));
}
.video-container {
width: 100%;
max-width: 500px;
margin: 0 auto;
display: none;
position: relative;
}
#video {
width: 100%;
border: 1px solid #d4bc8a; /* 金色边框 */
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}
.landmark-info {
margin-top: 30px;
padding: 28px;
border: 1px solid #d4bc8a; /* 金色边框 */
border-radius: 10px;
background-color: rgba(255, 253, 247, 0.8); /* 更浅的米色 */
display: none;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08), inset 0 1px 2px rgba(255, 255, 255, 0.7);
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23d4bc8a' fill-opacity='0.03' fill-rule='evenodd'/%3E%3C/svg%3E");
}
.landmark-name {
font-size: 24px;
font-weight: 600;
color: #1a1207; /* 黑色 */
margin-bottom: 18px;
border-bottom: 2px solid #d4bc8a;
padding-bottom: 12px;
text-align: center;
letter-spacing: 1px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
.landmark-description {
line-height: 1.8;
color: #2c2417;
font-size: 16px;
text-align: justify;
padding: 0 5px;
}
.file-input {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>WeWalk心情旅行</h1>
<!-- 标签页切换 -->
<div class="tabs">
<button id="route-tab" class="tab active">路线规划</button>
<button id="guide-tab" class="tab">专属导览</button>
</div>
<!-- 路线模块 -->
<div id="route-module" class="module active">
<!-- 第一页 - 心情输入页 -->
<div id="page1" class="page active">
<div class="input-container">
<label for="mood">描绘您的心境与旅途愿景:</label>
<textarea id="mood" placeholder="例如:渴望在静谧古城中徜徉,感受千年文明的脉动,品味地道佳肴与历史风韵的交织..."></textarea>
</div>
<div class="button-container">
<button id="submit-btn">启程探索</button>
</div>
<div class="description">
依据您的情感共鸣与心绪灵感,为您量身定制专属心情之旅
</div>
</div>
<!-- 加载中提示 -->
<div id="loading" class="loading">
<div class="loading-spinner"></div>
<p>正在为您精心编织专属旅程,静候佳音...</p>
</div>
<!-- 第二页 - 路线展示页 -->
<div id="page2" class="page">
<div class="route-container">
<div id="route-content" class="route-content">
<!-- 路线内容将通过JavaScript动态插入 -->
</div>
</div>
<div class="button-container">
<button id="back-btn">重新定制</button>
</div>
</div>
</div>
<!-- 导游模块 -->
<div id="guide-module" class="module">
<div class="description">
捕捉或上传景致映像,即刻获取专业解析与优雅语音讲述
</div>
<!-- 照片预览区域 -->
<div class="photo-container">
<div class="video-container">
<video id="video" autoplay playsinline></video>
</div>
<img id="photo-preview" class="photo-preview" src="fiu.jpg" alt="景点照片预览" style="display: block;" />
</div>
<!-- 操作按钮 -->
<div class="button-container">
<button id="camera-btn" style="display: none;">开启相机</button>
<button id="capture-btn" style="display: none;">定格美景</button>
<button id="retake-btn" style="display: none;">重新拍摄</button>
<button id="reupload-btn" style="display: none;">更换图像</button>
<input type="file" id="file-input" class="file-input" accept="image/*">
<button id="upload-btn" style="display: none;">上传照片</button>
<button id="identify-btn" style="display: none;">景点讲解</button>
</div>
<!-- 景点信息区域 -->
<div id="landmark-info" class="landmark-info">
<div id="landmark-name" class="landmark-name"></div>
<div id="landmark-description" class="landmark-description"></div>
<div class="button-container">
<button id="pause-btn" style="display: none;">暂停讲解</button>
</div>
</div>
<!-- 加载中提示 -->
<div id="guide-loading" class="loading">
<div class="loading-spinner"></div>
<p>正在解析景点精髓,片刻呈现...</p>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 路线模块元素
const page1 = document.getElementById('page1');
const page2 = document.getElementById('page2');
const loading = document.getElementById('loading');
const submitBtn = document.getElementById('submit-btn');
const backBtn = document.getElementById('back-btn');
const moodInput = document.getElementById('mood');
const routeContent = document.getElementById('route-content');
// 导游模块元素
const routeTab = document.getElementById('route-tab');
const guideTab = document.getElementById('guide-tab');
const routeModule = document.getElementById('route-module');
const guideModule = document.getElementById('guide-module');
const cameraBtn = document.getElementById('camera-btn');
const captureBtn = document.getElementById('capture-btn');
const retakeBtn = document.getElementById('retake-btn');
const reuploadBtn = document.getElementById('reupload-btn');
const uploadBtn = document.getElementById('upload-btn');
const fileInput = document.getElementById('file-input');
const identifyBtn = document.getElementById('identify-btn');
const photoPreview = document.getElementById('photo-preview');
const video = document.getElementById('video');
const videoContainer = document.querySelector('.video-container');
const landmarkInfo = document.getElementById('landmark-info');
const landmarkName = document.getElementById('landmark-name');
const landmarkDescription = document.getElementById('landmark-description');
const speakBtn = document.getElementById('speak-btn');
const guideLoading = document.getElementById('guide-loading');
const pauseBtn = document.getElementById('pause-btn');
// 音频元素
let audioElement = null;
// 检测设备类型并显示相应按钮
function detectDevice() {
// 检测是否为移动设备
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (isMobile && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// 移动设备且支持摄像头,显示拍照按钮
cameraBtn.style.display = 'inline-block';
uploadBtn.style.display = 'inline-block';
} else {
// 非移动设备或不支持摄像头,只显示上传按钮
uploadBtn.style.display = 'inline-block';
}
}
// 初始化时检测设备类型
detectDevice();
// 加载默认图片数据
function loadDefaultImage() {
// 显示识别景点按钮
identifyBtn.style.display = 'inline-block';
identifyBtn.disabled = false;
// 通过API获取默认图片数据
fetch('/api/default_image')
.then(response => {
if (!response.ok) {
throw new Error('获取默认图片数据失败');
}
return response.json();
})
.then(data => {
if (data.image) {
// 设置图片数据
imageData = data.image;
// 设置图片预览显示
photoPreview.src = 'data:image/jpeg;base64,' + data.image;
photoPreview.style.display = 'block';
}
})
.catch(error => console.error('加载默认图片失败:', error));
}
// 初始化时加载默认图片
loadDefaultImage();
// 标签页切换
routeTab.addEventListener('click', function() {
routeTab.classList.add('active');
guideTab.classList.remove('active');
routeModule.classList.add('active');
guideModule.classList.remove('active');
// 如果有流媒体流,停止它
stopMediaStream();
});
guideTab.addEventListener('click', function() {
guideTab.classList.add('active');
routeTab.classList.remove('active');
guideModule.classList.add('active');
routeModule.classList.remove('active');
});
// 路线模块功能
submitBtn.addEventListener('click', function() {
const mood = moodInput.value.trim();
if (!mood) {
alert('请描述您的心情或旅行期许');
return;
}
// 显示加载中
page1.classList.remove('active');
loading.style.display = 'block';
// 调用后端API
fetch('/api/analyze_mood', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ mood: mood })
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应不正常');
}
return response.json();
})
.then(data => {
// 隐藏加载中,显示第二页
loading.style.display = 'none';
page2.classList.add('active');
// 将路线内容转换为HTML并显示
routeContent.innerHTML = convertMarkdownToHtml(data.route);
})
.catch(error => {
loading.style.display = 'none';
page1.classList.add('active');
alert('获取路线失败:' + error.message);
});
});
backBtn.addEventListener('click', function() {
page2.classList.remove('active');
page1.classList.add('active');
});
// 导游模块功能
let mediaStream = null;
let imageData = null;
// 打开摄像头
cameraBtn.addEventListener('click', function() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function(stream) {
mediaStream = stream;
video.srcObject = stream;
videoContainer.style.display = 'block';
photoPreview.style.display = 'none';
cameraBtn.style.display = 'none';
captureBtn.style.display = 'inline-block';
uploadBtn.style.display = 'none';
identifyBtn.style.display = 'none';
landmarkInfo.style.display = 'none';
})
.catch(function(error) {
console.error('Error accessing camera: ', error);
alert('无法访问您的相机,请检查权限设置或尝试上传图片。');
});
} else {
alert('您的浏览器不支持相机功能,请使用图片上传。');
}
});
// 拍摄照片
captureBtn.addEventListener('click', function() {
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
// 显示照片预览
photoPreview.src = canvas.toDataURL('image/jpeg');
photoPreview.style.display = 'block';
videoContainer.style.display = 'none';
captureBtn.style.display = 'none';
retakeBtn.style.display = 'inline-block';
identifyBtn.style.display = 'inline-block';
// 保存图片数据
imageData = canvas.toDataURL('image/jpeg').split(',')[1];
});
// 重新拍摄
retakeBtn.addEventListener('click', function() {
if (mediaStream) {
videoContainer.style.display = 'block';
photoPreview.style.display = 'none';
retakeBtn.style.display = 'none';
captureBtn.style.display = 'inline-block';
identifyBtn.style.display = 'none';
landmarkInfo.style.display = 'none';
} else {
cameraBtn.click();
}
});
// 重新上传
reuploadBtn.addEventListener('click', function() {
fileInput.click();
landmarkInfo.style.display = 'none';
identifyBtn.disabled = false; // 确保识别景点按钮不被禁用
});
// 上传图片
uploadBtn.addEventListener('click', function() {
fileInput.click();
});
fileInput.addEventListener('change', function(e) {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function(event) {
// 显示图片预览
photoPreview.src = event.target.result;
photoPreview.style.display = 'block';
videoContainer.style.display = 'none';
captureBtn.style.display = 'none';
// 上传图片后显示重新上传按钮而不是重拍按钮
retakeBtn.style.display = 'none';
reuploadBtn.style.display = 'inline-block';
identifyBtn.style.display = 'inline-block';
identifyBtn.disabled = false; // 重置按钮的disabled属性
cameraBtn.style.display = 'none';
uploadBtn.style.display = 'none';
landmarkInfo.style.display = 'none';
// 保存图片数据
imageData = event.target.result.split(',')[1];
// 停止摄像头流
stopMediaStream();
};
reader.readAsDataURL(file);
}
});
// 识别景点
identifyBtn.addEventListener('click', function() {
if (!imageData) {
alert('请先拍摄或上传景点照片');
return;
}
// 显示加载中
guideLoading.style.display = 'block';
identifyBtn.disabled = true;
// 调用景点识别API
fetch('/api/identify_landmark', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ image: imageData })
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应不正常');
}
return response.json();
})
.then(data => {
// 隐藏加载中
guideLoading.style.display = 'none';
// 重置按钮状态
detectDevice(); // 重新显示拍照/上传按钮
identifyBtn.style.display = 'none';
retakeBtn.style.display = 'none';
reuploadBtn.style.display = 'none';
// 显示景点信息
landmarkName.textContent = data.landmark_name;
landmarkDescription.textContent = data.description;
landmarkInfo.style.display = 'block';
// 停止当前播放的音频
if (audioElement) {
audioElement.pause();
}
// 如果有音频URL,自动播放
if (data.audio_url) {
audioElement = new Audio(data.audio_url);
audioElement.play();
pauseBtn.style.display = 'inline-block';
pauseBtn.textContent = '暂停';
}
})
.catch(error => {
guideLoading.style.display = 'none';
identifyBtn.disabled = false;
alert('识别景点失败:' + error.message);
});
});
// 暂停/继续播放
pauseBtn.addEventListener('click', function() {
if (!audioElement) return;
if (audioElement.paused) {
audioElement.play();
pauseBtn.textContent = '暂停';
} else {
audioElement.pause();
pauseBtn.textContent = '继续';
}
});
// 停止摄像头流
function stopMediaStream() {
if (mediaStream) {
mediaStream.getTracks().forEach(track => track.stop());
mediaStream = null;
}
}
// TTS功能
function speakText(text) {
if ('speechSynthesis' in window) {
// 停止当前正在讲说的内容
window.speechSynthesis.cancel();
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = 'zh-CN';
window.speechSynthesis.speak(utterance);
} else {
alert('您的浏览器不支持语音合成功能,无法提供语音讲解。');
}
}
// Markdown转HTML函数
function convertMarkdownToHtml(markdown) {
if (!markdown) return '';
// 转换标题
let html = markdown
.replace(/^# (.*$)/gm, '<h1>$1</h1>')
.replace(/^## (.*$)/gm, '<h2>$1</h2>')
.replace(/^### (.*$)/gm, '<h3>$1</h3>')
.replace(/^#### (.*$)/gm, '<h4>$1</h4>');
// 转换粗体
html = html.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
// 转换列表项
html = html.replace(/^- (.*$)/gm, '<li>$1</li>');
html = html.replace(/<li>(.*)<\/li>/gm, function(match) {
return '<ul>' + match + '</ul>';
}).replace(/<\/ul><ul>/g, '');
// 转换段落
html = html.replace(/^(?!<[uh]|<li)(.+)$/gm, '<p>$1</p>');
return html;
}
});
</script>
</body>
</html>