-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathVideoDetail.vue
More file actions
2043 lines (1765 loc) · 55 KB
/
VideoDetail.vue
File metadata and controls
2043 lines (1765 loc) · 55 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
<template>
<div class="video-detail">
<!-- 头部导航 -->
<div class="detail-header">
<a-button type="text" @click="goBack" class="back-btn">
<template #icon>
<icon-left />
</template>
返回
</a-button>
<div class="header-title">
<span v-if="!originalVideoInfo.name">视频详情</span>
<span v-else class="title-with-info">
<span class="title-main">视频详情 - {{ originalVideoInfo.name }}</span>
<span class="title-source" v-if="currentSiteInfo.name">
({{ currentSiteInfo.name }} - ID: {{ originalVideoInfo.id }})
</span>
</span>
</div>
<!-- 收藏按钮 -->
<div class="header-actions" v-if="originalVideoInfo.id">
<a-button
:type="isCurrentFavorited ? 'primary' : 'outline'"
@click="toggleFavorite"
class="favorite-btn"
:loading="favoriteLoading"
>
<template #icon>
<icon-heart-fill v-if="isCurrentFavorited" />
<icon-heart v-else />
</template>
{{ isCurrentFavorited ? '取消收藏' : '收藏' }}
</a-button>
</div>
</div>
<!-- 加载状态 -->
<div v-if="loading" class="loading-container">
<a-spin :size="40" />
<div class="loading-text">正在加载详情...</div>
</div>
<!-- 错误状态 -->
<div v-else-if="error" class="error-container">
<a-result status="error" :title="error" />
<a-button type="primary" @click="loadVideoDetail">重新加载</a-button>
</div>
<!-- 详情内容 -->
<div v-else-if="videoDetail" class="detail-content">
<!-- 默认视频播放器组件 -->
<VideoPlayer
v-if="showVideoPlayer && actualVideoUrl && playerType === 'default'"
:video-url="actualVideoUrl"
:episode-name="currentEpisodeName"
:poster="videoDetail?.vod_pic"
:visible="showVideoPlayer"
:player-type="playerType"
:episodes="currentRouteEpisodes"
:current-episode-index="currentEpisodeIndex"
@close="handlePlayerClose"
@player-change="handlePlayerTypeChange"
@next-episode="handleNextEpisode"
/>
<!-- ArtPlayer 播放器组件 -->
<ArtVideoPlayer
v-if="showVideoPlayer && actualVideoUrl && playerType === 'artplayer'"
:video-url="actualVideoUrl"
:episode-name="currentEpisodeName"
:poster="videoDetail?.vod_pic"
:visible="showVideoPlayer"
:player-type="playerType"
:episodes="currentRouteEpisodes"
:current-episode-index="currentEpisodeIndex"
:auto-next="true"
@close="handlePlayerClose"
@player-change="handlePlayerTypeChange"
@next-episode="handleNextEpisode"
@episode-selected="handleEpisodeSelected"
/>
<!-- 小说阅读器组件 -->
<BookReader
v-if="showBookReader && parsedNovelContent"
:book-detail="videoDetail"
:chapter-content="parsedNovelContent"
:chapters="currentRouteEpisodes"
:current-chapter-index="currentEpisode"
:visible="showBookReader"
@close="handleReaderClose"
@next-chapter="handleNextChapter"
@prev-chapter="handlePrevChapter"
@chapter-selected="handleChapterSelected"
@chapter-change="handleChapterChange"
/>
<!-- 漫画阅读器组件 -->
<ComicReader
v-if="showComicReader && parsedComicContent"
:comic-detail="videoDetail"
:comic-title="videoDetail?.vod_name"
:chapter-name="currentEpisodeName"
:chapters="currentRouteEpisodes"
:current-chapter-index="currentEpisode"
:comic-content="parsedComicContent"
:visible="showComicReader"
@close="handleReaderClose"
@next-chapter="handleNextChapter"
@prev-chapter="handlePrevChapter"
@chapter-selected="handleChapterSelected"
@settings-change="handleSettingsChange"
/>
<!-- 视频信息卡片 -->
<a-card class="video-info-card" :class="{ 'collapsed-when-playing': showVideoPlayer || showBookReader }">
<div class="video-header">
<div class="video-poster" @click="showImageModal">
<img :src="videoDetail.vod_pic" :alt="videoDetail.vod_name" @error="handleImageError" />
<div class="poster-overlay">
<icon-eye class="view-icon" />
<span>查看大图</span>
</div>
</div>
<div class="video-meta">
<h1 class="video-title">{{ videoDetail.vod_name }}</h1>
<div class="video-tags">
<a-tag v-if="videoDetail.type_name" color="blue">{{ videoDetail.type_name }}</a-tag>
<a-tag v-if="videoDetail.vod_year" color="green">{{ videoDetail.vod_year }}</a-tag>
<a-tag v-if="videoDetail.vod_area" color="orange">{{ videoDetail.vod_area }}</a-tag>
</div>
<div class="video-info-grid">
<div v-if="videoDetail.vod_director" class="info-item">
<span class="label">导演:</span>
<span class="value">{{ videoDetail.vod_director }}</span>
</div>
<div v-if="videoDetail.vod_actor" class="info-item">
<span class="label">演员:</span>
<span class="value">{{ videoDetail.vod_actor }}</span>
</div>
<div v-if="videoDetail.vod_remarks" class="info-item">
<span class="label">备注:</span>
<span class="value">{{ videoDetail.vod_remarks }}</span>
</div>
</div>
</div>
<div class="video-actions">
<!-- 播放按钮区域 -->
<div v-if="currentEpisodeUrl" class="play-actions">
<a-button type="primary" size="large" @click="playVideo" class="play-btn">
<template #icon>
<icon-play-arrow v-if="!isNovelContent && !isComicContent" />
<icon-book v-else-if="isNovelContent" />
<icon-image v-else-if="isComicContent" />
</template>
{{ isNovelContent ? '开始阅读' : isComicContent ? '开始看漫画' : '播放视频' }}
</a-button>
<a-button @click="copyPlayUrl" class="copy-btn">
<template #icon>
<icon-copy />
</template>
复制链接
</a-button>
</div>
</div>
</div>
<!-- 剧情简介 -->
<div v-if="videoDetail.vod_content" class="video-description">
<h3>剧情简介</h3>
<div class="description-content" :class="{ expanded: descriptionExpanded }">
{{ videoDetail.vod_content }}
</div>
<a-button
v-if="videoDetail.vod_content.length > 200"
type="text"
@click="toggleDescription"
class="expand-btn"
>
{{ descriptionExpanded ? '收起' : '展开' }}
</a-button>
</div>
</a-card>
<!-- 播放线路和选集组件 -->
<EpisodeSelector
:video-detail="videoDetail"
:current-route="currentRoute"
:current-episode="currentEpisode"
@route-change="switchRoute"
@episode-change="selectEpisode"
/>
</div>
<!-- v-viewer 图片查看器 -->
<div v-viewer="viewerOptions" class="viewer" v-show="false">
<img
v-for="(imageData, index) in viewerImageData"
:key="index"
:src="imageData.src"
:alt="imageData.name"
:data-source="imageData.src"
:title="imageData.name"
/>
</div>
<!-- 解析提示弹窗 -->
<ActionDialog
:visible="showParseDialog"
:title="parseDialogConfig.title"
:width="400"
@close="showParseDialog = false"
>
<div class="parse-dialog-content">
<div class="parse-message">
{{ parseDialogConfig.message }}
</div>
<div class="parse-hint">
<div class="hint-icon">
<icon-eye />
</div>
<div class="hint-text">
敬请期待后续版本支持!
</div>
</div>
</div>
<template #footer>
<div class="parse-dialog-footer">
<a-button type="primary" @click="showParseDialog = false">
我知道了
</a-button>
</div>
</template>
</ActionDialog>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Message } from '@arco-design/web-vue'
import videoService from '@/api/services/video'
import { useSiteStore } from '@/stores/siteStore'
import { useFavoriteStore } from '@/stores/favoriteStore'
import { useHistoryStore } from '@/stores/historyStore'
import { usePageStateStore } from '@/stores/pageStateStore'
import VideoPlayer from '@/components/players/VideoPlayer.vue'
import ArtVideoPlayer from '@/components/players/ArtVideoPlayer.vue'
import EpisodeSelector from '@/components/players/EpisodeSelector.vue'
import BookReader from '@/components/readers/BookReader.vue'
import ComicReader from '@/components/readers/ComicReader.vue'
import ActionDialog from '@/components/actions/ActionDialog.vue'
import {
IconLeft,
IconPlayArrow,
IconCopy,
IconHeart,
IconHeartFill,
IconEye,
IconBook,
IconImage
} from '@arco-design/web-vue/es/icon'
const route = useRoute()
const router = useRouter()
const siteStore = useSiteStore()
const favoriteStore = useFavoriteStore()
const historyStore = useHistoryStore()
const pageStateStore = usePageStateStore()
// 响应式数据
const loading = ref(false)
const error = ref('')
const videoDetail = ref(null)
const originalVideoInfo = ref({
id: '',
name: '',
pic: '',
year: '',
area: '',
type: '',
remarks: '',
content: '',
actor: '',
director: ''
})
const descriptionExpanded = ref(false)
const currentRoute = ref(0)
const currentEpisode = ref(0)
const favoriteLoading = ref(false)
// 当前使用的站源信息(可能是全局站源或临时站源)
const currentSiteInfo = ref({
name: '',
api: '',
key: ''
})
// 视频播放器相关
const showVideoPlayer = ref(false)
// 解析后的播放URL(用于T4接口解析结果)
const parsedVideoUrl = ref('')
// 小说阅读器相关
const showBookReader = ref(false)
// 解析后的小说内容(用于T4接口解析结果)
const parsedNovelContent = ref(null)
// 漫画阅读器相关
const showComicReader = ref(false)
// 解析后的漫画内容(用于T4接口解析结果)
const parsedComicContent = ref(null)
// 解析提示弹窗相关
const showParseDialog = ref(false)
const parseDialogConfig = ref({
title: '',
message: '',
type: '' // 'sniff' 或 'parse'
})
// 从localStorage读取用户的播放器偏好,默认为'default'
const getPlayerPreference = () => {
try {
const saved = localStorage.getItem('drplayer_preferred_player_type')
return saved && ['default', 'artplayer'].includes(saved) ? saved : 'default'
} catch (error) {
console.warn('读取播放器偏好失败:', error)
return 'default'
}
}
// 保存播放器偏好到localStorage
const savePlayerPreference = (type) => {
try {
localStorage.setItem('drplayer_preferred_player_type', type)
console.log('播放器偏好已保存:', type)
} catch (error) {
console.warn('保存播放器偏好失败:', error)
}
}
const playerType = ref(getPlayerPreference()) // 'default' 或 'artplayer'
// 图片查看器相关
const viewerImages = ref([])
const viewerImageData = ref([])
const viewerOptions = ref({
inline: false,
button: true,
navbar: true,
title: true,
toolbar: {
zoomIn: 1,
zoomOut: 1,
oneToOne: 1,
reset: 1,
prev: 1,
play: {
show: 1,
size: 'large',
},
next: 1,
rotateLeft: 1,
rotateRight: 1,
flipHorizontal: 1,
flipVertical: 1,
},
tooltip: true,
movable: true,
zoomable: true,
rotatable: true,
scalable: true,
transition: true,
fullscreen: true,
keyboard: true,
backdrop: true,
})
// 计算属性
const playRoutes = computed(() => {
if (!videoDetail.value?.vod_play_from || !videoDetail.value?.vod_play_url) {
return []
}
const fromList = videoDetail.value.vod_play_from.split('$$$')
const urlList = videoDetail.value.vod_play_url.split('$$$')
return fromList.map((name, index) => ({
name: name.trim(),
episodes: parseEpisodes(urlList[index] || '')
}))
})
// 解析选集数据
const parseEpisodes = (urlString) => {
if (!urlString) return []
return urlString.split('#').map(item => {
const [name, url] = item.split('$')
return {
name: name?.trim() || '未知集数',
url: url?.trim() || ''
}
}).filter(item => item.url)
}
// 当前线路的选集列表
const currentRouteEpisodes = computed(() => {
return playRoutes.value[currentRoute.value]?.episodes || []
})
const currentEpisodeUrl = computed(() => {
const episodes = playRoutes.value[currentRoute.value]?.episodes || []
const episode = episodes[currentEpisode.value]
return episode?.url || ''
})
// 实际播放URL(优先使用解析后的URL)
const actualVideoUrl = computed(() => {
return parsedVideoUrl.value || currentEpisodeUrl.value
})
const currentEpisodeName = computed(() => {
const episodes = playRoutes.value[currentRoute.value]?.episodes || []
const episode = episodes[currentEpisode.value]
return episode?.name || '未知选集'
})
const currentEpisodeIndex = computed(() => {
return currentEpisode.value
})
const isCurrentFavorited = computed(() => {
if (!originalVideoInfo.value.id || !currentSiteInfo.value.api) return false
return favoriteStore.isFavorited(originalVideoInfo.value.id, currentSiteInfo.value.api)
})
// 判断当前内容是否为小说
const isNovelContent = computed(() => {
return parsedNovelContent.value !== null
})
// 判断当前内容是否为漫画
const isComicContent = computed(() => {
return showComicReader.value
})
// 方法
const loadVideoDetail = async () => {
if (!route.params.id) {
error.value = '视频ID不能为空'
return
}
// 从路由参数中获取原始视频信息
originalVideoInfo.value = {
id: route.params.id,
name: route.query.name || '',
pic: route.query.pic || '',
year: route.query.year || '',
area: route.query.area || '',
type: route.query.type || '',
type_name: route.query.type_name || '',
remarks: route.query.remarks || '',
content: route.query.content || '',
actor: route.query.actor || '',
director: route.query.director || ''
}
// 检查是否有当前站点
if (!siteStore.nowSite) {
error.value = '请先选择一个视频源'
return
}
loading.value = true
error.value = ''
// 检查是否从收藏、历史或推送进入,如果是则优先调用T4详情接口获取最新数据
const fromCollection = route.query.fromCollection === 'true'
const fromHistory = route.query.fromHistory === 'true'
const fromPush = route.query.fromPush === 'true'
const fromSpecialAction = route.query.fromSpecialAction === 'true'
try {
// 确定使用的站源信息
let module, apiUrl, siteName, extend
if ((fromCollection || fromHistory || fromPush||fromSpecialAction) && route.query.tempSiteKey) {
// 调试:打印接收到的路由参数
console.log('VideoDetail接收到的路由参数:', route.query)
console.log('tempSiteExt参数值:', route.query.tempSiteExt)
// 从收藏、历史或推送进入,使用临时站源信息,不影响全局状态
module = route.query.tempSiteKey
apiUrl = route.query.tempSiteApi
siteName = route.query.tempSiteName
extend = route.query.tempSiteExt || null
const sourceType = fromCollection ? '收藏' : fromHistory ? '历史' : '推送'
console.log(`从${sourceType}进入,使用临时站源:`, {
siteName,
module,
apiUrl,
extend
})
} else {
// 正常进入,使用全局站源
const currentSite = siteStore.nowSite
module = currentSite.key || currentSite.name
apiUrl = currentSite.api
siteName = currentSite.name
extend = currentSite.ext || null
}
// 设置当前使用的站源信息
currentSiteInfo.value = {
name: siteName,
api: apiUrl,
key: module,
ext: extend
}
console.log('获取视频详情:', {
videoId: route.params.id,
module: module,
apiUrl: apiUrl,
extend: extend,
fromCollection: fromCollection,
usingTempSite: fromCollection && route.query.tempSiteKey
})
if (fromCollection) {
console.log('从收藏进入,优先调用T4详情接口获取最新数据')
}
// 从收藏进入时跳过缓存,强制获取最新数据
const videoInfo = await videoService.getVideoDetails(module, route.params.id, apiUrl, fromCollection, extend)
if (videoInfo) {
// 添加API信息用于收藏
videoInfo.module = module
videoInfo.api_url = apiUrl
videoInfo.site_name = siteName
videoDetail.value = videoInfo
console.log('视频详情获取成功:', videoInfo)
// 处理历史记录恢复
const historyRoute = route.query.historyRoute
const historyEpisode = route.query.historyEpisode
if (historyRoute && historyEpisode) {
console.log('检测到历史记录参数,准备恢复播放位置:', { historyRoute, historyEpisode })
// 等待DOM更新和计算属性更新后恢复历史记录位置
nextTick(() => {
// 再次等待,确保playRoutes计算属性已完全更新
setTimeout(() => {
console.log('开始恢复历史记录,当前playRoutes长度:', playRoutes.value.length)
if (playRoutes.value.length > 0) {
restoreHistoryPosition(historyRoute, historyEpisode)
} else {
console.warn('playRoutes为空,无法恢复历史记录')
}
}, 100)
})
} else {
// 如果没有历史记录参数,确保默认选择第一个线路和选集
nextTick(() => {
setTimeout(() => {
if (playRoutes.value.length > 0 && currentRoute.value === 0) {
console.log('初始化默认播放位置')
currentRoute.value = 0
if (currentRouteEpisodes.value.length > 0) {
currentEpisode.value = 0
}
}
}, 100)
})
}
} else {
error.value = '未找到视频详情'
}
} catch (err) {
console.error('加载视频详情失败:', err)
error.value = err.message || '加载失败,请稍后重试'
} finally {
loading.value = false
}
}
const toggleFavorite = async () => {
if (!originalVideoInfo.value.id || !currentSiteInfo.value.api) return
favoriteLoading.value = true
try {
if (isCurrentFavorited.value) {
const success = favoriteStore.removeFavorite(originalVideoInfo.value.id, currentSiteInfo.value.api)
if (success) {
Message.success('已取消收藏')
}
} else {
// 构建收藏数据,优先使用列表数据,缺失时使用详情接口数据
const favoriteData = {
vod_id: originalVideoInfo.value.id,
vod_name: originalVideoInfo.value.name || videoDetail.value?.vod_name || '',
vod_pic: originalVideoInfo.value.pic || videoDetail.value?.vod_pic || '',
vod_year: originalVideoInfo.value.year || videoDetail.value?.vod_year || '',
vod_area: originalVideoInfo.value.area || videoDetail.value?.vod_area || '',
vod_type: originalVideoInfo.value.type || videoDetail.value?.vod_type || '',
type_name: originalVideoInfo.value.type_name || videoDetail.value?.type_name || '',
vod_remarks: originalVideoInfo.value.remarks || videoDetail.value?.vod_remarks || '',
vod_content: originalVideoInfo.value.content || videoDetail.value?.vod_content || '',
vod_actor: originalVideoInfo.value.actor || videoDetail.value?.vod_actor || '',
vod_director: originalVideoInfo.value.director || videoDetail.value?.vod_director || '',
// 播放相关数据使用详情接口返回的数据
vod_play_from: videoDetail.value?.vod_play_from || '',
vod_play_url: videoDetail.value?.vod_play_url || '',
// API信息使用当前站源信息
module: currentSiteInfo.value.key,
api_url: currentSiteInfo.value.api,
site_name: currentSiteInfo.value.name,
ext: currentSiteInfo.value.ext || null // 添加站源扩展配置
}
const success = favoriteStore.addFavorite(favoriteData)
if (success) {
Message.success('收藏成功')
} else {
Message.warning('该视频已在收藏列表中')
}
}
} catch (error) {
Message.error('操作失败,请稍后重试')
console.error('收藏操作失败:', error)
} finally {
favoriteLoading.value = false
}
}
const goBack = () => {
// 检查是否有来源页面信息
const sourceRouteName = route.query.sourceRouteName
const sourceRouteParams = route.query.sourceRouteParams
const sourceRouteQuery = route.query.sourceRouteQuery
const fromSearch = route.query.fromSearch // 新增:标识是否来自搜索
console.log('goBack 调用,来源信息:', { sourceRouteName, fromSearch, sourceRouteParams, sourceRouteQuery });
if (sourceRouteName) {
try {
// 解析来源页面的参数和查询
const params = sourceRouteParams ? JSON.parse(sourceRouteParams) : {}
const query = sourceRouteQuery ? JSON.parse(sourceRouteQuery) : {}
console.log('返回来源页面:', sourceRouteName, { params, query, fromSearch });
// 根据来源页面类型和是否来自搜索处理状态恢复
if (sourceRouteName === 'Video') {
if (fromSearch === 'true') {
// 来自Video页面的搜索结果,需要恢复搜索状态
console.log('从Video页面搜索返回,恢复搜索状态');
const savedSearchState = pageStateStore.getPageState('search');
if (savedSearchState && savedSearchState.keyword && !pageStateStore.isStateExpired('search')) {
console.log('发现保存的搜索状态,将恢复搜索结果:', savedSearchState);
// 添加搜索恢复标识
query._restoreSearch = 'true';
}
} else {
// 来自Video页面的分类列表,恢复分类状态
console.log('从Video页面分类返回,恢复分类状态');
if (query.activeKey) {
query._returnToActiveKey = query.activeKey;
console.log('设置返回分类:', query.activeKey);
}
// 检查是否有保存的Video页面状态
const savedVideoState = pageStateStore.getPageState('video');
if (savedVideoState && !pageStateStore.isStateExpired('video')) {
console.log('发现保存的Video页面状态,将恢复状态而非重新加载');
}
}
} else if (sourceRouteName === 'Home') {
// 返回Home页面,检查搜索状态
const savedSearchState = pageStateStore.getPageState('search');
if (savedSearchState && savedSearchState.keyword && !pageStateStore.isStateExpired('search')) {
console.log('发现保存的搜索状态,将恢复搜索结果');
// 添加搜索恢复标识
query._restoreSearch = 'true';
}
}
// 跳转到来源页面
router.push({
name: sourceRouteName,
params: params,
query: query
})
} catch (error) {
console.error('解析来源页面信息失败:', error)
// 如果解析失败,使用默认的返回方式
router.back()
}
} else {
console.log('没有来源信息,使用默认返回方式')
// 没有来源信息,使用默认的返回方式
router.back()
}
}
const handleImageError = (event) => {
// 防止无限循环:如果已经是默认图片,就不再重新设置
if (event.target.src.includes('default-poster.svg')) {
return
}
// 使用BASE_URL确保在任何路由层级和部署环境下都能正确访问
const basePath = import.meta.env.BASE_URL || '/'
event.target.src = `${basePath}default-poster.svg`
event.target.style.objectFit = 'contain'
event.target.style.backgroundColor = '#f7f8fa'
}
const showImageModal = () => {
if (videoDetail.value?.vod_pic) {
// 设置当前图片到 viewer,包含图片URL和名称
viewerImages.value = [videoDetail.value.vod_pic]
viewerImageData.value = [{
src: videoDetail.value.vod_pic,
name: videoDetail.value.vod_name || '未知标题'
}]
// 等待下一个 tick 后显示 viewer
setTimeout(() => {
const viewerElement = document.querySelector('.viewer')
if (viewerElement && viewerElement.$viewer) {
viewerElement.$viewer.show()
}
}, 100)
}
}
const restoreHistoryPosition = (historyRoute, historyEpisode) => {
try {
console.log('开始恢复历史记录位置:', { historyRoute, historyEpisode })
// 查找对应的线路和选集
const routes = playRoutes.value
const targetRoute = routes.find(route => route.name === historyRoute)
if (targetRoute) {
console.log('找到历史线路:', targetRoute.name)
// 设置当前线路索引
const routeIndex = routes.indexOf(targetRoute)
currentRoute.value = routeIndex
// 等待currentRouteEpisodes更新后查找选集
nextTick(() => {
const episodes = currentRouteEpisodes.value
const targetEpisode = episodes.find(ep => ep.name === historyEpisode)
if (targetEpisode) {
console.log('找到历史选集:', targetEpisode.name)
// 设置当前选集索引
const episodeIndex = episodes.indexOf(targetEpisode)
currentEpisode.value = episodeIndex
console.log('历史记录位置恢复成功:', { routeIndex, episodeIndex })
} else {
console.warn('未找到历史选集:', historyEpisode)
// 如果找不到历史选集,默认选择第一个选集
if (episodes.length > 0) {
currentEpisode.value = 0
}
}
})
} else {
console.warn('未找到历史线路:', historyRoute)
// 如果找不到历史线路,默认选择第一个线路
if (routes.length > 0) {
currentRoute.value = 0
nextTick(() => {
if (currentRouteEpisodes.value.length > 0) {
currentEpisode.value = 0
}
})
}
}
} catch (error) {
console.error('恢复历史记录位置失败:', error)
}
}
const toggleDescription = () => {
descriptionExpanded.value = !descriptionExpanded.value
}
const switchRoute = (index) => {
currentRoute.value = index
currentEpisode.value = 0 // 切换线路时重置选集
}
// 处理EpisodeSelector组件的事件
const handleRouteChange = (routeIndex) => {
switchRoute(routeIndex)
}
const handleEpisodeChange = (episodeIndex) => {
selectEpisode(episodeIndex)
}
// 处理VideoPlayer组件的关闭事件
const handlePlayerClose = () => {
showVideoPlayer.value = false
}
// 处理阅读器组件的关闭事件(小说和漫画)
const handleReaderClose = () => {
showBookReader.value = false
showComicReader.value = false
parsedNovelContent.value = null
parsedComicContent.value = null
}
// 处理阅读器章节切换事件
const handleChapterChange = (chapterIndex) => {
console.log('切换到章节:', chapterIndex)
selectEpisode(chapterIndex)
}
// 处理下一章事件
const handleNextChapter = () => {
if (currentEpisode.value < currentRouteEpisodes.value.length - 1) {
const nextIndex = currentEpisode.value + 1
console.log('切换到下一章:', nextIndex)
selectEpisode(nextIndex)
}
}
// 处理上一章事件
const handlePrevChapter = () => {
if (currentEpisode.value > 0) {
const prevIndex = currentEpisode.value - 1
console.log('切换到上一章:', prevIndex)
selectEpisode(prevIndex)
}
}
// 处理章节选择事件
const handleChapterSelected = (chapterIndex) => {
console.log('选择章节:', chapterIndex)
selectEpisode(chapterIndex)
}
// 处理播放器类型变更
const handlePlayerTypeChange = (newType) => {
console.log('切换播放器类型:', newType)
playerType.value = newType
// 保存用户的播放器偏好
savePlayerPreference(newType)
}
// 处理自动下一集事件
const handleNextEpisode = (nextEpisodeIndex) => {
console.log('切换到下一集:', nextEpisodeIndex)
// 检查索引是否有效
if (nextEpisodeIndex >= 0 && nextEpisodeIndex < currentRouteEpisodes.value.length) {
selectEpisode(nextEpisodeIndex)
} else {
console.warn('无效的选集索引:', nextEpisodeIndex)
Message.warning('无法播放下一集')
}
}
// 处理选集选择事件
const handleEpisodeSelected = (episode) => {
console.log('从播放器选择剧集:', episode)
// 查找选集在当前路线中的索引
const episodeIndex = currentRouteEpisodes.value.findIndex(ep =>
ep.name === episode.name && ep.url === episode.url
)
if (episodeIndex !== -1) {
selectEpisode(episodeIndex)
} else {
console.warn('未找到选集:', episode)
Message.warning('选集切换失败')
}
}
// 处理阅读器设置变更事件
const handleSettingsChange = (settings) => {
console.log('阅读器设置变更:', settings)
// 这里可以添加设置保存逻辑,如果需要的话
}
const selectEpisode = async (index) => {
currentEpisode.value = index
// 获取当前选集的URL和线路信息
const episodeUrl = currentRouteEpisodes.value[index]?.url
const routeName = playRoutes.value[currentRoute.value]?.name
if (!episodeUrl) {
console.log('选集URL为空,无法播放')
Message.error('选集URL为空,无法播放')
return
}
try {
console.log('开始解析选集播放地址:', { episodeUrl, routeName })
Message.info('正在解析播放地址...')
// 调用T4播放API进行解析
const parseParams = {
play: episodeUrl,
flag: routeName,
apiUrl: currentSiteInfo.value.api,
extend: currentSiteInfo.value.ext
}
const parseResult = await videoService.parseEpisodePlayUrl(currentSiteInfo.value.key, parseParams)
console.log('选集播放解析结果:', parseResult)
// 根据解析结果处理播放
if (parseResult.playType === 'direct') {
// parse:0 - 直链播放
// 检查是否为小说内容
if (parseResult.url && parseResult.url.startsWith('novel://')) {
console.log('检测到小说内容:', parseResult.url)
try {
// 解析小说内容
const novelData = parseResult.url.replace('novel://', '')
const novelContent = JSON.parse(novelData)
console.log('解析小说内容成功:', novelContent)
// 设置小说内容并显示阅读器
parsedNovelContent.value = {
title: novelContent.title || currentEpisodeName.value,
content: novelContent.content || '',
chapterIndex: index,
totalChapters: currentRouteEpisodes.value.length
}
// 关闭视频播放器和漫画阅读器,显示小说阅读器
showVideoPlayer.value = false
showComicReader.value = false
showBookReader.value = true
Message.success(`开始阅读: ${novelContent.title || currentEpisodeName.value}`)
} catch (error) {
console.error('解析小说内容失败:', error)
Message.error('解析小说内容失败')
}
} else if (parseResult.url && parseResult.url.startsWith('pics://')) {
console.log('检测到漫画内容:', parseResult.url)
try {
// 解析漫画内容
const comicData = parseResult.url.replace('pics://', '')
const imageUrls = comicData.split('&&').filter(url => url.trim())
console.log('解析漫画内容成功:', imageUrls)
// 设置漫画内容并显示阅读器
parsedComicContent.value = {
title: currentEpisodeName.value,
images: imageUrls,
chapterIndex: index,
totalChapters: currentRouteEpisodes.value.length
}
// 关闭视频播放器和小说阅读器,显示漫画阅读器
showVideoPlayer.value = false
showBookReader.value = false
showComicReader.value = true
Message.success(`开始看漫画: ${currentEpisodeName.value}`)
} catch (error) {
console.error('解析漫画内容失败:', error)
Message.error('解析漫画内容失败')
}
} else {
// 普通视频内容
console.log('启动内置播放器播放直链视频:', parseResult.url)
parsedVideoUrl.value = parseResult.url
parsedNovelContent.value = null
parsedComicContent.value = null
showBookReader.value = false