|
| 1 | +<template> |
| 2 | + <div class="vcp-m-dashboard" autoplay v-show="show" ref="dashboard"> |
| 3 | + <MobileControls :muted="muted" /> |
| 4 | + <Progress /> |
| 5 | + </div> |
| 6 | +</template> |
| 7 | + |
| 8 | +<script> |
| 9 | +import { DEFAULT_CONFIG, EVENTS } from '../constants' |
| 10 | +import { isDescendant } from '../helper/dom' |
| 11 | +import { isMobile } from '../helper/util' |
| 12 | +import Progress from './progress' |
| 13 | +import MobileControls from './mobile-controls' |
| 14 | +import coreMixins from '../mixins' |
| 15 | +
|
| 16 | +const pageCoor = { |
| 17 | + x: null, |
| 18 | + y: null |
| 19 | +} |
| 20 | +
|
| 21 | +export default { |
| 22 | + name: 'MobileDashboard', |
| 23 | + components: { |
| 24 | + Progress, |
| 25 | + MobileControls |
| 26 | + }, |
| 27 | + props: { |
| 28 | + controls: [Boolean, String], |
| 29 | + muted: Boolean |
| 30 | + }, |
| 31 | + data () { |
| 32 | + return { |
| 33 | + show: true |
| 34 | + } |
| 35 | + }, |
| 36 | + mixins: [coreMixins], |
| 37 | + methods: { |
| 38 | + showDashboard (delay) { |
| 39 | + window.clearTimeout(this._hideTimeout) |
| 40 | + this.show = true |
| 41 | + this.emit(EVENTS.UI_DASHBOARD_SHOW) |
| 42 | + if (delay === 0) { |
| 43 | + // TODO handle force show |
| 44 | + } else { |
| 45 | + this._hideTimeout = setTimeout(() => { |
| 46 | + this.hideDashboard() |
| 47 | + }, delay || DEFAULT_CONFIG.dashboardHideDelay) |
| 48 | + } |
| 49 | + }, |
| 50 | + hideDashboard () { |
| 51 | + this.show = false |
| 52 | + this.emit(EVENTS.UI_DASHBOARD_HIDE) |
| 53 | + }, |
| 54 | + _initAutoMode () { |
| 55 | + const $parent = this.$refs['dashboard'].parentNode |
| 56 | + if (isMobile) { |
| 57 | + $parent.addEventListener('touchend', this._onTouchend.bind(this), true) |
| 58 | + } else { |
| 59 | + $parent.addEventListener('mousemove', this._onMousemove.bind(this)) |
| 60 | + $parent.addEventListener('mouseleave', this._onMouseleave.bind(this)) |
| 61 | + $parent.addEventListener('mouseover', this._onMouseover.bind(this), true) |
| 62 | + } |
| 63 | + // first render delay |
| 64 | + this.showDashboard(4000) |
| 65 | + }, |
| 66 | + _onMousemove (e) { |
| 67 | + if (e.pageX === pageCoor.x && e.pageY === pageCoor.y) { |
| 68 | + pageCoor.x = e.pageX |
| 69 | + pageCoor.y = e.pageY |
| 70 | + return |
| 71 | + } |
| 72 | + pageCoor.x = e.pageX |
| 73 | + pageCoor.y = e.pageY |
| 74 | + if (isDescendant(this._el, e.target)) { |
| 75 | + return this.showDashboard(0) |
| 76 | + } |
| 77 | + this.showDashboard() |
| 78 | + }, |
| 79 | +
|
| 80 | + _onMouseleave () { |
| 81 | + this.showDashboard() |
| 82 | + }, |
| 83 | + _onMouseover () { |
| 84 | + this.showDashboard(0) |
| 85 | + }, |
| 86 | + _onTouchend () { |
| 87 | + this.showDashboard() |
| 88 | + } |
| 89 | + }, |
| 90 | + mounted () { |
| 91 | + const { controls } = this |
| 92 | + if (!controls) { |
| 93 | + this.show = false |
| 94 | + } else if (controls === 'fixed') { |
| 95 | + this.show = true |
| 96 | + } else { |
| 97 | + this._initAutoMode() |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +</script> |
| 102 | + |
| 103 | +<style> |
| 104 | +.vcp-m-dashboard { |
| 105 | + z-index: 11; |
| 106 | + position: absolute; |
| 107 | + left: 0; |
| 108 | + bottom: 0; |
| 109 | + width: 100%; |
| 110 | + height: 59px; |
| 111 | + background: linear-gradient(to top ,rgba(0,0,0, .7), rgba(0,0,0, 0)); |
| 112 | +} |
| 113 | +.fullscreen .vcp-m-dashboard { |
| 114 | + bottom: 12px; |
| 115 | +} |
| 116 | +.small .vcp-m-dashboard{ |
| 117 | + height: 49px; |
| 118 | +} |
| 119 | +.settings-open .vcp-m-dashboard { |
| 120 | + display: block !important; |
| 121 | +} |
| 122 | +.small .vcp-m-dashboard .vcp-controls { |
| 123 | + height: 40px; |
| 124 | +} |
| 125 | +</style> |
0 commit comments