-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathBookReader.vue
More file actions
1018 lines (883 loc) · 24.7 KB
/
Copy pathBookReader.vue
File metadata and controls
1018 lines (883 loc) · 24.7 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="book-reader" v-if="visible">
<!-- 阅读器头部 -->
<ReaderHeader
:chapter-name="chapterName"
:book-title="bookTitle"
:visible="visible"
:chapters="chapters"
:current-chapter-index="currentChapterIndex"
:reading-settings="readingSettings"
@close="handleClose"
@settings-change="handleShowSettings"
@next-chapter="handleNextChapter"
@prev-chapter="handlePrevChapter"
@chapter-selected="handleChapterSelected"
@chapter-list="handleToggleChapterPanel"
/>
<div class="reader-main-layout">
<div
v-if="showChapterPanel && isMobileViewport()"
class="chapter-sidebar-mask"
@click="showChapterPanel = false"
></div>
<aside class="chapter-sidebar" :class="{ open: showChapterPanel }">
<div class="chapter-sidebar-header">
<div class="chapter-sidebar-heading">
<div class="chapter-sidebar-title">章节目录</div>
<button type="button" class="chapter-sidebar-close" @click="showChapterPanel = false">×</button>
</div>
<div class="chapter-sidebar-book" :title="bookTitle">{{ bookTitle || '当前小说' }}</div>
<div class="chapter-sidebar-count">共 {{ chapters.length }} 章,当前第 {{ currentChapterIndex + 1 }} 章</div>
<a-input-search
v-model="chapterSearchKeyword"
allow-clear
placeholder="搜索章节名或序号"
class="chapter-sidebar-search"
/>
</div>
<div
class="chapter-sidebar-list"
ref="chapterPanelListRef"
@scroll="handleChapterListScroll"
>
<div
class="chapter-sidebar-spacer"
:style="{
paddingTop: `${virtualTopPadding}px`,
paddingBottom: `${virtualBottomPadding}px`
}"
>
<button
v-for="chapter in virtualChapters"
:key="chapter.index"
type="button"
class="chapter-sidebar-item"
:class="{
active: chapter.index === currentChapterIndex,
read: chapter.index < currentChapterIndex
}"
@click="handlePanelChapterSelect(chapter.index)"
>
<span class="chapter-sidebar-number">{{ chapter.index + 1 }}</span>
<span class="chapter-sidebar-item-title" :title="chapter.name">{{ chapter.name }}</span>
<span class="chapter-sidebar-current" v-if="chapter.index === currentChapterIndex">当前</span>
</button>
</div>
</div>
<div v-if="filteredChapters.length === 0" class="chapter-sidebar-empty">
<a-empty description="未找到匹配章节" />
</div>
</aside>
<!-- 阅读内容区域 -->
<main
class="reader-content"
ref="readerContentRef"
:style="contentStyles"
@touchstart.passive="handleReaderTouchStart"
@touchmove.passive="handleReaderTouchMove"
@touchend="handleReaderTouchEnd"
@wheel.passive="handleReaderWheel"
>
<!-- 加载状态 -->
<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="retryLoad">重新加载</a-button>
</div>
<!-- 章节内容 -->
<div v-else-if="chapterContent" class="chapter-container">
<!-- 章节标题 -->
<h1 class="chapter-title" :style="titleStyles">
{{ chapterContent.title }}
</h1>
<!-- 章节正文 -->
<div class="chapter-text" :style="textStyles" v-html="formattedContent"></div>
<!-- 章节导航 -->
<div class="chapter-navigation">
<a-button
:disabled="currentChapterIndex <= 0"
@click="handlePrevChapter"
class="nav-btn prev-btn"
>
<template #icon>
<icon-left />
</template>
上一章
</a-button>
<span class="chapter-progress">
{{ currentChapterIndex + 1 }} / {{ chapters.length }}
</span>
<a-button
:disabled="currentChapterIndex >= chapters.length - 1"
@click="handleNextChapter"
class="nav-btn next-btn"
>
下一章
<template #icon>
<icon-right />
</template>
</a-button>
</div>
<div
v-if="canAutoNextChapter && bottomSwipeProgress > 0"
class="bottom-scroll-hint"
:class="{ ready: bottomSwipeProgress >= 1 }"
>
{{ bottomSwipeProgress >= 1 ? '松开进入下一章' : '继续上滑进入下一章' }}
</div>
</div>
<!-- 空状态 -->
<div v-else class="empty-container">
<a-empty description="暂无章节内容" />
</div>
</main>
</div>
<!-- 阅读设置对话框 -->
<ReadingSettingsDialog
:visible="showSettingsDialog"
:settings="readingSettings"
@close="showSettingsDialog = false"
@settings-change="handleSettingsChange"
/>
</div>
</template>
<script setup>
import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
import { Message } from '@arco-design/web-vue'
import ReaderHeader from './ReaderHeader.vue'
import ReadingSettingsDialog from './ReadingSettingsDialog.vue'
import { IconLeft, IconRight } from '@arco-design/web-vue/es/icon'
import videoService from '@/api/services/video'
// Props
const props = defineProps({
visible: {
type: Boolean,
default: false
},
bookTitle: {
type: String,
default: ''
},
chapterName: {
type: String,
default: ''
},
chapters: {
type: Array,
default: () => []
},
currentChapterIndex: {
type: Number,
default: 0
},
bookDetail: {
type: Object,
default: () => ({})
}
})
// Emits
const emit = defineEmits([
'close',
'next-chapter',
'prev-chapter',
'chapter-selected',
'settings-change'
])
// 响应式数据
const loading = ref(false)
const error = ref('')
const chapterContent = ref(null)
const showSettingsDialog = ref(false)
const showChapterPanel = ref(!isMobileViewport())
const chapterSearchKeyword = ref('')
const chapterPanelListRef = ref(null)
const readerContentRef = ref(null)
const chapterListScrollTop = ref(0)
const chapterListViewportHeight = ref(0)
const bottomSwipeProgress = ref(0)
const touchStartY = ref(0)
const touchLastY = ref(0)
const bottomSwipeDistance = ref(0)
const bottomSwipeTriggered = ref(false)
const lastAutoNextAt = ref(0)
const CHAPTER_ITEM_HEIGHT = 38
const CHAPTER_LIST_BUFFER = 12
const AUTO_NEXT_COOLDOWN = 2000
// 阅读设置
const readingSettings = ref({
fontSize: 16,
lineHeight: 1.8,
fontFamily: 'system-ui',
backgroundColor: '#ffffff',
textColor: '#333333',
maxWidth: 800,
theme: 'light' // light, dark, sepia
})
// 从localStorage加载阅读设置
const loadReadingSettings = () => {
try {
const saved = localStorage.getItem('drplayer_reading_settings')
if (saved) {
const settings = JSON.parse(saved)
readingSettings.value = { ...readingSettings.value, ...settings }
}
} catch (error) {
console.warn('加载阅读设置失败:', error)
}
}
// 保存阅读设置到localStorage
const saveReadingSettings = () => {
try {
localStorage.setItem('drplayer_reading_settings', JSON.stringify(readingSettings.value))
} catch (error) {
console.warn('保存阅读设置失败:', error)
}
}
// 计算样式
const contentStyles = computed(() => ({
backgroundColor: readingSettings.value.backgroundColor,
color: readingSettings.value.textColor
}))
const titleStyles = computed(() => ({
fontSize: `${readingSettings.value.fontSize + 4}px`,
lineHeight: readingSettings.value.lineHeight,
fontFamily: readingSettings.value.fontFamily,
color: readingSettings.value.textColor
}))
const textStyles = computed(() => ({
fontSize: `${readingSettings.value.fontSize}px`,
lineHeight: readingSettings.value.lineHeight,
fontFamily: readingSettings.value.fontFamily,
maxWidth: `${readingSettings.value.maxWidth}px`,
color: readingSettings.value.textColor
}))
const filteredChapters = computed(() => {
const keyword = chapterSearchKeyword.value.trim().toLowerCase()
return props.chapters
.map((chapter, index) => ({
...chapter,
index,
name: chapter.name || `第${index + 1}章`
}))
.filter(chapter => {
if (!keyword) return true
return chapter.name.toLowerCase().includes(keyword) || String(chapter.index + 1).includes(keyword)
})
})
const virtualStartIndex = computed(() => {
if (filteredChapters.value.length === 0) return 0
return Math.max(0, Math.floor(chapterListScrollTop.value / CHAPTER_ITEM_HEIGHT) - CHAPTER_LIST_BUFFER)
})
const virtualVisibleCount = computed(() => {
const viewportRows = Math.ceil((chapterListViewportHeight.value || 360) / CHAPTER_ITEM_HEIGHT)
return viewportRows + CHAPTER_LIST_BUFFER * 2
})
const virtualEndIndex = computed(() => {
return Math.min(filteredChapters.value.length, virtualStartIndex.value + virtualVisibleCount.value)
})
const virtualChapters = computed(() => {
return filteredChapters.value.slice(virtualStartIndex.value, virtualEndIndex.value)
})
const virtualTopPadding = computed(() => virtualStartIndex.value * CHAPTER_ITEM_HEIGHT)
const virtualBottomPadding = computed(() => {
return Math.max(0, (filteredChapters.value.length - virtualEndIndex.value) * CHAPTER_ITEM_HEIGHT)
})
const canAutoNextChapter = computed(() => props.currentChapterIndex < props.chapters.length - 1)
// 格式化章节内容
const formattedContent = computed(() => {
if (!chapterContent.value?.content) return ''
// 将换行符转换为段落
return chapterContent.value.content
.split('\n')
.filter(line => line.trim())
.map(line => `<p>${line.trim()}</p>`)
.join('')
})
// 解析novel://协议的内容
const parseNovelContent = (novelUrl) => {
try {
if (!novelUrl.startsWith('novel://')) {
throw new Error('不是有效的小说内容格式')
}
const jsonStr = novelUrl.substring(8) // 移除 "novel://" 前缀
const data = JSON.parse(jsonStr)
if (!data.title || !data.content) {
throw new Error('小说内容格式不完整')
}
return data
} catch (error) {
console.error('解析小说内容失败:', error)
throw new Error('解析小说内容失败: ' + error.message)
}
}
// 加载章节内容
const loadChapterContent = async (chapterIndex) => {
if (!props.chapters[chapterIndex]) {
error.value = '章节不存在'
return
}
loading.value = true
error.value = ''
chapterContent.value = null
try {
const chapter = props.chapters[chapterIndex]
console.log('加载章节:', chapter)
// 调用T4 API获取章节内容
const response = await videoService.getPlayUrl(
props.bookDetail.module,
chapter.url,
props.bookDetail.api_url,
props.bookDetail.ext
)
console.log('章节内容响应:', response)
if (response && response.url) {
// 解析novel://协议的内容
const novelData = parseNovelContent(response.url)
chapterContent.value = novelData
console.log('解析后的章节内容:', novelData)
} else {
throw new Error('获取章节内容失败')
}
} catch (err) {
console.error('加载章节内容失败:', err)
error.value = err.message || '加载章节内容失败'
Message.error(error.value)
} finally {
loading.value = false
}
}
// 重试加载
const retryLoad = () => {
loadChapterContent(props.currentChapterIndex)
}
// 事件处理
const handleClose = () => {
emit('close')
}
const handleNextChapter = () => {
if (props.currentChapterIndex < props.chapters.length - 1) {
emit('next-chapter')
}
}
const handlePrevChapter = () => {
if (props.currentChapterIndex > 0) {
emit('prev-chapter')
}
}
const handleChapterSelected = (index) => {
emit('chapter-selected', index)
}
function isMobileViewport() {
return window.matchMedia('(max-width: 768px)').matches
}
const updateChapterListViewport = async () => {
await nextTick()
if (chapterPanelListRef.value) {
chapterListViewportHeight.value = chapterPanelListRef.value.clientHeight
chapterListScrollTop.value = chapterPanelListRef.value.scrollTop
}
}
const handleChapterListScroll = () => {
if (chapterPanelListRef.value) {
chapterListScrollTop.value = chapterPanelListRef.value.scrollTop
chapterListViewportHeight.value = chapterPanelListRef.value.clientHeight
}
}
const findFilteredChapterPosition = (chapterIndex) => {
return filteredChapters.value.findIndex(chapter => chapter.index === chapterIndex)
}
const scrollChapterPositionIntoView = async (position, block = 'center') => {
await nextTick()
const list = chapterPanelListRef.value
if (!list || position < 0) return
const itemTop = position * CHAPTER_ITEM_HEIGHT
const itemBottom = itemTop + CHAPTER_ITEM_HEIGHT
const viewportHeight = list.clientHeight
let nextScrollTop = list.scrollTop
if (block === 'center') {
nextScrollTop = itemTop - viewportHeight / 2 + CHAPTER_ITEM_HEIGHT / 2
} else if (itemTop < list.scrollTop) {
nextScrollTop = itemTop
} else if (itemBottom > list.scrollTop + viewportHeight) {
nextScrollTop = itemBottom - viewportHeight
}
list.scrollTop = Math.max(0, nextScrollTop)
chapterListScrollTop.value = list.scrollTop
chapterListViewportHeight.value = viewportHeight
}
const scrollActiveChapterIntoView = async () => {
await updateChapterListViewport()
await scrollChapterPositionIntoView(findFilteredChapterPosition(props.currentChapterIndex), 'center')
}
const scrollReaderToTop = async () => {
resetBottomSwipe()
await nextTick()
if (readerContentRef.value) {
readerContentRef.value.scrollTop = 0
}
}
const resetBottomSwipe = () => {
bottomSwipeProgress.value = 0
bottomSwipeDistance.value = 0
bottomSwipeTriggered.value = false
}
const canTriggerAutoNext = () => Date.now() - lastAutoNextAt.value >= AUTO_NEXT_COOLDOWN
const triggerAutoNextChapter = () => {
if (!canAutoNextChapter.value || bottomSwipeTriggered.value || !canTriggerAutoNext()) return false
bottomSwipeTriggered.value = true
lastAutoNextAt.value = Date.now()
handleNextChapter()
return true
}
const isReaderScrolledToBottom = () => {
const reader = readerContentRef.value
if (!reader) return false
return reader.scrollTop + reader.clientHeight >= reader.scrollHeight - 4
}
const handleReaderTouchStart = (event) => {
if (!canAutoNextChapter.value || !canTriggerAutoNext()) return
const touch = event.touches[0]
touchStartY.value = touch.clientY
touchLastY.value = touch.clientY
bottomSwipeDistance.value = 0
bottomSwipeTriggered.value = false
}
const handleReaderTouchMove = (event) => {
if (!canAutoNextChapter.value || !canTriggerAutoNext() || !isReaderScrolledToBottom()) {
bottomSwipeProgress.value = 0
return
}
const touch = event.touches[0]
const deltaY = touchLastY.value - touch.clientY
touchLastY.value = touch.clientY
if (deltaY <= 0) {
bottomSwipeDistance.value = Math.max(0, bottomSwipeDistance.value + deltaY)
} else {
bottomSwipeDistance.value += deltaY
}
bottomSwipeProgress.value = Math.min(1, bottomSwipeDistance.value / 72)
}
const handleReaderTouchEnd = () => {
if (bottomSwipeProgress.value >= 1) {
triggerAutoNextChapter()
}
resetBottomSwipe()
}
const handleReaderWheel = (event) => {
if (!canAutoNextChapter.value || event.deltaY <= 0 || !isReaderScrolledToBottom()) return
if (triggerAutoNextChapter()) {
window.setTimeout(resetBottomSwipe, AUTO_NEXT_COOLDOWN)
}
}
const handleToggleChapterPanel = async () => {
showChapterPanel.value = !showChapterPanel.value
if (showChapterPanel.value) {
await scrollActiveChapterIntoView()
}
}
const handlePanelChapterSelect = (index) => {
if (isMobileViewport()) {
showChapterPanel.value = false
}
chapterSearchKeyword.value = ''
handleChapterSelected(index)
scrollReaderToTop()
}
const handleShowSettings = (event) => {
if (event.showDialog) {
showSettingsDialog.value = true
}
}
const handleSettingsChange = (newSettings) => {
readingSettings.value = { ...readingSettings.value, ...newSettings }
saveReadingSettings()
emit('settings-change', readingSettings.value)
}
watch(() => chapterSearchKeyword.value, async () => {
chapterListScrollTop.value = 0
await nextTick()
if (chapterPanelListRef.value) {
chapterPanelListRef.value.scrollTop = 0
updateChapterListViewport()
}
})
// 监听章节变化
watch(() => props.currentChapterIndex, (newIndex) => {
if (props.visible && newIndex >= 0) {
loadChapterContent(newIndex)
scrollReaderToTop()
scrollActiveChapterIntoView()
}
}, { immediate: true })
// 监听可见性变化
watch(() => props.visible, (visible) => {
if (visible && props.currentChapterIndex >= 0) {
showChapterPanel.value = !isMobileViewport()
loadChapterContent(props.currentChapterIndex)
scrollActiveChapterIntoView()
} else {
showChapterPanel.value = false
chapterSearchKeyword.value = ''
}
})
// 键盘快捷键
const handleKeydown = (event) => {
if (!props.visible) return
const target = event.target
const isInputFocused = target instanceof HTMLElement && ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName)
switch (event.key) {
case 'ArrowLeft':
if (isInputFocused) return
event.preventDefault()
handlePrevChapter()
break
case 'ArrowRight':
if (isInputFocused) return
event.preventDefault()
handleNextChapter()
break
case 'Escape':
event.preventDefault()
if (showChapterPanel.value) {
showChapterPanel.value = false
return
}
handleClose()
break
}
}
// 组件挂载
onMounted(() => {
loadReadingSettings()
document.addEventListener('keydown', handleKeydown)
})
// 组件卸载
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown)
})
</script>
<style scoped>
.book-reader {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--color-bg-1);
z-index: 1000;
display: flex;
flex-direction: column;
overflow: hidden;
}
.reader-main-layout {
position: relative;
flex: 1;
min-height: 0;
display: flex;
overflow: hidden;
}
.chapter-sidebar {
width: 0;
flex: 0 0 0;
min-height: 0;
display: flex;
flex-direction: column;
border-right: 0;
background: var(--color-bg-1);
box-shadow: none;
overflow: hidden;
z-index: 2;
transition: width 0.2s ease, flex-basis 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.chapter-sidebar.open {
width: 320px;
flex-basis: 320px;
border-right: 1px solid var(--color-border-2);
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.04);
}
.chapter-sidebar-header {
flex-shrink: 0;
padding: 14px 14px 12px;
border-bottom: 1px solid var(--color-border-2);
background: var(--color-bg-2);
}
.chapter-sidebar-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.chapter-sidebar-title {
color: var(--color-text-1);
font-size: 16px;
font-weight: 700;
}
.chapter-sidebar-close {
display: none;
width: 30px;
height: 30px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--color-text-2);
font-size: 24px;
line-height: 1;
cursor: pointer;
}
.chapter-sidebar-book {
color: var(--color-text-1);
font-size: 13px;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.chapter-sidebar-count {
margin: 2px 0 10px;
color: var(--color-text-3);
font-size: 12px;
}
.chapter-sidebar-search {
width: 100%;
}
.chapter-sidebar-list {
flex: 1;
min-height: 0;
padding: 8px;
overflow-y: auto;
}
.chapter-sidebar-item {
display: grid;
grid-template-columns: 38px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
width: 100%;
min-height: 38px;
padding: 7px 8px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--color-text-1);
text-align: left;
cursor: pointer;
transition: background 0.18s ease, color 0.18s ease;
}
.chapter-sidebar-item:hover {
background: var(--color-fill-2);
}
.chapter-sidebar-item.active {
background: var(--color-primary-light-1);
color: var(--color-text-1);
font-weight: 600;
}
.chapter-sidebar-item.read:not(.active) {
color: var(--color-text-2);
}
.chapter-sidebar-number {
color: var(--color-text-3);
font-size: 12px;
font-weight: 600;
text-align: right;
}
.chapter-sidebar-item.active .chapter-sidebar-number {
color: var(--color-text-3);
}
.chapter-sidebar-item-title {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 13px;
}
.chapter-sidebar-current {
padding: 1px 6px;
border-radius: 999px;
background: var(--color-fill-3);
color: var(--color-text-1);
font-size: 11px;
font-weight: 500;
}
.chapter-sidebar-empty {
padding: 24px 12px;
}
.chapter-sidebar-mask {
display: none;
}
.reader-content {
flex: 1;
min-width: 0;
min-height: 0;
overflow-y: auto;
padding: 20px;
transition: background-color 0.3s ease, color 0.3s ease;
}
.loading-container,
.error-container,
.empty-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
min-height: 400px;
}
.loading-text {
margin-top: 16px;
color: var(--color-text-2);
font-size: 14px;
}
.chapter-container {
max-width: 1000px;
margin: 0 auto;
padding: 40px 20px;
}
.chapter-title {
text-align: center;
margin-bottom: 40px;
font-weight: 600;
border-bottom: 2px solid var(--color-border-2);
padding-bottom: 20px;
}
.chapter-text {
margin: 0 auto 60px;
text-align: justify;
word-break: break-word;
hyphens: auto;
}
.chapter-text :deep(p) {
margin-bottom: 1.5em;
text-indent: 2em;
}
.chapter-text :deep(p:first-child) {
margin-top: 0;
}
.chapter-text :deep(p:last-child) {
margin-bottom: 0;
}
.chapter-navigation {
display: grid;
grid-template-columns: minmax(110px, 1fr) auto minmax(110px, 1fr);
align-items: center;
gap: 14px;
padding: 18px 0 8px;
border-top: 1px solid var(--color-border-2);
margin-top: 40px;
}
.nav-btn {
width: 100%;
min-width: 0;
height: 40px;
border-radius: 999px;
font-weight: 500;
}
.prev-btn {
justify-self: start;
}
.next-btn {
justify-self: end;
}
.chapter-progress {
padding: 4px 10px;
border-radius: 999px;
background: var(--color-fill-2);
color: var(--color-text-2);
font-size: 13px;
font-weight: 500;
white-space: nowrap;
}
.bottom-scroll-hint {
margin: 12px auto 0;
width: fit-content;
padding: 6px 14px;
border-radius: 999px;
background: var(--color-fill-2);
color: var(--color-text-3);
font-size: 12px;
transition: background 0.2s ease, color 0.2s ease;
}
.bottom-scroll-hint.ready {
background: var(--color-primary-light-1);
color: var(--color-primary-6);
}
/* 响应式设计 */
@media (max-width: 768px) {
.reader-main-layout {
display: block;
}
.chapter-sidebar-mask {
position: absolute;
inset: 0;
display: block;
background: rgba(0, 0, 0, 0.42);
opacity: 1;
z-index: 5;
}
.chapter-sidebar {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: min(82vw, 320px);
max-width: calc(100vw - 52px);
transform: translateX(-104%);
transition: transform 0.24s ease;
box-shadow: 6px 0 22px rgba(0, 0, 0, 0.18);
z-index: 6;
}
.reader-main-layout .chapter-sidebar.open {
transform: translateX(0) !important;
}
.chapter-sidebar-close {
display: inline-flex;
align-items: center;
justify-content: center;
}
.chapter-sidebar-header {
padding: 12px;
}
.chapter-sidebar-list {
height: calc(100dvh - 172px);
padding: 6px;
}
.chapter-sidebar-item {
min-height: 36px;
padding: 6px 8px;
border-radius: 7px;
}
.chapter-sidebar-item-title {
font-size: 13px;
}
.reader-content {
height: 100%;
padding: 10px;
}
.chapter-container {
padding: 20px 10px;
}
.chapter-title {
font-size: 20px;
margin-bottom: 30px;
}
.chapter-navigation {
display: grid;
grid-template-columns: minmax(84px, 1fr) auto minmax(84px, 1fr);