瀏覽代碼

feat(VideoPlayer): 根据视频 URL 自动匹配封面

lsc 4 天之前
父節點
當前提交
a0c2737a2c
共有 2 個文件被更改,包括 28 次插入 和 3 次删除
  1. 1 1
      .trae/rules/git-commit-message.md
  2. 27 2
      src/views/components/element/VideoElement/VideoPlayer/index.vue

+ 1 - 1
.trae/rules/git-commit-message.md

@@ -3,4 +3,4 @@ alwaysApply: true
 scene: git_message
 scene: git_message
 ---
 ---
 
 
-在此处编写规则,自定义 AI 生成提交信息的风格。要中文,不能是繁体中文。
+在此处编写规则,自定义 AI 生成提交信息的风格。要中文,不能是繁体中文。。要中文,不能是繁体中文。。要中文,不能是繁体中文。。要中文,不能是繁体中文。

+ 27 - 2
src/views/components/element/VideoElement/VideoPlayer/index.vue

@@ -7,7 +7,7 @@
       width: width * scale + 'px',
       width: width * scale + 'px',
       height: height * scale + 'px',
       height: height * scale + 'px',
       transform: `scale(${1 / scale})`,
       transform: `scale(${1 / scale})`,
-      backgroundImage: poster ? `url(${poster})` : '',
+      backgroundImage: finalPoster ? `url(${finalPoster})` : '',
     }"
     }"
   >
   >
     <IconPlayOne class="thumb-play-icon" />
     <IconPlayOne class="thumb-play-icon" />
@@ -33,7 +33,7 @@
         class="video"
         class="video"
         preload="none"
         preload="none"
         ref="videoRef"
         ref="videoRef"
-        :poster="poster"
+        :poster="finalPoster"
         webkit-playsinline
         webkit-playsinline
         playsinline
         playsinline
         @durationchange="handleDurationchange()"
         @durationchange="handleDurationchange()"
@@ -156,6 +156,31 @@ const props = withDefaults(defineProps<{
   scale: 1,
   scale: 1,
 })
 })
 
 
+// 固定的视频-封面配对表:根据视频 URL 自动匹配封面
+// 以视频文件名(URL 最后一段)做精确匹配,兼容带编码的中文字符
+const VIDEO_POSTER_MAP: Record<string, string> = {
+  '10月18日_1080p1792724012018.mp4': 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Snipaste_2026-10-31_12-55-061793422736232.png',
+  'video_1791624823714_1791624823762_web4801792658106925.mp4': 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Snipaste_2026-10-31_12-55-431793422736226.png',
+  'video_1791624823715_1791624823748_web4801792658106941.mp4': 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Snipaste_2026-10-31_12-56-011793422736221.png',
+  'video_1791624823715_1791624823764_web4801792658106945.mp4': 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Snipaste_2026-10-31_12-56-201793422736191.png',
+}
+
+// 从完整 URL 里提取文件名(最后一段,兼容 URL 编码)
+const getVideoFileName = (url: string): string => {
+  if (!url) return ''
+  const decoded = decodeURIComponent(url.split('?')[0])
+  return decoded.substring(decoded.lastIndexOf('/') + 1)
+}
+
+// 最终生效的封面:先查固定配对表,匹配不上回退到 props.poster
+const finalPoster = computed(() => {
+  const fileName = getVideoFileName(props.src)
+  if (fileName && VIDEO_POSTER_MAP[fileName]) {
+    return VIDEO_POSTER_MAP[fileName]
+  }
+  return props.poster
+})
+
 const secondToTime = (second = 0) => {
 const secondToTime = (second = 0) => {
   if (second === 0 || isNaN(second)) return '00:00'
   if (second === 0 || isNaN(second)) return '00:00'