-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathVideoCard.vue
More file actions
322 lines (281 loc) · 7.34 KB
/
VideoCard.vue
File metadata and controls
322 lines (281 loc) · 7.34 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
<template>
<div
class="video-card"
:class="{ 'last-clicked': isLastClicked }"
@click="handleCardClick"
>
<div class="card-poster">
<img :src="cardImage" :alt="cardTitle" @error="handleImageError" />
<!-- vod_remarks 浮层 (仅video类型显示) -->
<div v-if="props.type === 'video' && item.vod_remarks" class="video-remarks-overlay" v-html="item.vod_remarks"></div>
<div class="card-overlay">
<a-button type="primary" size="small" class="play-btn">
<template #icon>
<icon-play-arrow />
</template>
播放
</a-button>
<a-button
v-if="props.type !== 'video'"
type="outline"
size="small"
class="image-btn"
@click.stop="handleImageClick"
>
<template #icon>
<icon-eye />
</template>
</a-button>
<a-button
v-if="showActionButton"
type="outline"
size="small"
:class="actionButtonClass"
@click.stop="handleActionClick"
>
<template #icon>
<component :is="actionButtonIcon" />
</template>
</a-button>
</div>
</div>
<div class="card-info">
<h3 class="card-title" :title="cardTitle">{{ cardTitle }}</h3>
<div class="card-meta">
<a-tag v-if="item.type_name" size="small" color="blue">{{ item.type_name }}</a-tag>
<a-tag v-if="item.year" size="small" color="green">{{ item.year }}</a-tag>
<a-tag v-if="item.area" size="small" color="orange">{{ item.area }}</a-tag>
</div>
<!-- 历史记录特有信息 -->
<div v-if="showHistoryInfo" class="card-history">
<div class="history-episode">
<icon-play-arrow />
<span>{{ item.current_route_name }} - {{ item.current_episode_name }}</span>
</div>
</div>
<div v-if="showSourceInfo" class="card-source">
<icon-link />
<span>{{ item.api_info.site_name }}</span>
</div>
<div v-if="showTimeInfo" class="card-time">
{{ timeLabel }} {{ formatDate(item[timeField]) }}
</div>
</div>
</div>
</template>
<script setup>
import { computed } from 'vue'
import {
IconPlayArrow,
IconEye,
IconHeartFill,
IconDelete
} from '@arco-design/web-vue/es/icon'
import { useVisitedStore } from '@/stores/visitedStore'
const props = defineProps({
item: {
type: Object,
required: true
},
type: {
type: String,
default: 'favorite', // 'favorite' | 'history' | 'video'
validator: (value) => ['favorite', 'history', 'video'].includes(value)
}
})
const emit = defineEmits(['card-click', 'image-click', 'action-click'])
// 访问状态管理
const visitedStore = useVisitedStore()
// 计算属性
const showHistoryInfo = computed(() => props.type === 'history')
const showSourceInfo = computed(() => props.type !== 'video')
const showTimeInfo = computed(() => props.type !== 'video')
const showActionButton = computed(() => {
return props.type === 'favorite' || props.type === 'history'
})
const actionButtonClass = computed(() => {
return props.type === 'favorite' ? 'remove-btn' : 'delete-btn'
})
const actionButtonIcon = computed(() => {
return props.type === 'favorite' ? IconHeartFill : IconDelete
})
const timeLabel = computed(() => {
return props.type === 'favorite' ? '收藏于' : '观看于'
})
const timeField = computed(() => {
return props.type === 'favorite' ? 'created_at' : 'updated_at'
})
// 处理不同数据格式
const cardImage = computed(() => {
return props.type === 'video' ? props.item.vod_pic : props.item.pic
})
const cardTitle = computed(() => {
return props.type === 'video' ? props.item.vod_name : props.item.name
})
// 检查是否是最后点击的视频
const isLastClicked = computed(() => {
const videoId = props.type === 'video' ? props.item.vod_id : props.item.id
return visitedStore.isLastClicked(videoId)
})
// 事件处理
const handleCardClick = () => {
emit('card-click', props.item)
}
const handleImageClick = () => {
emit('image-click', props.item)
}
const handleActionClick = () => {
emit('action-click', props.item)
}
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 formatDate = (dateString) => {
const date = new Date(dateString)
return date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'short',
day: 'numeric'
})
}
</script>
<style scoped>
.video-card {
background: var(--color-bg-2);
border-radius: 8px;
overflow: hidden;
transition: all 0.3s ease;
cursor: pointer;
border: 1px solid var(--color-border-2);
}
.video-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
border-color: var(--color-primary-light-3);
}
/* 最后点击的视频样式 */
.video-card.last-clicked .card-title {
color: var(--color-primary-6);
}
.card-poster {
position: relative;
width: 100%;
height: 240px;
overflow: hidden;
}
.card-poster img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.video-card:hover .card-poster img {
transform: scale(1.05);
}
.card-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
opacity: 0;
transition: opacity 0.3s ease;
}
.video-card:hover .card-overlay {
opacity: 1;
}
.play-btn {
background: var(--color-primary);
border: none;
}
.image-btn, .remove-btn, .delete-btn {
background: rgba(255, 255, 255, 0.9);
border: none;
color: var(--color-text-1);
}
.remove-btn:hover {
background: var(--color-danger);
color: white;
}
.delete-btn:hover {
background: var(--color-danger);
color: white;
}
.card-info {
padding: 16px;
}
.card-title {
font-size: 16px;
font-weight: 600;
margin: 0 0 8px 0;
color: var(--color-text-1);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-meta {
display: flex;
gap: 4px;
margin-bottom: 8px;
flex-wrap: wrap;
}
.card-history {
margin-bottom: 8px;
}
.history-episode {
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: var(--color-primary);
background: var(--color-primary-light-1);
padding: 4px 8px;
border-radius: 4px;
}
.card-source {
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: var(--color-text-3);
margin-bottom: 4px;
}
.card-time {
font-size: 12px;
color: var(--color-text-4);
}
.video-remarks-overlay {
position: absolute;
top: 4px;
right: 4px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 3px 6px;
border-radius: 4px;
font-size: 10px;
font-weight: 500;
max-width: 60%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(4px);
}
/* 最后点击的视频样式 */
.video-card.last-clicked .card-title {
color: var(--color-primary);
}
</style>