From c739d691a2a2ef3d9e17426a45a8ca9d479cf211 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Mon, 13 Jul 2026 14:11:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(diy-video):=20=E9=80=82=E9=85=8D=E9=B8=BF?= =?UTF-8?q?=E8=92=99=E5=85=83=E6=9C=8D=E5=8A=A1=E7=AB=AF=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增鸿蒙平台专属video组件渲染分支 2. 新增窗口宽度初始化逻辑用于计算鸿蒙视频高度 3. 针对不同平台调整视频容器样式计算逻辑 4. 补充视频加载元数据和错误回调 5. 修复微信小程序视频比例适配逻辑 --- components-diy/diy-video.vue | 84 +++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/components-diy/diy-video.vue b/components-diy/diy-video.vue index 51a1cab..28a4012 100644 --- a/components-diy/diy-video.vue +++ b/components-diy/diy-video.vue @@ -26,6 +26,23 @@ :poster="posterUrl" :style="videoWarpCss" controls + object-fit="cover" + @loadedmetadata="onVideoLoaded" + @error="onVideoError" + > + + + + + @@ -45,13 +62,15 @@ export default { }, data() { return { - videoRatio: null, // 视频比例:'landscape'(横屏)或 'portrait'(竖屏) + videoRatio: null, videoUrl: '', - posterUrl: '' + posterUrl: '', + windowWidth: 0 }; }, created() { this.initVideoData(); + this.initWindowWidth(); }, mixins: [DiyMinx], watch: { @@ -79,18 +98,43 @@ export default { containerStyle() { let style = ''; + // #ifdef H5 if (this.videoRatio === 'landscape') { - // 横屏视频:16/9比例 style += 'aspect-ratio: 16 / 9;'; } else if (this.videoRatio === 'portrait') { - // 竖屏视频:9/16比例 style += 'aspect-ratio: 9 / 16;'; } else { - // 未加载完成 → 默认使用竖屏比例 style += 'aspect-ratio: 9 / 16;'; } + // #endif + + // #ifdef MP-WEIXIN + if (this.videoRatio === 'landscape') { + style += 'padding-top: 56.25%;'; + } else if (this.videoRatio === 'portrait') { + style += 'padding-top: 177.78%;'; + } else { + style += 'padding-top: 177.78%;'; + } + // #endif + + // #ifdef MP-HARMONY + style += 'width: 100%;'; + style += 'height: ' + this.harmonyVideoHeight + 'px;'; + // #endif return style; + }, + + // 鸿蒙平台视频高度 + harmonyVideoHeight() { + if (!this.videoRatio) { + return (this.windowWidth * 9) / 16; + } + if (this.videoRatio === 'landscape') { + return (this.windowWidth * 9) / 16; + } + return (this.windowWidth * 16) / 9; } }, methods: { @@ -104,6 +148,16 @@ export default { // #endif }, + // 初始化窗口宽度 + initWindowWidth() { + try { + const systemInfo = uni.getSystemInfoSync(); + this.windowWidth = systemInfo.windowWidth || 375; + } catch (e) { + this.windowWidth = 375; + } + }, + // 获取视频URL getVideoUrl() { if (!this.value || !this.value.videoUrl) return ''; @@ -169,6 +223,13 @@ export default { } // #endif + // #ifdef MP-HARMONY + if (event && event.detail) { + width = event.detail.width || 0; + height = event.detail.height || 0; + } + // #endif + if (width && height) { this.videoRatio = width >= height ? 'landscape' : 'portrait'; } @@ -225,6 +286,19 @@ export default { .mp-video { width: 100%; height: 100%; + position: absolute; + top: 0; + left: 0; +} +/* #endif */ + +/* 鸿蒙元服务端样式 */ +/* #ifdef MP-HARMONY */ +.harmony-video { + width: 100%; + height: 100%; + display: block; + box-sizing: border-box; } /* #endif */