From b7b43c0b4229ae6225dcf6644a08dceca4e605ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E5=85=B8=E5=8D=93?= Date: Tue, 10 Jun 2025 10:50:25 +0800 Subject: [PATCH] =?UTF-8?q?flat:=E4=BC=98=E5=8C=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageA/pages/post/.DS_Store | Bin 0 -> 6148 bytes packageA/pages/post/component/videoPlayer.vue | 42 +++++++++++++++--- unpackage/dist/.DS_Store | Bin 6148 -> 6148 bytes 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 packageA/pages/post/.DS_Store diff --git a/packageA/pages/post/.DS_Store b/packageA/pages/post/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f5d12569620c4308e9d90a68dadf17e26f636566 GIT binary patch literal 6148 zcmeHKJ8Hu~5S>X}IJi;ia<7mZEJ8kkE?|g_n?w#FNv+D~^3nX}gRzj)1k!{zF!Oe2 z=dI8yG#U}n_G|Yn(ul|sZYU=UbF*{vnLT7ifpFY$ltK3J&+mR#eLrE`CwT$$P2O+$ zAH(Z$IK<8OsmxLVDnJFO02QDDzfiz>FKoFAWTXOAfC^j{u#>1^!xr3*GA#u>b%7 literal 0 HcmV?d00001 diff --git a/packageA/pages/post/component/videoPlayer.vue b/packageA/pages/post/component/videoPlayer.vue index 2b026ee..d118dba 100644 --- a/packageA/pages/post/component/videoPlayer.vue +++ b/packageA/pages/post/component/videoPlayer.vue @@ -6,8 +6,8 @@ :style="{ left: position.x + 'px', top: position.y + 'px', - width: isFullScreen ? '100%' : '300rpx', - height: isFullScreen ? '100vh' : '200rpx', + width: isFullScreen ? '100%' : videoWidth + 'rpx', + height: isFullScreen ? '100vh' : videoHeight + 'rpx', }" @touchstart="handleTouchStart" @touchmove="handleTouchMove" @@ -24,8 +24,10 @@ height: '100%', }" id="myVideo" + ref="videoRef" @play="onPlay" @pause="onPause" + @loadedmetadata="onLoadedMetadata" > @@ -41,6 +43,8 @@ import { ref, reactive, onMounted } from 'vue'; import { nextTick } from 'vue'; +const videoRef = ref(null); + const visible = ref(false); const isPlaying = ref(false); const isFullScreen = ref(false); @@ -49,6 +53,8 @@ const position = reactive({ x: 20, y: 100 }); const videoContext = ref(null); const startPos = reactive({ x: 0, y: 0 }); const moving = ref(false); +const videoWidth = ref(0); +const videoHeight = ref(0); // 初始化视频上下文 onMounted(() => { @@ -71,8 +77,8 @@ const handleTouchMove = (e) => { const newY = e.touches[0].clientY - startPos.y; // 边界检测 - const maxX = window.innerWidth - 150; // 300rpx换算后的值 - const maxY = 50 + window.innerHeight - 200; + const maxX = window.innerWidth - videoWidth.value / 2; // 300rpx换算后的值 + const maxY = window.innerHeight - videoHeight.value / 2; position.x = Math.max(0, Math.min(newX, maxX)); position.y = Math.max(0, Math.min(newY, maxY)); @@ -124,6 +130,32 @@ const open = (url) => { }); }; +const onLoadedMetadata = (e) => { + const video = e.detail; + const width = video.width; + const height = video.height; + const ratio = width / height; + + // 设置宽度:横屏宽 300,竖屏宽 180(可自定义) + if (ratio >= 1) { + videoWidth.value = 300; // 横屏 + videoHeight.value = 300 * (height / width); // 保持比例 + } else { + videoWidth.value = 180; // 竖屏 + videoHeight.value = 180 * (height / width); // 保持比例 + } + // console.log(`宽高: ${width}x${height}`); + // console.log(`比例: ${ratio.toFixed(2)} (${getRatioName(ratio)})`); +}; + +function getRatioName(ratio) { + const rounded = Math.round(ratio * 100) / 100; + if (Math.abs(rounded - 16 / 9) < 0.01) return '16:9'; + if (Math.abs(rounded - 4 / 3) < 0.01) return '4:3'; + if (Math.abs(rounded - 1) < 0.01) return '1:1'; + return `${rounded.toFixed(2)}:1`; +} + // 暴露方法 defineExpose({ open }); @@ -155,4 +187,4 @@ defineExpose({ open }); background: rgba(255, 255, 255, 0.2); border-radius: 4rpx; } - + \ No newline at end of file diff --git a/unpackage/dist/.DS_Store b/unpackage/dist/.DS_Store index 0a582e887839a10772c38d154f957da027399dc2..ac56028c8819583893eab5689e5c38438e8fa18b 100644 GIT binary patch delta 48 zcmZoMXffE}&&0TMasX2yk7RYVp^<^5j)Iwi`Q$T9(v01cUogot_H5>0{>QSJo#QV* E0BaTx2><{9 delta 47 zcmZoMXffE}&&0T6asX2yw?uWdiIJs_f|-HE