Browse Source

优化

pull/29/head
zyronon 2 years ago
parent
commit
e5a5516781
  1. 45
      src/components/slide/BVideo.vue
  2. 21
      src/pages/slideHooks/VInfinite.vue
  3. 4
      src/pages/slideHooks/index.vue
  4. 4
      src/utils/bus.js
  5. 4
      src/utils/mixin.js

45
src/components/slide/BVideo.vue

@ -53,8 +53,8 @@
@touchend="touchend" @touchend="touchend"
> >
<div class="time" v-if="isMove"> <div class="time" v-if="isMove">
<span class="currentTime">{{ $duration(currentTime) }}</span> <span class="currentTime">{{ LUtils.$duration(currentTime) }}</span>
<span class="duration"> / {{ $duration(duration) }}</span> <span class="duration"> / {{ LUtils.$duration(duration) }}</span>
</div> </div>
<div class="bg"></div> <div class="bg"></div>
<div class="progress-line" :style="durationStyle"></div> <div class="progress-line" :style="durationStyle"></div>
@ -158,7 +158,7 @@ export default {
height: 0, height: 0,
width: 0, width: 0,
isMove: false, isMove: false,
isSingleClick: false, ignoreWaiting: false,//waitingwaiting
test: [1, 2], test: [1, 2],
localItem: this.item, localItem: this.item,
progressBarRect: {}, progressBarRect: {},
@ -166,6 +166,7 @@ export default {
videoPoster: `?vframe/jpg/offset/0/w/${document.body.clientWidth}`, videoPoster: `?vframe/jpg/offset/0/w/${document.body.clientWidth}`,
commentVisible: false, commentVisible: false,
isMarginTop: false, isMarginTop: false,
LUtils: Utils
} }
}, },
mounted() { mounted() {
@ -188,9 +189,10 @@ export default {
let eventTester = (e, t) => { let eventTester = (e, t) => {
video.addEventListener(e, () => { video.addEventListener(e, () => {
// console.log('eventTester', e, this.item.id)
if (e === 'playing') this.loading = false if (e === 'playing') this.loading = false
if (e === 'waiting') { if (e === 'waiting') {
if (!this.paused && !this.isSingleClick) { if (!this.paused && !this.ignoreWaiting) {
this.loading = true this.loading = true
} }
} }
@ -283,26 +285,31 @@ export default {
this.commentVisible = false this.commentVisible = false
} }
}, },
click(val) { click({id, type}) {
if (this.item.id === val) { if (this.item.id === id) {
if (this.status === SlideItemPlayStatus.Play) { if (type === EVENT_KEY.ITEM_TOGGLE) {
if (this.status === SlideItemPlayStatus.Play) {
this.pause()
} else {
this.play()
}
}
if (type === EVENT_KEY.ITEM_STOP) {
this.$refs.video.currentTime = 0
this.ignoreWaiting = true
this.pause() this.pause()
} else { setTimeout(() => this.ignoreWaiting = false, 300)
}
if (type === EVENT_KEY.ITEM_PLAY) {
this.$refs.video.currentTime = 0
this.ignoreWaiting = true
this.play() this.play()
//playgwaitingloading setTimeout(() => this.ignoreWaiting = false, 300)
// this.isSingleClick = true
setTimeout(() => {
// this.isSingleClick = false
}, 300)
} }
this.loading = false
} }
}, },
play() { play() {
this.status = SlideItemPlayStatus.Play this.status = SlideItemPlayStatus.Play
if (this.currentTime !== -1) {
this.$refs.video.currentTime = this.currentTime
}
this.$refs.video.volume = 1 this.$refs.video.volume = 1
this.$refs.video.play() this.$refs.video.play()
}, },
@ -310,9 +317,6 @@ export default {
this.status = SlideItemPlayStatus.Pause this.status = SlideItemPlayStatus.Pause
this.$refs.video.pause() this.$refs.video.pause()
}, },
formatNumber(v) {
return Utils.formatNumber(v)
},
touchstart(e) { touchstart(e) {
Utils.$stopPropagation(e) Utils.$stopPropagation(e)
this.start.x = e.touches[0].pageX this.start.x = e.touches[0].pageX
@ -335,6 +339,7 @@ export default {
Utils.$stopPropagation(e) Utils.$stopPropagation(e)
if (this.isPlaying) return if (this.isPlaying) return
setTimeout(() => this.isMove = false, 1000) setTimeout(() => this.isMove = false, 1000)
this.$refs.video.currentTime = this.currentTime
this.play() this.play()
} }
} }

21
src/pages/slideHooks/VInfinite.vue

@ -4,7 +4,7 @@ import GM from '../../utils'
import {getSlideDistance, slideInit, slideReset, slideTouchEnd, slideTouchMove, slideTouchStart} from "./common"; import {getSlideDistance, slideInit, slideReset, slideTouchEnd, slideTouchMove, slideTouchStart} from "./common";
import {SlideType} from "../../utils/const_var"; import {SlideType} from "../../utils/const_var";
import SlideItem from './SlideItem' import SlideItem from './SlideItem'
import bus from "../../utils/bus"; import bus, {EVENT_KEY} from "../../utils/bus";
import {useStore} from 'vuex' import {useStore} from 'vuex'
import Utils from "../../utils"; import Utils from "../../utils";
import Dom from "@/utils/dom"; import Dom from "@/utils/dom";
@ -91,12 +91,19 @@ watch(
} }
) )
watch( watch(
()=>props.index, () => props.index,
()=>{ (newVal, oldVal) => {
// new Dom(this.wrapper).find(`.v-${this.prefix}-${newVal}-video`).trigger('play') // console.log('watch-index', newVal, oldVal, props.list[newVal].id)
// setTimeout(() => { bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
// new Dom(this.wrapper).find(`.v-${this.prefix}-${oldVal}-video`).trigger('stop') id: props.list[newVal].id,
// }, 200) type: EVENT_KEY.ITEM_PLAY
})
setTimeout(() => {
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
id: props.list[oldVal].id,
type: EVENT_KEY.ITEM_STOP
})
}, 200)
} }
) )

4
src/pages/slideHooks/index.vue

@ -335,12 +335,12 @@ function end() {
onMounted(() => { onMounted(() => {
getData() getData()
bus.on('singleClick', () => { bus.on(EVENT_KEY.SINGLE_CLICK, () => {
let id = '' let id = ''
if (state.navIndex === 4) { if (state.navIndex === 4) {
id = state.recommendVideos[state.itemIndex].id id = state.recommendVideos[state.itemIndex].id
} }
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, id) bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {id, type: EVENT_KEY.ITEM_TOGGLE})
}) })
bus.on('update:item', val => { bus.on('update:item', val => {
const {baseIndex, navIndex, itemIndex} = val.position const {baseIndex, navIndex, itemIndex} = val.position

4
src/utils/bus.js

@ -42,6 +42,7 @@ export default {
} }
export const EVENT_KEY = { export const EVENT_KEY = {
SINGLE_CLICK: 'SINGLE_CLICK',
SINGLE_CLICK_BROADCAST: 'SINGLE_CLICK_BROADCAST', SINGLE_CLICK_BROADCAST: 'SINGLE_CLICK_BROADCAST',
ENTER_FULLSCREEN: 'ENTER_FULLSCREEN', ENTER_FULLSCREEN: 'ENTER_FULLSCREEN',
EXIT_FULLSCREEN: 'EXIT_FULLSCREEN', EXIT_FULLSCREEN: 'EXIT_FULLSCREEN',
@ -53,4 +54,7 @@ export const EVENT_KEY = {
DIALOG_END: 'DIALOG_END', DIALOG_END: 'DIALOG_END',
OPEN_SUB_TYPE: 'OPEN_SUB_TYPE', OPEN_SUB_TYPE: 'OPEN_SUB_TYPE',
CLOSE_SUB_TYPE: 'CLOSE_SUB_TYPE', CLOSE_SUB_TYPE: 'CLOSE_SUB_TYPE',
ITEM_TOGGLE: 'ITEM_TOGGLE',
ITEM_PLAY: 'ITEM_PLAY',
ITEM_STOP: 'ITEM_STOP',
} }

4
src/utils/mixin.js

@ -15,7 +15,7 @@ import Loading from "../components/Loading";
import BaseButton from "../components/BaseButton"; import BaseButton from "../components/BaseButton";
import CONST_VAR from "./const_var"; import CONST_VAR from "./const_var";
import Dom from "./dom"; import Dom from "./dom";
import bus from "./bus"; import bus, {EVENT_KEY} from "./bus";
import {random} from "lodash"; import {random} from "lodash";
export default { export default {
@ -152,7 +152,7 @@ export default {
} else { } else {
clickTimer = setTimeout(() => { clickTimer = setTimeout(() => {
console.log('单击') console.log('单击')
bus.emit('singleClick') bus.emit(EVENT_KEY.SINGLE_CLICK)
}, checkTime); }, checkTime);
} }
lastClickTime = nowTime; lastClickTime = nowTime;

Loading…
Cancel
Save