Browse Source

优化播放逻辑

pull/19/head
zyronon 4 years ago
parent
commit
826ac2322b
  1. 4
      src/components/Footer.vue
  2. 30
      src/components/Video.vue
  3. 5
      src/main.js

4
src/components/Footer.vue

@ -35,9 +35,11 @@ export default {
}, },
methods: { methods: {
move(e) { move(e) {
this.mitt.emit(this.$store.state.currentVideoId, e.touches[0].pageX) this.mitt.emit(this.$store.state.currentVideoId, {isMove: true, e: e.touches[0].pageX})
this.$stopPropagation(e)
}, },
end(e) { end(e) {
this.mitt.emit(this.$store.state.currentVideoId, {isMove: false,})
}, },
tab(index) { tab(index) {
this.currentTab = index this.currentTab = index

30
src/components/Video.vue

@ -84,7 +84,6 @@ export default {
}, },
computed: { computed: {
durationStyle() { durationStyle() {
// return {left: this.$store.state.playDuration + 'px'}
return {left: this.playDuration + 'px'} return {left: this.playDuration + 'px'}
} }
}, },
@ -92,10 +91,18 @@ export default {
disabled: { disabled: {
immediate: true, immediate: true,
handler(v) { handler(v) {
// console.log('disabled', this.currentVideoId, v) console.log('disabled', this.currentVideoId, v)
this.isPlaying = !v this.isPlaying = !v
if (!v) { if (!v) {
this.$store.commit('setCurrentVideoId', this.currentVideoId) this.$store.commit('setCurrentVideoId', this.currentVideoId)
console.log(this.$refs)
if (this.$refs.video) {
this.$refs.video.play()
}
} else {
if (this.$refs.video) {
this.$refs.video.pause()
}
} }
} }
} }
@ -121,9 +128,9 @@ export default {
this.width = document.body.clientWidth this.width = document.body.clientWidth
this.line = this.$refs.line this.line = this.$refs.line
this.point = this.$refs.point this.point = this.$refs.point
this.mitt.on(this.currentVideoId, e => { this.mitt.on(this.currentVideoId, v => {
console.log('mitt-test', e) this.isMove = v.isMove
this.playDuration = e this.playDuration = v.isMove ? v.e : this.playDuration
}) })
}, },
methods: { methods: {
@ -186,20 +193,13 @@ export default {
move(e) { move(e) {
this.isMove = true this.isMove = true
this.playDuration = e.touches[0].pageX this.playDuration = e.touches[0].pageX
// this.$store.commit('setPlayDuration',e.touches[0].pageX) this.$stopPropagation(e)
// this.$setCss(this.line, 'width', e.touches[0].pageX + 'px')
// this.$setCss(this.point, 'left', e.touches[0].pageX + 'px')
this.stop(e)
}, },
end(e) { end(e) {
this.isMove = false this.isMove = false
this.stop(e) this.$stopPropagation(e)
},
stop(e) {
e.stopImmediatePropagation()
e.stopPropagation()
e.preventDefault()
}, },
} }
} }
</script> </script>

5
src/main.js

@ -58,6 +58,11 @@ const store = Vuex.createStore({
const myMixin = { const myMixin = {
methods: { methods: {
$stopPropagation(e) {
e.stopImmediatePropagation()
e.stopPropagation()
e.preventDefault()
},
$getCss(curEle, attr) { $getCss(curEle, attr) {
let val = null, reg = null let val = null, reg = null
if ("getComputedStyle" in window) { if ("getComputedStyle" in window) {

Loading…
Cancel
Save