Commit 23de226a by liimin

fix(media): 修复 OSS 视频截图拉伸问题并优化媒体预览组件

- 修复 OSS 视频截图参数,移除固定高度避免画面拉伸变形
- 优化预览图片组件的预览列表逻辑,当前点击图片优先展示
- 为视频预览组件新增封面填充方式配置项
- 调整工作页快递信息卡片的布局样式
1 parent 24dd0c4c
...@@ -103,11 +103,18 @@ export default { ...@@ -103,11 +103,18 @@ export default {
return this.src; return this.src;
}, },
previewList() { previewList() {
if (this.previewSrcList && this.previewSrcList.length > 0) { const base =
return this.previewSrcList; this.previewSrcList && this.previewSrcList.length > 0
? this.previewSrcList
: this.src
? [this.src]
: [];
if (!this.src) {
return base;
} }
// 没传预览列表时,预览用原图(不拼缩略图参数) // el-image 原生预览永远从第 0 项打开:把当前这张图排到首位,
return this.src ? [this.src] : []; // 点哪张默认呈现哪张,其余图按顺序跟在后面仍可左右切换。
return [this.src, ...base.filter((u) => u !== this.src)];
}, },
}, },
}; };
...@@ -120,6 +127,7 @@ export default { ...@@ -120,6 +127,7 @@ export default {
.preview_img { .preview_img {
width: 100%; width: 100%;
height: 100%; height: 100%;
border-radius: 4px;
display: block; display: block;
} }
// 名称浮层:左下角 // 名称浮层:左下角
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
@click="openVideo" @click="openVideo"
> >
<!-- 封面:外部传入优先,没传则用抓到的首帧 --> <!-- 封面:外部传入优先,没传则用抓到的首帧 -->
<img v-if="realCover" class="video_cover" :src="realCover" alt="" /> <img v-if="realCover" class="video_cover" :src="realCover" :style="{ objectFit: coverFit }" alt="" />
<!-- 播放按钮 --> <!-- 播放按钮 -->
<i class="el-icon-video-play video_play"></i> <i class="el-icon-video-play video_play"></i>
...@@ -67,6 +67,8 @@ import { capturePoster, cachePoster, getCachedPoster } from "@/utils/videoPoster ...@@ -67,6 +67,8 @@ import { capturePoster, cachePoster, getCachedPoster } from "@/utils/videoPoster
* captureTime Number 取第几秒的画面,默认 0.1(首帧常是黑场) * captureTime Number 取第几秒的画面,默认 0.1(首帧常是黑场)
* ossProcess Boolean OSS 链接是否用服务端截图作封面,默认 true * ossProcess Boolean OSS 链接是否用服务端截图作封面,默认 true
* (优先级高于前端 canvas 抓帧,且无跨域问题) * (优先级高于前端 canvas 抓帧,且无跨域问题)
* coverFit String 封面图填充方式(CSS object-fit),默认 cover
* (fill / contain / cover / none / scale-down)
* width/height String 容器尺寸,默认 100%(撑满父级) * width/height String 容器尺寸,默认 100%(撑满父级)
* name String 名称,浮在左下角,不传则不显示 * name String 名称,浮在左下角,不传则不显示
* showName Boolean 是否显示名称,默认 true * showName Boolean 是否显示名称,默认 true
...@@ -111,6 +113,12 @@ export default { ...@@ -111,6 +113,12 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
// 封面图填充方式(对应 CSS object-fit),默认 cover 撑满裁切
// 可选:fill / contain / cover / none / scale-down
coverFit: {
type: String,
default: "cover",
},
width: { width: {
type: String, type: String,
default: "100%", default: "100%",
......
...@@ -21,9 +21,11 @@ const OSS_HOST_RE = /https?:\/\/[\w.-]+\.oss-[\w.-]+\.aliyuncs\.com/i; ...@@ -21,9 +21,11 @@ const OSS_HOST_RE = /https?:\/\/[\w.-]+\.oss-[\w.-]+\.aliyuncs\.com/i;
export const IMAGE_OSS_PROCESS = export const IMAGE_OSS_PROCESS =
"x-oss-process=image/resize,m_fill,w_200/quality,q_60"; "x-oss-process=image/resize,m_fill,w_200/quality,q_60";
// 视频截图:取第 7 秒一帧,输出 800x600 的 jpg(m_fast 快速模式) // 视频截图:取第 7 秒一帧,只限定宽度 800,高度按原视频比例自适应(m_fast 快速模式)
// 注:不要同时写 w_800,h_600,那会强制输出固定 4:3,把非 4:3 视频在服务端硬拉伸变形;
// 只给宽度,OSS 按原始宽高比算高度,封面不变形,再由组件 object-fit 裁切铺满。
export const VIDEO_OSS_PROCESS = export const VIDEO_OSS_PROCESS =
"x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast"; "x-oss-process=video/snapshot,t_7000,f_jpg,w_800,m_fast";
// 是否 OSS 链接 // 是否 OSS 链接
export function isOssUrl(url) { export function isOssUrl(url) {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
:preview-src-list="imagePreviewList" :preview-src-list="imagePreviewList"
:name="item.name" :name="item.name"
width="100%" width="100%"
height="180px" height="100%"
></preview-image> ></preview-image>
<!-- 视频:公共组件,点击弹窗播放 --> <!-- 视频:公共组件,点击弹窗播放 -->
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
:cover="item.cover" :cover="item.cover"
:name="item.name" :name="item.name"
width="100%" width="100%"
height="180px" height="100%"
flag-text="视频" flag-text="视频"
></preview-video> ></preview-video>
</div> </div>
...@@ -101,12 +101,15 @@ export default { ...@@ -101,12 +101,15 @@ export default {
overflow: hidden; overflow: hidden;
} }
.express_cell { .express_cell {
width: calc(50% - 8px); // width: calc(50% - 8px);
width:120px;
height: 120px;
margin-right: 16px; margin-right: 16px;
margin-bottom: 16px; margin-bottom: 16px;
float: left; float: left;
box-sizing: border-box; box-sizing: border-box;
border: 1px solid #e4e7ed; padding: 4px;
border: 1px dashed #e4e7ed;
// 圆角由格子统一兜住,图片/视频组件只管内容 // 圆角由格子统一兜住,图片/视频组件只管内容
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!