提交 34941693 编写于 作者: Q qiang

refactor(h5): video

上级 1b4d1705
import { onMounted, onBeforeUnmount, reactive } from 'vue'
import { passive } from '@dcloudio/uni-shared'
export interface UserActionState {
userAction: boolean
}
const passiveOptions = passive(true)
const states: UserActionState[] = []
let userInteract: number = 0
let inited: boolean
function addInteractListener(vm: UserActionState) {
if (!inited) {
const eventNames = [
'touchstart',
'touchmove',
'touchend',
'mousedown',
'mouseup',
]
eventNames.forEach((eventName) => {
document.addEventListener(
eventName,
function () {
states.forEach((vm) => {
vm.userAction = true
userInteract++
setTimeout(() => {
userInteract--
if (!userInteract) {
vm.userAction = false
}
}, 0)
})
},
passiveOptions
)
})
inited = true
}
states.push(vm)
}
function removeInteractListener(vm: UserActionState) {
const index = states.indexOf(vm)
if (index >= 0) {
states.splice(index, 1)
}
}
export function useUserAction() {
const state: UserActionState = reactive({
/**
* 是否用户激活
*/
userAction: false,
})
onMounted(() => {
addInteractListener(state)
})
onBeforeUnmount(() => {
removeInteractListener(state)
})
return {
state,
}
}
export * from './components'
export { useOn, useSubscribe } from './helpers/useSubscribe'
export { useCustomEvent } from './helpers/useEvent'
export { useUserAction } from './helpers/useUserAction'
此差异已折叠。
import Video from './video/index.vue'
import Video from './video/index'
export { Video }
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册