feat(视频播放器): 添加触摸模拟器支持以优化移动端交互
在移动端设备上,添加了@vant/touch-emulator依赖并引入触摸模拟器,以优化视频播放器的交互体验。具体修改包括在VideoPlayer.vue中添加touchstart事件监听,实现点击播放/暂停功能,并确保点击控制栏区域时不触发自定义行为。
Showing
4 changed files
with
31 additions
and
1 deletions
| ... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
| 9 | "version": "0.0.0", | 9 | "version": "0.0.0", |
| 10 | "dependencies": { | 10 | "dependencies": { |
| 11 | "@heroicons/vue": "^2.2.0", | 11 | "@heroicons/vue": "^2.2.0", |
| 12 | + "@vant/touch-emulator": "^1.4.0", | ||
| 12 | "@vant/use": "^1.6.0", | 13 | "@vant/use": "^1.6.0", |
| 13 | "@videojs-player/vue": "^1.0.0", | 14 | "@videojs-player/vue": "^1.0.0", |
| 14 | "dayjs": "^1.11.13", | 15 | "dayjs": "^1.11.13", |
| ... | @@ -1214,6 +1215,11 @@ | ... | @@ -1214,6 +1215,11 @@ |
| 1214 | "resolved": "https://registry.npmjs.org/@vant/popperjs/-/popperjs-1.3.0.tgz", | 1215 | "resolved": "https://registry.npmjs.org/@vant/popperjs/-/popperjs-1.3.0.tgz", |
| 1215 | "integrity": "sha512-hB+czUG+aHtjhaEmCJDuXOep0YTZjdlRR+4MSmIFnkCQIxJaXLQdSsR90XWvAI2yvKUI7TCGqR8pQg2RtvkMHw==" | 1216 | "integrity": "sha512-hB+czUG+aHtjhaEmCJDuXOep0YTZjdlRR+4MSmIFnkCQIxJaXLQdSsR90XWvAI2yvKUI7TCGqR8pQg2RtvkMHw==" |
| 1216 | }, | 1217 | }, |
| 1218 | + "node_modules/@vant/touch-emulator": { | ||
| 1219 | + "version": "1.4.0", | ||
| 1220 | + "resolved": "https://registry.npmjs.org/@vant/touch-emulator/-/touch-emulator-1.4.0.tgz", | ||
| 1221 | + "integrity": "sha512-Zt+zISV0+wpOew2S1siOJ3G22y+hapHAKmXM+FhpvWzsRc4qahaYXatCAITuuXt0EcDp7WvEeTO4F7p9AtX/pw==" | ||
| 1222 | + }, | ||
| 1217 | "node_modules/@vant/use": { | 1223 | "node_modules/@vant/use": { |
| 1218 | "version": "1.6.0", | 1224 | "version": "1.6.0", |
| 1219 | "resolved": "https://registry.npmjs.org/@vant/use/-/use-1.6.0.tgz", | 1225 | "resolved": "https://registry.npmjs.org/@vant/use/-/use-1.6.0.tgz", | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | }, | 16 | }, |
| 17 | "dependencies": { | 17 | "dependencies": { |
| 18 | "@heroicons/vue": "^2.2.0", | 18 | "@heroicons/vue": "^2.2.0", |
| 19 | + "@vant/touch-emulator": "^1.4.0", | ||
| 19 | "@vant/use": "^1.6.0", | 20 | "@vant/use": "^1.6.0", |
| 20 | "@videojs-player/vue": "^1.0.0", | 21 | "@videojs-player/vue": "^1.0.0", |
| 21 | "dayjs": "^1.11.13", | 22 | "dayjs": "^1.11.13", | ... | ... |
| ... | @@ -16,6 +16,7 @@ import { ref, computed, onMounted, onBeforeUnmount, defineProps, defineEmits } f | ... | @@ -16,6 +16,7 @@ import { ref, computed, onMounted, onBeforeUnmount, defineProps, defineEmits } f |
| 16 | import { VideoPlayer } from "@videojs-player/vue"; | 16 | import { VideoPlayer } from "@videojs-player/vue"; |
| 17 | import videojs from "video.js"; | 17 | import videojs from "video.js"; |
| 18 | import "video.js/dist/video-js.css"; | 18 | import "video.js/dist/video-js.css"; |
| 19 | +import { wxInfo } from "@/utils/tools" | ||
| 19 | 20 | ||
| 20 | const props = defineProps({ | 21 | const props = defineProps({ |
| 21 | options: { | 22 | options: { |
| ... | @@ -68,6 +69,27 @@ const handleMounted = (payload) => { | ... | @@ -68,6 +69,27 @@ const handleMounted = (payload) => { |
| 68 | player.value = payload.player; | 69 | player.value = payload.player; |
| 69 | if (player.value) { | 70 | if (player.value) { |
| 70 | player.value.play(); | 71 | player.value.play(); |
| 72 | + if (!wxInfo().isPc) { | ||
| 73 | + // 添加touchstart事件监听 | ||
| 74 | + player.value.on('touchstart', (event) => { | ||
| 75 | + // 阻止事件冒泡,避免触发controls的默认行为 | ||
| 76 | + event.preventDefault(); | ||
| 77 | + event.stopPropagation(); | ||
| 78 | + | ||
| 79 | + // 检查点击位置是否在controls区域 | ||
| 80 | + const controlBar = player.value.getChild('ControlBar'); | ||
| 81 | + const controlBarEl = controlBar && controlBar.el(); | ||
| 82 | + if (controlBarEl && controlBarEl.contains(event.target)) { | ||
| 83 | + return; // 如果点击在controls区域,不执行自定义行为 | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + if (player.value.paused()) { | ||
| 87 | + player.value.play(); | ||
| 88 | + } else { | ||
| 89 | + player.value.pause(); | ||
| 90 | + } | ||
| 91 | + }); | ||
| 92 | + } | ||
| 71 | } | 93 | } |
| 72 | }; | 94 | }; |
| 73 | 95 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-20 20:36:36 | 2 | * @Date: 2025-03-20 20:36:36 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-24 13:52:52 | 4 | + * @LastEditTime: 2025-03-24 23:32:16 |
| 5 | * @FilePath: /mlaj/src/main.js | 5 | * @FilePath: /mlaj/src/main.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -11,6 +11,7 @@ import App from './App.vue' | ... | @@ -11,6 +11,7 @@ import App from './App.vue' |
| 11 | import router from './router' | 11 | import router from './router' |
| 12 | import axios from '@/utils/axios'; | 12 | import axios from '@/utils/axios'; |
| 13 | import 'vant/lib/index.css' | 13 | import 'vant/lib/index.css' |
| 14 | +import '@vant/touch-emulator'; | ||
| 14 | 15 | ||
| 15 | const app = createApp(App) | 16 | const app = createApp(App) |
| 16 | // 屏蔽警告信息 | 17 | // 屏蔽警告信息 | ... | ... |
-
Please register or login to post a comment