From c342ba26d0b9c44a6cf8616d36ad7b872d6cdbf9 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 25 Dec 2019 16:10:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96H5=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=85=A8=E5=B1=8F=E6=92=AD=E6=94=BE=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/mixins/index.js | 5 + src/core/view/mixins/interact.js | 54 ++ .../h5/view/components/video/index.vue | 468 ++++++++---------- 3 files changed, 256 insertions(+), 271 deletions(-) create mode 100644 src/core/view/mixins/interact.js diff --git a/src/core/view/mixins/index.js b/src/core/view/mixins/index.js index 187d6f7987..6975523e4f 100644 --- a/src/core/view/mixins/index.js +++ b/src/core/view/mixins/index.js @@ -22,3 +22,8 @@ export { default as keyboard } from './keyboard' + +export { + default as interact +} + from './interact' diff --git a/src/core/view/mixins/interact.js b/src/core/view/mixins/interact.js new file mode 100644 index 0000000000..90acf49b9a --- /dev/null +++ b/src/core/view/mixins/interact.js @@ -0,0 +1,54 @@ +import { + supportsPassive +} from 'uni-shared' + +const passiveOptions = supportsPassive ? { + passive: true, + capture: true +} : true +const vms = [] +let userInteract = 0 +let inited +function addInteractListener (vm) { + if (!inited) { + const eventNames = ['touchstart', 'touchmove', 'touchend', 'mousedown', 'mouseup'] + eventNames.forEach(eventName => { + document.addEventListener(eventName, function () { + vms.forEach(vm => { + vm.userInteract = true + userInteract++ + setTimeout(() => { + userInteract-- + if (!userInteract) { + vm.userInteract = false + } + }, 0) + }) + }, passiveOptions) + }) + } + vms.push(vm) +} +function removeInteractListener (vm) { + const index = vms.indexOf(vm) + if (index >= 0) { + vms.splice(index, 1) + } +} + +export default { + data () { + return { + /** + * 是否用户交互行为 + */ + userInteract: false + } + }, + mounted () { + addInteractListener(this) + }, + beforeDestroy () { + removeInteractListener(this) + } +} diff --git a/src/platforms/h5/view/components/video/index.vue b/src/platforms/h5/view/components/video/index.vue index 86956dd921..7f70df4f3e 100644 --- a/src/platforms/h5/view/components/video/index.vue +++ b/src/platforms/h5/view/components/video/index.vue @@ -1,17 +1,16 @@