-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathEpisodeSelector.vue
More file actions
433 lines (371 loc) · 9.96 KB
/
EpisodeSelector.vue
File metadata and controls
433 lines (371 loc) · 9.96 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
<template>
<a-card v-if="playRoutes.length > 0" class="play-section">
<h3>播放线路</h3>
<!-- 线路选择 -->
<div class="route-tabs">
<a-button
v-for="(route, index) in playRoutes"
:key="index"
:type="currentRoute === index ? 'primary' : 'outline'"
@click="switchRoute(index)"
class="route-btn"
>
<span class="route-name">{{ route.name }}</span>
<a-badge :count="route.episodes.length" class="route-badge" />
</a-button>
</div>
<!-- 选集列表 -->
<div v-if="currentRouteEpisodes.length > 0" class="episodes-section">
<div class="episodes-header">
<h4>选集列表 ({{ currentRouteEpisodes.length }}集)</h4>
<div class="episodes-controls">
<!-- 排序按钮 -->
<a-button
type="text"
size="small"
@click="toggleEpisodeSort"
:title="episodeSortOrder === 'asc' ? '切换为倒序' : '切换为正序'"
class="sort-btn"
>
<template #icon>
<icon-sort-ascending v-if="episodeSortOrder === 'asc'" />
<icon-sort-descending v-else />
</template>
{{ episodeSortOrder === 'asc' ? '正序' : '倒序' }}
</a-button>
<!-- 显示策略选择 -->
<a-select
v-model="episodeDisplayStrategy"
@change="changeDisplayStrategy"
size="small"
class="strategy-select"
:style="{ width: '150px' }"
position="bl"
:popup-container="'body'"
>
<template #prefix>
<icon-settings />
</template>
<a-option value="full">完整显示</a-option>
<a-option value="smart">智能去重</a-option>
<a-option value="simple">精简显示</a-option>
</a-select>
<!-- 布局选项 -->
<a-select
v-model="episodeLayoutColumns"
@change="changeLayoutColumns"
size="small"
class="layout-select"
:style="{ width: '120px' }"
position="bl"
:popup-container="'body'"
>
<template #prefix>
<icon-menu />
</template>
<a-option value="smart">智能</a-option>
<a-option value="12">12列</a-option>
<a-option value="9">9列</a-option>
<a-option value="6">6列</a-option>
<a-option value="3">3列</a-option>
</a-select>
</div>
</div>
<div class="episodes-grid" :style="{ '--episodes-columns': actualLayoutColumns }">
<a-button
v-for="(episode, index) in currentRouteEpisodes"
:key="index"
:type="currentEpisode === index ? 'primary' : 'outline'"
@click="selectEpisode(index)"
class="episode-btn"
size="small"
:title="episode.name"
>
<span class="episode-text">{{ episode.displayName || episode.name }}</span>
</a-button>
</div>
</div>
</a-card>
<!-- 无播放资源提示 -->
<a-card v-else class="no-play-section">
<a-empty description="暂无播放资源" />
</a-card>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import {
IconSortAscending,
IconSortDescending,
IconSettings,
IconMenu
} from '@arco-design/web-vue/es/icon'
// Props
const props = defineProps({
videoDetail: {
type: Object,
default: () => ({})
},
currentRoute: {
type: Number,
default: 0
},
currentEpisode: {
type: Number,
default: 0
}
})
// Emits
const emit = defineEmits(['route-change', 'episode-change'])
// 响应式数据
const episodeSortOrder = ref('asc') // 'asc' 正序, 'desc' 倒序
const episodeDisplayStrategy = ref(localStorage.getItem('episodeDisplayStrategy') || 'full') // 'full' 完整显示, 'smart' 智能去重, 'simple' 精简显示
const episodeLayoutColumns = ref(localStorage.getItem('episodeLayoutColumns') || 'smart') // 每行显示的按钮数量,支持智能布局
// 解析选集数据
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 processEpisodeName = (name) => {
if (!name) return '未知'
switch (episodeDisplayStrategy.value) {
case 'simple':
// 精简显示:只保留数字部分
const match = name.match(/\d+/)
return match ? match[0] : name
case 'smart':
// 智能去重:移除常见前缀
return name.replace(/^(第|集|话|期|EP|Episode)\s*/i, '').replace(/\s*(集|话|期)$/i, '')
case 'full':
default:
// 完整显示
return name
}
}
// 计算属性
const playRoutes = computed(() => {
if (!props.videoDetail?.vod_play_from || !props.videoDetail?.vod_play_url) {
return []
}
const fromList = props.videoDetail.vod_play_from.split('$$$')
const urlList = props.videoDetail.vod_play_url.split('$$$')
return fromList.map((name, index) => ({
name: name.trim(),
episodes: parseEpisodes(urlList[index] || '')
}))
})
const currentRouteEpisodes = computed(() => {
let episodes = playRoutes.value[props.currentRoute]?.episodes || []
// 应用显示策略
episodes = episodes.map(episode => ({
...episode,
displayName: processEpisodeName(episode.name)
}))
// 应用排序
if (episodeSortOrder.value === 'desc') {
episodes = [...episodes].reverse()
}
return episodes
})
// 智能布局计算属性
const smartLayoutColumns = computed(() => {
if (!currentRouteEpisodes.value.length) return 12
// 计算最长的选集名称长度
const maxNameLength = Math.max(...currentRouteEpisodes.value.map(episode =>
(episode.displayName || episode.name || '').length
))
// 以总宽度60为基础,每个字符大约占用1个单位宽度
// 考虑按钮的padding、margin等额外空间,每个按钮需要额外2-3个单位
const buttonWidth = maxNameLength + 1 // 文字宽度 + 按钮内边距等
// 计算能容纳的列数,范围在1-12之间
let columns = Math.floor(60 / buttonWidth)
// 确保列数在1-12范围内
columns = Math.max(1, Math.min(12, columns))
console.log('智能布局计算:', { maxNameLength, buttonWidth, columns })
return columns
})
// 实际使用的列数
const actualLayoutColumns = computed(() => {
if (episodeLayoutColumns.value === 'smart') {
return smartLayoutColumns.value
}
return parseInt(episodeLayoutColumns.value) || 12
})
// 方法
const switchRoute = (index) => {
emit('route-change', index)
}
const selectEpisode = (index) => {
emit('episode-change', index)
}
const toggleEpisodeSort = () => {
episodeSortOrder.value = episodeSortOrder.value === 'asc' ? 'desc' : 'asc'
}
const changeDisplayStrategy = (value) => {
episodeDisplayStrategy.value = value
localStorage.setItem('episodeDisplayStrategy', value)
}
const changeLayoutColumns = (value) => {
episodeLayoutColumns.value = value
localStorage.setItem('episodeLayoutColumns', value)
}
// 监听显示策略变化
watch(episodeDisplayStrategy, () => {
// 触发重新计算
})
</script>
<style scoped>
.play-section {
margin-bottom: 20px;
border-radius: 12px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
.play-section h3 {
font-size: 20px;
font-weight: 600;
color: var(--color-text-1);
margin-bottom: 20px;
}
.route-tabs {
display: flex;
gap: 12px;
margin-bottom: 24px;
flex-wrap: wrap;
}
.route-btn {
position: relative;
border-radius: 8px;
font-weight: 500;
transition: all 0.2s ease;
min-width: 120px;
height: 40px;
}
.route-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.route-name {
margin-right: 8px;
}
.route-badge {
font-size: 12px;
}
.episodes-section {
margin-top: 20px;
}
.episodes-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
flex-wrap: wrap;
gap: 12px;
}
.episodes-header h4 {
font-size: 16px;
font-weight: 600;
color: var(--color-text-1);
margin: 0;
}
.episodes-controls {
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
}
.sort-btn {
border-radius: 6px;
transition: all 0.2s ease;
}
.strategy-select,
.layout-select {
border-radius: 6px;
}
.episodes-grid {
display: grid;
grid-template-columns: repeat(var(--episodes-columns, 12), minmax(0, 1fr));
gap: 8px;
margin-top: 16px;
width: 100%;
box-sizing: border-box;
}
.episode-btn {
border-radius: 6px;
transition: all 0.2s ease;
min-height: 36px;
font-size: 13px;
width: 100%;
max-width: 100%;
box-sizing: border-box;
overflow: hidden;
}
.episode-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.episode-text {
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
padding: 0 8px;
}
.no-play-section {
text-align: center;
padding: 40px;
border-radius: 12px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
/* 响应式设计 */
@media (max-width: 768px) {
.episodes-header {
flex-direction: column;
align-items: flex-start;
}
.episodes-controls {
width: 100%;
justify-content: space-between;
}
.strategy-select,
.layout-select {
width: 120px !important;
}
.route-tabs {
gap: 8px;
}
.route-btn {
min-width: 100px;
height: 36px;
font-size: 12px;
}
.episodes-grid {
gap: 6px;
}
.episode-btn {
min-height: 32px;
font-size: 12px;
}
}
@media (max-width: 480px) {
.episodes-grid {
grid-template-columns: repeat(6, 1fr);
}
.route-btn {
min-width: 80px;
height: 32px;
font-size: 11px;
}
.episode-btn {
min-height: 28px;
font-size: 11px;
}
}
</style>